Generate a different patch name if it already exists
authorCatalin Marinas <catalin.marinas@gmail.com>
Sat, 8 Nov 2008 21:18:09 +0000 (21:18 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Sat, 8 Nov 2008 21:36:10 +0000 (21:36 +0000)
This is a fix for bug #12518. If the patch name already exists, the pick
command generates another by appending a numbered suffix.

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

index 0fc54b8..ee08c01 100644 (file)
@@ -64,6 +64,8 @@ def __pick_commit(commit_id, patchname, options):
 
     if options.name:
         patchname = options.name
+    if patchname:
+        patchname = find_patch_name(patchname, crt_series.patch_exists)
 
     if options.parent:
         parent = git_id(crt_series, options.parent)
@@ -181,7 +183,12 @@ def func(parser, options, args):
         raise CmdException, 'No patches applied'
 
     if commit_id:
-        __pick_commit(commit_id, None, options)
+        # Try to guess a patch name if the argument was <branch>:<patch>
+        try:
+            patchname = args[0].split(':')[1]
+        except IndexError:
+            patchname = None
+        __pick_commit(commit_id, patchname, options)
     else:
         if options.unapplied:
             patches.reverse()
index 751cb4a..81035a5 100644 (file)
@@ -200,6 +200,15 @@ def edit_string(s, filename):
     os.remove(filename)
     return s
 
+def find_patch_name(patchname, unacceptable):
+    """Find a patch name which is acceptable."""
+    if unacceptable(patchname):
+        suffix = 0
+        while unacceptable('%s-%d' % (patchname, suffix)):
+            suffix += 1
+        patchname = '%s-%d' % (patchname, suffix)
+    return patchname
+
 def patch_name_from_msg(msg):
     """Return a string to be used as a patch name. This is generated
     from the top line of the string passed as argument."""
@@ -220,12 +229,7 @@ def make_patch_name(msg, unacceptable, default_name = 'patch'):
     patchname = patch_name_from_msg(msg)
     if not patchname:
         patchname = default_name
-    if unacceptable(patchname):
-        suffix = 0
-        while unacceptable('%s-%d' % (patchname, suffix)):
-            suffix += 1
-        patchname = '%s-%d' % (patchname, suffix)
-    return patchname
+    return find_patch_name(patchname, unacceptable)
 
 # any and all functions are builtin in Python 2.5 and higher, but not
 # in 2.4.