More thoughts on converting git branches
Greg Ward
gerg.ward+hg at gmail.com
Sat Dec 20 23:00:39 UTC 2008
Hi all -- a couple of weeks ago, I whined here about the fact that "hg
convert" from a git repository loses branch names while preserving
structure. David Sorria Parra kindly explained how this is a side
effect of git's way of representing branches, namely as a "floating
tag" that merely labels the tip of the branch. As a result, it's
impossible to know with git where the branch started, which commits
are on the branch, etc. So no wonder "hg convert" can't preserve
branch names.
(Aside: egads, even CVS is better than git here! Taking a CVS
revision number like 1.6.16.4 and figuring out a) what trunk revision
the branch is derived from and b) which revisions are on the same
branch is fairly straightforward. Of course you have to repeat the
computation for every file, but that's CVS for you. But with git, you
cannot tell when the branch was created, what the first commit was,
what commits belong to the branch.)
I've been thinking about the problem and there might be a way to do
it, at least for users who are sufficiently motivated to give "hg
convert" some hints (like me). Specifically:
* get the user to tell us which git commit is the "base" of a
branch, i.e. the first commit made on the branch
* set btip to the commit that the the branch name points to, i.e.
the tip of the branch
* set broot = parent(base), i.e. the commit from which the branch is
derived (this means that base cannot be a merge commit!)
* set uncles = children(broot), minus base
* for every commit c:
if ((c == base) or (c is a descendant of base) and
(c == btip) or (c is an ancestor of btip) and
c is not a descendant of any uncle):
then c is on the branch
I don't think that's 100% correct: it doesn't handle rebasing or
repeatedly merging the branch onto its ancestor branch. I need to
draw some pictures to figure out all the cases. But it's a start.
Whaddya think? Am I on to something here? Or has this already been
tried unsuccessfully?
Greg
--
Greg Ward http://www.gerg.ca/
I brought my BOWLING BALL -- and some DRUGS!!
More information about the Mercurial
mailing list