Allow to drop numbers from patch names via --no-patch-numbers
authorGuido Günther <agx@sigxcpu.org>
Sun, 26 Dec 2010 22:31:57 +0000 (23:31 +0100)
committerGuido Günther <agx@sigxcpu.org>
Sun, 26 Dec 2010 23:02:40 +0000 (00:02 +0100)
so patch names remain constant when interim patches are dropped.

Closes: #592129

docs/manpages/gbp-pq.sgml
gbp-pq
gbp/config.py

index 0080584..c599114 100644 (file)
@@ -20,6 +20,9 @@
   <refsynopsisdiv>
     <cmdsynopsis>
       &gbp-pq;
+      <arg><option>--verbose</option></arg>
+      <arg><option>--color=</option><replaceable>[auto|on|off]</replaceable></arg>
+      <arg><option>--[no-]patch-numbers</option></arg>
       <group choice="plain">
       <arg><option>export</option></arg>
       <arg><option>import</option></arg>
@@ -44,7 +47,7 @@
     </para>
   </refsect1>
   <refsect1>
-    <title>OPTIONS</title>
+    <title>ACTIONS</title>
     <variablelist>
       <varlistentry>
         <term><option>import</option>
     </variablelist>
   </refsect1>
   <refsect1>
+    <title>OPTIONS</title>
+    <variablelist>
+      <varlistentry>
+        <term><option>--verbose</option></term>
+       <term><option>-v</option></term>
+        <listitem>
+          <para>verbose execution</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>--color=</option><replaceable>[auto|on|off]</replaceable>
+        </term>
+        <listitem>
+          <para>Wheter to use colored output.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>--[no-]patch-numbers</option>
+        </term>
+        <listitem>
+          <para>Whether the patch files should start with a number or not.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+  <refsect1>
     <title>SEE ALSO</title>
     <para>
       <citerefentry>
diff --git a/gbp-pq b/gbp-pq
index 7fbb787..7c35a99 100755 (executable)
--- a/gbp-pq
+++ b/gbp-pq
@@ -18,6 +18,8 @@
 #
 """manage patches in a patch queue"""
 
+import errno
+import re
 import os
 import shutil
 import subprocess
@@ -46,7 +48,9 @@ def pq_branch_base(pq_branch):
     if is_pq_branch(pq_branch):
         return pq_branch[len(PQ_BRANCH_PREFIX):]
 
-def export_patches(repo, branch):
+def export_patches(repo, branch, options):
+    patch_re = re.compile("[0-9]+-(?P<name>.+)")
+
     if is_pq_branch(branch):
         base = pq_branch_base(branch)
         gbp.log.info("On '%s', switching to '%s'" % (branch, base))
@@ -54,7 +58,13 @@ def export_patches(repo, branch):
         repo.set_branch(branch)
 
     pq_branch = pq_branch_name(branch)
-    shutil.rmtree(PATCH_DIR)
+    try:
+        shutil.rmtree(PATCH_DIR)
+    except OSError, (e, msg):
+        if e != errno.ENOENT:
+            raise GbpError, "Failed to remove patch dir: %s" % msg
+        else:
+            gbp.log.debug("%s does not exist." % PATCH_DIR)
 
     patches = repo.format_patches(branch, pq_branch, PATCH_DIR)
     if patches:
@@ -65,7 +75,15 @@ def export_patches(repo, branch):
            # info) of the patch file
             Command("sed -i -e '1d' -e 'N;$!P;$!D;$d' %s" % patch, shell=True)()
             Command("sed -i -e 's/^-- \\n[0-9\.]+$//' %s" % patch, shell=True)()
-            f.write(patch[len(PATCH_DIR):])
+
+            name = patch[len(PATCH_DIR):]
+            if not options.patch_numbers:
+                m = patch_re.match(name)
+                if m:
+                    name = m.group('name')
+                    shutil.move(patch, os.path.join(PATCH_DIR, name))
+
+            f.write(name + '\n')
         f.close()
         GitCommand('status')(['--', PATCH_DIR])
     else:
@@ -141,6 +159,7 @@ def main(argv):
         "  rebase         switch to patch queue branch associated to the current\n"
         "                 branch and rebase against current branch.\n"
         "  drop           drop (delete) the patch queue associated to the current branch.")
+    parser.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers")
     parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
                       help="verbose command execution")
     parser.add_config_file_option(option_name="color", dest="color")
@@ -166,7 +185,7 @@ def main(argv):
     try:
         current = repo.get_branch()
         if action == "export":
-            export_patches(repo, current)
+            export_patches(repo, current, options)
         elif action == "import":
             import_patches(repo, current)
         elif action == "drop":
index 61862f3..134d64f 100644 (file)
@@ -82,6 +82,7 @@ class GbpOptionParser(OptionParser):
                  'color'           : 'auto',
                  'customizations'  : '',
                  'spawn-editor'    : 'release',
+                 'patch-numbers'   : 'True',
              }
     help = {
              'debian-branch':
@@ -134,6 +135,8 @@ class GbpOptionParser(OptionParser):
                   "color output, default is '%(color)s'",
              'spawn-editor':
                   "Wether to spawn an editor after adding the changelog entry, default is '%(spawn-editor)s'",
+             'patch-numbers':
+                  "Wether to number patch files, default is %(patch-numbers)s",
            }
     config_files = [ '/etc/git-buildpackage/gbp.conf',
                      os.path.expanduser('~/.gbp.conf'),