mq: use list of already known target files instead of matching object for diff
'hg qnew' passes matching object to 'patch.diff()' to specify target
filenames, and it causes 'dirstate.walk()' via 'repo.status()' in
'patch.diff()'.
but target files are already known before 'patch.diff()' invocation.
to avoid useless 'dirstate.walk()' invocation, this patch uses
'changes' argument to pass already known target files to
'patch.diff()' instead of 'match' argument.
'changes' argument of 'patch.diff()' should have lists for modified,
added and removed files separately, so this patch saves status of
'.hgsubstate' before commit, and put it into appropriate list in
'changes'.
--- a/hgext/mq.py Thu Apr 05 23:52:06 2012 +0900
+++ b/hgext/mq.py Thu Apr 05 23:52:55 2012 +0900
@@ -950,6 +950,7 @@
inclsubs = self.checksubstate(repo)
if inclsubs:
inclsubs.append('.hgsubstate')
+ substatestate = repo.dirstate['.hgsubstate']
if opts.get('include') or opts.get('exclude') or pats:
if inclsubs:
pats = list(pats or []) + inclsubs
@@ -959,9 +960,11 @@
if f != '.hgsubstate': # .hgsubstate is auto-created
raise util.Abort('%s: %s' % (f, msg))
match.bad = badfn
- m, a, r, d = repo.status(match=match)[:4]
+ changes = repo.status(match=match)
+ m, a, r, d = changes[:4]
else:
- m, a, r, d = self.checklocalchanges(repo, force=True)
+ changes = self.checklocalchanges(repo, force=True)
+ m, a, r, d = changes
match = scmutil.matchfiles(repo, m + a + r + inclsubs)
if len(repo[None].parents()) > 1:
raise util.Abort(_('cannot manage merge changesets'))
@@ -1010,8 +1013,15 @@
p.write(msg)
if commitfiles:
parent = self.qparents(repo, n)
+ if inclsubs:
+ if substatestate in 'a?':
+ changes[1].append('.hgsubstate')
+ elif substatestate in 'r':
+ changes[2].append('.hgsubstate')
+ else: # modified
+ changes[0].append('.hgsubstate')
chunks = patchmod.diff(repo, node1=parent, node2=n,
- match=match, opts=diffopts)
+ changes=changes, opts=diffopts)
for chunk in chunks:
p.write(chunk)
p.close()