annotate tests/test-lrucachedict.py @ 27372:a79cba6cb206

help: add documentation for changegroup formats There is no formal location for spec-like technical/internal docs. The repository makes sense as such a location because spec-like documentation should be reviewed (ruling out a wiki). mpm has also stated that he would like this documentation to be part of the built-in help system. So, we establish an "internals" sub-directory to hold this class of documentation. The format of changegroups does not appear to be documented anywhere, even in source code. It therefore seemed like an appropriate first thing to document. This patch adds low-level documentation of versions 1 and 2 of the changegroup foromat. It currently only describes the raw data format. There is probably room to write higher-level documentation on strategies for producing and consuming the data. We'll leave that for another day. The added file is not yet accessible via `hg help` nor via hgweb. Support for this will follow in subsequent patches.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 25 Oct 2015 00:19:45 +0100
parents 45d996a566d7
children 6cd3044985c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18603
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
1 from mercurial import util
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
2
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
3 def printifpresent(d, xs):
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
4 for x in xs:
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
5 present = x in d
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
6 print "'%s' in d: %s" % (x, present)
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
7 if present:
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
8 print "d['%s']: %s" % (x, d[x])
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
9
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
10 def test_lrucachedict():
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
11 d = util.lrucachedict(4)
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
12 d['a'] = 'va'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
13 d['b'] = 'vb'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
14 d['c'] = 'vc'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
15 d['d'] = 'vd'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
16
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
17 # all of these should be present
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
18 printifpresent(d, ['a', 'b', 'c', 'd'])
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
19
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
20 # 'a' should be dropped because it was least recently used
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
21 d['e'] = 've'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
22 printifpresent(d, ['a', 'b', 'c', 'd', 'e'])
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
23
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
24 # touch entries in some order (get or set).
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
25 d['e']
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
26 d['c'] = 'vc2'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
27 d['d']
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
28 d['b'] = 'vb2'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
29
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
30 # 'e' should be dropped now
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
31 d['f'] = 'vf'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
32 printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
33
19710
887ffa22fd0d lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents: 18603
diff changeset
34 d.clear()
887ffa22fd0d lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents: 18603
diff changeset
35 printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
887ffa22fd0d lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents: 18603
diff changeset
36
27371
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
37 # Now test dicts that aren't full.
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
38 d = util.lrucachedict(4)
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
39 d['a'] = 1
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
40 d['b'] = 2
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
41 d['a']
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
42 d['b']
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
43 printifpresent(d, ['a', 'b'])
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
44
18603
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
45 if __name__ == '__main__':
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
46 test_lrucachedict()