Mercurial > hg
annotate tests/test-push-validation.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 | ef60083b5536 |
children | 2a03a365f645 |
rev | line source |
---|---|
12279 | 1 $ hg init test |
2 $ cd test | |
3 | |
4 $ cat > .hg/hgrc <<EOF | |
5 > [server] | |
6 > validate=1 | |
7 > EOF | |
8 | |
9 $ echo alpha > alpha | |
10 $ echo beta > beta | |
11 $ hg addr | |
12 adding alpha | |
13 adding beta | |
14 $ hg ci -m 1 | |
15 | |
16 $ cd .. | |
17 $ hg clone test test-clone | |
18 updating to branch default | |
19 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
20 | |
18422
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
21 Test spurious filelog entries: |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
22 |
12279 | 23 $ cd test-clone |
18422
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
24 $ echo blah >> beta |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
25 $ cp .hg/store/data/beta.i tmp1 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
26 $ hg ci -m 2 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
27 $ cp .hg/store/data/beta.i tmp2 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
28 $ hg -q rollback |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
29 $ mv tmp2 .hg/store/data/beta.i |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
30 $ echo blah >> beta |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
31 $ hg ci -m '2 (corrupt)' |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
32 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
33 Expected to fail: |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
34 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
35 $ hg verify |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
36 checking changesets |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
37 checking manifests |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
38 crosschecking files in changesets and manifests |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
39 checking files |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
40 beta@1: dddc47b3ba30 not in manifests |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
41 2 files, 2 changesets, 4 total revisions |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
42 1 integrity errors encountered! |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
43 (first damaged changeset appears to be 1) |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
44 [1] |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
45 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
46 $ hg push |
18506
ef60083b5536
tests: fix for windows - slashes and no serve
Mads Kiilerich <madski@unity3d.com>
parents:
18422
diff
changeset
|
47 pushing to $TESTTMP/test (glob) |
18422
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
48 searching for changes |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
49 adding changesets |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
50 adding manifests |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
51 adding file changes |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
52 transaction abort! |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
53 rollback completed |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
54 abort: received spurious file revlog entry |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
55 [255] |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
56 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
57 $ hg -q rollback |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
58 $ mv tmp1 .hg/store/data/beta.i |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
59 $ echo beta > beta |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
60 |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
61 Test missing filelog entries: |
f009804e2a43
validate: check for spurious incoming filelog entries
Sune Foldager <cryo@cyanite.org>
parents:
16913
diff
changeset
|
62 |
12279 | 63 $ cp .hg/store/data/beta.i tmp |
64 $ echo blah >> beta | |
65 $ hg ci -m '2 (corrupt)' | |
66 $ mv tmp .hg/store/data/beta.i | |
10418
5fc090ba08a6
localrepo: add optional validation (defaults to off) for incoming changes
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
67 |
12279 | 68 Expected to fail: |
69 | |
70 $ hg verify | |
71 checking changesets | |
72 checking manifests | |
73 crosschecking files in changesets and manifests | |
74 checking files | |
75 beta@1: dddc47b3ba30 in manifests not found | |
76 2 files, 2 changesets, 2 total revisions | |
77 1 integrity errors encountered! | |
78 (first damaged changeset appears to be 1) | |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12279
diff
changeset
|
79 [1] |
10418
5fc090ba08a6
localrepo: add optional validation (defaults to off) for incoming changes
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
80 |
12279 | 81 $ hg push |
15447
9910f60a37ee
tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents:
12640
diff
changeset
|
82 pushing to $TESTTMP/test (glob) |
12279 | 83 searching for changes |
84 adding changesets | |
85 adding manifests | |
86 adding file changes | |
87 transaction abort! | |
88 rollback completed | |
89 abort: missing file data for beta:dddc47b3ba30e54484720ce0f4f768a0f4b6efb9 - run hg verify | |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12279
diff
changeset
|
90 [255] |
12279 | 91 |
16913
f2719b387380
tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents:
15447
diff
changeset
|
92 $ cd .. |