# HG changeset patch # User Patrick Mezard # Date 1262371985 -3600 # Node ID 296a0b14a68621f6990c54fdba0083f6f20935bf # Parent 7637fe4f525d69bd789904f15129166533eb58f7 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. diff -r 7637fe4f525d -r 296a0b14a686 hgext/mq.py --- 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() diff -r 7637fe4f525d -r 296a0b14a686 tests/test-mq-qfold --- 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 .. diff -r 7637fe4f525d -r 296a0b14a686 tests/test-mq-qfold.out --- 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