Patchwork [3,of,5] journal: use fm.formatlist() to pass hashes in appropriate type (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 3, 2016, 1:04 p.m.
Message ID <3afa71f0be6185b22ff5.1470229466@mimosa>
Download mbox | patch
Permalink /patch/16053/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 3, 2016, 1:04 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1469951786 -32400
#      Sun Jul 31 16:56:26 2016 +0900
# Node ID 3afa71f0be6185b22ff586718bbe0897e0eeb56e
# Parent  1b5145c36bacafb90f2efb686bc5993f0bdd1d9b
journal: use fm.formatlist() to pass hashes in appropriate type (BC)

Patch

diff --git a/hgext/journal.py b/hgext/journal.py
--- a/hgext/journal.py
+++ b/hgext/journal.py
@@ -475,8 +475,10 @@  def journal(ui, repo, *args, **opts):
     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)
diff --git a/tests/test-journal.t b/tests/test-journal.t
--- a/tests/test-journal.t
+++ b/tests/test-journal.t
@@ -130,7 +130,7 @@  Test that you can list all entries as we
   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 @@  Test that verbose, JSON and commit outpu
     "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