From eff17c6baeb62c32a79ec6720c3c873f6ba778be Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Mon, 16 Jul 2007 23:48:30 +0100 Subject: [PATCH] Allow 'refresh' to annotate the patch log entries With the '--annotate' option, the patch log entry generated by refresh can contain an additional message. The patch also removes the '-a' shortcut for '--author' and adds it to '--annotate' (the latter would be used more often). Signed-off-by: Catalin Marinas --- stgit/commands/log.py | 36 ++++++++++++++++++++++++++++-------- stgit/commands/refresh.py | 9 ++++++--- stgit/stack.py | 9 ++++++--- t/t1400-patch-history.sh | 29 ++++++++++++++++++----------- 4 files changed, 58 insertions(+), 25 deletions(-) diff --git a/stgit/commands/log.py b/stgit/commands/log.py index 1c79c7c..ebd8cab 100644 --- a/stgit/commands/log.py +++ b/stgit/commands/log.py @@ -47,30 +47,50 @@ options = [make_option('-b', '--branch', make_option('-p', '--patch', help = 'show the refresh diffs', action = 'store_true'), + make_option('-f', '--full', + help = 'show the full commit ids', + action = 'store_true'), make_option('-g', '--graphical', help = 'run gitk instead of printing', action = 'store_true')] -def show_log(log, show_patch): +def show_log(log, options): """List the patch changelog """ commit = git.get_commit(log) diff_str = '' while commit: - descr = commit.get_log().rstrip() + log = commit.get_log().split('\n') + + cmd_rev = log[0].split() + if len(cmd_rev) >= 2: + cmd = cmd_rev[0] + rev = cmd_rev[1] + elif len(cmd_rev) == 1: + cmd = cmd_rev[0] + rev = '' + else: + cmd = rev = '' - if show_patch: - if descr.startswith('refresh') or descr.startswith('undo') \ - or descr.startswith('sync'): + if options.patch: + if cmd in ['refresh', 'undo', 'sync']: diff_str = '%s%s\n' % (diff_str, git.pretty_commit(commit.get_id_hash())) else: + if len(log) >= 3: + notes = log[2] + else: + notes = '' author_name, author_email, author_date = \ name_email_date(commit.get_author()) secs, tz = author_date.split() date = '%s %s' % (time.ctime(int(secs)), tz) - out.stdout('%s %s' % (descr, date)) + if options.full: + out.stdout('%-7s %-40s %s' % (cmd[:7], rev[:40], date)) + else: + out.stdout('%-8s [%-7s] %-28s %s' % \ + (rev[:8], cmd[:7], notes[:28], date)) parent = commit.get_parent() if parent: @@ -78,7 +98,7 @@ def show_log(log, show_patch): else: commit = None - if show_patch and diff_str: + if options.patch and diff_str: pager(diff_str.rstrip()) def func(parser, options, args): @@ -106,4 +126,4 @@ def func(parser, options, args): if os.system('gitk %s' % log) != 0: raise CmdException, 'gitk execution failed' else: - show_log(log, options.patch) + show_log(log, options) diff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py index 911c127..7145431 100644 --- a/stgit/commands/refresh.py +++ b/stgit/commands/refresh.py @@ -56,7 +56,9 @@ options = [make_option('-f', '--force', make_option('-m', '--message', help = 'use MESSAGE as the patch ' \ 'description'), - make_option('-a', '--author', metavar = '"NAME "', + make_option('-a', '--annotate', metavar = 'NOTE', + help = 'annotate the patch log entry'), + make_option('--author', metavar = '"NAME "', help = 'use "NAME " as the author details'), make_option('--authname', help = 'use AUTHNAME as the author name'), @@ -126,7 +128,7 @@ def func(parser, options, args): or options.edit or options.message \ or options.authname or options.authemail or options.authdate \ or options.commname or options.commemail \ - or options.sign or options.ack: + or options.sign or options.ack or options.annotate: if options.patch: applied = crt_series.get_applied() @@ -154,7 +156,8 @@ def func(parser, options, args): author_date = options.authdate, committer_name = options.commname, committer_email = options.commemail, - backup = True, sign_str = sign_str) + backup = True, sign_str = sign_str, + notes = options.annotate) if crt_series.empty_patch(patch): out.done('empty patch') diff --git a/stgit/stack.py b/stgit/stack.py index e33fe62..3c43aa3 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -733,7 +733,8 @@ class Series(PatchSet): author_name = None, author_email = None, author_date = None, committer_name = None, committer_email = None, - backup = False, sign_str = None, log = 'refresh'): + backup = False, sign_str = None, log = 'refresh', + notes = None): """Generates a new commit for the given patch """ name = self.get_current() @@ -796,7 +797,7 @@ class Series(PatchSet): patch.set_commemail(committer_email) if log: - self.log_patch(patch, log) + self.log_patch(patch, log, notes) return commit_id @@ -1167,11 +1168,13 @@ class Series(PatchSet): else: raise StackException, 'Unknown patch "%s"' % oldname - def log_patch(self, patch, message): + def log_patch(self, patch, message, notes = None): """Generate a log commit for a patch """ top = git.get_commit(patch.get_top()) msg = '%s\t%s' % (message, top.get_id_hash()) + if notes: + msg += '\n\n' + notes old_log = patch.get_log() if old_log: diff --git a/t/t1400-patch-history.sh b/t/t1400-patch-history.sh index 59dc134..b182838 100755 --- a/t/t1400-patch-history.sh +++ b/t/t1400-patch-history.sh @@ -21,7 +21,7 @@ test_expect_success \ stg new foo -m "Foo Patch" && echo foo > test && echo foo2 >> test && stg add test && - stg refresh + stg refresh --annotate="foo notes" ' test_expect_success \ @@ -35,10 +35,17 @@ test_expect_success \ test_expect_success \ 'Check the "new" and "refresh" logs' \ ' - stg log foo | grep -q -e "^new" && - stg log foo | grep -q -e "^refresh" && - stg log | grep -q -e "^new" && - stg log | grep -q -e "^refresh" + stg log --full foo | grep -q -e "^new" && + stg log --full foo | grep -q -e "^refresh" && + stg log --full | grep -q -e "^new" && + stg log --full | grep -q -e "^refresh" + ' + +test_expect_success \ + 'Check the log annotation' \ + ' + stg log foo | grep -q -e "\[refresh\] foo notes " + stg log bar | grep -q -e "\[refresh\] " ' test_expect_success \ @@ -47,7 +54,7 @@ test_expect_success \ stg pop && echo foo > test2 && stg add test2 && stg refresh && stg push && - stg log | grep -q -e "^push " + stg log --full | grep -q -e "^push " ' test_expect_success \ @@ -56,7 +63,7 @@ test_expect_success \ stg pop && stg refresh -m "Foo2 Patch" && stg push && - stg log | grep -q -e "^push(f) " + stg log --full | grep -q -e "^push(f) " ' test_expect_success \ @@ -65,7 +72,7 @@ test_expect_success \ stg pop && echo foo2 > test && stg refresh && stg push && - stg log | grep -q -e "^push(m) " + stg log --full | grep -q -e "^push(m) " ' test_expect_success \ @@ -75,21 +82,21 @@ test_expect_success \ stg pop && echo foo > test && stg refresh && ! stg push && - stg log | grep -q -e "^push(c) " + stg log --full | grep -q -e "^push(c) " ' test_expect_success \ 'Check the push "undo" log' \ ' stg push --undo && - stg log bar | grep -q -e "^undo " + stg log --full bar | grep -q -e "^undo " ' test_expect_success \ 'Check the refresh "undo" log' \ ' stg refresh --undo && - stg log | grep -q -e "^undo " + stg log --full | grep -q -e "^undo " ' test_done -- 2.11.0