Mercurial > hg
diff hgext/mq.py @ 10185:7637fe4f525d stable
mq: preserve --git flag when merging patches
Without this, merging a patch queue without diff.git=1 downgrades all git
patches to regular patches, losing data in the process.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 01 Jan 2010 19:53:05 +0100 |
parents | 8a47347d298b |
children | 296a0b14a686 |
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 @@ -261,12 +261,21 @@ def diffopts(self, opts={}, patchfn=None): diffopts = patch.diffopts(self.ui, opts) if patchfn: - # if the patch was a git patch, refresh it as a git patch - patchf = self.opener(patchfn, 'r') - for line in patchf: - if line.startswith('diff --git'): - diffopts.git = True - break + diffopts = self.patchopts(diffopts, patchfn) + return diffopts + + def patchopts(self, diffopts, patchfn): + """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() return diffopts def join(self, *p): @@ -469,6 +478,7 @@ except: raise util.Abort(_("unable to read %s") % patch) + diffopts = self.patchopts(diffopts, patch) patchf = self.opener(patch, "w") comments = str(ph) if comments: