Pick --revert option (formerly --reverse)
authorCatalin Marinas <catalin.marinas@gmail.com>
Tue, 20 Oct 2009 10:00:43 +0000 (11:00 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 20 Oct 2009 10:00:43 +0000 (11:00 +0100)
This patch renames --reverse to --revert and sets the picked patch
message similar to the "git revert" command.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/pick.py
t/t3400-pick.sh

index e0e6624..e8bafa9 100644 (file)
@@ -30,7 +30,7 @@ description = """
 Import one or more patches from a different branch or a commit object
 into the current series. By default, the name of the imported patch is
 used as the name of the current patch. It can be overridden with the
 Import one or more patches from a different branch or a commit object
 into the current series. By default, the name of the imported patch is
 used as the name of the current patch. It can be overridden with the
-'--name' option. A commit object can be reverted with the '--reverse'
+'--name' option. A commit object can be reverted with the '--revert'
 option. The log and author information are those of the commit
 object."""
 
 option. The log and author information are those of the commit
 object."""
 
@@ -42,8 +42,8 @@ options = [
         short = 'Use NAME as the patch name'),
     opt('-B', '--ref-branch', args = [argparse.stg_branches],
         short = 'Pick patches from BRANCH'),
         short = 'Use NAME as the patch name'),
     opt('-B', '--ref-branch', args = [argparse.stg_branches],
         short = 'Pick patches from BRANCH'),
-    opt('-r', '--reverse', action = 'store_true',
-        short = 'Reverse the commit object before importing'),
+    opt('-r', '--revert', action = 'store_true',
+        short = 'Revert the given commit object'),
     opt('-p', '--parent', metavar = 'COMMITID', args = [argparse.commit],
         short = 'Use COMMITID as parent'),
     opt('-x', '--expose', action = 'store_true',
     opt('-p', '--parent', metavar = 'COMMITID', args = [argparse.commit],
         short = 'Use COMMITID as parent'),
     opt('-x', '--expose', action = 'store_true',
@@ -66,6 +66,8 @@ def __pick_commit(commit_id, patchname, options):
 
     if options.name:
         patchname = options.name
 
     if options.name:
         patchname = options.name
+    elif patchname and options.revert:
+        patchname = 'revert-' + patchname
     if patchname:
         patchname = find_patch_name(patchname, crt_series.patch_exists)
 
     if patchname:
         patchname = find_patch_name(patchname, crt_series.patch_exists)
 
@@ -74,7 +76,7 @@ def __pick_commit(commit_id, patchname, options):
     else:
         parent = commit.get_parent()
 
     else:
         parent = commit.get_parent()
 
-    if not options.reverse:
+    if not options.revert:
         bottom = parent
         top = commit_id
     else:
         bottom = parent
         top = commit_id
     else:
@@ -105,7 +107,14 @@ def __pick_commit(commit_id, patchname, options):
         out.done()
     else:
         message = commit.get_log()
         out.done()
     else:
         message = commit.get_log()
-        if options.expose:
+        if options.revert:
+            if message:
+                subject = message.splitlines()[0]
+            else:
+                subject = commit.get_id_hash()
+            message = 'Revert "%s"\n\nThis reverts commit %s.\n' \
+                    % (subject, commit.get_id_hash())
+        elif options.expose:
             message += '(imported from commit %s)\n' % commit.get_id_hash()
         author_name, author_email, author_date = \
                      name_email_date(commit.get_author())
             message += '(imported from commit %s)\n' % commit.get_id_hash()
         author_name, author_email, author_date = \
                      name_email_date(commit.get_author())
index 3bd5c4f..6e92de3 100755 (executable)
@@ -39,9 +39,9 @@ test_expect_success \
        '
 
 test_expect_success \
        '
 
 test_expect_success \
-       'Pick --fold --reverse local patch' \
+       'Pick --fold --revert local patch' \
        '
        '
-       stg pick --fold --reverse D &&
+       stg pick --fold --revert D &&
        stg refresh && stg clean &&
        test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
        test "$(echo $(stg series --unapplied --noprefix))" = "D"
        stg refresh && stg clean &&
        test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
        test "$(echo $(stg series --unapplied --noprefix))" = "D"