changeset 10186:296a0b14a686 stable 1.4.2

mq: preserve --git flag when folding patches Without this, folding a git patch into a regular one downgrades the resulting patch to a regular patch.
author Patrick Mezard <pmezard@gmail.com>
date Fri, 01 Jan 2010 19:53:05 +0100
parents 7637fe4f525d
children fcc15ba18c03 fd6e9c7cd98c 36209ca38219
files hgext/mq.py tests/test-mq-qfold tests/test-mq-qfold.out
diffstat 3 files changed, 71 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Fri Jan 01 19:53:05 2010 +0100
+++ b/hgext/mq.py	Fri Jan 01 19:53:05 2010 +0100
@@ -264,18 +264,19 @@
             diffopts = self.patchopts(diffopts, patchfn)
         return diffopts
 
-    def patchopts(self, diffopts, patchfn):
+    def patchopts(self, diffopts, *patches):
         """Return a copy of input diff options with git set to true if
         referenced patch is a git patch.
         """
         diffopts = diffopts.copy()
-        patchf = self.opener(patchfn, 'r')
-        # if the patch was a git patch, refresh it as a git patch
-        for line in patchf:
-            if line.startswith('diff --git'):
-                diffopts.git = True
-                break
-        patchf.close()
+        for patchfn in patches:
+            patchf = self.opener(patchfn, 'r')
+            # if the patch was a git patch, refresh it as a git patch
+            for line in patchf:
+                if line.startswith('diff --git'):
+                    diffopts.git = True
+                    break
+            patchf.close()
         return diffopts
 
     def join(self, *p):
@@ -2070,7 +2071,8 @@
     if opts['edit']:
         message = ui.edit(message, user or ui.username())
 
-    q.refresh(repo, msg=message)
+    diffopts = q.patchopts(q.diffopts(), *patches)
+    q.refresh(repo, msg=message, git=diffopts.git)
     q.delete(repo, patches, opts)
     q.save_dirty()
 
--- a/tests/test-mq-qfold	Fri Jan 01 19:53:05 2010 +0100
+++ b/tests/test-mq-qfold	Fri Jan 01 19:53:05 2010 +0100
@@ -25,12 +25,35 @@
 hg qpop p1
 hg qdiff | filterdiff
 hg qfold p2
+grep git .hg/patches/p1 && echo 'git patch found!'
 hg qser
 hg qdiff | filterdiff
 echo '% fold with local changes'
 echo d >> a
 hg qfold p3
 hg diff -c . | filterdiff
+hg revert -a --no-backup
+
+echo '% fold git patch into a regular patch, expect git patch'
+echo a >> a
+hg qnew -f regular
+hg cp a aa
+hg qnew --git -f git
+hg qpop
+hg qfold git
+cat .hg/patches/regular
+hg qpop
+hg qdel regular
+
+echo '% fold regular patch into a git patch, expect git patch'
+hg cp a aa
+hg qnew --git -f git
+echo b >> aa
+hg qnew -f regular
+hg qpop
+hg qfold regular
+cat .hg/patches/git
+
 cd ..
 
 
--- a/tests/test-mq-qfold.out	Fri Jan 01 19:53:05 2010 +0100
+++ b/tests/test-mq-qfold.out	Fri Jan 01 19:53:05 2010 +0100
@@ -25,3 +25,40 @@
  a
 +a
 +b
+reverting a
+% fold git patch into a regular patch, expect git patch
+popping git
+now at: regular
+diff --git a/a b/a
+--- a/a
++++ b/a
+@@ -1,3 +1,4 @@
+ a
+ a
+ b
++a
+diff --git a/a b/aa
+copy from a
+copy to aa
+--- a/a
++++ b/aa
+@@ -1,3 +1,4 @@
+ a
+ a
+ b
++a
+popping regular
+now at: p1
+% fold regular patch into a git patch, expect git patch
+popping regular
+now at: git
+diff --git a/a b/aa
+copy from a
+copy to aa
+--- a/a
++++ b/aa
+@@ -1,3 +1,4 @@
+ a
+ a
+ b
++b