Add the --strip option to import
authorCatalin Marinas <catalin.marinas@gmail.com>
Thu, 16 Mar 2006 20:08:15 +0000 (20:08 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 16 Mar 2006 20:08:34 +0000 (20:08 +0000)
This option strips the patch name of any leading numbering and .diff or
.patch extension. Useful when importing a series or local files. The export
command is able to automatically generate the numbering and extension.

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

index ad61b88..373372d 100644 (file)
@@ -41,6 +41,9 @@ options = [make_option('-m', '--mail',
                        action = 'store_true'),
            make_option('-n', '--name',
                        help = 'use NAME as the patch name'),
+           make_option('-t', '--strip',
+                       help = 'strip numbering and extension from patch name',
+                       action = 'store_true'),
            make_option('-s', '--series',
                        help = 'import a series of patches',
                        action = 'store_true'),
@@ -73,6 +76,9 @@ def __end_descr(line):
     return re.match('---\s*$', line) or re.match('diff -', line) or \
             re.match('Index: ', line)
 
+def __strip_patch_name(name):
+    return re.sub('^[0-9]+-(.*)\.(diff|patch)$', '\g<1>', name)
+
 def __parse_description(descr):
     """Parse the patch description and return the new description and
     author information (if any).
@@ -275,6 +281,8 @@ def __import_series(filename, options):
         patch = re.sub('#.*$', '', line).strip()
         if not patch:
             continue
+        if options.strip:
+            patch = __strip_patch_name(patch)
         if options.ignore and patch in applied:
             print 'Ignoring already applied patch "%s"' % patch
             continue
@@ -306,6 +314,8 @@ def func(parser, options, args):
             patch = os.path.basename(filename)
         else:
             raise CmdException, 'Unknown patch name'
+        if options.strip:
+            patch = __strip_patch_name(patch)
 
         __import_patch(patch, filename, options)