Patchwork hgweb: implement json-graph

login
register
mail settings
Submitter Anton Shestakov
Date Dec. 7, 2017, 10:02 a.m.
Message ID <4c48bb27dbf7473326b3.1512640955@neuro>
Download mbox | patch
Permalink /patch/25991/
State Accepted
Headers show

Comments

Anton Shestakov - Dec. 7, 2017, 10:02 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1512638309 -28800
#      Thu Dec 07 17:18:29 2017 +0800
# Node ID 4c48bb27dbf7473326b372c776bc1abc57a65d3d
# Parent  cb0df5a3affba6e8f1789de337230cbeecda9c5a
hgweb: implement json-graph

It's essentially a copy of json-log with graph-related things added (col, row,
color, edges).
Yuya Nishihara - Dec. 12, 2017, 1:57 p.m.
On Thu, 07 Dec 2017 18:02:35 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1512638309 -28800
> #      Thu Dec 07 17:18:29 2017 +0800
> # Node ID 4c48bb27dbf7473326b372c776bc1abc57a65d3d
> # Parent  cb0df5a3affba6e8f1789de337230cbeecda9c5a
> hgweb: implement json-graph
> 
> It's essentially a copy of json-log with graph-related things added (col, row,
> color, edges).

Seems fine. Queued, thanks.

Patch

diff --git a/contrib/wix/templates.wxs b/contrib/wix/templates.wxs
--- a/contrib/wix/templates.wxs
+++ b/contrib/wix/templates.wxs
@@ -42,6 +42,7 @@ 
         <Directory Id="templates.jsondir" Name="json">
           <Component Id="templates.json" Guid="$(var.templates.json.guid)" Win64='$(var.IsX64)'>
             <File Id="json.changelist.tmpl" Name="changelist.tmpl" KeyPath="yes" />
+            <File Id="json.graph.tmpl"      Name="graph.tmpl" />
             <File Id="json.map"             Name="map" />
           </Component>
         </Directory>
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -1277,7 +1277,7 @@  def graph(web, req, tmpl):
     return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount,
                 uprev=uprev,
                 lessvars=lessvars, morevars=morevars, downrev=downrev,
-                cols=cols, rows=rows,
+                cols=cols, rows=rows, changesets=count,
                 canvaswidth=(cols + 1) * bg_height,
                 truecanvasheight=rows * bg_height,
                 canvasheight=canvasheight, bg_height=bg_height,
diff --git a/mercurial/templates/json/graph.tmpl b/mercurial/templates/json/graph.tmpl
new file mode 100644
--- /dev/null
+++ b/mercurial/templates/json/graph.tmpl
@@ -0,0 +1,5 @@ 
+\{
+  "node": {node|json},
+  "changeset_count": {changesets|json},
+  "changesets": [{join(nodes%graphentry, ", ")}]
+}
diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -25,6 +25,7 @@  searchentry = '{changelistentry}'
 # number of entries.
 changelog = changelist.tmpl
 shortlog = changelist.tmpl
+graph = graph.tmpl
 changelistentry = '\{
   "node": {node|json},
   "date": {date|json},
@@ -37,6 +38,22 @@  changelistentry = '\{
   "parents": [{if(allparents, join(allparents%changesetparent, ", "),
                   join(parent%changesetparent, ", "))}]
   }'
+graphentry = '\{
+  "node": {node|json},
+  "date": {date|json},
+  "desc": {desc|utf8|json},
+  "branch": {if(branch, branch%changesetbranch, "default"|json)},
+  "bookmarks": [{join(bookmarks%changelistentryname, ", ")}],
+  "tags": [{join(tags%changelistentryname, ", ")}],
+  "user": {author|utf8|json},
+  "phase": {phase|json},
+  "col": {col|json},
+  "row": {row|json},
+  "color": {color|json},
+  "edges": {edges|json},
+  "parents": [{if(allparents, join(allparents%changesetparent, ", "),
+                  join(parent%changesetparent, ", "))}]
+  }'
 changelistentryname = '{name|utf8|json}'
 changeset = '\{
   "node": {node|json},
@@ -198,7 +215,6 @@  fileannotation = '\{
 filelog = '\{
   "entries": [{join(entries%changelistentry, ", ")}]
   }'
-graph = '"not yet implemented"'
 helptopics = '\{
   "topics": [{join(topics%helptopicentry, ", ")}],
   "earlycommands": [{join(earlycommands%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
@@ -1335,7 +1335,356 @@  graph/ shows information that can be use
   $ request json-graph
   200 Script output follows
   
-  "not yet implemented"
+  {
+    "changeset_count": 10,
+    "changesets": [
+      {
+        "bookmarks": [],
+        "branch": "default",
+        "col": 0,
+        "color": 1,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "merge test-branch into default",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7",
+        "parents": [
+          "ceed296fe500c3fac9541e31dad860cb49c89e45",
+          "ed66c30e87eb65337c05a4229efaa5f1d5285a90"
+        ],
+        "phase": "draft",
+        "row": 0,
+        "tags": [
+          "tip"
+        ],
+        "user": "test"
+      },
+      {
+        "bookmarks": [],
+        "branch": "test-branch",
+        "col": 1,
+        "color": 2,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "another commit in test-branch",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90",
+        "parents": [
+          "6ab967a8ab3489227a83f80e920faa039a71819f"
+        ],
+        "phase": "draft",
+        "row": 1,
+        "tags": [],
+        "user": "test"
+      },
+      {
+        "bookmarks": [],
+        "branch": "test-branch",
+        "col": 1,
+        "color": 2,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "create test branch",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "6ab967a8ab3489227a83f80e920faa039a71819f",
+        "parents": [
+          "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+        ],
+        "phase": "draft",
+        "row": 2,
+        "tags": [],
+        "user": "test"
+      },
+      {
+        "bookmarks": [
+          "bookmark2"
+        ],
+        "branch": "default",
+        "col": 0,
+        "color": 1,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "create tag2",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "ceed296fe500c3fac9541e31dad860cb49c89e45",
+        "parents": [
+          "f2890a05fea49bfaf9fb27ed5490894eba32da78"
+        ],
+        "phase": "draft",
+        "row": 3,
+        "tags": [],
+        "user": "test"
+      },
+      {
+        "bookmarks": [],
+        "branch": "default",
+        "col": 0,
+        "color": 1,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "another commit to da/foo",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78",
+        "parents": [
+          "93a8ce14f89156426b7fa981af8042da53f03aa0"
+        ],
+        "phase": "draft",
+        "row": 4,
+        "tags": [
+          "tag2"
+        ],
+        "user": "test"
+      },
+      {
+        "bookmarks": [],
+        "branch": "default",
+        "col": 0,
+        "color": 1,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "create tag",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "93a8ce14f89156426b7fa981af8042da53f03aa0",
+        "parents": [
+          "78896eb0e102174ce9278438a95e12543e4367a7"
+        ],
+        "phase": "public",
+        "row": 5,
+        "tags": [],
+        "user": "test"
+      },
+      {
+        "bookmarks": [],
+        "branch": "default",
+        "col": 0,
+        "color": 1,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "move foo",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "78896eb0e102174ce9278438a95e12543e4367a7",
+        "parents": [
+          "8d7c456572acf3557e8ed8a07286b10c408bcec5"
+        ],
+        "phase": "public",
+        "row": 6,
+        "tags": [
+          "tag1"
+        ],
+        "user": "test"
+      },
+      {
+        "bookmarks": [
+          "bookmark1"
+        ],
+        "branch": "default",
+        "col": 0,
+        "color": 1,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "modify da/foo",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 1,
+            "width": -1
+          }
+        ],
+        "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5",
+        "parents": [
+          "f8bbb9024b10f93cdbb8d940337398291d40dea8"
+        ],
+        "phase": "public",
+        "row": 7,
+        "tags": [],
+        "user": "test"
+      },
+      {
+        "bookmarks": [],
+        "branch": "default",
+        "col": 0,
+        "color": 1,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "modify foo",
+        "edges": [
+          {
+            "bcolor": "",
+            "col": 0,
+            "color": 1,
+            "nextcol": 0,
+            "width": -1
+          },
+          {
+            "bcolor": "",
+            "col": 1,
+            "color": 2,
+            "nextcol": 0,
+            "width": -1
+          }
+        ],
+        "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+        "parents": [
+          "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+        ],
+        "phase": "public",
+        "row": 8,
+        "tags": [],
+        "user": "test"
+      },
+      {
+        "bookmarks": [],
+        "branch": "default",
+        "col": 0,
+        "color": 2,
+        "date": [
+          0.0,
+          0
+        ],
+        "desc": "initial",
+        "edges": [],
+        "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e",
+        "parents": [],
+        "phase": "public",
+        "row": 9,
+        "tags": [],
+        "user": "test"
+      }
+    ],
+    "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7"
+  }
 
 help/ shows help topics