Pick --revert option (formerly --reverse)

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>
diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py
index e0e6624..e8bafa9 100644
--- a/stgit/commands/pick.py
+++ b/stgit/commands/pick.py
@@ -30,7 +30,7 @@
 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."""
 
@@ -42,8 +42,8 @@
         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',
@@ -66,6 +66,8 @@
 
     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)
 
@@ -74,7 +76,7 @@
     else:
         parent = commit.get_parent()
 
-    if not options.reverse:
+    if not options.revert:
         bottom = parent
         top = commit_id
     else:
@@ -105,7 +107,14 @@
         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())
diff --git a/t/t3400-pick.sh b/t/t3400-pick.sh
index 3bd5c4f..6e92de3 100755
--- a/t/t3400-pick.sh
+++ b/t/t3400-pick.sh
@@ -39,9 +39,9 @@
 	'
 
 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"