[patch] limit log to a single branch

Dustin Sallings dustin at spy.net
Fri Feb 8 23:35:20 CST 2008


On Feb 8, 2008, at 21:24, Bryan O'Sullivan wrote:

> Good patch, bad name for the long option.  Something like --only- 
> branch
> would be more appropriate, as it makes it clear what's going on.


	I'm terrible with names, thanks.

	I changed it per your recommendation and added a test (added it to  
the branch test since it already did all the setup).

	http://hg.west.spy.net/hg/hacks/hg/
	http://hg.west.spy.net/hg/hacks/hg/rev/57c1a7052982


# HG changeset patch
# User Dustin Sallings <dustin at spy.net>
# Date 1202535063 28800
# Node ID 57c1a705298204b659d04adc42425df815ef03cd
# Parent  348132c112cf1c9c6135af7b37b8b246ec2e4fed
Option to log to only show changesets within a specified branch.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1713,6 +1713,8 @@
      if opts["date"]:
          df = util.matchdate(opts["date"])

+    only_branches = opts['only_branch']
+
      displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
      for st, rev, fns in changeiter:
          if st == 'add':
@@ -1723,6 +1725,11 @@
                  continue
              if opts['only_merges'] and len(parents) != 2:
                  continue
+
+            if only_branches:
+                revbranch = get(rev)[5]['branch']
+                if revbranch not in only_branches:
+                    continue

              if df:
                  changes = get(rev)
@@ -2930,6 +2937,8 @@
            ('M', 'no-merges', None, _('do not show merges')),
            ('', 'style', '', _('display using template map file')),
            ('m', 'only-merges', None, _('show only merges')),
+          ('b', 'only-branch', [],
+            _('show only changesets within the given named branch')),
            ('p', 'patch', None, _('show patch')),
            ('P', 'prune', [], _('do not display revision or any of  
its ancestors')),
            ('', 'template', '', _('display with template')),
diff --git a/tests/test-branches b/tests/test-branches
--- a/tests/test-branches
+++ b/tests/test-branches
@@ -34,3 +34,9 @@
  hg branches
  echo '-------'
  hg branches -a
+
+echo "--- Branch a"
+hg log -b a
+
+echo "---- Branch b"
+hg log -b b
diff --git a/tests/test-branches.out b/tests/test-branches.out
--- a/tests/test-branches.out
+++ b/tests/test-branches.out
@@ -10,3 +10,31 @@
  -------
  c                              5:5ca481e59b8c
  a                              1:dd6b440dd85a
+--- Branch a
+changeset:   1:dd6b440dd85a
+branch:      a
+user:        test
+date:        Thu Jan 01 00:00:01 1970 +0000
+summary:     Adding a branch
+
+---- Branch b
+changeset:   4:22df7444f7c1
+branch:      b
+parent:      2:ac22033332d1
+user:        test
+date:        Thu Jan 01 00:00:04 1970 +0000
+summary:     Adding b branch head 2
+
+changeset:   3:aee39cd168d0
+branch:      b
+user:        test
+date:        Thu Jan 01 00:00:03 1970 +0000
+summary:     Adding b branch head 1
+
+changeset:   2:ac22033332d1
+branch:      b
+parent:      0:19709c5a4e75
+user:        test
+date:        Thu Jan 01 00:00:02 1970 +0000
+summary:     Adding b branch
+


-- 
Dustin Sallings





More information about the Mercurial mailing list