Mercurial > public > mercurial-scm > hg
comparison mercurial/manifest.py @ 43106:d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
This commit finishes porting .iteritems() to pycompat.iteritems()
for the mercurial package.
The translation of .iteritems() to .items() was the last conversion
performed by the source transformer. With the porting to pycompat
complete, we no longer have a need for the source transformer. So
the source transformer has been removed. Good riddance! The code
base is now compatible with Python 2 and Python 3.
For the record, as the person who introduced the source transformer,
it brings me joy to delete it. It accomplished its goal to facilitate
a port to Python 3 without overly burdening people on some painful
low-level differences between Python 2 and 3. It is unfortunate we
still have to wallpaper over many differences with the pycompat
shim. But it is what it is.
Differential Revision: https://phab.mercurial-scm.org/D7015
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 00:04:04 -0400 |
parents | c59eb1560c44 |
children | 8ff1ecfadcd1 |
comparison
equal
deleted
inserted
replaced
43105:649d3ac37a12 | 43106:d783f945a701 |
---|---|
485 m2 = m2.matches(match) | 485 m2 = m2.matches(match) |
486 return m1.filesnotin(m2) | 486 return m1.filesnotin(m2) |
487 diff = self.diff(m2) | 487 diff = self.diff(m2) |
488 files = set( | 488 files = set( |
489 filepath | 489 filepath |
490 for filepath, hashflags in diff.iteritems() | 490 for filepath, hashflags in pycompat.iteritems(diff) |
491 if hashflags[1][0] is None | 491 if hashflags[1][0] is None |
492 ) | 492 ) |
493 return files | 493 return files |
494 | 494 |
495 @propertycache | 495 @propertycache |
787 def _subpath(self, path): | 787 def _subpath(self, path): |
788 return self._dir + path | 788 return self._dir + path |
789 | 789 |
790 def _loadalllazy(self): | 790 def _loadalllazy(self): |
791 selfdirs = self._dirs | 791 selfdirs = self._dirs |
792 for d, (path, node, readsubtree, docopy) in self._lazydirs.iteritems(): | 792 for d, (path, node, readsubtree, docopy) in pycompat.iteritems( |
793 self._lazydirs | |
794 ): | |
793 if docopy: | 795 if docopy: |
794 selfdirs[d] = readsubtree(path, node).copy() | 796 selfdirs[d] = readsubtree(path, node).copy() |
795 else: | 797 else: |
796 selfdirs[d] = readsubtree(path, node) | 798 selfdirs[d] = readsubtree(path, node) |
797 self._lazydirs = {} | 799 self._lazydirs = {} |
826 other (it may already be loaded or it may not exist, doesn't matter) | 828 other (it may already be loaded or it may not exist, doesn't matter) |
827 - if it's present in _lazydirs in both, compare the nodeid; if it | 829 - if it's present in _lazydirs in both, compare the nodeid; if it |
828 differs, load it in both | 830 differs, load it in both |
829 """ | 831 """ |
830 toloadlazy = [] | 832 toloadlazy = [] |
831 for d, v1 in t1._lazydirs.iteritems(): | 833 for d, v1 in pycompat.iteritems(t1._lazydirs): |
832 v2 = t2._lazydirs.get(d) | 834 v2 = t2._lazydirs.get(d) |
833 if not v2 or v2[1] != v1[1]: | 835 if not v2 or v2[1] != v1[1]: |
834 toloadlazy.append(d) | 836 toloadlazy.append(d) |
835 for d, v1 in t2._lazydirs.iteritems(): | 837 for d, v1 in pycompat.iteritems(t2._lazydirs): |
836 if d not in t1._lazydirs: | 838 if d not in t1._lazydirs: |
837 toloadlazy.append(d) | 839 toloadlazy.append(d) |
838 | 840 |
839 for d in toloadlazy: | 841 for d in toloadlazy: |
840 t1._loadlazy(d) | 842 t1._loadlazy(d) |
908 itertools.chain(self._dirs.items(), self._files.items()) | 910 itertools.chain(self._dirs.items(), self._files.items()) |
909 ): | 911 ): |
910 if p in self._files: | 912 if p in self._files: |
911 yield self._subpath(p), n | 913 yield self._subpath(p), n |
912 else: | 914 else: |
913 for f, sn in n.iteritems(): | 915 for f, sn in pycompat.iteritems(n): |
914 yield f, sn | 916 yield f, sn |
915 | 917 |
916 iteritems = items | 918 iteritems = items |
917 | 919 |
918 def iterkeys(self): | 920 def iterkeys(self): |
1050 | 1052 |
1051 def _copyfunc(s): | 1053 def _copyfunc(s): |
1052 self._load() | 1054 self._load() |
1053 s._lazydirs = { | 1055 s._lazydirs = { |
1054 d: (p, n, r, True) | 1056 d: (p, n, r, True) |
1055 for d, (p, n, r, c) in self._lazydirs.iteritems() | 1057 for d, (p, n, r, c) in pycompat.iteritems(self._lazydirs) |
1056 } | 1058 } |
1057 sdirs = s._dirs | 1059 sdirs = s._dirs |
1058 for d, v in self._dirs.iteritems(): | 1060 for d, v in pycompat.iteritems(self._dirs): |
1059 sdirs[d] = v.copy() | 1061 sdirs[d] = v.copy() |
1060 s._files = dict.copy(self._files) | 1062 s._files = dict.copy(self._files) |
1061 s._flags = dict.copy(self._flags) | 1063 s._flags = dict.copy(self._flags) |
1062 | 1064 |
1063 if self._loadfunc is _noop: | 1065 if self._loadfunc is _noop: |
1081 if t1._node == t2._node and not t1._dirty and not t2._dirty: | 1083 if t1._node == t2._node and not t1._dirty and not t2._dirty: |
1082 return | 1084 return |
1083 t1._load() | 1085 t1._load() |
1084 t2._load() | 1086 t2._load() |
1085 self._loaddifflazy(t1, t2) | 1087 self._loaddifflazy(t1, t2) |
1086 for d, m1 in t1._dirs.iteritems(): | 1088 for d, m1 in pycompat.iteritems(t1._dirs): |
1087 if d in t2._dirs: | 1089 if d in t2._dirs: |
1088 m2 = t2._dirs[d] | 1090 m2 = t2._dirs[d] |
1089 _filesnotin(m1, m2) | 1091 _filesnotin(m1, m2) |
1090 else: | 1092 else: |
1091 files.update(m1.iterkeys()) | 1093 files.update(m1.iterkeys()) |
1198 ret._files[fn] = self._files[fn] | 1200 ret._files[fn] = self._files[fn] |
1199 if fn in self._flags: | 1201 if fn in self._flags: |
1200 ret._flags[fn] = self._flags[fn] | 1202 ret._flags[fn] = self._flags[fn] |
1201 | 1203 |
1202 visit = self._loadchildrensetlazy(visit) | 1204 visit = self._loadchildrensetlazy(visit) |
1203 for dir, subm in self._dirs.iteritems(): | 1205 for dir, subm in pycompat.iteritems(self._dirs): |
1204 if visit and dir[:-1] not in visit: | 1206 if visit and dir[:-1] not in visit: |
1205 continue | 1207 continue |
1206 m = subm._matches(match) | 1208 m = subm._matches(match) |
1207 if not m._isempty(): | 1209 if not m._isempty(): |
1208 ret._dirs[dir] = m | 1210 ret._dirs[dir] = m |
1240 return | 1242 return |
1241 t1._load() | 1243 t1._load() |
1242 t2._load() | 1244 t2._load() |
1243 self._loaddifflazy(t1, t2) | 1245 self._loaddifflazy(t1, t2) |
1244 | 1246 |
1245 for d, m1 in t1._dirs.iteritems(): | 1247 for d, m1 in pycompat.iteritems(t1._dirs): |
1246 m2 = t2._dirs.get(d, emptytree) | 1248 m2 = t2._dirs.get(d, emptytree) |
1247 stack.append((m1, m2)) | 1249 stack.append((m1, m2)) |
1248 | 1250 |
1249 for d, m2 in t2._dirs.iteritems(): | 1251 for d, m2 in pycompat.iteritems(t2._dirs): |
1250 if d not in t1._dirs: | 1252 if d not in t1._dirs: |
1251 stack.append((emptytree, m2)) | 1253 stack.append((emptytree, m2)) |
1252 | 1254 |
1253 for fn, n1 in t1._files.iteritems(): | 1255 for fn, n1 in pycompat.iteritems(t1._files): |
1254 fl1 = t1._flags.get(fn, b'') | 1256 fl1 = t1._flags.get(fn, b'') |
1255 n2 = t2._files.get(fn, None) | 1257 n2 = t2._files.get(fn, None) |
1256 fl2 = t2._flags.get(fn, b'') | 1258 fl2 = t2._flags.get(fn, b'') |
1257 if n1 != n2 or fl1 != fl2: | 1259 if n1 != n2 or fl1 != fl2: |
1258 result[t1._subpath(fn)] = ((n1, fl1), (n2, fl2)) | 1260 result[t1._subpath(fn)] = ((n1, fl1), (n2, fl2)) |
1259 elif clean: | 1261 elif clean: |
1260 result[t1._subpath(fn)] = None | 1262 result[t1._subpath(fn)] = None |
1261 | 1263 |
1262 for fn, n2 in t2._files.iteritems(): | 1264 for fn, n2 in pycompat.iteritems(t2._files): |
1263 if fn not in t1._files: | 1265 if fn not in t1._files: |
1264 fl2 = t2._flags.get(fn, b'') | 1266 fl2 = t2._flags.get(fn, b'') |
1265 result[t2._subpath(fn)] = ((None, b''), (n2, fl2)) | 1267 result[t2._subpath(fn)] = ((None, b''), (n2, fl2)) |
1266 | 1268 |
1267 stackls = [] | 1269 stackls = [] |
1308 """Get the full data of this directory as a bytestring. Make sure that | 1310 """Get the full data of this directory as a bytestring. Make sure that |
1309 any submanifests have been written first, so their nodeids are correct. | 1311 any submanifests have been written first, so their nodeids are correct. |
1310 """ | 1312 """ |
1311 self._load() | 1313 self._load() |
1312 flags = self.flags | 1314 flags = self.flags |
1313 lazydirs = [(d[:-1], v[1], b't') for d, v in self._lazydirs.iteritems()] | 1315 lazydirs = [ |
1316 (d[:-1], v[1], b't') for d, v in pycompat.iteritems(self._lazydirs) | |
1317 ] | |
1314 dirs = [(d[:-1], self._dirs[d]._node, b't') for d in self._dirs] | 1318 dirs = [(d[:-1], self._dirs[d]._node, b't') for d in self._dirs] |
1315 files = [(f, self._files[f], flags(f)) for f in self._files] | 1319 files = [(f, self._files[f], flags(f)) for f in self._files] |
1316 return _text(sorted(dirs + files + lazydirs)) | 1320 return _text(sorted(dirs + files + lazydirs)) |
1317 | 1321 |
1318 def read(self, gettext, readsubtree): | 1322 def read(self, gettext, readsubtree): |
1337 # let's skip investigating things that `match` says we do not need. | 1341 # let's skip investigating things that `match` says we do not need. |
1338 visit = match.visitchildrenset(self._dir[:-1]) | 1342 visit = match.visitchildrenset(self._dir[:-1]) |
1339 visit = self._loadchildrensetlazy(visit) | 1343 visit = self._loadchildrensetlazy(visit) |
1340 if visit == b'this' or visit == b'all': | 1344 if visit == b'this' or visit == b'all': |
1341 visit = None | 1345 visit = None |
1342 for d, subm in self._dirs.iteritems(): | 1346 for d, subm in pycompat.iteritems(self._dirs): |
1343 if visit and d[:-1] not in visit: | 1347 if visit and d[:-1] not in visit: |
1344 continue | 1348 continue |
1345 subp1 = getnode(m1, d) | 1349 subp1 = getnode(m1, d) |
1346 subp2 = getnode(m2, d) | 1350 subp2 = getnode(m2, d) |
1347 if subp1 == nullid: | 1351 if subp1 == nullid: |
1360 yield self | 1364 yield self |
1361 | 1365 |
1362 self._load() | 1366 self._load() |
1363 # OPT: use visitchildrenset to avoid loading everything. | 1367 # OPT: use visitchildrenset to avoid loading everything. |
1364 self._loadalllazy() | 1368 self._loadalllazy() |
1365 for d, subm in self._dirs.iteritems(): | 1369 for d, subm in pycompat.iteritems(self._dirs): |
1366 for subtree in subm.walksubtrees(matcher=matcher): | 1370 for subtree in subm.walksubtrees(matcher=matcher): |
1367 yield subtree | 1371 yield subtree |
1368 | 1372 |
1369 | 1373 |
1370 class manifestfulltextcache(util.lrucachedict): | 1374 class manifestfulltextcache(util.lrucachedict): |
2142 # Need to perform a slow delta | 2146 # Need to perform a slow delta |
2143 r0 = store.deltaparent(store.rev(self._node)) | 2147 r0 = store.deltaparent(store.rev(self._node)) |
2144 m0 = self._manifestlog.get(self._dir, store.node(r0)).read() | 2148 m0 = self._manifestlog.get(self._dir, store.node(r0)).read() |
2145 m1 = self.read() | 2149 m1 = self.read() |
2146 md = treemanifest(dir=self._dir) | 2150 md = treemanifest(dir=self._dir) |
2147 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): | 2151 for f, ((n0, fl0), (n1, fl1)) in pycompat.iteritems(m0.diff(m1)): |
2148 if n1: | 2152 if n1: |
2149 md[f] = n1 | 2153 md[f] = n1 |
2150 if fl1: | 2154 if fl1: |
2151 md.setflag(f, fl1) | 2155 md.setflag(f, fl1) |
2152 return md | 2156 return md |