comparison mercurial/context.py @ 30360:0298a07f64d9

dirstate: change placeholder hash length to 20 bytes Previously the new-node placeholder hash for manifests generated from the dirstate was a 21byte long string of "!" characters. Normal hashes are only 20 bytes long. This makes it complicated to implement more efficient manifest implementations which rely on the hashes being fixed length. Let's change this hash to just be 20 bytes long, and rely on the astronomical improbability of an actual hash being 20 "!" bytes in a row (just like we rely on no hash ever being the nullid). A future diff will do this for added and modified dirstate markers as well, so we're putting the new newnodeid in node.py so there's a common place for these placeholders.
author Durham Goode <durham@fb.com>
date Thu, 10 Nov 2016 02:17:22 -0800
parents 362f6f651b2e
children 1070df141718
comparison
equal deleted inserted replaced
30359:673f0fdc1046 30360:0298a07f64d9
14 14
15 from .i18n import _ 15 from .i18n import _
16 from .node import ( 16 from .node import (
17 bin, 17 bin,
18 hex, 18 hex,
19 newnodeid,
19 nullid, 20 nullid,
20 nullrev, 21 nullrev,
21 short, 22 short,
22 wdirid, 23 wdirid,
23 ) 24 )
37 util, 38 util,
38 ) 39 )
39 40
40 propertycache = util.propertycache 41 propertycache = util.propertycache
41 42
42 # Phony node value to stand-in for new files in some uses of
43 # manifests. Manifests support 21-byte hashes for nodes which are
44 # dirty in the working copy.
45 _newnode = '!' * 21
46
47 nonascii = re.compile(r'[^\x21-\x7f]').search 43 nonascii = re.compile(r'[^\x21-\x7f]').search
48 44
49 class basectx(object): 45 class basectx(object):
50 """A basectx object represents the common logic for its children: 46 """A basectx object represents the common logic for its children:
51 changectx: read-only context that is already present in the repo, 47 changectx: read-only context that is already present in the repo,
140 added.append(fn) 136 added.append(fn)
141 elif node2 is None: 137 elif node2 is None:
142 removed.append(fn) 138 removed.append(fn)
143 elif flag1 != flag2: 139 elif flag1 != flag2:
144 modified.append(fn) 140 modified.append(fn)
145 elif node2 != _newnode: 141 elif node2 != newnodeid:
146 # When comparing files between two commits, we save time by 142 # When comparing files between two commits, we save time by
147 # not comparing the file contents when the nodeids differ. 143 # not comparing the file contents when the nodeids differ.
148 # Note that this means we incorrectly report a reverted change 144 # Note that this means we incorrectly report a reverted change
149 # to a file as a modification. 145 # to a file as a modification.
150 modified.append(fn) 146 modified.append(fn)
1585 which means this function is comparing with a non-parent; therefore we 1581 which means this function is comparing with a non-parent; therefore we
1586 need to build a manifest and return what matches. 1582 need to build a manifest and return what matches.
1587 """ 1583 """
1588 mf = self._repo['.']._manifestmatches(match, s) 1584 mf = self._repo['.']._manifestmatches(match, s)
1589 for f in s.modified + s.added: 1585 for f in s.modified + s.added:
1590 mf[f] = _newnode 1586 mf[f] = newnodeid
1591 mf.setflag(f, self.flags(f)) 1587 mf.setflag(f, self.flags(f))
1592 for f in s.removed: 1588 for f in s.removed:
1593 if f in mf: 1589 if f in mf:
1594 del mf[f] 1590 del mf[f]
1595 return mf 1591 return mf