[PATCH] Deleting a named branch.

Matt Mackall mpm at selenic.com
Tue Jan 22 10:31:56 CST 2008


On Mon, 2008-01-21 at 20:13 -0600, Govind Salinas wrote:
> # HG changeset patch
> # User Govind Salinas <blix at sophiasuchtig.com>
> # Date 1200967247 21600
> # Node ID 7a01fea81b8d0f80fcd214104f538412bf2258eb
> # Parent  d39af2eabb8c8656c200ecc23d07faacf95be68c
> Delete a branch and take any nodes not reachable from another head.
> 
> This is a patch for comment.  Please take a look and let me know what
> needs to be changed.  I am neither very familiar with hg nor is python
> my native language so I am sure there are instances where things could
> be done better and more efficiently.  I have a test which I have
> passing which I will submit with the real patch.  I also understand
> that the code should be moved somewhere else, I am not sure if it
> should go in localrepo or in repair.
> 
> Basic algorithm:
> 
> If you are on the branch you want to delete, bail.  That leaves you in
> a weird situation.
> 
> If the branch you want to delete doesn't exist, bail.
> 
> Get an orderd list of all the reachable commits for the branch to
> delete (children before parents).
> 
> Accumulate a set of all the commits reachable from other branchheads.
> The intersection of the two are places where a parent of the branch to
> delete is reachable from another branch.  These are the common
> ancestors.
> 
> Go down the ordered list of commits to the branch to delete until you
> find a common ancestor.  The commit previous to this is the last
> commit you can delete.
> 
> use repair to strip the commits from the limit onwards.

You'll notice that nowhere in the main code actually calls strip. That's
because it violates one of our basic rules: we never rewrite files, we
only append. Instead, code that does this lives in extensions, and the
user will thereby know they're playing outside of the box.

Probably the best way to do this, ui-wise, is to add some more smarts to
the strip command in the mq extension.

> diff -r d39af2eabb8c -r 7a01fea81b8d mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py    Fri Jan 18 10:48:25 2008 -0600
> +++ b/mercurial/cmdutil.py    Mon Jan 21 20:00:47 2008 -0600
> @@ -761,7 +761,7 @@ class changeset_templater(changeset_prin
>              branch = changes[5].get("branch")
>              if branch != 'default':
>                  branch = util.tolocal(branch)
> -                return showlist('branch', [branch], plural='branches', **args)
> +            return showlist('branch', [branch], plural='branches', **args)

Unrelated and probably undesirable change.

> +        branches = self.branchtags()
> +        nodes = set()

Using set() is discouraged. It currently has no advantages over a dict
(with the exception of finding intersections), and is not compatible
with Python 2.3.

> +        for b in branches:
> +            nodes.add(self.changectx(b).node())

Consider how much more useful this is than your set:

nodes[self.lookup(b)] = b

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list