chiark / gitweb /
Allow refresh --annotate to replace the top log entry
authorCatalin Marinas <catalin.marinas@gmail.com>
Tue, 17 Jul 2007 23:01:21 +0000 (00:01 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 17 Jul 2007 23:01:21 +0000 (00:01 +0100)
If there is no changes to check in and therefore no patch commit to
generate, the --annotate option simply replaces the top log with one
containing the notes.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/refresh.py
stgit/stack.py
t/t1400-patch-history.sh

index 71454310243d2f21b376268ebb99fc0cdbdd1e08..827738899a4da2bee17d1f953303505976f5438c 100644 (file)
@@ -128,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.annotate:
+           or options.sign or options.ack:
 
         if options.patch:
             applied = crt_series.get_applied()
@@ -167,5 +167,10 @@ def func(parser, options, args):
         if options.patch:
             between.reverse()
             push_patches(between)
+    elif options.annotate:
+        # only annotate the top log entry as there is no need to
+        # refresh the patch and generate a full commit
+        crt_series.log_patch(crt_series.get_patch(patch), None,
+                             notes = options.annotate)
     else:
         out.info('Patch "%s" is already up to date' % patch)
index b03fdc062d996a9a86784b97c83e4ef397157d58..7ffaf758ef6080c452143085f2f1194d5c6db508 100644 (file)
@@ -1188,15 +1188,33 @@ class Series(PatchSet):
         """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:
-            parents = [old_log]
+
+        if message is None:
+            # replace the current log entry
+            if not old_log:
+                raise StackException, \
+                      'No log entry to annotate for patch "%s"' \
+                      % patch.get_name()
+            replace = True
+            log_commit = git.get_commit(old_log)
+            msg = log_commit.get_log().split('\n')[0]
+            log_parent = log_commit.get_parent()
+            if log_parent:
+                parents = [log_parent]
+            else:
+                parents = []
         else:
-            parents = []
+            # generate a new log entry
+            replace = False
+            msg = '%s\t%s' % (message, top.get_id_hash())
+            if old_log:
+                parents = [old_log]
+            else:
+                parents = []
+
+        if notes:
+            msg += '\n\n' + notes
 
         log = git.commit(message = msg, parents = parents,
                          cache_update = False, tree_id = top.get_tree(),
index b18283869839fb9af9acbda16e6ab7c2affe7697..b0602ff159ec4ff0c712ef9573b6e182428c6ebd 100755 (executable)
@@ -44,8 +44,11 @@ test_expect_success \
 test_expect_success \
        'Check the log annotation' \
        '
-       stg log foo | grep -q -e "\[refresh\] foo notes "
-       stg log bar | grep -q -e "\[refresh\]           "
+       stg log foo | grep -q -e    "\[refresh\] foo notes  " &&
+       stg log bar | grep -q -e    "\[refresh\]            " &&
+       stg refresh -p foo --annotate="foo notes 2" &&
+       stg log foo | grep -q -v -e "\[refresh\] foo notes  " &&
+       stg log foo | grep -q -e    "\[refresh\] foo notes 2"
        '
 
 test_expect_success \