annotate tests/test-relink.t @ 24545:9e0c67e84896

json: implement {tags} template Tags is pretty easy to implement. Let's start there. The output is slightly different from `hg tags -Tjson`. For reference, the CLI has the following output: [ { "node": "e2049974f9a23176c2addb61d8f5b86e0d620490", "rev": 29880, "tag": "tip", "type": "" }, ... ] Our output has the format: { "node": "0aeb19ea57a6d223bacddda3871cb78f24b06510", "tags": [ { "node": "e2049974f9a23176c2addb61d8f5b86e0d620490", "tag": "tag1", "date": [1427775457.0, 25200] }, ... ] } "rev" is omitted because it isn't a reliable identifier. We shouldn't be exposing them in web APIs and giving the impression it remotely resembles a stable identifier. Perhaps we could one day hide this behind a config option (it might be useful to expose when running servers locally). The "type" of the tag isn't defined because this information isn't yet exposed to the hgweb templater (it could be in a follow-up) and because it is questionable whether different types should be exposed at all. (Should the web interface really be exposing "local" tags?) We use an object for the outer type instead of Array for a few reasons. First, it is extensible. If we ever need to throw more global properties into the output, we can do that without breaking backwards compatibility (property additions should be backwards compatible). Second, uniformity in web APIs is nice. Having everything return objects seems much saner than a mix of array and object. Third, there are security issues with arrays in older browsers. The JSON web services world almost never uses arrays as the main type for this reason. Another possibly controversial part about this patch is how dates are defined. While JSON has a Date type, it is based on the JavaScript Date type, which is widely considered a pile of garbage. It is a non-starter for this reason. Many of Mercurial's built-in date filters drop seconds resolution. So that's a non-starter as well, since we want the API to be lossless where possible. rfc3339date, rfc822date, isodatesec, and date are all lossless. However, they each require the client to perform string parsing on top of JSON decoding. While date parsing libraries are pretty ubiquitous, some languages don't have them out of the box. However, pretty much every programming language can deal with UNIX timestamps (which are just integers or floats). So, we choose to use Mercurial's internal date representation, which in JSON is modeled as float seconds since UNIX epoch and an integer timezone offset from UTC (keep in mind JavaScript/JSON models all "Numbers" as double prevision floating point numbers, so there isn't a difference between ints and floats in JSON).
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 31 Mar 2015 14:52:21 -0700
parents 6cc1f388ac80
children bd625cd4e5e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22046
7a9cbb315d84 tests: replace exit 80 with #require
Matt Mackall <mpm@selenic.com>
parents: 16971
diff changeset
1 #require hardlink
16971
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16350
diff changeset
2
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
3 $ echo "[extensions]" >> $HGRCPATH
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
4 $ echo "relink=" >> $HGRCPATH
10217
2bbb4c8eb27e Add test for relink extension
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
5
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
6 $ fix_path() {
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
7 > tr '\\' /
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
8 > }
10217
2bbb4c8eb27e Add test for relink extension
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
9
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
10 $ cat > arelinked.py <<EOF
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
11 > import sys, os
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
12 > from mercurial import util
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
13 > path1, path2 = sys.argv[1:3]
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
14 > if util.samefile(path1, path2):
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
15 > print '%s == %s' % (path1, path2)
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
16 > else:
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
17 > print '%s != %s' % (path1, path2)
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
18 > EOF
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
19
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
20
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
21 create source repository
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 10217
diff changeset
22
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
23 $ hg init repo
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
24 $ cd repo
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
25 $ echo a > a
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
26 $ echo b > b
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
27 $ hg ci -Am addfile
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
28 adding a
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
29 adding b
16350
4f795f5fbb0b tests: make tests work if directory contains special characters
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15447
diff changeset
30 $ cat "$TESTDIR/binfile.bin" >> a
4f795f5fbb0b tests: make tests work if directory contains special characters
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15447
diff changeset
31 $ cat "$TESTDIR/binfile.bin" >> b
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
32 $ hg ci -Am changefiles
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
33
13656
0e200e1801f4 relink: format reclaimed byte count nicely
Martin Geisler <mg@lazybytes.net>
parents: 13655
diff changeset
34 make another commit to create files larger than 1 KB to test
0e200e1801f4 relink: format reclaimed byte count nicely
Martin Geisler <mg@lazybytes.net>
parents: 13655
diff changeset
35 formatting of final byte count
0e200e1801f4 relink: format reclaimed byte count nicely
Martin Geisler <mg@lazybytes.net>
parents: 13655
diff changeset
36
16350
4f795f5fbb0b tests: make tests work if directory contains special characters
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15447
diff changeset
37 $ cat "$TESTDIR/binfile.bin" >> a
4f795f5fbb0b tests: make tests work if directory contains special characters
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15447
diff changeset
38 $ cat "$TESTDIR/binfile.bin" >> b
13656
0e200e1801f4 relink: format reclaimed byte count nicely
Martin Geisler <mg@lazybytes.net>
parents: 13655
diff changeset
39 $ hg ci -m anotherchange
0e200e1801f4 relink: format reclaimed byte count nicely
Martin Geisler <mg@lazybytes.net>
parents: 13655
diff changeset
40
13657
b69102740e57 relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents: 12847
diff changeset
41 don't sit forever trying to double-lock the source repo
b69102740e57 relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents: 12847
diff changeset
42
b69102740e57 relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents: 12847
diff changeset
43 $ hg relink .
15447
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 13659
diff changeset
44 relinking $TESTTMP/repo/.hg/store to $TESTTMP/repo/.hg/store (glob)
13657
b69102740e57 relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents: 12847
diff changeset
45 there is nothing to relink
b69102740e57 relink: avoid trying to lock the same repo twice
Martin Geisler <mg@lazybytes.net>
parents: 12847
diff changeset
46
13659
a73f38d8bbdb merge with stable
Martin Geisler <mg@lazybytes.net>
parents: 13656 13657
diff changeset
47
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
48 Test files are read in binary mode
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
49
22947
c63a09b6b337 tests: use $PYTHON instead of hardcoding python
Augie Fackler <raf@durin42.com>
parents: 22046
diff changeset
50 $ $PYTHON -c "file('.hg/store/data/dummy.i', 'wb').write('a\r\nb\n')"
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
51 $ cd ..
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
52
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
53
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
54 clone and pull to break links
10217
2bbb4c8eb27e Add test for relink extension
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
55
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
56 $ hg clone --pull -r0 repo clone
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
57 adding changesets
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
58 adding manifests
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
59 adding file changes
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
60 added 1 changesets with 2 changes to 2 files
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
61 updating to branch default
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
62 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
63 $ cd clone
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
64 $ hg pull -q
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
65 $ echo b >> b
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
66 $ hg ci -m changeb
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
67 created new head
22947
c63a09b6b337 tests: use $PYTHON instead of hardcoding python
Augie Fackler <raf@durin42.com>
parents: 22046
diff changeset
68 $ $PYTHON -c "file('.hg/store/data/dummy.i', 'wb').write('a\nb\r\n')"
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
69
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
70
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
71 relink
10217
2bbb4c8eb27e Add test for relink extension
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
72
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
73 $ hg relink --debug | fix_path
12640
6cc4b14fb76b tests: remove redundant globs
Mads Kiilerich <mads@kiilerich.com>
parents: 12376
diff changeset
74 relinking $TESTTMP/repo/.hg/store to $TESTTMP/clone/.hg/store
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
75 tip has 2 files, estimated total number of files: 3
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
76 collecting: 00changelog.i 1/3 files (33.33%)
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
77 collecting: 00manifest.i 2/3 files (66.67%)
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
78 collecting: a.i 3/3 files (100.00%)
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
79 collecting: b.i 4/3 files (133.33%)
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
80 collecting: dummy.i 5/3 files (166.67%)
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
81 collected 5 candidate storage files
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
82 not linkable: 00changelog.i
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
83 not linkable: 00manifest.i
12744
0793d763e413 progress: dropping superfluous space from units
timeless <timeless@gmail.com>
parents: 12640
diff changeset
84 pruning: data/a.i 3/5 files (60.00%)
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
85 not linkable: data/b.i
12744
0793d763e413 progress: dropping superfluous space from units
timeless <timeless@gmail.com>
parents: 12640
diff changeset
86 pruning: data/dummy.i 5/5 files (100.00%)
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
87 pruned down to 2 probably relinkable files
12744
0793d763e413 progress: dropping superfluous space from units
timeless <timeless@gmail.com>
parents: 12640
diff changeset
88 relinking: data/a.i 1/2 files (50.00%)
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
89 not linkable: data/dummy.i
23285
6cc1f388ac80 revlog: store fulltext when compressed delta is bigger than it
Siddharth Agarwal <sid0@fb.com>
parents: 22947
diff changeset
90 relinked 1 files (1.36 KB reclaimed)
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
91 $ cd ..
10217
2bbb4c8eb27e Add test for relink extension
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
92
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
93
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
94 check hardlinks
10217
2bbb4c8eb27e Add test for relink extension
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
95
12115
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
96 $ python arelinked.py repo/.hg/store/data/a.i clone/.hg/store/data/a.i
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
97 repo/.hg/store/data/a.i == clone/.hg/store/data/a.i
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
98 $ python arelinked.py repo/.hg/store/data/b.i clone/.hg/store/data/b.i
a0dcbcbd1590 tests: unify test-relink
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10218
diff changeset
99 repo/.hg/store/data/b.i != clone/.hg/store/data/b.i
10217
2bbb4c8eb27e Add test for relink extension
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
100