Add an option to the command 'hg log' in order to show merges only

Goffredo Baroncelli kreijack at inwind.it
Fri Jul 1 13:09:28 CDT 2005


Hi,

the patch below add an option ( -m ) to the command 'hg log' in order to show merges only;

Matt, in your TODO you say that a merge have two parents or parent != changeset-1; ok
for the first clauses, but parent != changeset-1 happens also in a pull from 
another repository; so my patch checks only the number of parents.

examples:

$ python hg log | head -20
changeset:   559:bf9d55ed67f6e43b880c00b775964b59449ff952
tag:         tip
user:        mpm at selenic.com
date:        Fri Jul  1 19:04:50 2005
summary:     [PATCH] hg clone stored path fix

changeset:   558:0ceea19182a9da6ed9f25e13207e58a7c0b55420
user:        mpm at selenic.com
date:        Fri Jul  1 19:01:07 2005
summary:     transaction: __del__ should do nothing if the journal already exists

changeset:   557:b9fee419a1bdbb8edae6982d49172344067897ec
user:        mpm at selenic.com
date:        Fri Jul  1 18:54:52 2005
summary:     recover: the journal is named 'journal'

changeset:   556:f6c6fa15ff706c79d77b47baacfb7e4fafd1a22e
user:        mpm at selenic.com
date:        Fri Jul  1 10:34:50 2005
summary:     Move dirstate.uniq to util.unique
close failed: [Errno 32] Broken pipe
$ hg log -m | head -20
changeset:   553:f2442a6a589355e6c29b01882acaa8e439611ee0
parent:      551:b460a2fd8bb7855348fafb861cd22de1616d331e
parent:      552:2204311609a08017171372e6be13304222dccaa1
user:        mpm at selenic.com
date:        Fri Jul  1 10:10:52 2005
summary:     Merge with TAH

changeset:   547:4fc63e22b1fe707bb542ab1149403daa9a77cdf8
parent:      540:53872e2be33a09350ee57384574f9fcab78f1b41
parent:      546:c8ae964109c1eb09a17a9f6e478f48571101dac0
user:        mpm at selenic.com
date:        Fri Jul  1 09:28:16 2005
summary:     Merge with TAH

changeset:   542:eda4c32c167af7dc718b6ab1bb8d2555f1d2e5c2
parent:      541:abaea35387a81b39dbb0532328a12508644dfb0b
parent:      535:fba26990604a48dcea3506399409145aed3b7dc8
user:        Thomas Arendsen Hein <thomas at intevation.de>
date:        Thu Jun 30 22:47:23 2005
summary:     Merge with upstream


Goffredo



diff -r bf9d55ed67f6 TODO
--- a/TODO Fri Jul  1 17:04:50 2005
+++ b/TODO Fri Jul  1 19:55:04 2005
@@ -27,7 +27,6 @@
 - commands.py: number of args too much magic (e.g. in patch())
 - automatic pull fallback to old-http://
 - hg pull default in a subdir doesn't work, if it is a relative path
-- optionally only show merges (two parents or parent != changeset-1, etc.)
 
 Web:
 - show tags in hgweb
diff -r bf9d55ed67f6 mercurial/commands.py
--- a/mercurial/commands.py Fri Jul  1 17:04:50 2005
+++ b/mercurial/commands.py Fri Jul  1 19:55:04 2005
@@ -80,7 +80,8 @@
         tn = None
         sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r))
 
-def show_changeset(ui, repo, rev=0, changenode=None, filelog=None):
+def show_changeset(ui, repo, rev=0, changenode=None, filelog=None, 
+    onlymerge=None):
     """show a single changeset or file revision"""
     changelog = repo.changelog
     if filelog:
@@ -98,15 +99,18 @@
             rev = changerev = changelog.rev(changenode)
         node = changenode
 
+    changes = changelog.read(changenode)
+
+    parents = [(log.rev(parent), hg.hex(parent))
+               for parent in log.parents(node)
+               if ui.debugflag or parent != hg.nullid]
+
+    if onlymerge and len(parents) == 1: return
+    
     if ui.quiet:
         ui.write("%d:%s\n" % (rev, hg.hex(node)))
         return
 
-    changes = changelog.read(changenode)
-
-    parents = [(log.rev(parent), hg.hex(parent))
-               for parent in log.parents(node)
-               if ui.debugflag or parent != hg.nullid]
     if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1:
         parents = []
 
@@ -541,7 +545,8 @@
             off = a > b and -1 or 1
             revlist.extend(range(a, b + off, off))
     for i in revlist or range(log.count() - 1, -1, -1):
-        show_changeset(ui, repo, filelog=filelog, rev=i)
+        show_changeset(ui, repo, filelog=filelog, 
+                   rev=i, onlymerge=opts["merge"])
 
 def manifest(ui, repo, rev = []):
     """output the latest or given revision of the project manifest"""
@@ -783,7 +788,8 @@
                      "hg import [options] <patches>"),
     "init": (init, [], 'hg init'),
     "log|history": (log,
-                    [('r', 'rev', [], 'revision')],
+                    [('r', 'rev', [], 'revision'),
+                     ('m', 'merge', None, 'show only merge')],
                     'hg log [-r A] [-r B] [file]'),
     "manifest": (manifest, [], 'hg manifest [rev]'),
     "parents": (parents, [], 'hg parents [node]'),

-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack at inwind.it>
Key fingerprint = CE3C 7E01 6782 30A3 5B87  87C0 BB86 505C 6B2A CFF9


More information about the Mercurial mailing list