[PATCH] hgweb: add parents to json-log (issue5074)

Anton Shestakov av6 at dwimlabs.net
Thu Mar 31 11:40:25 UTC 2016


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1459418949 -28800
#      Thu Mar 31 18:09:09 2016 +0800
# Node ID d3b8071f35d78aded26801a169e9a3d250909b34
# Parent  ff0d3b6b287f89594bd8d0308fe2810d2a18ea01
hgweb: add parents to json-log (issue5074)

Entries prepared in webutil.changelistentry() skip showing parents in the
trivial case when there's only one parent and it's the previous revision. This
doesn't work well for the json-log template, which is supposed to just dump raw
data in an easy-to-parse format, so let's provide all parents as another
keyword: allparents.

Using a lambda function here means that the performance of templates that don't
use allparents won't be affected (see 41957e50e109).

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -341,6 +341,7 @@ def changelistentry(web, ctx, tmpl):
 
     entry = commonentry(repo, ctx)
     entry.update(
+        allparents=lambda **x: parents(ctx),
         parent=lambda **x: parents(ctx, rev - 1),
         child=lambda **x: children(ctx, rev + 1),
         changelogtag=showtags,
diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -11,7 +11,8 @@ changelistentry = '\{
   "desc": {desc|utf8|json},
   "bookmarks": [{join(bookmarks%changelistentryname, ", ")}],
   "tags": [{join(tags%changelistentryname, ", ")}],
-  "user": {author|utf8|json}
+  "user": {author|utf8|json},
+  "parents": [{join(allparents%changesetparent, ", ")}]
   }'
 changelistentryname = '{name|utf8|json}'
 changeset = '\{
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
@@ -175,6 +175,10 @@ changelog/ shows information about sever
         ],
         "desc": "merge test-branch into default",
         "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7",
+        "parents": [
+          "ceed296fe500c3fac9541e31dad860cb49c89e45",
+          "ed66c30e87eb65337c05a4229efaa5f1d5285a90"
+        ],
         "tags": [
           "tip"
         ],
@@ -188,6 +192,9 @@ changelog/ shows information about sever
         ],
         "desc": "another commit in test-branch",
         "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90",
+        "parents": [
+          "6ab967a8ab3489227a83f80e920faa039a71819f"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -199,6 +206,9 @@ changelog/ shows information about sever
         ],
         "desc": "create test branch",
         "node": "6ab967a8ab3489227a83f80e920faa039a71819f",
+        "parents": [
+          "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -212,6 +222,9 @@ changelog/ shows information about sever
         ],
         "desc": "create tag2",
         "node": "ceed296fe500c3fac9541e31dad860cb49c89e45",
+        "parents": [
+          "f2890a05fea49bfaf9fb27ed5490894eba32da78"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -223,6 +236,9 @@ changelog/ shows information about sever
         ],
         "desc": "another commit to da/foo",
         "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78",
+        "parents": [
+          "93a8ce14f89156426b7fa981af8042da53f03aa0"
+        ],
         "tags": [
           "tag2"
         ],
@@ -236,6 +252,9 @@ changelog/ shows information about sever
         ],
         "desc": "create tag",
         "node": "93a8ce14f89156426b7fa981af8042da53f03aa0",
+        "parents": [
+          "78896eb0e102174ce9278438a95e12543e4367a7"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -247,6 +266,9 @@ changelog/ shows information about sever
         ],
         "desc": "move foo",
         "node": "78896eb0e102174ce9278438a95e12543e4367a7",
+        "parents": [
+          "8d7c456572acf3557e8ed8a07286b10c408bcec5"
+        ],
         "tags": [
           "tag1"
         ],
@@ -262,6 +284,9 @@ changelog/ shows information about sever
         ],
         "desc": "modify da/foo",
         "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5",
+        "parents": [
+          "f8bbb9024b10f93cdbb8d940337398291d40dea8"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -273,6 +298,9 @@ changelog/ shows information about sever
         ],
         "desc": "modify foo",
         "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+        "parents": [
+          "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -284,6 +312,7 @@ changelog/ shows information about sever
         ],
         "desc": "initial",
         "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e",
+        "parents": [],
         "tags": [],
         "user": "test"
       }
@@ -307,6 +336,9 @@ changelog/{revision} shows information s
         ],
         "desc": "modify foo",
         "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+        "parents": [
+          "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -318,6 +350,7 @@ changelog/{revision} shows information s
         ],
         "desc": "initial",
         "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e",
+        "parents": [],
         "tags": [],
         "user": "test"
       }
@@ -341,6 +374,10 @@ shortlog/ shows information about a set 
         ],
         "desc": "merge test-branch into default",
         "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7",
+        "parents": [
+          "ceed296fe500c3fac9541e31dad860cb49c89e45",
+          "ed66c30e87eb65337c05a4229efaa5f1d5285a90"
+        ],
         "tags": [
           "tip"
         ],
@@ -354,6 +391,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "another commit in test-branch",
         "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90",
+        "parents": [
+          "6ab967a8ab3489227a83f80e920faa039a71819f"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -365,6 +405,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "create test branch",
         "node": "6ab967a8ab3489227a83f80e920faa039a71819f",
+        "parents": [
+          "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -378,6 +421,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "create tag2",
         "node": "ceed296fe500c3fac9541e31dad860cb49c89e45",
+        "parents": [
+          "f2890a05fea49bfaf9fb27ed5490894eba32da78"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -389,6 +435,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "another commit to da/foo",
         "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78",
+        "parents": [
+          "93a8ce14f89156426b7fa981af8042da53f03aa0"
+        ],
         "tags": [
           "tag2"
         ],
@@ -402,6 +451,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "create tag",
         "node": "93a8ce14f89156426b7fa981af8042da53f03aa0",
+        "parents": [
+          "78896eb0e102174ce9278438a95e12543e4367a7"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -413,6 +465,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "move foo",
         "node": "78896eb0e102174ce9278438a95e12543e4367a7",
+        "parents": [
+          "8d7c456572acf3557e8ed8a07286b10c408bcec5"
+        ],
         "tags": [
           "tag1"
         ],
@@ -428,6 +483,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "modify da/foo",
         "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5",
+        "parents": [
+          "f8bbb9024b10f93cdbb8d940337398291d40dea8"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -439,6 +497,9 @@ shortlog/ shows information about a set 
         ],
         "desc": "modify foo",
         "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+        "parents": [
+          "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+        ],
         "tags": [],
         "user": "test"
       },
@@ -450,6 +511,7 @@ shortlog/ shows information about a set 
         ],
         "desc": "initial",
         "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e",
+        "parents": [],
         "tags": [],
         "user": "test"
       }


More information about the Mercurial-devel mailing list