Mercurial > hg
annotate tests/test-http-branchmap.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 | 7a9cbb315d84 |
children | 4d2b9b304ad0 |
rev | line source |
---|---|
22046
7a9cbb315d84
tests: replace exit 80 with #require
Matt Mackall <mpm@selenic.com>
parents:
17467
diff
changeset
|
1 #require killdaemons |
9879
7bb004fc14ec
Extend test-branchmap to test c51494c53841
Thomas Arendsen Hein <thomas@intevation.de>
parents:
9789
diff
changeset
|
2 |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
3 $ hgserve() { |
17467
448d0c452140
test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
15623
diff
changeset
|
4 > hg serve -a localhost -p $HGPORT1 -d --pid-file=hg.pid \ |
448d0c452140
test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
15623
diff
changeset
|
5 > -E errors.log -v $@ > startup.log |
448d0c452140
test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
15623
diff
changeset
|
6 > # Grepping hg serve stdout would hang on Windows |
448d0c452140
test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
15623
diff
changeset
|
7 > grep -v 'listening at' startup.log |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
8 > cat hg.pid >> "$DAEMON_PIDS" |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
9 > } |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
10 $ hg init a |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
11 $ hg --encoding utf-8 -R a branch æ |
12942
05fffd665170
tests: use (esc) for all non-ASCII test output
Mads Kiilerich <mads@kiilerich.com>
parents:
12700
diff
changeset
|
12 marked working directory as branch \xc3\xa6 (esc) |
15615 | 13 (branches are permanent and global, did you want a bookmark?) |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
14 $ echo foo > a/foo |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
15 $ hg -R a ci -Am foo |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
16 adding foo |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
17 $ hgserve -R a --config web.push_ssl=False --config web.allow_push=* --encoding latin1 |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
18 $ hg --encoding utf-8 clone http://localhost:$HGPORT1 b |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
19 requesting all changes |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
20 adding changesets |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
21 adding manifests |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
22 adding file changes |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
23 added 1 changesets with 1 changes to 1 files |
12942
05fffd665170
tests: use (esc) for all non-ASCII test output
Mads Kiilerich <mads@kiilerich.com>
parents:
12700
diff
changeset
|
24 updating to branch \xc3\xa6 (esc) |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
25 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
26 $ hg --encoding utf-8 -R b log |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
27 changeset: 0:867c11ce77b8 |
12942
05fffd665170
tests: use (esc) for all non-ASCII test output
Mads Kiilerich <mads@kiilerich.com>
parents:
12700
diff
changeset
|
28 branch: \xc3\xa6 (esc) |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
29 tag: tip |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
30 user: test |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
31 date: Thu Jan 01 00:00:00 1970 +0000 |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
32 summary: foo |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
33 |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
34 $ echo bar >> b/foo |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
35 $ hg -R b ci -m bar |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
36 $ hg --encoding utf-8 -R b push |
13815
d066d8d652c8
url: add trailing slashes to URLs with hostnames that don't have one
Brodie Rao <brodie@bitheap.org>
parents:
12942
diff
changeset
|
37 pushing to http://localhost:$HGPORT1/ |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
38 searching for changes |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
39 remote: adding changesets |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
40 remote: adding manifests |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
41 remote: adding file changes |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
42 remote: added 1 changesets with 1 changes to 1 files |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
43 $ hg -R a --encoding utf-8 log |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
44 changeset: 1:58e7c90d67cb |
12942
05fffd665170
tests: use (esc) for all non-ASCII test output
Mads Kiilerich <mads@kiilerich.com>
parents:
12700
diff
changeset
|
45 branch: \xc3\xa6 (esc) |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
46 tag: tip |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
47 user: test |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
48 date: Thu Jan 01 00:00:00 1970 +0000 |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
49 summary: bar |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
50 |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
51 changeset: 0:867c11ce77b8 |
12942
05fffd665170
tests: use (esc) for all non-ASCII test output
Mads Kiilerich <mads@kiilerich.com>
parents:
12700
diff
changeset
|
52 branch: \xc3\xa6 (esc) |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
53 user: test |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
54 date: Thu Jan 01 00:00:00 1970 +0000 |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
55 summary: foo |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
56 |
17467
448d0c452140
test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
15623
diff
changeset
|
57 $ "$TESTDIR/killdaemons.py" hg.pid |
9879
7bb004fc14ec
Extend test-branchmap to test c51494c53841
Thomas Arendsen Hein <thomas@intevation.de>
parents:
9789
diff
changeset
|
58 |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
59 verify 7e7d56fe4833 (encoding fallback in branchmap to maintain compatibility with 1.3.x) |
9879
7bb004fc14ec
Extend test-branchmap to test c51494c53841
Thomas Arendsen Hein <thomas@intevation.de>
parents:
9789
diff
changeset
|
60 |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
61 $ cat <<EOF > oldhg |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
62 > import sys |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
63 > from mercurial import ui, hg, commands |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
64 > |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
65 > class StdoutWrapper(object): |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
66 > def __init__(self, stdout): |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
67 > self._file = stdout |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
68 > |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
69 > def write(self, data): |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
70 > if data == '47\n': |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
71 > # latin1 encoding is one %xx (3 bytes) shorter |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
72 > data = '44\n' |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
73 > elif data.startswith('%C3%A6 '): |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
74 > # translate to latin1 encoding |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
75 > data = '%%E6 %s' % data[7:] |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
76 > self._file.write(data) |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
77 > |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
78 > def __getattr__(self, name): |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
79 > return getattr(self._file, name) |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
80 > |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
81 > sys.stdout = StdoutWrapper(sys.stdout) |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
82 > sys.stderr = StdoutWrapper(sys.stderr) |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
83 > |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
84 > myui = ui.ui() |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
85 > repo = hg.repository(myui, 'a') |
14647
2e9f379de0ac
serve: add --cmdserver option to communicate with hg over a pipe
Idan Kamara <idankk86@gmail.com>
parents:
13815
diff
changeset
|
86 > commands.serve(myui, repo, stdio=True, cmdserver=False) |
12447
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
87 > EOF |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
88 $ echo baz >> b/foo |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
89 $ hg -R b ci -m baz |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
90 $ hg push -R b -e 'python oldhg' ssh://dummy/ --encoding latin1 |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
91 pushing to ssh://dummy/ |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
92 searching for changes |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
93 remote: adding changesets |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
94 remote: adding manifests |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
95 remote: adding file changes |
f5f90d3808e2
tests: unify test-http-branchmap
Matt Mackall <mpm@selenic.com>
parents:
11617
diff
changeset
|
96 remote: added 1 changesets with 1 changes to 1 files |