Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 22785:abc44fcc9c57
revlog: move references to revlog.hash to inside the revlog class
This will make it possible for subclasses to have different hashing
schemes when appropriate. I anticipate using this in manifests.
Note that there's still one client of mercurial.revlog.hash() outside
of revlog: mercurial.context.memctx uses it to construct the file
entries in an in-memory manifest. I don't think this will be a problem
in the immediate future, so I've left it as-is.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 24 Sep 2014 15:14:44 -0400 |
parents | 0f4e655136ef |
children | 8a096d4d0862 |
comparison
equal
deleted
inserted
replaced
22784:0f4e655136ef | 22785:abc44fcc9c57 |
---|---|
1034 text = self._checkhash(text, node, rev) | 1034 text = self._checkhash(text, node, rev) |
1035 | 1035 |
1036 self._cache = (node, rev, text) | 1036 self._cache = (node, rev, text) |
1037 return text | 1037 return text |
1038 | 1038 |
1039 def hash(self, text, p1, p2): | |
1040 """Compute a node hash. | |
1041 | |
1042 Available as a function so that subclasses can replace the hash | |
1043 as needed. | |
1044 """ | |
1045 return hash(text, p1, p2) | |
1046 | |
1039 def _checkhash(self, text, node, rev): | 1047 def _checkhash(self, text, node, rev): |
1040 p1, p2 = self.parents(node) | 1048 p1, p2 = self.parents(node) |
1041 self.checkhash(text, p1, p2, node, rev) | 1049 self.checkhash(text, p1, p2, node, rev) |
1042 return text | 1050 return text |
1043 | 1051 |
1044 def checkhash(self, text, p1, p2, node, rev=None): | 1052 def checkhash(self, text, p1, p2, node, rev=None): |
1045 if node != hash(text, p1, p2): | 1053 if node != self.hash(text, p1, p2): |
1046 revornode = rev | 1054 revornode = rev |
1047 if revornode is None: | 1055 if revornode is None: |
1048 revornode = templatefilters.short(hex(node)) | 1056 revornode = templatefilters.short(hex(node)) |
1049 raise RevlogError(_("integrity check failed on %s:%s") | 1057 raise RevlogError(_("integrity check failed on %s:%s") |
1050 % (self.indexfile, revornode)) | 1058 % (self.indexfile, revornode)) |
1102 use different hashing method (and override checkhash() in such case) | 1110 use different hashing method (and override checkhash() in such case) |
1103 """ | 1111 """ |
1104 if link == nullrev: | 1112 if link == nullrev: |
1105 raise RevlogError(_("attempted to add linkrev -1 to %s") | 1113 raise RevlogError(_("attempted to add linkrev -1 to %s") |
1106 % self.indexfile) | 1114 % self.indexfile) |
1107 node = node or hash(text, p1, p2) | 1115 node = node or self.hash(text, p1, p2) |
1108 if node in self.nodemap: | 1116 if node in self.nodemap: |
1109 return node | 1117 return node |
1110 | 1118 |
1111 dfh = None | 1119 dfh = None |
1112 if not self._inline: | 1120 if not self._inline: |