comparison hgext/mq.py @ 50061:64b3cc021833

dirstate-guard: remove it usage in `mq` The code it covered is also covered by a `changing_parents` context.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 14 Feb 2023 00:31:23 +0100
parents 3c431f7551dd
children 2a46555c5522
comparison
equal deleted inserted replaced
50060:4f758b51bf9b 50061:64b3cc021833
80 open, 80 open,
81 ) 81 )
82 from mercurial import ( 82 from mercurial import (
83 cmdutil, 83 cmdutil,
84 commands, 84 commands,
85 dirstateguard,
86 encoding, 85 encoding,
87 error, 86 error,
88 extensions, 87 extensions,
89 hg, 88 hg,
90 localrepo, 89 localrepo,
1991 match = scmutil.matchfiles(repo, files) 1990 match = scmutil.matchfiles(repo, files)
1992 1991
1993 bmlist = repo[top].bookmarks() 1992 bmlist = repo[top].bookmarks()
1994 1993
1995 with repo.dirstate.changing_parents(repo): 1994 with repo.dirstate.changing_parents(repo):
1996 # XXX do we actually need the dirstateguard 1995 if diffopts.git or diffopts.upgrade:
1997 dsguard = None 1996 copies = {}
1998 try: 1997 for dst in a:
1999 dsguard = dirstateguard.dirstateguard(repo, b'mq.refresh') 1998 src = repo.dirstate.copied(dst)
2000 if diffopts.git or diffopts.upgrade: 1999 # during qfold, the source file for copies may
2001 copies = {} 2000 # be removed. Treat this as a simple add.
2002 for dst in a: 2001 if src is not None and src in repo.dirstate:
2003 src = repo.dirstate.copied(dst) 2002 copies.setdefault(src, []).append(dst)
2004 # during qfold, the source file for copies may 2003 repo.dirstate.update_file(
2005 # be removed. Treat this as a simple add. 2004 dst, p1_tracked=False, wc_tracked=True
2006 if src is not None and src in repo.dirstate: 2005 )
2007 copies.setdefault(src, []).append(dst) 2006 # remember the copies between patchparent and qtip
2008 repo.dirstate.update_file( 2007 for dst in aaa:
2009 dst, p1_tracked=False, wc_tracked=True 2008 src = ctx[dst].copysource()
2009 if src:
2010 copies.setdefault(src, []).extend(
2011 copies.get(dst, [])
2010 ) 2012 )
2011 # remember the copies between patchparent and qtip 2013 if dst in a:
2012 for dst in aaa: 2014 copies[src].append(dst)
2013 src = ctx[dst].copysource() 2015 # we can't copy a file created by the patch itself
2014 if src: 2016 if dst in copies:
2015 copies.setdefault(src, []).extend( 2017 del copies[dst]
2016 copies.get(dst, []) 2018 for src, dsts in copies.items():
2017 ) 2019 for dst in dsts:
2018 if dst in a: 2020 repo.dirstate.copy(src, dst)
2019 copies[src].append(dst) 2021 else:
2020 # we can't copy a file created by the patch itself 2022 for dst in a:
2021 if dst in copies: 2023 repo.dirstate.update_file(
2022 del copies[dst] 2024 dst, p1_tracked=False, wc_tracked=True
2023 for src, dsts in copies.items(): 2025 )
2024 for dst in dsts: 2026 # Drop useless copy information
2025 repo.dirstate.copy(src, dst) 2027 for f in list(repo.dirstate.copies()):
2026 else: 2028 repo.dirstate.copy(None, f)
2027 for dst in a: 2029 for f in r:
2028 repo.dirstate.update_file( 2030 repo.dirstate.update_file_p1(f, p1_tracked=True)
2029 dst, p1_tracked=False, wc_tracked=True 2031 # if the patch excludes a modified file, mark that
2030 ) 2032 # file with mtime=0 so status can see it.
2031 # Drop useless copy information 2033 mm = []
2032 for f in list(repo.dirstate.copies()): 2034 for i in range(len(m) - 1, -1, -1):
2033 repo.dirstate.copy(None, f) 2035 if not match1(m[i]):
2034 for f in r: 2036 mm.append(m[i])
2035 repo.dirstate.update_file_p1(f, p1_tracked=True) 2037 del m[i]
2036 # if the patch excludes a modified file, mark that 2038 for f in m:
2037 # file with mtime=0 so status can see it. 2039 repo.dirstate.update_file_p1(f, p1_tracked=True)
2038 mm = [] 2040 for f in mm:
2039 for i in range(len(m) - 1, -1, -1): 2041 repo.dirstate.update_file_p1(f, p1_tracked=True)
2040 if not match1(m[i]): 2042 for f in forget:
2041 mm.append(m[i]) 2043 repo.dirstate.update_file_p1(f, p1_tracked=False)
2042 del m[i] 2044
2043 for f in m: 2045 user = ph.user or ctx.user()
2044 repo.dirstate.update_file_p1(f, p1_tracked=True) 2046
2045 for f in mm: 2047 oldphase = repo[top].phase()
2046 repo.dirstate.update_file_p1(f, p1_tracked=True) 2048
2047 for f in forget: 2049 # assumes strip can roll itself back if interrupted
2048 repo.dirstate.update_file_p1(f, p1_tracked=False) 2050 repo.setparents(*cparents)
2049 2051 self.applied.pop()
2050 user = ph.user or ctx.user() 2052 self.applieddirty = True
2051 2053 strip(self.ui, repo, [top], update=False, backup=False)
2052 oldphase = repo[top].phase()
2053
2054 # assumes strip can roll itself back if interrupted
2055 repo.setparents(*cparents)
2056 self.applied.pop()
2057 self.applieddirty = True
2058 strip(self.ui, repo, [top], update=False, backup=False)
2059 dsguard.close()
2060 finally:
2061 release(dsguard)
2062 2054
2063 try: 2055 try:
2064 # might be nice to attempt to roll back strip after this 2056 # might be nice to attempt to roll back strip after this
2065 2057
2066 defaultmsg = b"[mq]: %s" % patchfn 2058 defaultmsg = b"[mq]: %s" % patchfn