threads / patch / 20979

patch, 5 partsAdd the -p option to fold

Subject: [StGit PATCH 4/5] Add the -p option to fold

## tl;dr

6 messages between Sep 16, 2009 and Sep 16, 2009. Diffs are folded; open one to read it.

replies: 5people: 1as markdown or json

Catalin Marinas· Sep 16, 2009, 21:40 UTC · lore

[StGit PATCH 0/5] More UI clean-up

The series adds makes the fold and import options consistent regarding the -p and --reject options. The autosigning of new patches was extended to the import command as well.

---
Catalin Marinas (5):
      Remove the 'fail_dump' argument to git.apply_patch()
      Add the --reject option to fold
      Do not create an empty patch if import failed without --reject
      Add the -p option to fold
      Autosign imported patches
 stgit/commands/fold.py  |   15 +++++++++++----
 stgit/commands/imprt.py |   18 +++++++++++++-----
 stgit/git.py            |   11 ++---------
 3 files changed, 26 insertions(+), 18 deletions(-)
-- 
Catalin
Catalin Marinas· Sep 16, 2009, 21:40 UTC · re: Catalin Marinas · lore

[StGit PATCH 1/5] Remove the 'fail_dump' argument to git.apply_patch()

Since we have a 'reject' argument, there is no need for the failed diff to be dumped.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/git.py |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)
Show changes to stgit/git.py +2 −9
diff --git a/stgit/git.py b/stgit/git.py
index 012e282..97b1e96 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, strip = None):
+                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
     """
@@ -847,14 +847,7 @@ def apply_patch(filename = None, diff = None, base = None,
     except GitRunException:
         if base:
             switch(orig_head)
-        if fail_dump:
-            # write the failed diff to a file
-            f = file('.stgit-failed.patch', 'w+')
-            f.write(diff)
-            f.close()
-            out.warn('Diff written to the .stgit-failed.patch file')
-
-        raise
+        raise GitException('Diff does not apply cleanly')
 
     if base:
         top = commit(message = 'temporary commit used for applying a patch',
Catalin Marinas· Sep 16, 2009, 21:41 UTC · re: Catalin Marinas · lore

[StGit PATCH 2/5] Add the --reject option to fold

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/fold.py |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
Show changes to stgit/commands/fold.py +7 −4
diff --git a/stgit/commands/fold.py b/stgit/commands/fold.py
index 66a2dd9..28e824c 100644
--- a/stgit/commands/fold.py
+++ b/stgit/commands/fold.py
@@ -38,7 +38,9 @@ options = [
     opt('-t', '--threeway', action = 'store_true',
         short = 'Perform a three-way merge with the current patch'),
     opt('-b', '--base', args = [argparse.commit],
-        short = 'Use BASE instead of HEAD applying the patch')]
+        short = 'Use BASE instead of HEAD when applying the patch'),
+    opt('--reject', action = 'store_true',
+        short = 'Leave the rejected hunks in corresponding *.rej files')]
 
 directory = DirectoryHasRepository(log = True)
 
@@ -72,11 +74,12 @@ def func(parser, options, args):
     if options.threeway:
         crt_patch = crt_series.get_patch(current)
         bottom = crt_patch.get_bottom()
-        git.apply_patch(filename = filename, base = bottom)
+        git.apply_patch(filename = filename, base = bottom,
+                        reject = options.reject)
     elif options.base:
-        git.apply_patch(filename = filename,
+        git.apply_patch(filename = filename, reject = options.reject,
                         base = git_id(crt_series, options.base))
     else:
-        git.apply_patch(filename = filename)
+        git.apply_patch(filename = filename, reject = options.reject)
 
     out.done()
Catalin Marinas· Sep 16, 2009, 21:41 UTC · re: Catalin Marinas · lore

[StGit PATCH 3/5] Do not create an empty patch if import failed without --reject

If the import failed, do not leave an empty patch on the stack. If this is required, the --reject option should be passed. The patch also fixes a lowercase typo in the --reject option description.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/imprt.py |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
Show changes to stgit/commands/imprt.py +8 −3
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index aa75065..de77635 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -68,7 +68,7 @@ options = [
     opt('-b', '--base', args = [argparse.commit],
         short = 'Use BASE instead of HEAD for file importing'),
     opt('--reject', action = 'store_true',
-        short = 'leave the rejected hunks in corresponding *.rej files'),
+        short = 'Leave the rejected hunks in corresponding *.rej files'),
     opt('-e', '--edit', action = 'store_true',
         short = 'Invoke an editor for the patch description'),
     opt('-d', '--showdiff', action = 'store_true',
@@ -154,8 +154,13 @@ 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,
-                        strip = options.strip)
+        try:
+            git.apply_patch(diff = diff, base = base, reject = options.reject,
+                            strip = options.strip)
+        except git.GitException:
+            if not options.reject:
+                crt_series.delete_patch(patch)
+            raise
         crt_series.refresh_patch(edit = options.edit,
                                  show_patch = options.showdiff,
                                  author_date = author_date,
Catalin Marinas· Sep 16, 2009, 21:41 UTC · re: Catalin Marinas · lore

This option was added to import, so it makes sense for fold to have it as well.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/fold.py |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
Show changes to stgit/commands/fold.py +6 −2
diff --git a/stgit/commands/fold.py b/stgit/commands/fold.py
index 28e824c..ce0459e 100644
--- a/stgit/commands/fold.py
+++ b/stgit/commands/fold.py
@@ -39,6 +39,8 @@ options = [
         short = 'Perform a three-way merge with the current patch'),
     opt('-b', '--base', args = [argparse.commit],
         short = 'Use BASE instead of HEAD when applying the patch'),
+    opt('-p', '--strip', type = 'int', metavar = 'N',
+        short = 'Remove N leading slashes from diff paths (default 1)'),
     opt('--reject', action = 'store_true',
         short = 'Leave the rejected hunks in corresponding *.rej files')]
 
@@ -75,11 +77,13 @@ def func(parser, options, args):
         crt_patch = crt_series.get_patch(current)
         bottom = crt_patch.get_bottom()
         git.apply_patch(filename = filename, base = bottom,
-                        reject = options.reject)
+                        strip = options.strip, reject = options.reject)
     elif options.base:
         git.apply_patch(filename = filename, reject = options.reject,
+                        strip = options.strip,
                         base = git_id(crt_series, options.base))
     else:
-        git.apply_patch(filename = filename, reject = options.reject)
+        git.apply_patch(filename = filename, strip = options.strip,
+                        reject = options.reject)
 
     out.done()
Catalin Marinas· Sep 16, 2009, 21:41 UTC · re: Catalin Marinas · lore

[StGit PATCH 5/5] Autosign imported patches

If stgit.autosign configuration is set, allow the automatic signing of the imported patches, similar to the 'new' command.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/imprt.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
Show changes to stgit/commands/imprt.py +5 −2
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index de77635..0f78490 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -141,6 +141,10 @@ def __create_patch(filename, message, author_name, author_email,
     if options.authdate:
         author_date = options.authdate
 
+    sign_str = options.sign_str
+    if not options.sign_str:
+        sign_str = config.get('stgit.autosign')
+
     crt_series.new_patch(patch, message = message, can_edit = False,
                          author_name = author_name,
                          author_email = author_email,
@@ -164,8 +168,7 @@ def __create_patch(filename, message, author_name, author_email,
         crt_series.refresh_patch(edit = options.edit,
                                  show_patch = options.showdiff,
                                  author_date = author_date,
-                                 sign_str = options.sign_str,
-                                 backup = False)
+                                 sign_str = sign_str, backup = False)
         out.done()
 
 def __mkpatchname(name, suffix):

← back to recent threads