Mercurial > hg
annotate tests/test-hashutil.py @ 45121:b6269741ed42
config: add option to control creation of empty successors during rewrite
The default for many history-rewriting commands (e.g. rebase and absorb) is
that changesets which would become empty are not created in the target branch.
This makes sense if the source branch consists of small fix-up changes. For
more advanced workflows that make heavy use of history-editing to create
curated patch series, dropping empty changesets is not as important or even
undesirable.
Some users want to keep the meta-history, e.g. to make finding comments in a
code review tool easier or to avoid that divergent bookmarks are created. For
that, obsmarkers from the (to-be) empty changeset to the changeset(s) that
already made the changes should be added. If a to-be empty changeset is pruned
without a successor, adding the obsmarkers is hard because the changeset has to
be found within the hidden part of the history.
If rebasing in TortoiseHg, it’s easy to miss the fact that the to-be empty
changeset was pruned. An empty changeset will function as a reminder that
obsmarkers should be added.
Martin von Zweigbergk mentioned another advantage. Stripping the successor will
de-obsolete the predecessor. If no (empty) successor is created, this won’t be
possible.
In the future, we may want to consider other behaviors, like e.g. creating the
empty successor, but pruning it right away. Therefore this configuration
accepts 'skip' and 'keep' instead of being a boolean configuration.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Sat, 11 Jul 2020 23:53:27 +0200 |
parents | dc9b53482689 |
children | 6000f5b25c9b |
rev | line source |
---|---|
44058
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 # Tests to ensure that sha1dc.sha1 is exactly a drop-in for |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 # hashlib.sha1 for our needs. |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 from __future__ import absolute_import |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 import hashlib |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 import unittest |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 import silenttestrunner |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 try: |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 from mercurial.thirdparty import sha1dc |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 except ImportError: |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 sha1dc = None |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 class hashertestsbase(object): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 def test_basic_hash(self): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 h = self.hasher() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 h.update(b'foo') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', h.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 h.update(b'bar') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 '8843d7f92416211de9ebb963ff4ce28125932878', h.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 def test_copy_hasher(self): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 h = self.hasher() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 h.update(b'foo') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 h2 = h.copy() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 h.update(b'baz') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 h2.update(b'bar') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 '21eb6533733a5e4763acacd1d45a60c2e0e404e1', h.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 '8843d7f92416211de9ebb963ff4ce28125932878', h2.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 def test_init_hasher(self): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 h = self.hasher(b'initial string') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 b'\xc9y|n\x1f3S\xa4:\xbaJ\xca,\xc1\x1a\x9e\xb8\xd8\xdd\x86', |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 h.digest(), |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 |
44087
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
48 def test_bytes_like_types(self): |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
49 h = self.hasher() |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
50 h.update(bytearray(b'foo')) |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
51 h.update(memoryview(b'baz')) |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
52 self.assertEqual( |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
53 '21eb6533733a5e4763acacd1d45a60c2e0e404e1', h.hexdigest() |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
54 ) |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
55 |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
56 h = self.hasher(bytearray(b'foo')) |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
57 h.update(b'baz') |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
58 self.assertEqual( |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
59 '21eb6533733a5e4763acacd1d45a60c2e0e404e1', h.hexdigest() |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
60 ) |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
61 |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
62 h = self.hasher(memoryview(b'foo')) |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
63 h.update(b'baz') |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
64 self.assertEqual( |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
65 '21eb6533733a5e4763acacd1d45a60c2e0e404e1', h.hexdigest() |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
66 ) |
dc9b53482689
sha1dc: use buffer protocol when parsing arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44058
diff
changeset
|
67 |
44058
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
69 class hashlibtests(unittest.TestCase, hashertestsbase): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
70 hasher = hashlib.sha1 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 if sha1dc: |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 class sha1dctests(unittest.TestCase, hashertestsbase): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
76 hasher = sha1dc.sha1 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
77 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 if __name__ == '__main__': |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 silenttestrunner.main(__name__) |