comparison mercurial/context.py @ 23085:e9165c18f8df stable

status: make 'hg status --rev' faster when there are deleted files In order not to avoid listing files as both added and deleted, for example, we check for every file in the manifest if it is in the _list_ of deleted files. This can get quite slow when there are many deleted files. Change it to a set to make the containment check faster. On a somewhat contrived example of the Mozilla repo with the entire testing/ directory deleted (~14k files), this makes 'hg status --rev .^' go from 26s to 2s.
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 24 Oct 2014 14:24:28 -0700
parents c586cb50872b
children 692bde7f486d
comparison
equal deleted inserted replaced
23084:3ef893520a85 23085:e9165c18f8df
119 mf1 = other._manifestmatches(match, s) 119 mf1 = other._manifestmatches(match, s)
120 mf2 = self._manifestmatches(match, s) 120 mf2 = self._manifestmatches(match, s)
121 121
122 modified, added, clean = [], [], [] 122 modified, added, clean = [], [], []
123 deleted, unknown, ignored = s[3], s[4], s[5] 123 deleted, unknown, ignored = s[3], s[4], s[5]
124 deletedset = set(deleted)
124 withflags = mf1.withflags() | mf2.withflags() 125 withflags = mf1.withflags() | mf2.withflags()
125 for fn, mf2node in mf2.iteritems(): 126 for fn, mf2node in mf2.iteritems():
126 if fn in mf1: 127 if fn in mf1:
127 if (fn not in deleted and 128 if (fn not in deletedset and
128 ((fn in withflags and mf1.flags(fn) != mf2.flags(fn)) or 129 ((fn in withflags and mf1.flags(fn) != mf2.flags(fn)) or
129 (mf1[fn] != mf2node and 130 (mf1[fn] != mf2node and
130 (mf2node or self[fn].cmp(other[fn]))))): 131 (mf2node or self[fn].cmp(other[fn]))))):
131 modified.append(fn) 132 modified.append(fn)
132 elif listclean: 133 elif listclean:
133 clean.append(fn) 134 clean.append(fn)
134 del mf1[fn] 135 del mf1[fn]
135 elif fn not in deleted: 136 elif fn not in deletedset:
136 added.append(fn) 137 added.append(fn)
137 removed = mf1.keys() 138 removed = mf1.keys()
138 if removed: 139 if removed:
139 # need to filter files if they are already reported as removed 140 # need to filter files if they are already reported as removed
140 unknown = [fn for fn in unknown if fn not in mf1] 141 unknown = [fn for fn in unknown if fn not in mf1]