Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlog.py @ 39882:f8eb71f9e3bd
storageutil: new module for storage primitives (API)
There will exist common code between storage backends. It would
be nice to have a central place to put that code.
This commit attempts to create that place by creating the
"storageutil" module.
The first thing we move is revlog.hash(), which is the function for
computing the SHA-1 hash of revision fulltext and parents.
Differential Revision: https://phab.mercurial-scm.org/D4753
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 24 Sep 2018 14:23:54 -0700 |
parents | 733db72f0f54 |
children | 3e896b51aa5d |
line wrap: on
line diff
--- a/mercurial/revlog.py Mon Sep 24 13:35:50 2018 -0700 +++ b/mercurial/revlog.py Mon Sep 24 14:23:54 2018 -0700 @@ -16,7 +16,6 @@ import collections import contextlib import errno -import hashlib import os import re import struct @@ -74,6 +73,7 @@ ) from .utils import ( interfaceutil, + storageutil, stringutil, ) @@ -197,33 +197,6 @@ raise ValueError('unknown revlog index flags') return int(int(offset) << 16 | type) -_nullhash = hashlib.sha1(nullid) - -def hash(text, p1, p2): - """generate a hash from the given text and its parent hashes - - This hash combines both the current file contents and its history - in a manner that makes it easy to distinguish nodes with the same - content in the revision graph. - """ - # As of now, if one of the parent node is null, p2 is null - if p2 == nullid: - # deep copy of a hash is faster than creating one - s = _nullhash.copy() - s.update(p1) - else: - # none of the parent nodes are nullid - if p1 < p2: - a = p1 - b = p2 - else: - a = p2 - b = p1 - s = hashlib.sha1(a) - s.update(b) - s.update(text) - return s.digest() - @attr.s(slots=True, frozen=True) class _revisioninfo(object): """Information about a revision that allows building its fulltext @@ -1383,7 +1356,7 @@ returns True if text is different than what is stored. """ p1, p2 = self.parents(node) - return hash(text, p1, p2) != node + return storageutil.hashrevisionsha1(text, p1, p2) != node def _cachesegment(self, offset, data): """Add a segment to the revlog cache. @@ -1672,7 +1645,7 @@ Available as a function so that subclasses can replace the hash as needed. """ - return hash(text, p1, p2) + return storageutil.hashrevisionsha1(text, p1, p2) def _processflags(self, text, flags, operation, raw=False): """Inspect revision data flags and applies transforms defined by