This is more correct, and move our plan of separated API for different dirstate
usage forward.
note: maybe the parentchange context manager should replace the dirstateguard
entirely ? (in this case we should probably deprecated dirstateguard).
Alphare |
hg-reviewers |
This is more correct, and move our plan of separated API for different dirstate
usage forward.
note: maybe the parentchange context manager should replace the dirstateguard
entirely ? (in this case we should probably deprecated dirstateguard).
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | hgext/mq.py (124 lines) |
files = set(inclsubs) | files = set(inclsubs) | ||||
for x in refreshchanges: | for x in refreshchanges: | ||||
files.update(x) | files.update(x) | ||||
match = scmutil.matchfiles(repo, files) | match = scmutil.matchfiles(repo, files) | ||||
bmlist = repo[top].bookmarks() | bmlist = repo[top].bookmarks() | ||||
with repo.dirstate.parentchange(): | |||||
# XXX do we actually need the dirstateguard | |||||
dsguard = None | dsguard = None | ||||
try: | try: | ||||
dsguard = dirstateguard.dirstateguard(repo, b'mq.refresh') | dsguard = dirstateguard.dirstateguard(repo, b'mq.refresh') | ||||
if diffopts.git or diffopts.upgrade: | if diffopts.git or diffopts.upgrade: | ||||
copies = {} | copies = {} | ||||
for dst in a: | for dst in a: | ||||
src = repo.dirstate.copied(dst) | src = repo.dirstate.copied(dst) | ||||
# during qfold, the source file for copies may | # during qfold, the source file for copies may | ||||
# be removed. Treat this as a simple add. | # be removed. Treat this as a simple add. | ||||
if src is not None and src in repo.dirstate: | if src is not None and src in repo.dirstate: | ||||
copies.setdefault(src, []).append(dst) | copies.setdefault(src, []).append(dst) | ||||
repo.dirstate.add(dst) | repo.dirstate.add(dst) | ||||
# remember the copies between patchparent and qtip | # remember the copies between patchparent and qtip | ||||
for dst in aaa: | for dst in aaa: | ||||
src = ctx[dst].copysource() | src = ctx[dst].copysource() | ||||
if src: | if src: | ||||
copies.setdefault(src, []).extend( | copies.setdefault(src, []).extend( | ||||
copies.get(dst, []) | copies.get(dst, []) | ||||
) | ) | ||||
if dst in a: | if dst in a: | ||||
copies[src].append(dst) | copies[src].append(dst) | ||||
# we can't copy a file created by the patch itself | # we can't copy a file created by the patch itself | ||||
if dst in copies: | if dst in copies: | ||||
del copies[dst] | del copies[dst] | ||||
for src, dsts in pycompat.iteritems(copies): | for src, dsts in pycompat.iteritems(copies): | ||||
for dst in dsts: | for dst in dsts: | ||||
repo.dirstate.copy(src, dst) | repo.dirstate.copy(src, dst) | ||||
else: | else: | ||||
for dst in a: | for dst in a: | ||||
repo.dirstate.add(dst) | repo.dirstate.add(dst) | ||||
# Drop useless copy information | # Drop useless copy information | ||||
for f in list(repo.dirstate.copies()): | for f in list(repo.dirstate.copies()): | ||||
repo.dirstate.copy(None, f) | repo.dirstate.copy(None, f) | ||||
for f in r: | for f in r: | ||||
repo.dirstate.remove(f) | repo.dirstate.remove(f) | ||||
# if the patch excludes a modified file, mark that | # if the patch excludes a modified file, mark that | ||||
# file with mtime=0 so status can see it. | # file with mtime=0 so status can see it. | ||||
mm = [] | mm = [] | ||||
for i in pycompat.xrange(len(m) - 1, -1, -1): | for i in pycompat.xrange(len(m) - 1, -1, -1): | ||||
if not match1(m[i]): | if not match1(m[i]): | ||||
mm.append(m[i]) | mm.append(m[i]) | ||||
del m[i] | del m[i] | ||||
for f in m: | for f in m: | ||||
repo.dirstate.normal(f) | repo.dirstate.normal(f) | ||||
for f in mm: | for f in mm: | ||||
repo.dirstate.normallookup(f) | repo.dirstate.normallookup(f) | ||||
for f in forget: | for f in forget: | ||||
repo.dirstate.drop(f) | repo.dirstate.drop(f) | ||||
user = ph.user or ctx.user() | user = ph.user or ctx.user() | ||||
oldphase = repo[top].phase() | oldphase = repo[top].phase() | ||||
# assumes strip can roll itself back if interrupted | # assumes strip can roll itself back if interrupted | ||||
repo.setparents(*cparents) | repo.setparents(*cparents) | ||||
self.applied.pop() | self.applied.pop() | ||||
self.applieddirty = True | self.applieddirty = True | ||||
strip(self.ui, repo, [top], update=False, backup=False) | strip(self.ui, repo, [top], update=False, backup=False) | ||||
dsguard.close() | dsguard.close() | ||||
finally: | finally: | ||||
release(dsguard) | release(dsguard) | ||||
try: | try: | ||||
# might be nice to attempt to roll back strip after this | # might be nice to attempt to roll back strip after this | ||||
defaultmsg = b"[mq]: %s" % patchfn | defaultmsg = b"[mq]: %s" % patchfn | ||||
editor = cmdutil.getcommiteditor(editform=editform) | editor = cmdutil.getcommiteditor(editform=editform) | ||||
if edit: | if edit: | ||||