[PATCH 2 of 4] branch closing: mark closed branches with a 'close' extra

John Mulligan phlogistonjohn at asynchrono.us
Tue Dec 23 13:31:38 CST 2008


# HG changeset patch
# User John Mulligan <phlogistonjohn at asynchrono.us>
# Date 1230060620 18000
# Node ID 8fb6d10eaebc5cf8a55f5bd7098e219d69d92ffa
# Parent  d41bcb6a1b19d2bce5cce3497e5b93d896b425ed
branch closing: mark closed branches with a 'close' extra

Adds a --close-branch option to commit.
When --close-branch is present the commit will mark the changeset
with close=1 in the changeset extras field.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -610,9 +610,13 @@
 
     See 'hg help dates' for a list of formats valid for -d/--date.
     """
+    extra = {}
+    if opts.get('close_branch'):
+        extra['close'] = 1
     def commitfunc(ui, repo, message, match, opts):
-        return repo.commit(match.files(), message, opts.get('user'), opts.get('date'),
-                           match, force_editor=opts.get('force_editor'))
+        return repo.commit(match.files(), message, opts.get('user'), 
+            opts.get('date'), match, force_editor=opts.get('force_editor'), 
+            extra=extra)
 
     node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
     if not node:
@@ -3122,6 +3126,8 @@
         (commit,
          [('A', 'addremove', None,
            _('mark new/missing files as added/removed before committing')),
+          ('', 'close-branch', None, 
+           _('mark a branch as closed, hiding it from the branch list')),
          ] + walkopts + commitopts + commitopts2,
          _('[OPTION]... [FILE]...')),
     "copy|cp":
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -763,6 +763,8 @@
                match=None, force=False, force_editor=False,
                p1=None, p2=None, extra={}, empty_ok=False):
         wlock = lock = None
+        if extra.get("close"):
+            force = True
         if files:
             files = util.unique(files)
         try:
@@ -837,6 +839,8 @@
             user = wctx.user()
             text = wctx.description()
 
+            if branchname == 'default' and extra.get('close'):
+                raise util.Abort(_('closing the default branch is invalid'))
             p1, p2 = [p.node() for p in wctx.parents()]
             c1 = self.changelog.read(p1)
             c2 = self.changelog.read(p2)


More information about the Mercurial-devel mailing list