dirstate: eliminate reference cycle from normalize

Bound methods hold a reference to self, so assigning a bound method to
an instance unavoidably creates a cycle. Work around this by choosing
a normalize method at walk time instead. Eliminate default arg while
we're at it.
This commit is contained in:
Matt Mackall 2009-06-08 18:14:44 -05:00
parent 4269cb82b8
commit edecde7d3c

View File

@ -114,12 +114,6 @@ class dirstate(object):
def _checkcase(self): def _checkcase(self):
return not util.checkcase(self._join('.hg')) return not util.checkcase(self._join('.hg'))
@propertycache
def normalize(self):
if self._checkcase:
return self._normalize
return lambda x, y=False: x
def _join(self, f): def _join(self, f):
# much faster than os.path.join() # much faster than os.path.join()
# it's safe because f is always a relative path # it's safe because f is always a relative path
@ -345,7 +339,7 @@ class dirstate(object):
except KeyError: except KeyError:
self._ui.warn(_("not in dirstate: %s\n") % f) self._ui.warn(_("not in dirstate: %s\n") % f)
def _normalize(self, path, knownpath=False): def _normalize(self, path, knownpath):
norm_path = os.path.normcase(path) norm_path = os.path.normcase(path)
fold_path = self._foldmap.get(norm_path, None) fold_path = self._foldmap.get(norm_path, None)
if fold_path is None: if fold_path is None:
@ -450,7 +444,6 @@ class dirstate(object):
badfn = match.bad badfn = match.bad
dmap = self._map dmap = self._map
normpath = util.normpath normpath = util.normpath
normalize = self.normalize
listdir = osutil.listdir listdir = osutil.listdir
lstat = os.lstat lstat = os.lstat
getkind = stat.S_IFMT getkind = stat.S_IFMT
@ -461,6 +454,11 @@ class dirstate(object):
work = [] work = []
wadd = work.append wadd = work.append
if self._checkcase:
normalize = self._normalize
else:
normalize = lambda x, y: x
exact = skipstep3 = False exact = skipstep3 = False
if matchfn == match.exact: # match.exact if matchfn == match.exact: # match.exact
exact = True exact = True
@ -475,7 +473,7 @@ class dirstate(object):
# step 1: find all explicit files # step 1: find all explicit files
for ff in sorted(files): for ff in sorted(files):
nf = normalize(normpath(ff)) nf = normalize(normpath(ff), True)
if nf in results: if nf in results:
continue continue