{"thread":{"id":"20884","subject":"[StGit PATCH] Add import -p option","startedAt":"2009-09-08T21:43:39Z","lastAt":"2009-09-10T08:24:36Z","messageCount":4,"participants":["Catalin Marinas","Karl Wiberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"122737","messageId":"b0943d9e0909081443g47978cb7mee241d74dc52adf7@mail.gmail.com","threadId":"20884","inReplyTo":null,"subject":"[StGit PATCH] Add import -p option","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2009-09-08T21:43:39Z","receivedAt":"2009-09-08T21:43:39Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"This patch renames some of the existing import options and adds the -p\n(--strip) option which allows stripping the leading slashes of the diff\npaths.\n\nSigned-off-by: Catalin Marinas <catalin.marinas@arm.com>\n---\n stgit/commands/imprt.py |   13 ++++++++-----\n stgit/git.py            |    4 +++-\n 2 files changed, 11 insertions(+), 6 deletions(-)\n\ndiff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py\nindex 8067beb..0bbacbc 100644\n--- a/stgit/commands/imprt.py\n+++ b/stgit/commands/imprt.py\n@@ -57,7 +57,9 @@ options = [\n         short = 'Import a patch from a URL'),\n     opt('-n', '--name',\n         short = 'Use NAME as the patch name'),\n-    opt('-t', '--strip', action = 'store_true',\n+    opt('-p', '--strip', type = 'int', metavar = 'N',\n+        short = 'Remove N leading slashes from diff paths (default 1)'),\n+    opt('-t', '--stripname', action = 'store_true',\n         short = 'Strip numbering and extension from patch name'),\n     opt('-i', '--ignore', action = 'store_true',\n         short = 'Ignore the applied patches in the series'),\n@@ -69,7 +71,7 @@ options = [\n         short = 'leave the rejected hunks in corresponding *.rej files'),\n     opt('-e', '--edit', action = 'store_true',\n         short = 'Invoke an editor for the patch description'),\n-    opt('-p', '--showpatch', action = 'store_true',\n+    opt('-d', '--showdiff', action = 'store_true',\n         short = 'Show the patch content in the editor buffer'),\n     opt('-a', '--author', metavar = '\"NAME <EMAIL>\"',\n         short = 'Use \"NAME <EMAIL>\" as the author details'),\n@@ -104,7 +106,7 @@ def __create_patch(filename, message, author_name,\nauthor_email,\n         patch = os.path.basename(filename)\n     else:\n         patch = ''\n-    if options.strip:\n+    if options.stripname:\n         patch = __strip_patch_name(patch)\n\n     if not patch:\n@@ -152,9 +154,10 @@ def __create_patch(filename, message,\nauthor_name, author_email,\n             base = git_id(crt_series, options.base)\n         else:\n             base = None\n-        git.apply_patch(diff = diff, base = base, reject = options.reject)\n+        git.apply_patch(diff = diff, base = base, reject = options.reject,\n+                        strip = options.strip)\n         crt_series.refresh_patch(edit = options.edit,\n-                                 show_patch = options.showpatch,\n+                                 show_patch = options.showdiff,\n                                  sign_str = options.sign_str,\n                                  backup = False)\n         out.done()\ndiff --git a/stgit/git.py b/stgit/git.py\nindex 268c44b..0886207 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -818,7 +818,7 @@ def repack():\n     GRun('repack', '-a', '-d', '-f').run()\n\n def apply_patch(filename = None, diff = None, base = None,\n-                fail_dump = True, reject = False):\n+                fail_dump = True, reject = False, strip = None):\n     \"\"\"Apply a patch onto the current or given index. There must not\n     be any local changes in the tree, otherwise the command fails\n     \"\"\"\n@@ -840,6 +840,8 @@ def apply_patch(filename = None, diff = None, base = None,\n     cmd = ['apply', '--index']\n     if reject:\n         cmd += ['--reject']\n+    if strip:\n+        cmd += ['-p', strip]\n     try:\n         GRun(*cmd).raw_input(diff).no_output()\n     except GitRunException:\n"},{"id":"122742","messageId":"20090908223714.GA6364@diana.vm.bytemark.co.uk","threadId":"20884","inReplyTo":"b0943d9e0909081443g47978cb7mee241d74dc52adf7@mail.gmail.com","subject":"Re: [StGit PATCH] Add import -p option","fromName":"Karl Wiberg","fromEmail":"kha@treskal.com","sentAt":"2009-09-08T22:37:14Z","receivedAt":"2009-09-08T22:37:14Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2009-09-08 22:43:39 +0100, Catalin Marinas wrote:\n\n> This patch renames some of the existing import options and adds the\n> -p (--strip) option which allows stripping the leading slashes of\n> the diff paths.\n\nLooks good (and the intent is very good). The import test should\nprobably be augmented with a test case for -pN, though. (And since you\ndidn't have to change the test in this patch, presumably the two\noptions you renamed weren't tested either.)\n\n> +    if strip:\n> +        cmd += ['-p', strip]\n\nThis test should probably be \"if strip != None\". It doesn't _really_\nmatter, technically, since -p0 is the default, but still ...\n\n-- \nKarl Wiberg, kha@treskal.com\n    www.treskal.com/kalle\n"},{"id":"122782","messageId":"b0943d9e0909091509i16b556f0x9dd3aa6788054298@mail.gmail.com","threadId":"20884","inReplyTo":"20090908223714.GA6364@diana.vm.bytemark.co.uk","subject":"Re: [StGit PATCH] Add import -p option","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2009-09-09T22:09:51Z","receivedAt":"2009-09-09T22:09:51Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"2009/9/8 Karl Wiberg <kha@treskal.com>:\n> On 2009-09-08 22:43:39 +0100, Catalin Marinas wrote:\n>\n>> This patch renames some of the existing import options and adds the\n>> -p (--strip) option which allows stripping the leading slashes of\n>> the diff paths.\n>\n> Looks good (and the intent is very good). The import test should\n> probably be augmented with a test case for -pN, though.\n\nYes. I'll try to add one. As you noticed, not all options are tested.\n\n>> +    if strip:\n>> +        cmd += ['-p', strip]\n>\n> This test should probably be \"if strip != None\". It doesn't _really_\n> matter, technically, since -p0 is the default, but still ...\n\nI modified it after posting the patch. The git default is -p1, so we\nwould miss the -p0 case.\n\n-- \nCatalin\n"},{"id":"122795","messageId":"20090910082436.GA1388@diana.vm.bytemark.co.uk","threadId":"20884","inReplyTo":"b0943d9e0909091509i16b556f0x9dd3aa6788054298@mail.gmail.com","subject":"Re: [StGit PATCH] Add import -p option","fromName":"Karl Wiberg","fromEmail":"kha@treskal.com","sentAt":"2009-09-10T08:24:36Z","receivedAt":"2009-09-10T08:24:36Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2009-09-09 23:09:51 +0100, Catalin Marinas wrote:\n\n> 2009/9/8 Karl Wiberg <kha@treskal.com>:\n>\n> > On 2009-09-08 22:43:39 +0100, Catalin Marinas wrote:\n> >\n> > > +    if strip:\n> > > +        cmd += ['-p', strip]\n> >\n> > This test should probably be \"if strip != None\". It doesn't\n> > _really_ matter, technically, since -p0 is the default, but still\n> > ...\n>\n> I modified it after posting the patch. The git default is -p1, so we\n> would miss the -p0 case.\n\nAh ha! Sometimes it actually does pay to be pedantic ...\n\n-- \nKarl Wiberg, kha@treskal.com\n    www.treskal.com/kalle\n"}]}