chiark / gitweb /
Allow 'refresh' to annotate the patch log entries
authorCatalin Marinas <catalin.marinas@gmail.com>
Mon, 16 Jul 2007 22:48:30 +0000 (23:48 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Mon, 16 Jul 2007 22:48:30 +0000 (23:48 +0100)
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 <catalin.marinas@gmail.com>
stgit/commands/log.py
stgit/commands/refresh.py
stgit/stack.py
t/t1400-patch-history.sh

index 1c79c7c717dd3be33c426e4f9859d16163f3bb88..ebd8cabf5420676d5ba452105325c324dc94075a 100644 (file)
@@ -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)
index 911c127f4f27229a8a673e8fc7200f01d2e4846c..71454310243d2f21b376268ebb99fc0cdbdd1e08 100644 (file)
@@ -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 <EMAIL>"',
+           make_option('-a', '--annotate', metavar = 'NOTE',
+                       help = 'annotate the patch log entry'),
+           make_option('--author', metavar = '"NAME <EMAIL>"',
                        help = 'use "NAME <EMAIL>" 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')
index e33fe62fcd518fdbb8caf4f5ccf3f9e543b1a5bc..3c43aa39370728a7db063df1c40c441e66bb50e4 100644 (file)
@@ -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:
index 59dc134ad7b05bd61e4767e51317a0373ae4df05..b18283869839fb9af9acbda16e6ab7c2affe7697 100755 (executable)
@@ -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