[PATCH 7 of 9] add branch --close and merge --close
Alexis S. L. Carvalho
alexis at cecm.usp.br
Sun Mar 2 13:01:29 CST 2008
# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1204481759 10800
# Node ID 5cf7311702a4ae5dd8e3e865bdd88d4cff3f2e1f
# Parent 09195d7818674502a33a74060ac41e58092c6a50
add branch --close and merge --close
diff -r 09195d781867 -r 5cf7311702a4 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Sun Mar 02 15:15:59 2008 -0300
+++ b/mercurial/cmdutil.py Sun Mar 02 15:15:59 2008 -0300
@@ -1175,3 +1175,37 @@ def commit(ui, repo, commitfunc, pats, o
return commitfunc(ui, repo, files, message, match, opts)
except ValueError, inst:
raise util.Abort(str(inst))
+
+def closebranch(repo, name, abort=True):
+ '''schedule the branch name to be closed on the next commit'''
+ localname = util.tolocal(name)
+ parents = repo.parents()
+
+ msg = None
+ nodes = repo.closebranchnodes(localname, repo.dirstate.parents())
+ if name == repo.dirstate.branch():
+ msg = _("refusing to close current branch \"%s\"") % localname
+ elif not nodes:
+ msg = (_("no head of branch %s is an ancestor of the parents of "
+ "the working directory.") % localname)
+
+ if msg:
+ if abort:
+ raise util.Abort(msg)
+ repo.ui.warn(msg + '\n')
+ return
+
+ repo.dirstate.closebranch(name)
+
+ if len(nodes) == len(repo.branchtags()[localname]):
+ repo.ui.status(_("branch %s will be closed on the next commit\n")
+ % localname)
+ else:
+ repo.ui.status(_("the following heads from branch %s will be "
+ "closed on the next commit:\n") % localname)
+ cl = repo.changelog
+ for p in parents:
+ if p.branch() == name:
+ repo.ui.status(_(" %d:%s\n") % (cl.rev(n), short(n)))
+ repo.ui.status(_("some heads will stay opened.\n"))
+
diff -r 09195d781867 -r 5cf7311702a4 mercurial/commands.py
--- a/mercurial/commands.py Sun Mar 02 15:15:59 2008 -0300
+++ b/mercurial/commands.py Sun Mar 02 15:15:59 2008 -0300
@@ -339,17 +339,29 @@ def bisect(ui, repo, rev=None, extra=Non
return hg.clean(repo, node)
def branch(ui, repo, label=None, **opts):
- """set or show the current branch name
+ """set or show the current branch name or close a branch
With no argument, show the current branch name. With one argument,
set the working directory branch name (the branch does not exist in
the repository until the next commit).
+
+ With --close, if an argument is given, schedule the given branch
+ to be closed on the next commit. Otherwise, show the branch that
+ will be closed.
Unless --force is specified, branch will not let you set a
branch name that shadows an existing branch.
Use the command 'hg update' to switch to an existing branch.
"""
+
+ if opts.get('close'):
+ if label is not None:
+ cmdutil.closebranch(repo, util.fromlocal(label))
+ else:
+ name = util.tolocal(repo.dirstate.getclosedbranch())
+ ui.write(_("%s\n") % name)
+ return
if label:
if not opts.get('force') and label in repo.branchtags():
@@ -1833,7 +1845,7 @@ def manifest(ui, repo, node=None, rev=No
ui.write("%3s %1s " % (perm, type))
ui.write("%s\n" % f)
-def merge(ui, repo, node=None, force=None, rev=None):
+def merge(ui, repo, node=None, force=None, rev=None, close=None):
"""merge working directory with another revision
Merge the contents of the current working directory and the
@@ -1845,6 +1857,9 @@ def merge(ui, repo, node=None, force=Non
head revision, and the repository contains exactly one other head,
the other head is merged with by default. Otherwise, an explicit
revision to merge with must be provided.
+
+ With --close the branch of the requested revision will be closed
+ after the commit.
"""
if rev and node:
@@ -1869,7 +1884,11 @@ def merge(ui, repo, node=None, force=Non
raise util.Abort(_('working dir not at a head rev - '
'use "hg update" or merge with an explicit rev'))
node = parent == heads[0] and heads[-1] or heads[0]
- return hg.merge(repo, node, force=force)
+ ret = hg.merge(repo, node, force=force)
+ if close:
+ otherbranch = repo.parents()[1].branch()
+ cmdutil.closebranch(repo, otherbranch, abort=False)
+ return ret
def outgoing(ui, repo, dest=None, **opts):
"""show changesets not found in destination
@@ -2849,7 +2868,8 @@ table = {
"branch":
(branch,
[('f', 'force', None,
- _('set branch name even if it shadows an existing branch'))],
+ _('set branch name even if it shadows an existing branch')),
+ ('c', 'close', None, _('close the specified branch'))],
_('hg branch [-f] [NAME]')),
"branches":
(branches,
@@ -3052,6 +3072,7 @@ table = {
(merge,
[('f', 'force', None, _('force a merge with outstanding changes')),
('r', 'rev', '', _('revision to merge')),
+ ('c', 'close', None, _('close the branch of the merged revision')),
],
_('hg merge [-f] [[-r] REV]')),
"outgoing|out":
diff -r 09195d781867 -r 5cf7311702a4 tests/test-globalopts.out
--- a/tests/test-globalopts.out Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-globalopts.out Sun Mar 02 15:15:59 2008 -0300
@@ -154,7 +154,7 @@ list of commands:
archive create unversioned archive of a repository revision
backout reverse effect of earlier changeset
bisect subdivision search of changesets
- branch set or show the current branch name
+ branch set or show the current branch name or close a branch
branches list repository named branches
bundle create a changegroup file
cat output the current or given revision of files
@@ -207,7 +207,7 @@ list of commands:
archive create unversioned archive of a repository revision
backout reverse effect of earlier changeset
bisect subdivision search of changesets
- branch set or show the current branch name
+ branch set or show the current branch name or close a branch
branches list repository named branches
bundle create a changegroup file
cat output the current or given revision of files
diff -r 09195d781867 -r 5cf7311702a4 tests/test-help.out
--- a/tests/test-help.out Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-help.out Sun Mar 02 15:15:59 2008 -0300
@@ -46,7 +46,7 @@ list of commands:
archive create unversioned archive of a repository revision
backout reverse effect of earlier changeset
bisect subdivision search of changesets
- branch set or show the current branch name
+ branch set or show the current branch name or close a branch
branches list repository named branches
bundle create a changegroup file
cat output the current or given revision of files
@@ -95,7 +95,7 @@ use "hg -v help" to show aliases and glo
archive create unversioned archive of a repository revision
backout reverse effect of earlier changeset
bisect subdivision search of changesets
- branch set or show the current branch name
+ branch set or show the current branch name or close a branch
branches list repository named branches
bundle create a changegroup file
cat output the current or given revision of files
diff -r 09195d781867 -r 5cf7311702a4 tests/test-newbranch
--- a/tests/test-newbranch Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-newbranch Sun Mar 02 15:15:59 2008 -0300
@@ -17,11 +17,20 @@ echo % branch shadowing
echo % branch shadowing
hg branch default
hg branch -f default
+echo % fail to close current branch
+hg branch -c default
+echo % fail to close a branch that does not exist
+hg branch -c invalid
+echo % close branch bar
+hg branch -c bar
+hg branch -c
hg ci -m "clear branch name" -d "1000000 0"
hg co foo
hg branch
echo bleah > a
+echo % fail to close a branch where no head is our ancestor
+hg branch -c default
hg ci -m "modify a branch" -d "1000000 0"
hg merge
@@ -67,8 +76,9 @@ echo ff > ff
echo ff > ff
hg ci -Am'fast forward' -d '1000000 0'
hg up foo
-hg merge ff
+hg merge --close ff
hg branch
+hg branch -c
hg commit -m'Merge ff into foo' -d '1000000 0'
hg parents
hg manifest
diff -r 09195d781867 -r 5cf7311702a4 tests/test-newbranch.out
--- a/tests/test-newbranch.out Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-newbranch.out Sun Mar 02 15:15:59 2008 -0300
@@ -4,8 +4,17 @@ marked working directory as branch bar
% branch shadowing
abort: a branch of the same name already exists (use --force to override)
marked working directory as branch default
+% fail to close current branch
+abort: refusing to close current branch "default"
+% fail to close a branch that does not exist
+abort: there's no branch named invalid!
+% close branch bar
+branch bar will be closed on the next commit
+bar
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
foo
+% fail to close a branch where no head is our ancestor
+abort: no head of branch default is an ancestor of the parents of the working directory.
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
foo
@@ -103,7 +112,9 @@ 0 files updated, 0 files merged, 1 files
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
+branch ff will be closed on the next commit
foo
+ff
changeset: 6:f0c74f92a385
branch: foo
tag: tip
More information about the Mercurial-devel
mailing list