Patchwork [4,of,4] json: implement {fileannotate} template

login
register
mail settings
Submitter Gregory Szorc
Date April 11, 2015, 2:40 a.m.
Message ID <caabf8dd0c2c055059be.1428720043@gps-mbp.local>
Download mbox | patch
Permalink /patch/8606/
State Accepted
Commit 3ed315b13b7a2261c0364e562fe036cd2071f909
Headers show

Comments

Gregory Szorc - April 11, 2015, 2:40 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1428719860 14400
#      Fri Apr 10 22:37:40 2015 -0400
# Node ID caabf8dd0c2c055059be96269a4f79ea20b1e8de
# Parent  cb1e30a5c4f4c8ebd09afc617e160c5de0e10362
json: implement {fileannotate} template
Augie Fackler - April 11, 2015, 9:25 p.m.
On Fri, Apr 10, 2015 at 10:40:43PM -0400, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1428719860 14400
> #      Fri Apr 10 22:37:40 2015 -0400
> # Node ID caabf8dd0c2c055059be96269a4f79ea20b1e8de
> # Parent  cb1e30a5c4f4c8ebd09afc617e160c5de0e10362
> json: implement {fileannotate} template
>
> diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
> --- a/mercurial/templates/json/map
> +++ b/mercurial/templates/json/map
> @@ -133,9 +133,29 @@ comparisonline = '\{
>    "ll": {leftline|json},
>    "rn": {rightlineno|json},
>    "rl": {rightline|json}
>    }'
> -fileannotate = '"not yet implemented"'
> +fileannotate = '\{
> +  "abspath": {file|json},
> +  "node": {node|json},
> +  "author": {author|json},
> +  "date": {date|json},
> +  "desc": {desc|json},
> +  "parents": [{join(parent%changesetparent, ", ")}],
> +  "children": [{join(child%changesetparent, ", ")}],
> +  "permissions": {permissions|json},
> +  "annotate": [{join(annotate%fileannotation, ", ")}]
> +  }'
> +fileannotation = '\{
> +  "node": {node|json},
> +  "author": {author|json},
> +  "desc": {desc|json},
> +  "abspath": {file|json},
> +  "targetline": {targetline|json},
> +  "line": {line|json},
> +  "lineno": {lineno|json},

It seems somewhat redundant to have the line number when the lines
already end up in a list. Is there something I'm missing?

This is a small nit on an otherwise good series, so I'm going to queue
it and we can fix it in a followup.


> +  "revdate": {revdate|json}
> +  }'
>  filelog = '"not yet implemented"'
>  graph = '"not yet implemented"'
>  helptopics = '\{
>    "topics": [{join(topics%helptopicentry, ", ")}],
> diff --git a/tests/test-hgweb-json.t b/tests/test-hgweb-json.t
> --- a/tests/test-hgweb-json.t
> +++ b/tests/test-hgweb-json.t
> @@ -764,9 +764,38 @@ annotate/{revision}/{path} shows annotat
>
>    $ request json-annotate/f8bbb9024b10/foo
>    200 Script output follows
>
> -  "not yet implemented"
> +  {
> +    "abspath": "foo",
> +    "annotate": [
> +      {
> +        "abspath": "foo",
> +        "author": "test",
> +        "desc": "modify foo",
> +        "line": "bar\n",
> +        "lineno": 1,
> +        "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
> +        "revdate": [
> +          0.0,
> +          0
> +        ],
> +        "targetline": 1
> +      }
> +    ],
> +    "author": "test",
> +    "children": [],
> +    "date": [
> +      0.0,
> +      0
> +    ],
> +    "desc": "modify foo",
> +    "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
> +    "parents": [
> +      "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
> +    ],
> +    "permissions": ""
> +  }
>
>  filelog/{revision}/{path} shows history of a single file
>
>    $ request json-filelog/f8bbb9024b10/foo
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Gregory Szorc - April 12, 2015, 10:07 p.m.
On Sat, Apr 11, 2015 at 5:25 PM, Augie Fackler <raf@durin42.com> wrote:

> On Fri, Apr 10, 2015 at 10:40:43PM -0400, Gregory Szorc wrote:
> > # HG changeset patch
> > # User Gregory Szorc <gregory.szorc@gmail.com>
> > # Date 1428719860 14400
> > #      Fri Apr 10 22:37:40 2015 -0400
> > # Node ID caabf8dd0c2c055059be96269a4f79ea20b1e8de
> > # Parent  cb1e30a5c4f4c8ebd09afc617e160c5de0e10362
> > json: implement {fileannotate} template
> >
> > diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
> > --- a/mercurial/templates/json/map
> > +++ b/mercurial/templates/json/map
> > @@ -133,9 +133,29 @@ comparisonline = '\{
> >    "ll": {leftline|json},
> >    "rn": {rightlineno|json},
> >    "rl": {rightline|json}
> >    }'
> > -fileannotate = '"not yet implemented"'
> > +fileannotate = '\{
> > +  "abspath": {file|json},
> > +  "node": {node|json},
> > +  "author": {author|json},
> > +  "date": {date|json},
> > +  "desc": {desc|json},
> > +  "parents": [{join(parent%changesetparent, ", ")}],
> > +  "children": [{join(child%changesetparent, ", ")}],
> > +  "permissions": {permissions|json},
> > +  "annotate": [{join(annotate%fileannotation, ", ")}]
> > +  }'
> > +fileannotation = '\{
> > +  "node": {node|json},
> > +  "author": {author|json},
> > +  "desc": {desc|json},
> > +  "abspath": {file|json},
> > +  "targetline": {targetline|json},
> > +  "line": {line|json},
> > +  "lineno": {lineno|json},
>
> It seems somewhat redundant to have the line number when the lines
> already end up in a list. Is there something I'm missing?
>
> This is a small nit on an otherwise good series, so I'm going to queue
> it and we can fix it in a followup.
>
>
Yeah, it's redundant.

I could foresee someone adding a parameter to the blame API to limit what
lines are returned. At that time, line number would be required. So we
might as well throw it in to be consistent. Or we can always rip it out
since YAGNI applies and add it when necessary. I'd rather implement support
for start and end line to the web API :)

Patch

diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -133,9 +133,29 @@  comparisonline = '\{
   "ll": {leftline|json},
   "rn": {rightlineno|json},
   "rl": {rightline|json}
   }'
-fileannotate = '"not yet implemented"'
+fileannotate = '\{
+  "abspath": {file|json},
+  "node": {node|json},
+  "author": {author|json},
+  "date": {date|json},
+  "desc": {desc|json},
+  "parents": [{join(parent%changesetparent, ", ")}],
+  "children": [{join(child%changesetparent, ", ")}],
+  "permissions": {permissions|json},
+  "annotate": [{join(annotate%fileannotation, ", ")}]
+  }'
+fileannotation = '\{
+  "node": {node|json},
+  "author": {author|json},
+  "desc": {desc|json},
+  "abspath": {file|json},
+  "targetline": {targetline|json},
+  "line": {line|json},
+  "lineno": {lineno|json},
+  "revdate": {revdate|json}
+  }'
 filelog = '"not yet implemented"'
 graph = '"not yet implemented"'
 helptopics = '\{
   "topics": [{join(topics%helptopicentry, ", ")}],
diff --git a/tests/test-hgweb-json.t b/tests/test-hgweb-json.t
--- a/tests/test-hgweb-json.t
+++ b/tests/test-hgweb-json.t
@@ -764,9 +764,38 @@  annotate/{revision}/{path} shows annotat
 
   $ request json-annotate/f8bbb9024b10/foo
   200 Script output follows
   
-  "not yet implemented"
+  {
+    "abspath": "foo",
+    "annotate": [
+      {
+        "abspath": "foo",
+        "author": "test",
+        "desc": "modify foo",
+        "line": "bar\n",
+        "lineno": 1,
+        "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+        "revdate": [
+          0.0,
+          0
+        ],
+        "targetline": 1
+      }
+    ],
+    "author": "test",
+    "children": [],
+    "date": [
+      0.0,
+      0
+    ],
+    "desc": "modify foo",
+    "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+    "parents": [
+      "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+    ],
+    "permissions": ""
+  }
 
 filelog/{revision}/{path} shows history of a single file
 
   $ request json-filelog/f8bbb9024b10/foo