[PATCH 1 of 2] Added more named brach support to the following commands: heads, branch

Sune Foldager cryo at cyanite.org
Tue Aug 26 05:45:11 CDT 2008


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1219747445 -7200
# Node ID c4c14e1a60fac20280fcaa5db80a948ae0aa0669
# Parent  6dcbe191a9b51799a4cd40bd398e826bcd9b4dac
Added more named brach support to the following commands: heads, branch.

hg heads now has a -b (--branch) option, to list the heads of the current
named branch. The branch name is taken from the dirstate, not the last commit.

hg branch now has a -C (--clean) option, to reset the current (dirstate)
branch to the branch of the last commit (first parent).

diff -r 6dcbe191a9b5 -r c4c14e1a60fa mercurial/commands.py
--- a/mercurial/commands.py	Mon Aug 18 16:50:36 2008 -0500
+++ b/mercurial/commands.py	Tue Aug 26 12:44:05 2008 +0200
@@ -365,10 +365,17 @@
     Unless --force is specified, branch will not let you set a
     branch name that shadows an existing branch.
 
+    Use --clean to reset the working directory branch to that of the
+    parent of the working directory, negating a previous branch change.
+
     Use the command 'hg update' to switch to an existing branch.
     """
 
-    if label:
+    if opts['clean']:
+        label = repo[repo.dirstate.parents()[0]].branch()
+        repo.dirstate.setbranch(label)
+        ui.status(_('reset working directory to branch %s\n') % label)
+    elif label:
         if not opts.get('force') and label in repo.branchtags():
             if label not in [p.branch() for p in repo.parents()]:
                 raise util.Abort(_('a branch of the same name already exists'
@@ -1194,6 +1201,10 @@
         start = repo.lookup(opts['rev'])
     else:
         start = None
+    if opts['branch']:
+        if branchrevs:
+            raise util.Abort(_("revision names can't be given when the --branch option is used"))
+        branchrevs = [repo.dirstate.branch()] # or [repo[repo.dirstate.parents()[0]].branch()]
     if not branchrevs:
         # Assume we're looking repo-wide heads if no revs were specified.
         heads = repo.heads(start)
@@ -2798,7 +2809,7 @@
     """update working directory
 
     Update the repository's working directory to the specified revision,
-    or the tip of the current branch if none is specified.
+    or the head of the current branch if none is specified.
 
     If the requested revision is a descendant of the working
     directory, any outstanding changes in the working directory will
@@ -2974,8 +2985,10 @@
     "branch":
         (branch,
          [('f', 'force', None,
-           _('set branch name even if it shadows an existing branch'))],
-         _('hg branch [-f] [NAME]')),
+           _('set branch name even if it shadows an existing branch')),
+          ('C', 'clean', None, _('reset branch name to parent branch name')),
+         ],
+         _('hg branch [-fC] [NAME]')),
     "branches":
         (branches,
          [('a', 'active', False,
@@ -3092,8 +3105,9 @@
     "heads":
         (heads,
          [('r', 'rev', '', _('show only heads which are descendants of rev')),
+          ('b', 'branch', None, _('show only heads of the current branch')),
          ] + templateopts,
-         _('hg heads [-r REV] [REV]...')),
+         _('hg heads [-b] [-r REV] [REV]...')),
     "help": (help_, [], _('hg help [COMMAND]')),
     "identify|id":
         (identify,


More information about the Mercurial-devel mailing list