changeset 4825:3cf94964c56b

hg log: Move filtering implicit parents to own method and use it in templater. Extended test repo in test-command-template to contain changeset to test this.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sun, 08 Jul 2007 12:52:08 +0200
parents f3f84d5cd268
children 15efc1d06143
files mercurial/cmdutil.py tests/test-command-template tests/test-command-template.out
diffstat 3 files changed, 91 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sun Jul 08 10:43:57 2007 +0200
+++ b/mercurial/cmdutil.py	Sun Jul 08 12:52:08 2007 +0200
@@ -758,14 +758,8 @@
 
         hexfunc = self.ui.debugflag and hex or short
 
-        parents = log.parentrevs(rev)
-        if not self.ui.debugflag:
-            if parents[1] == nullrev:
-                if parents[0] >= rev - 1:
-                    parents = []
-                else:
-                    parents = [parents[0]]
-        parents = [(p, hexfunc(log.node(p))) for p in parents]
+        parents = [(p, hexfunc(log.node(p)))
+                   for p in self._meaningful_parentrevs(log, rev)]
 
         self.ui.write(_("changeset:   %d:%s\n") % (rev, hexfunc(changenode)))
 
@@ -823,6 +817,22 @@
                        opts=patch.diffopts(self.ui))
             self.ui.write("\n")
 
+    def _meaningful_parentrevs(self, log, rev):
+        """Return list of meaningful (or all if debug) parentrevs for rev.
+
+        For merges (two non-nullrev revisions) both parents are meaningful.
+        Otherwise the first parent revision is considered meaningful if it
+        is not the preceding revision.
+        """
+        parents = log.parentrevs(rev)
+        if not self.ui.debugflag and parents[1] == nullrev:
+            if parents[0] >= rev - 1:
+                parents = []
+            else:
+                parents = [parents[0]]
+        return parents
+
+
 class changeset_templater(changeset_printer):
     '''format changeset information.'''
 
@@ -919,12 +929,8 @@
                 return showlist('branch', [branch], plural='branches', **args)
 
         def showparents(**args):
-            parents = [[('rev', log.rev(p)), ('node', hex(p))]
-                       for p in log.parents(changenode)
-                       if self.ui.debugflag or p != nullid]
-            if (not self.ui.debugflag and len(parents) == 1 and
-                parents[0][0][1] == rev - 1):
-                return
+            parents = [[('rev', p), ('node', hex(log.node(p)))]
+                       for p in self._meaningful_parentrevs(log, rev)]
             return showlist('parent', parents, **args)
 
         def showtags(**args):
--- a/tests/test-command-template	Sun Jul 08 10:43:57 2007 +0200
+++ b/tests/test-command-template	Sun Jul 08 12:52:08 2007 +0200
@@ -25,6 +25,11 @@
 hg commit -m 'new head' -d '1500000 0' -u 'person'
 hg merge -q
 hg commit -m 'merge' -d '1500001 0' -u 'person'
+# second branch starting at nullrev
+hg update null
+echo second > second
+hg add second
+hg commit -m second -d '1000000 0' -u 'User Name <user@hostname>'
 
 # make sure user/global hgrc does not affect tests
 echo '[ui]' > .hg/hgrc
--- a/tests/test-command-template.out	Sun Jul 08 10:43:57 2007 +0200
+++ b/tests/test-command-template.out	Sun Jul 08 12:52:08 2007 +0200
@@ -1,3 +1,4 @@
+0 files updated, 0 files merged, 4 files removed, 0 files unresolved
 # default style is like normal output
 #  normal
 #  verbose
@@ -5,7 +6,10 @@
 # revision with no copies (used to print a traceback)
 
 # compact style works
-6[tip]:5,4   c7b487c6c50e   1970-01-18 08:40 +0000   person
+7[tip]:-1   29114dbae42b   1970-01-12 13:46 +0000   user
+  second
+
+6:5,4   c7b487c6c50e   1970-01-18 08:40 +0000   person
   merge
 
 5:3   13207e5a10d9   1970-01-18 08:40 +0000   person
@@ -26,7 +30,10 @@
 0   1e4e1b8f71e0   1970-01-12 13:46 +0000   user
   line 1
 
-6[tip]:5,4   c7b487c6c50e   1970-01-18 08:40 +0000   person
+7[tip]:-1   29114dbae42b   1970-01-12 13:46 +0000   user
+  second
+
+6:5,4   c7b487c6c50e   1970-01-18 08:40 +0000   person
   merge
 
 5:3   13207e5a10d9   1970-01-18 08:40 +0000   person
@@ -47,7 +54,10 @@
 0   1e4e1b8f71e0   1970-01-12 13:46 +0000   user
   line 1
 
-6[tip]:5,4   c7b487c6c50e   1970-01-18 08:40 +0000   person
+7[tip]:-1,-1   29114dbae42b   1970-01-12 13:46 +0000   user
+  second
+
+6:5,4   c7b487c6c50e   1970-01-18 08:40 +0000   person
   merge
 
 5:3,-1   13207e5a10d9   1970-01-18 08:40 +0000   person
@@ -77,6 +87,7 @@
 # error if include fails
 abort: template file ./q: Permission denied
 # include works
+7
 6
 5
 4
@@ -85,6 +96,7 @@
 1
 0
 # ui.style works
+7
 6
 5
 4
@@ -93,10 +105,16 @@
 1
 0
 # issue338
+1970-01-12  User Name  <user@hostname>
+
+	* second:
+	second
+	[29114dbae42b] [tip]
+
 1970-01-18  person  <person>
 
 	* merge
-	[c7b487c6c50e] [tip]
+	[c7b487c6c50e]
 
 	* d:
 	new head
@@ -134,6 +152,7 @@
 	[1e4e1b8f71e0]
 
 # keys work
+author: User Name <user@hostname>
 author: person
 author: person
 author: person
@@ -141,6 +160,7 @@
 author: other@place
 author: A. N. Other <other@place>
 author: User Name <user@hostname>
+author--verbose: User Name <user@hostname>
 author--verbose: person
 author--verbose: person
 author--verbose: person
@@ -148,6 +168,7 @@
 author--verbose: other@place
 author--verbose: A. N. Other <other@place>
 author--verbose: User Name <user@hostname>
+author--debug: User Name <user@hostname>
 author--debug: person
 author--debug: person
 author--debug: person
@@ -157,6 +178,7 @@
 author--debug: User Name <user@hostname>
 branches: 
 branches: 
+branches: 
 branches: foo
 branches: 
 branches: 
@@ -164,6 +186,7 @@
 branches: 
 branches--verbose: 
 branches--verbose: 
+branches--verbose: 
 branches--verbose: foo
 branches--verbose: 
 branches--verbose: 
@@ -171,11 +194,13 @@
 branches--verbose: 
 branches--debug: 
 branches--debug: 
+branches--debug: 
 branches--debug: foo
 branches--debug: 
 branches--debug: 
 branches--debug: 
 branches--debug: 
+date: 1000000.00
 date: 1500001.00
 date: 1500000.00
 date: 1400000.00
@@ -183,6 +208,7 @@
 date: 1200000.00
 date: 1100000.00
 date: 1000000.00
+date--verbose: 1000000.00
 date--verbose: 1500001.00
 date--verbose: 1500000.00
 date--verbose: 1400000.00
@@ -190,6 +216,7 @@
 date--verbose: 1200000.00
 date--verbose: 1100000.00
 date--verbose: 1000000.00
+date--debug: 1000000.00
 date--debug: 1500001.00
 date--debug: 1500000.00
 date--debug: 1400000.00
@@ -197,6 +224,7 @@
 date--debug: 1200000.00
 date--debug: 1100000.00
 date--debug: 1000000.00
+desc: second
 desc: merge
 desc: new head
 desc: new branch
@@ -208,6 +236,7 @@
 other 3
 desc: line 1
 line 2
+desc--verbose: second
 desc--verbose: merge
 desc--verbose: new head
 desc--verbose: new branch
@@ -219,6 +248,7 @@
 other 3
 desc--verbose: line 1
 line 2
+desc--debug: second
 desc--debug: merge
 desc--debug: new head
 desc--debug: new branch
@@ -237,6 +267,8 @@
 file_adds: 
 file_adds: 
 file_adds: 
+file_adds: 
+file_adds--verbose: 
 file_adds--verbose: 
 file_adds--verbose: 
 file_adds--verbose: 
@@ -244,6 +276,7 @@
 file_adds--verbose: 
 file_adds--verbose: 
 file_adds--verbose: 
+file_adds--debug: second
 file_adds--debug: 
 file_adds--debug: d
 file_adds--debug: 
@@ -258,6 +291,7 @@
 file_dels: 
 file_dels: 
 file_dels: 
+file_dels: 
 file_dels--verbose: 
 file_dels--verbose: 
 file_dels--verbose: 
@@ -265,6 +299,8 @@
 file_dels--verbose: 
 file_dels--verbose: 
 file_dels--verbose: 
+file_dels--verbose: 
+file_dels--debug: 
 file_dels--debug: 
 file_dels--debug: 
 file_dels--debug: 
@@ -272,6 +308,7 @@
 file_dels--debug: 
 file_dels--debug: 
 file_dels--debug: 
+files: second
 files: 
 files: d
 files: 
@@ -279,6 +316,7 @@
 files: c
 files: b
 files: a
+files--verbose: second
 files--verbose: 
 files--verbose: d
 files--verbose: 
@@ -289,6 +327,7 @@
 files--debug: 
 files--debug: 
 files--debug: 
+files--debug: 
 files--debug: c
 files--debug: 
 files--debug: 
@@ -300,6 +339,7 @@
 manifest: 
 manifest: 
 manifest: 
+manifest: 
 manifest--verbose: 
 manifest--verbose: 
 manifest--verbose: 
@@ -307,6 +347,8 @@
 manifest--verbose: 
 manifest--verbose: 
 manifest--verbose: 
+manifest--verbose: 
+manifest--debug: 7:f2dbc354b94e5ec0b4f10680ee0cee816101d0bf
 manifest--debug: 6:91015e9dbdd76a6791085d12b0a0ec7fcd22ffbf
 manifest--debug: 5:4dc3def4f9b4c6e8de820f6ee74737f91e96a216
 manifest--debug: 4:90ae8dda64e1a876c792bccb9af66284f6018363
@@ -314,6 +356,7 @@
 manifest--debug: 2:6e0e82995c35d0d57a52aca8da4e56139e06b4b1
 manifest--debug: 1:4e8d705b1e53e3f9375e0e60dc7b525d8211fe55
 manifest--debug: 0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0
+node: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
 node: c7b487c6c50ef1cf464cafdc4f4f5e615fc5999f
 node: 13207e5a10d9fd28ec424934298e176197f2c67f
 node: 32a18f097fcccf76ef282f62f8a85b3adf8d13c4
@@ -321,6 +364,7 @@
 node: 97054abb4ab824450e9164180baf491ae0078465
 node: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
 node: 1e4e1b8f71e05681d422154f5421e385fec3454f
+node--verbose: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
 node--verbose: c7b487c6c50ef1cf464cafdc4f4f5e615fc5999f
 node--verbose: 13207e5a10d9fd28ec424934298e176197f2c67f
 node--verbose: 32a18f097fcccf76ef282f62f8a85b3adf8d13c4
@@ -328,6 +372,7 @@
 node--verbose: 97054abb4ab824450e9164180baf491ae0078465
 node--verbose: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
 node--verbose: 1e4e1b8f71e05681d422154f5421e385fec3454f
+node--debug: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
 node--debug: c7b487c6c50ef1cf464cafdc4f4f5e615fc5999f
 node--debug: 13207e5a10d9fd28ec424934298e176197f2c67f
 node--debug: 32a18f097fcccf76ef282f62f8a85b3adf8d13c4
@@ -335,6 +380,7 @@
 node--debug: 97054abb4ab824450e9164180baf491ae0078465
 node--debug: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
 node--debug: 1e4e1b8f71e05681d422154f5421e385fec3454f
+parents: -1:000000000000 
 parents: 5:13207e5a10d9 4:32a18f097fcc 
 parents: 3:10e46f2dcbf4 
 parents: 
@@ -342,6 +388,7 @@
 parents: 
 parents: 
 parents: 
+parents--verbose: -1:000000000000 
 parents--verbose: 5:13207e5a10d9 4:32a18f097fcc 
 parents--verbose: 3:10e46f2dcbf4 
 parents--verbose: 
@@ -349,6 +396,7 @@
 parents--verbose: 
 parents--verbose: 
 parents--verbose: 
+parents--debug: -1:0000000000000000000000000000000000000000 -1:0000000000000000000000000000000000000000 
 parents--debug: 5:13207e5a10d9fd28ec424934298e176197f2c67f 4:32a18f097fcccf76ef282f62f8a85b3adf8d13c4 
 parents--debug: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47 -1:0000000000000000000000000000000000000000 
 parents--debug: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47 -1:0000000000000000000000000000000000000000 
@@ -356,6 +404,7 @@
 parents--debug: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965 -1:0000000000000000000000000000000000000000 
 parents--debug: 0:1e4e1b8f71e05681d422154f5421e385fec3454f -1:0000000000000000000000000000000000000000 
 parents--debug: -1:0000000000000000000000000000000000000000 -1:0000000000000000000000000000000000000000 
+rev: 7
 rev: 6
 rev: 5
 rev: 4
@@ -363,6 +412,7 @@
 rev: 2
 rev: 1
 rev: 0
+rev--verbose: 7
 rev--verbose: 6
 rev--verbose: 5
 rev--verbose: 4
@@ -370,6 +420,7 @@
 rev--verbose: 2
 rev--verbose: 1
 rev--verbose: 0
+rev--debug: 7
 rev--debug: 6
 rev--debug: 5
 rev--debug: 4
@@ -384,6 +435,7 @@
 tags: 
 tags: 
 tags: 
+tags: 
 tags--verbose: tip
 tags--verbose: 
 tags--verbose: 
@@ -391,6 +443,7 @@
 tags--verbose: 
 tags--verbose: 
 tags--verbose: 
+tags--verbose: 
 tags--debug: tip
 tags--debug: 
 tags--debug: 
@@ -398,7 +451,9 @@
 tags--debug: 
 tags--debug: 
 tags--debug: 
+tags--debug: 
 # filters work
+hostname
 
 
 
@@ -406,6 +461,7 @@
 place
 place
 hostname
+User Name
 person
 person
 person
@@ -413,6 +469,7 @@
 other
 A. N. Other
 User Name
+user
 person
 person
 person
@@ -420,6 +477,7 @@
 other
 other
 user
+Mon Jan 12 13:46:40 1970 +0000
 Sun Jan 18 08:40:01 1970 +0000
 Sun Jan 18 08:40:00 1970 +0000
 Sat Jan 17 04:53:20 1970 +0000
@@ -427,6 +485,7 @@
 Wed Jan 14 21:20:00 1970 +0000
 Tue Jan 13 17:33:20 1970 +0000
 Mon Jan 12 13:46:40 1970 +0000
+1970-01-12 13:46 +0000
 1970-01-18 08:40 +0000
 1970-01-18 08:40 +0000
 1970-01-17 04:53 +0000
@@ -434,6 +493,7 @@
 1970-01-14 21:20 +0000
 1970-01-13 17:33 +0000
 1970-01-12 13:46 +0000
+Mon, 12 Jan 1970 13:46:40 +0000
 Sun, 18 Jan 1970 08:40:01 +0000
 Sun, 18 Jan 1970 08:40:00 +0000
 Sat, 17 Jan 1970 04:53:20 +0000
@@ -441,6 +501,7 @@
 Wed, 14 Jan 1970 21:20:00 +0000
 Tue, 13 Jan 1970 17:33:20 +0000
 Mon, 12 Jan 1970 13:46:40 +0000
+second
 merge
 new head
 new branch
@@ -448,6 +509,7 @@
 no person
 other 1
 line 1
+29114dbae42b
 c7b487c6c50e
 13207e5a10d9
 32a18f097fcc