equal
deleted
inserted
replaced
|
1 # storageutil.py - Storage functionality agnostic of backend implementation. |
|
2 # |
|
3 # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> |
|
4 # |
|
5 # This software may be used and distributed according to the terms of the |
|
6 # GNU General Public License version 2 or any later version. |
|
7 |
|
8 from __future__ import absolute_import |
|
9 |
|
10 import hashlib |
|
11 |
|
12 from ..node import ( |
|
13 nullid, |
|
14 ) |
|
15 |
|
16 _nullhash = hashlib.sha1(nullid) |
|
17 |
|
18 def hashrevisionsha1(text, p1, p2): |
|
19 """Compute the SHA-1 for revision data and its parents. |
|
20 |
|
21 This hash combines both the current file contents and its history |
|
22 in a manner that makes it easy to distinguish nodes with the same |
|
23 content in the revision graph. |
|
24 """ |
|
25 # As of now, if one of the parent node is null, p2 is null |
|
26 if p2 == nullid: |
|
27 # deep copy of a hash is faster than creating one |
|
28 s = _nullhash.copy() |
|
29 s.update(p1) |
|
30 else: |
|
31 # none of the parent nodes are nullid |
|
32 if p1 < p2: |
|
33 a = p1 |
|
34 b = p2 |
|
35 else: |
|
36 a = p2 |
|
37 b = p1 |
|
38 s = hashlib.sha1(a) |
|
39 s.update(b) |
|
40 s.update(text) |
|
41 return s.digest() |