git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [StGit PATCH] Add import -p option
@ 2009-09-08 21:43 Catalin Marinas
  2009-09-08 22:37 ` Karl Wiberg
  0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2009-09-08 21:43 UTC (permalink / raw)
  To: Gustav Hållberg, Karl Hasselström, Git Mailing List

This patch renames some of the existing import options and adds the -p
(--strip) option which allows stripping the leading slashes of the diff
paths.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
 stgit/commands/imprt.py |   13 ++++++++-----
 stgit/git.py            |    4 +++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index 8067beb..0bbacbc 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -57,7 +57,9 @@ options = [
         short = 'Import a patch from a URL'),
     opt('-n', '--name',
         short = 'Use NAME as the patch name'),
-    opt('-t', '--strip', action = 'store_true',
+    opt('-p', '--strip', type = 'int', metavar = 'N',
+        short = 'Remove N leading slashes from diff paths (default 1)'),
+    opt('-t', '--stripname', action = 'store_true',
         short = 'Strip numbering and extension from patch name'),
     opt('-i', '--ignore', action = 'store_true',
         short = 'Ignore the applied patches in the series'),
@@ -69,7 +71,7 @@ options = [
         short = 'leave the rejected hunks in corresponding *.rej files'),
     opt('-e', '--edit', action = 'store_true',
         short = 'Invoke an editor for the patch description'),
-    opt('-p', '--showpatch', action = 'store_true',
+    opt('-d', '--showdiff', action = 'store_true',
         short = 'Show the patch content in the editor buffer'),
     opt('-a', '--author', metavar = '"NAME <EMAIL>"',
         short = 'Use "NAME <EMAIL>" as the author details'),
@@ -104,7 +106,7 @@ def __create_patch(filename, message, author_name,
author_email,
         patch = os.path.basename(filename)
     else:
         patch = ''
-    if options.strip:
+    if options.stripname:
         patch = __strip_patch_name(patch)

     if not patch:
@@ -152,9 +154,10 @@ def __create_patch(filename, message,
author_name, author_email,
             base = git_id(crt_series, options.base)
         else:
             base = None
-        git.apply_patch(diff = diff, base = base, reject = options.reject)
+        git.apply_patch(diff = diff, base = base, reject = options.reject,
+                        strip = options.strip)
         crt_series.refresh_patch(edit = options.edit,
-                                 show_patch = options.showpatch,
+                                 show_patch = options.showdiff,
                                  sign_str = options.sign_str,
                                  backup = False)
         out.done()
diff --git a/stgit/git.py b/stgit/git.py
index 268c44b..0886207 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -818,7 +818,7 @@ def repack():
     GRun('repack', '-a', '-d', '-f').run()

 def apply_patch(filename = None, diff = None, base = None,
-                fail_dump = True, reject = False):
+                fail_dump = True, reject = False, strip = None):
     """Apply a patch onto the current or given index. There must not
     be any local changes in the tree, otherwise the command fails
     """
@@ -840,6 +840,8 @@ def apply_patch(filename = None, diff = None, base = None,
     cmd = ['apply', '--index']
     if reject:
         cmd += ['--reject']
+    if strip:
+        cmd += ['-p', strip]
     try:
         GRun(*cmd).raw_input(diff).no_output()
     except GitRunException:

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [StGit PATCH] Add import -p option
  2009-09-08 21:43 [StGit PATCH] Add import -p option Catalin Marinas
@ 2009-09-08 22:37 ` Karl Wiberg
  2009-09-09 22:09   ` Catalin Marinas
  0 siblings, 1 reply; 4+ messages in thread
From: Karl Wiberg @ 2009-09-08 22:37 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: Gustav Hållberg, Git Mailing List

On 2009-09-08 22:43:39 +0100, Catalin Marinas wrote:

> This patch renames some of the existing import options and adds the
> -p (--strip) option which allows stripping the leading slashes of
> the diff paths.

Looks good (and the intent is very good). The import test should
probably be augmented with a test case for -pN, though. (And since you
didn't have to change the test in this patch, presumably the two
options you renamed weren't tested either.)

> +    if strip:
> +        cmd += ['-p', strip]

This test should probably be "if strip != None". It doesn't _really_
matter, technically, since -p0 is the default, but still ...

-- 
Karl Wiberg, kha@treskal.com
    www.treskal.com/kalle

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [StGit PATCH] Add import -p option
  2009-09-08 22:37 ` Karl Wiberg
@ 2009-09-09 22:09   ` Catalin Marinas
  2009-09-10  8:24     ` Karl Wiberg
  0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2009-09-09 22:09 UTC (permalink / raw)
  To: Karl Wiberg; +Cc: Gustav Hållberg, Git Mailing List

2009/9/8 Karl Wiberg <kha@treskal.com>:
> On 2009-09-08 22:43:39 +0100, Catalin Marinas wrote:
>
>> This patch renames some of the existing import options and adds the
>> -p (--strip) option which allows stripping the leading slashes of
>> the diff paths.
>
> Looks good (and the intent is very good). The import test should
> probably be augmented with a test case for -pN, though.

Yes. I'll try to add one. As you noticed, not all options are tested.

>> +    if strip:
>> +        cmd += ['-p', strip]
>
> This test should probably be "if strip != None". It doesn't _really_
> matter, technically, since -p0 is the default, but still ...

I modified it after posting the patch. The git default is -p1, so we
would miss the -p0 case.

-- 
Catalin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [StGit PATCH] Add import -p option
  2009-09-09 22:09   ` Catalin Marinas
@ 2009-09-10  8:24     ` Karl Wiberg
  0 siblings, 0 replies; 4+ messages in thread
From: Karl Wiberg @ 2009-09-10  8:24 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: Gustav Hållberg, Git Mailing List

On 2009-09-09 23:09:51 +0100, Catalin Marinas wrote:

> 2009/9/8 Karl Wiberg <kha@treskal.com>:
>
> > On 2009-09-08 22:43:39 +0100, Catalin Marinas wrote:
> >
> > > +    if strip:
> > > +        cmd += ['-p', strip]
> >
> > This test should probably be "if strip != None". It doesn't
> > _really_ matter, technically, since -p0 is the default, but still
> > ...
>
> I modified it after posting the patch. The git default is -p1, so we
> would miss the -p0 case.

Ah ha! Sometimes it actually does pay to be pedantic ...

-- 
Karl Wiberg, kha@treskal.com
    www.treskal.com/kalle

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-09-10  8:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-08 21:43 [StGit PATCH] Add import -p option Catalin Marinas
2009-09-08 22:37 ` Karl Wiberg
2009-09-09 22:09   ` Catalin Marinas
2009-09-10  8:24     ` Karl Wiberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).