From e5ff0574bf4d7167ff69d94f5f9420341acca921 Mon Sep 17 00:00:00 2001 From: "Ryan S. Arnold" Date: Thu, 22 Dec 2016 01:33:49 -0600 Subject: Provide variations on git log and git rev-list Prepare for patch-set that will squash multiple commits. Change-Id: I14bc8b5d524aaf5b2bce6be800c36035b4e48c82 --- linaropy/git/gitrepo.py | 32 +++++++++++++++++++++++++------- linaropy/rn/rngen.py | 6 +++++- linaropy/rn/rnseries.py | 10 +++++++++- rn.py | 1 + 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/linaropy/git/gitrepo.py b/linaropy/git/gitrepo.py index 69e47bb..5c72f83 100644 --- a/linaropy/git/gitrepo.py +++ b/linaropy/git/gitrepo.py @@ -167,12 +167,12 @@ class GitRepo(object): logging.info("Attempting to commit changes to %s" % self.repodir) try: with cd(self.repodir): - # Git commit first with a boiler plate message and then allow the user - # to amend. + # Git commit first with a boiler plate message and then allow + # the user to amend. if git("status", "--porcelain"): # using python sh will suppress the git editor - subprocess.call(["git", "commit", "-m", message]) - subprocess.call(["git", "commit", "--amend"]) + subprocess.call(["git", "commit", "-q", "-m", message]) + subprocess.call(["git", "commit", "-q", "--amend"]) else: logging.info("Nothing to commit.") return False @@ -183,12 +183,30 @@ class GitRepo(object): return True # TODO: Write unit tests for this. - def log(self, numcommits): + def print_log(self, numcommits,oneline=False): try: with cd(self.repodir): - print git("log", "-n %d" % numcommits) + if oneline: + print git("log", "--oneline", "-n %d" % numcommits) + else: + print git("log", "-n %d" % numcommits) except ErrorReturnCode: - raise EnvironmentError("Unable to git log -n %d", numcommits) + raise EnvironmentError("Unable to git log -n %d" % numcommits) + + # versus is a branchname to compare against. It will cause git rev-list to + # list the differing commits. + def rev_list(self, branch, numcommits=None, versus=None): + try: + with cd(self.repodir): + if versus is not None: + return git("rev-list", "%s..%s" % (versus, + branch)).stdout.rstrip() + else: + return git("rev-list", branch, "--max-count=%d" % + numcommits).stdout.rstrip() + except ErrorReturnCode as exc: + raise EnvironmentError("Unable to git rev-list because: %s" % + (numcommits, str(exc))) # TODO: Does this need to 'cd' first? def edit(self, toedit): diff --git a/linaropy/rn/rngen.py b/linaropy/rn/rngen.py index b0d1a1a..47d63f8 100644 --- a/linaropy/rn/rngen.py +++ b/linaropy/rn/rngen.py @@ -38,6 +38,8 @@ from gccclone import GCCClone from ..rninput import finput +# Terminal color codes. +from linaropy.colors import * def get_gcc_version(gccclone): dct = {} @@ -307,6 +309,8 @@ def rngen(rn_series, gccclone, history): rn_series.rn_series.add(bin_readme) rn_series.rn_series.add(src_readme) + print_info("Generated release notes for %s. Please add a commit message." + % nextseries.label()) rn_series.rn_series.commit( "Generated Release Notes for %s." % nextseries.label()) - rn_series.rn_series.log(1) + rn_series.rn_series.print_log(1) diff --git a/linaropy/rn/rnseries.py b/linaropy/rn/rnseries.py index 87dacb8..f68c547 100644 --- a/linaropy/rn/rnseries.py +++ b/linaropy/rn/rnseries.py @@ -223,6 +223,8 @@ class RNSeries(object): workdir=self.next_series.shorttype(), track=track, branchname=self.next_series.branchname()) + + else: print_info( "Deriving your release-notes from branch %s%s%s%s" @@ -235,9 +237,12 @@ class RNSeries(object): track=remote_track, branchname=self.next_series.branchname()) + self.starting_commit=self.rn_series.rev_list( + self.rn_series.getbranch(),1) + # TODO: Detect if the user changed the template README.textile or # template README.textile.series and ask if they want to merge the - # changes into the new rn_series files. + # changes. if not headless: answer = yninput( @@ -248,6 +253,9 @@ class RNSeries(object): # TODO: If there are multiple commits, the subsequent calls should use # commit --amend. Add an 'amend' parameter to GitRepo::commit(). + commits=self.rn_series.rev_list(self.rn_series.getbranch(), + versus=self.starting_commit) + return self.rn_series.commit( "Added NEWS items for %s." % self.next_series.branchname()) diff --git a/rn.py b/rn.py index 2f64b1a..819475f 100644 --- a/rn.py +++ b/rn.py @@ -105,6 +105,7 @@ def generate(track, to_date, to_series, gccsource, persist): next_rn.update_series_readmes() while ans: + next_rn.rn_series.print_log(1) # Generate the temporary output files to the projdir. with cd(rnProj[0].projdir): try: -- cgit v1.2.3