Mercurial > public > mercurial-scm > hg-stable
diff hgext/mq.py @ 17152:f287d4a62031
mq: create patch file after commit to import diff of ".hgsubstate" at qrefresh
Even though the committed revision contains diff of ".hgsubstate", the
patch file created by qrefresh doesn't contain it, because:
- ".hgsubstate" is not listed up as one of target files of the patch
for reasons below, so diff of ".hgsubstate" is not imported into
patch file
- status of ".hgsubstate" in working directory is usually "clean"
- ".hgsubstate" is not specified explicitly by users
- the patch file is created before commit processing which updates
or creates ".hgsubstate" automatically, so there is no diff for it
at that time
This patch resolves this problem by:
- putting ".hgsubstate" into target list of the patch, if needed:
this allows "patch.diff()" to import diff of ".hgsubstate" into
patch file.
- creating the patch file after commit processing:
this updates ".hgsubstate" before "patch.diff()" invocation.
For the former fixing, this patch introduces "putsubstate2changes()"
to share same implementation with qnew. This is invoked only once per
qnew/qrefresh at most, so there is less performance impact.
This patch also omits "match" argument for "patch.diff()" invocation,
because "patch.diff()" ignores "match" if "changes" is specified.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Wed, 27 Jun 2012 22:03:27 +0900 |
parents | 986df5249b65 |
children | 54da604fefee |
line wrap: on
line diff
--- a/hgext/mq.py Wed Jun 27 22:03:22 2012 +0900 +++ b/hgext/mq.py Wed Jun 27 22:03:27 2012 +0900 @@ -946,6 +946,18 @@ inclsubs.append(s) return inclsubs + def putsubstate2changes(self, substatestate, changes): + for files in changes[:3]: + if '.hgsubstate' in files: + return # already listed up + # not yet listed up + if substatestate in 'a?': + changes[1].append('.hgsubstate') + elif substatestate in 'r': + changes[2].append('.hgsubstate') + else: # modified + changes[0].append('.hgsubstate') + def localchangesfound(self, refresh=True): if refresh: raise util.Abort(_("local changes found, refresh first")) @@ -1064,17 +1076,7 @@ if commitfiles: parent = self.qparents(repo, n) if inclsubs: - for files in changes[:3]: - if '.hgsubstate' in files: - break # already listed up - else: - # not yet listed up - if substatestate in 'a?': - changes[1].append('.hgsubstate') - elif substatestate in 'r': - changes[2].append('.hgsubstate') - else: # modified - changes[0].append('.hgsubstate') + self.putsubstate2changes(substatestate, changes) chunks = patchmod.diff(repo, node1=parent, node2=n, changes=changes, opts=diffopts) for chunk in chunks: @@ -1487,6 +1489,9 @@ hint=_('see "hg help phases" for details')) inclsubs = self.checksubstate(repo) + if inclsubs: + inclsubs.append('.hgsubstate') + substatestate = repo.dirstate['.hgsubstate'] cparents = repo.changelog.parents(top) patchparent = self.qparents(repo, top) @@ -1567,10 +1572,6 @@ a = list(aa) c = [filter(matchfn, l) for l in (m, a, r)] match = scmutil.matchfiles(repo, set(c[0] + c[1] + c[2] + inclsubs)) - chunks = patchmod.diff(repo, patchparent, match=match, - changes=c, opts=diffopts) - for chunk in chunks: - patchf.write(chunk) try: if diffopts.git or diffopts.upgrade: @@ -1649,6 +1650,12 @@ n = newcommit(repo, oldphase, message, user, ph.date, match=match, force=True) # only write patch after a successful commit + if inclsubs: + self.putsubstate2changes(substatestate, c) + chunks = patchmod.diff(repo, patchparent, + changes=c, opts=diffopts) + for chunk in chunks: + patchf.write(chunk) patchf.close() self.applied.append(statusentry(n, patchfn)) except: # re-raises