chiark / gitweb /
Discard stderr output from git apply if the caller wants
authorKarl Hasselström <kha@treskal.com>
Wed, 23 Jul 2008 21:29:09 +0000 (23:29 +0200)
committerKarl Hasselström <kha@treskal.com>
Thu, 24 Jul 2008 22:03:14 +0000 (00:03 +0200)
It prints error messages when it fails, and sometimes we don't need to
see them since we don't care exactly _why_ it failed. (The only
current user does want to see the errors, but future patches will
introduce callers that don't.)

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/edit.py
stgit/lib/git.py

index a8499c6301527ef8c4e107c82678cd1b4e2a93c7..3b36a6ceafe7073068a28b282487af95c1f6f1df 100644 (file)
@@ -96,7 +96,7 @@ def update_patch_description(repository, cd, text):
                                  .set_date(gitlib.Date.maybe(authdate))))
     failed_diff = None
     if diff:
-        tree = repository.apply(cd.parent.data.tree, diff)
+        tree = repository.apply(cd.parent.data.tree, diff, quiet = False)
         if tree == None:
             failed_diff = diff
         else:
index 6ccdfa77f2f7a18d33182d6fd266ac94786d41a0..6929698712fe58d06f7bf3cd67108e589c75e5d3 100644 (file)
@@ -483,7 +483,7 @@ class Repository(RunWithEnv):
                 return None
         finally:
             index.delete()
-    def apply(self, tree, patch_text):
+    def apply(self, tree, patch_text, quiet):
         """Given a L{Tree} and a patch, will either return the new L{Tree}
         that results when the patch is applied, or None if the patch
         couldn't be applied."""
@@ -494,7 +494,7 @@ class Repository(RunWithEnv):
         try:
             index.read_tree(tree)
             try:
-                index.apply(patch_text)
+                index.apply(patch_text, quiet)
                 return index.write_tree()
             except MergeException:
                 return None
@@ -552,11 +552,13 @@ class Index(RunWithEnv):
         """In-index merge, no worktree involved."""
         self.run(['git', 'read-tree', '-m', '-i', '--aggressive',
                   base.sha1, ours.sha1, theirs.sha1]).no_output()
-    def apply(self, patch_text):
+    def apply(self, patch_text, quiet):
         """In-index patch application, no worktree involved."""
         try:
-            self.run(['git', 'apply', '--cached']
-                     ).raw_input(patch_text).no_output()
+            r = self.run(['git', 'apply', '--cached']).raw_input(patch_text)
+            if quiet:
+                r = r.discard_stderr()
+            r.no_output()
         except run.RunException:
             raise MergeException('Patch does not apply cleanly')
     def delete(self):