changeset 29677:69890b5dd32b

journal: use fm.formatlist() to pass hashes in appropriate type (BC)
author Yuya Nishihara <yuya@tcha.org>
date Sun, 31 Jul 2016 16:56:26 +0900
parents c3a9cd78b151
children 2f3f18ad55a2
files hgext/journal.py tests/test-journal.t
diffstat 2 files changed, 31 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/journal.py	Sun Jul 10 21:03:06 2016 +0900
+++ b/hgext/journal.py	Sun Jul 31 16:56:26 2016 +0900
@@ -475,8 +475,10 @@
     for count, entry in enumerate(repo.journal.filtered(name=name)):
         if count == limit:
             break
-        newhashesstr = ','.join([fm.hexfunc(hash) for hash in entry.newhashes])
-        oldhashesstr = ','.join([fm.hexfunc(hash) for hash in entry.oldhashes])
+        newhashesstr = fm.formatlist(map(fm.hexfunc, entry.newhashes),
+                                     name='node', sep=',')
+        oldhashesstr = fm.formatlist(map(fm.hexfunc, entry.oldhashes),
+                                     name='node', sep=',')
 
         fm.startitem()
         fm.condwrite(ui.verbose, 'oldhashes', '%s -> ', oldhashesstr)
--- a/tests/test-journal.t	Sun Jul 10 21:03:06 2016 +0900
+++ b/tests/test-journal.t	Sun Jul 31 16:56:26 2016 +0900
@@ -130,7 +130,7 @@
   cb9a9f314b8b  bar       book -f bar
   1e6c11564562  bar       book -r tip bar
 
-Test that verbose, JSON and commit output work
+Test that verbose, JSON, template and commit output work
 
   $ hg journal --verbose --all
   previous locations of the working copy and bookmarks:
@@ -148,35 +148,53 @@
     "command": "up",
     "date": "1970-01-01 00:00 +0000",
     "name": ".",
-    "newhashes": "1e6c11564562b4ed919baca798bc4338bd299d6a",
-    "oldhashes": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b",
+    "newhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
+    "oldhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
     "user": "foobar"
    },
    {
     "command": "up 0",
     "date": "1970-01-01 00:00 +0000",
     "name": ".",
-    "newhashes": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b",
-    "oldhashes": "1e6c11564562b4ed919baca798bc4338bd299d6a",
+    "newhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
+    "oldhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
     "user": "foobar"
    },
    {
     "command": "commit -Aqm b",
     "date": "1970-01-01 00:00 +0000",
     "name": ".",
-    "newhashes": "1e6c11564562b4ed919baca798bc4338bd299d6a",
-    "oldhashes": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b",
+    "newhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
+    "oldhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
     "user": "foobar"
    },
    {
     "command": "commit -Aqm a",
     "date": "1970-01-01 00:00 +0000",
     "name": ".",
-    "newhashes": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b",
-    "oldhashes": "0000000000000000000000000000000000000000",
+    "newhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
+    "oldhashes": ["0000000000000000000000000000000000000000"],
     "user": "foobar"
    }
   ]
+
+  $ cat <<EOF >> $HGRCPATH
+  > [templates]
+  > j = "{oldhashes % '{node|upper}'} -> {newhashes % '{node|upper}'}
+  >      - user: {user}
+  >      - command: {command}
+  >      - newhashes: {newhashes}
+  >      - oldhashes: {oldhashes}
+  >      "
+  > EOF
+  $ hg journal -Tj -l1
+  previous locations of '.':
+  CB9A9F314B8B07BA71012FCDBC544B5A4D82FF5B -> 1E6C11564562B4ED919BACA798BC4338BD299D6A
+  - user: foobar
+  - command: up
+  - newhashes: 1e6c11564562b4ed919baca798bc4338bd299d6a
+  - oldhashes: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
+
   $ hg journal --commit
   previous locations of '.':
   1e6c11564562  up