Patchwork D9158: templatekw: make {successorssets} always return a list (issue6342)

login
register
mail settings
Submitter phabricator
Date Oct. 6, 2020, 5:48 p.m.
Message ID <differential-rev-PHID-DREV-rs5cwaqpa7bs43g3zu4n-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47387/
State Superseded
Headers show

Comments

phabricator - Oct. 6, 2020, 5:48 p.m.
aayjaychan created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Previously, {successorssets} returns an empty string instead of an empty list
  for a non-obsolete changeset. The changing type of the JSON output makes it
  hard to consume from statically-typed languages.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9158

AFFECTED FILES
  mercurial/templatekw.py
  tests/test-obsmarker-template.t

CHANGE DETAILS




To: aayjaychan, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-obsmarker-template.t b/tests/test-obsmarker-template.t
--- a/tests/test-obsmarker-template.t
+++ b/tests/test-obsmarker-template.t
@@ -89,7 +89,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -105,7 +105,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  d004c8f274b9
@@ -176,7 +176,7 @@ 
   |    map: 2:a468dc9b36338b14fdb7825f55ce3df4e71517ad
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  a468dc9b3633
   |/     Predecessors:
   |      semi-colon:
@@ -192,7 +192,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  d004c8f274b9
@@ -211,7 +211,7 @@ 
   |    map: 2:a468dc9b36338b14fdb7825f55ce3df4e71517ad
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  a468dc9b3633
   |/     Predecessors: 1:471f378eab4c
   |      semi-colon: 1:471f378eab4c
@@ -235,7 +235,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog --hidden
   o  d004c8f274b9
@@ -259,7 +259,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -267,7 +267,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg tlog --hidden
   @  d004c8f274b9
@@ -277,7 +277,7 @@ 
   |    map: 2:a468dc9b36338b14fdb7825f55ce3df4e71517ad
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  a468dc9b3633
   |/     Predecessors: 1:471f378eab4c
   |      semi-colon: 1:471f378eab4c
@@ -301,7 +301,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   @  d004c8f274b9
@@ -501,7 +501,7 @@ 
   |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  337fec4d2edc
   |    Predecessors: 1:471597cad322
   |    semi-colon: 1:471597cad322
@@ -509,7 +509,7 @@ 
   |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  471597cad322
   |/     Predecessors:
   |      semi-colon:
@@ -525,7 +525,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  f257fde29c7a
@@ -549,7 +549,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  337fec4d2edc
   |    Predecessors:
   |    semi-colon:
@@ -557,7 +557,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -565,7 +565,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
 Predecessors template should show both predecessors as we force their display
 with --hidden
@@ -577,7 +577,7 @@ 
   |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  337fec4d2edc
   |    Predecessors: 1:471597cad322
   |    semi-colon: 1:471597cad322
@@ -585,7 +585,7 @@ 
   |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  471597cad322
   |/     Predecessors:
   |      semi-colon:
@@ -601,7 +601,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog --hidden
   @  f257fde29c7a
@@ -764,7 +764,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -780,7 +780,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  eb5a0daa2192
@@ -804,7 +804,7 @@ 
   |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  0dec01379d3b
   | |    Predecessors:
   | |    semi-colon:
@@ -828,7 +828,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  eb5a0daa2192
@@ -852,7 +852,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -860,7 +860,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 Predecessors template should show both predecessors as we force their display
 with --hidden
   $ hg tlog --hidden
@@ -871,7 +871,7 @@ 
   |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  0dec01379d3b
   | |    Predecessors:
   | |    semi-colon:
@@ -895,7 +895,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog --hidden
   @  eb5a0daa2192
@@ -1090,7 +1090,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | *  fdf9bde5129a
   |/     Predecessors: 1:471f378eab4c
   |      semi-colon: 1:471f378eab4c
@@ -1098,7 +1098,7 @@ 
   |      map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |      Successors:
   |      multi-line:
-  |      json: ""
+  |      json: []
   | @  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -1115,7 +1115,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
   $ hg fatelog
   *  019fadeab383
   |
@@ -1138,7 +1138,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  fdf9bde5129a
   |/     Predecessors:
   |      semi-colon:
@@ -1146,7 +1146,7 @@ 
   |      map:
   |      Successors:
   |      multi-line:
-  |      json: ""
+  |      json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -1154,7 +1154,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   *  019fadeab383
@@ -1173,7 +1173,7 @@ 
   |    map: 3:65b757b745b935093c87a2bccd877521cccffcbd
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  65b757b745b9
   |/     Predecessors: 1:471f378eab4c
   |      semi-colon: 1:471f378eab4c
@@ -1189,7 +1189,7 @@ 
   |      map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |      Successors:
   |      multi-line:
-  |      json: ""
+  |      json: []
   | x  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -1206,7 +1206,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog --hidden
   *  019fadeab383
@@ -1409,7 +1409,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -1425,7 +1425,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  eb5a0daa2192
@@ -1448,7 +1448,7 @@ 
   |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  0dec01379d3b
   | |    Predecessors:
   | |    semi-colon:
@@ -1472,7 +1472,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  eb5a0daa2192
@@ -1497,7 +1497,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874 3:b7ea6d14e664bdc8922221f7992631b50da3fb07
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  b7ea6d14e664
   | |    Predecessors:
   | |    semi-colon:
@@ -1521,7 +1521,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  eb5a0daa2192
@@ -1544,7 +1544,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -1552,7 +1552,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   @  eb5a0daa2192
@@ -1569,7 +1569,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874 3:b7ea6d14e664bdc8922221f7992631b50da3fb07
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  b7ea6d14e664
   | |    Predecessors: 2:0dec01379d3b
   | |    semi-colon: 2:0dec01379d3b
@@ -1601,7 +1601,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog --hidden
   @  eb5a0daa2192
@@ -1799,7 +1799,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -1815,7 +1815,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  7a230b46bf61
@@ -1836,7 +1836,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -1844,7 +1844,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   @  7a230b46bf61
@@ -1861,7 +1861,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -1877,7 +1877,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog --hidden
   @  7a230b46bf61
@@ -1970,7 +1970,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -1978,7 +1978,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   @  f897c6137566
@@ -1998,7 +1998,7 @@ 
   |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  0dec01379d3b
   | |    Predecessors: 1:471f378eab4c
   | |    semi-colon: 1:471f378eab4c
@@ -2023,7 +2023,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  f897c6137566
@@ -2045,7 +2045,7 @@ 
   |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  471f378eab4c
   |/     Predecessors:
   |      semi-colon:
@@ -2061,7 +2061,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  f897c6137566
@@ -2081,7 +2081,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   @  ea207398892e
        Predecessors:
        semi-colon:
@@ -2089,7 +2089,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   o  f897c6137566
@@ -2105,7 +2105,7 @@ 
   |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  0dec01379d3b
   | |    Predecessors: 1:471f378eab4c
   | |    semi-colon: 1:471f378eab4c
@@ -2130,7 +2130,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
 Check other fatelog implementations
 -----------------------------------
@@ -2365,7 +2365,7 @@ 
   |    map: 6:4a004186e63889f20cb16434fcbd72220bd1eace
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | *  b18bc8331526
   |/     Predecessors: 6:4a004186e638
   |      semi-colon: 6:4a004186e638
@@ -2373,7 +2373,7 @@ 
   |      map: 6:4a004186e63889f20cb16434fcbd72220bd1eace
   |      Successors:
   |      multi-line:
-  |      json: ""
+  |      json: []
   | *  ba2ed02b0c9a
   | |    Predecessors:
   | |    semi-colon:
@@ -2381,7 +2381,7 @@ 
   | |    map:
   | |    Successors:
   | |    multi-line:
-  | |    json: ""
+  | |    json: []
   | x  4a004186e638
   |/     Predecessors:
   |      semi-colon:
@@ -2398,7 +2398,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  f897c6137566
   |    Predecessors:
   |    semi-colon:
@@ -2406,7 +2406,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -2414,7 +2414,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
   $ hg fatelog
   @  0b997eb7ceee
   |
@@ -2438,7 +2438,7 @@ 
   |    map: 6:4a004186e63889f20cb16434fcbd72220bd1eace
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | *  b18bc8331526
   |/     Predecessors: 6:4a004186e638
   |      semi-colon: 6:4a004186e638
@@ -2446,7 +2446,7 @@ 
   |      map: 6:4a004186e63889f20cb16434fcbd72220bd1eace
   |      Successors:
   |      multi-line:
-  |      json: ""
+  |      json: []
   | *  ba2ed02b0c9a
   | |    Predecessors: 4:9bd10a0775e4
   | |    semi-colon: 4:9bd10a0775e4
@@ -2454,7 +2454,7 @@ 
   | |    map: 4:9bd10a0775e478708cada5f176ec6de654359ce7
   | |    Successors:
   | |    multi-line:
-  | |    json: ""
+  | |    json: []
   | x  4a004186e638
   |/     Predecessors: 4:9bd10a0775e4
   |      semi-colon: 4:9bd10a0775e4
@@ -2471,7 +2471,7 @@ 
   |    map: 4:9bd10a0775e478708cada5f176ec6de654359ce7
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  9bd10a0775e4
   |/     Predecessors:
   |      semi-colon:
@@ -2487,7 +2487,7 @@ 
   |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | x  0dec01379d3b
   | |    Predecessors: 1:471f378eab4c
   | |    semi-colon: 1:471f378eab4c
@@ -2512,7 +2512,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
   $ hg fatelog --hidden
   @  0b997eb7ceee
   |
@@ -2569,7 +2569,7 @@ 
   |    map: 4:9bd10a0775e478708cada5f176ec6de654359ce7
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | *  0b997eb7ceee
   | |    Predecessors: 4:9bd10a0775e4
   | |    semi-colon: 4:9bd10a0775e4
@@ -2577,7 +2577,7 @@ 
   | |    map: 4:9bd10a0775e478708cada5f176ec6de654359ce7
   | |    Successors:
   | |    multi-line:
-  | |    json: ""
+  | |    json: []
   * |  b18bc8331526
   |/     Predecessors: 4:9bd10a0775e4
   |      semi-colon: 4:9bd10a0775e4
@@ -2585,7 +2585,7 @@ 
   |      map: 4:9bd10a0775e478708cada5f176ec6de654359ce7
   |      Successors:
   |      multi-line:
-  |      json: ""
+  |      json: []
   *  dd800401bd8c
   |    Predecessors: 4:9bd10a0775e4
   |    semi-colon: 4:9bd10a0775e4
@@ -2593,7 +2593,7 @@ 
   |    map: 4:9bd10a0775e478708cada5f176ec6de654359ce7
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   | @  9bd10a0775e4
   |/     Predecessors:
   |      semi-colon:
@@ -2610,7 +2610,7 @@ 
   |    map:
   |    Successors:
   |    multi-line:
-  |    json: ""
+  |    json: []
   o  ea207398892e
        Predecessors:
        semi-colon:
@@ -2618,7 +2618,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
   $ hg fatelog
   *  eceed8f98ffc
@@ -2822,7 +2822,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
   $ hg fatelog
   @  471f378eab4c
   |    Obsfate: pruned by test (at 1970-01-01 00:00 +0000);
@@ -2875,7 +2875,7 @@ 
        map:
        Successors:
        multi-line:
-       json: ""
+       json: []
 
 # todo: the obsfate output is not ideal
   $ hg fatelog
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -712,21 +712,20 @@ 
     while also diverged into ctx3. (EXPERIMENTAL)"""
     repo = context.resource(mapping, b'repo')
     ctx = context.resource(mapping, b'ctx')
-    if not ctx.obsolete():
-        return b''
+    data = []
 
-    ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
-    ssets = [[hex(n) for n in ss] for ss in ssets]
+    if ctx.obsolete():
+        ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
+        ssets = [[hex(n) for n in ss] for ss in ssets]
 
-    data = []
-    for ss in ssets:
-        h = _hybrid(
-            None,
-            ss,
-            lambda x: {b'ctx': repo[x]},
-            lambda x: scmutil.formatchangeid(repo[x]),
-        )
-        data.append(h)
+        for ss in ssets:
+            h = _hybrid(
+                None,
+                ss,
+                lambda x: {b'ctx': repo[x]},
+                lambda x: scmutil.formatchangeid(repo[x]),
+            )
+            data.append(h)
 
     # Format the successorssets
     def render(d):