convert/bzr: convert all branches (issue3229) (BC)
Instead of opening the target bzr checkout as a single branch, we try to open
it as a repository. This has the following effects:
- All branches are now converted
- bzr branch names are preserved. Previously, the selected branch was always
converted as 'default'. Branches without a name or 'trunk' are mapped to
'default branch.
- Lightweight checkouts are no longer supported. Maybe they can be, I did not
try to fix that at all.
Implementation notes:
- This was a quick fix, I have no knowledge of bzr API besides browsing 2.0.3
sources.
- The fix was only tested on OSX against bzr 2.4.2.
- Tags discovery does not handle collisions. I have no idea how tags work in
bzr so maybe such collisions are not possible.
--- a/hgext/convert/bzr.py Thu Feb 02 10:15:04 2012 +0100
+++ b/hgext/convert/bzr.py Thu Feb 02 10:15:12 2012 +0100
@@ -23,7 +23,7 @@
try:
# bazaar imports
- from bzrlib import branch, revision, errors
+ from bzrlib import bzrdir, revision, errors
from bzrlib.revisionspec import RevisionSpec
except ImportError:
pass
@@ -42,14 +42,17 @@
try:
# access bzrlib stuff
- branch
+ bzrdir
except NameError:
raise NoRepo(_('Bazaar modules could not be loaded'))
path = os.path.abspath(path)
self._checkrepotype(path)
- self.branch = branch.Branch.open(path)
- self.sourcerepo = self.branch.repository
+ try:
+ self.sourcerepo = bzrdir.BzrDir.open(path).open_repository()
+ except errors.NoRepositoryPresent:
+ raise NoRepo(_('%s does not look like a Bazaar repository')
+ % path)
self._parentids = {}
def _checkrepotype(self, path):
@@ -90,14 +93,21 @@
def getheads(self):
if not self.rev:
- return [self.branch.last_revision()]
- try:
- r = RevisionSpec.from_string(self.rev)
- info = r.in_history(self.branch)
- except errors.BzrError:
- raise util.Abort(_('%s is not a valid revision in current branch')
- % self.rev)
- return [info.rev_id]
+ heads = sorted([b.last_revision()
+ for b in self.sourcerepo.find_branches()])
+ else:
+ revid = None
+ for branch in self.sourcerepo.find_branches():
+ try:
+ r = RevisionSpec.from_string(self.rev)
+ info = r.in_history(branch)
+ except errors.BzrError:
+ pass
+ revid = info.rev_id
+ if revid is None:
+ raise util.Abort(_('%s is not a valid revision') % self.rev)
+ heads = [revid]
+ return heads
def getfile(self, name, rev):
revtree = self.sourcerepo.revision_tree(rev)
@@ -140,19 +150,24 @@
parents = self._filterghosts(rev.parent_ids)
self._parentids[version] = parents
+ branch = self.recode(rev.properties.get('branch-nick', u'default'))
+ if branch == 'trunk':
+ branch = 'default'
return commit(parents=parents,
date='%d %d' % (rev.timestamp, -rev.timezone),
author=self.recode(rev.committer),
desc=self.recode(rev.message),
+ branch=branch,
rev=version)
def gettags(self):
- if not self.branch.supports_tags():
- return {}
- tagdict = self.branch.tags.get_tag_dict()
bytetags = {}
- for name, rev in tagdict.iteritems():
- bytetags[self.recode(name)] = rev
+ for branch in self.sourcerepo.find_branches():
+ if not branch.supports_tags():
+ return {}
+ tagdict = branch.tags.get_tag_dict()
+ for name, rev in tagdict.iteritems():
+ bytetags[self.recode(name)] = rev
return bytetags
def getchangedfiles(self, rev, i):
--- a/tests/bzr-definitions Thu Feb 02 10:15:04 2012 +0100
+++ b/tests/bzr-definitions Thu Feb 02 10:15:12 2012 +0100
@@ -9,7 +9,7 @@
glog()
{
- hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@"
+ hg glog --template '{rev}@{branch} "{desc|firstline}" files: {files}\n' "$@"
}
manifest()
--- a/tests/test-convert-bzr-ghosts.t Thu Feb 02 10:15:04 2012 +0100
+++ b/tests/test-convert-bzr-ghosts.t Thu Feb 02 10:15:12 2012 +0100
@@ -30,7 +30,7 @@
1 Initial layout setup
0 Commit with ghost revision
$ glog -R source-hg
- o 1 "Commit with ghost revision" files: somefile
+ o 1@source "Commit with ghost revision" files: somefile
|
- o 0 "Initial layout setup" files: somefile
+ o 0@source "Initial layout setup" files: somefile
--- a/tests/test-convert-bzr-merges.t Thu Feb 02 10:15:04 2012 +0100
+++ b/tests/test-convert-bzr-merges.t Thu Feb 02 10:15:12 2012 +0100
@@ -48,17 +48,17 @@
1 Added brach2 file
0 Merged branches
$ glog -R source-hg
- o 5 "(octopus merge fixup)" files:
+ o 5@source "(octopus merge fixup)" files:
|\
- | o 4 "Merged branches" files: file-branch2
+ | o 4@source "Merged branches" files: file-branch2
| |\
- o---+ 3 "Added brach2 file" files: file-branch2
+ o---+ 3@source-branch2 "Added brach2 file" files: file-branch2
/ /
- | o 2 "Added parent file" files: file-parent
+ | o 2@source "Added parent file" files: file-parent
| |
- o | 1 "Added branch1 file" files: file file-branch1
+ o | 1@source-branch1 "Added branch1 file" files: file file-branch1
|/
- o 0 "Initial add" files: file
+ o 0@source "Initial add" files: file
$ manifest source-hg tip
% manifest of tip
--- a/tests/test-convert-bzr.t Thu Feb 02 10:15:04 2012 +0100
+++ b/tests/test-convert-bzr.t Thu Feb 02 10:15:12 2012 +0100
@@ -32,9 +32,9 @@
1 Initial add: a, c, e
0 rename a into b, create a, rename c into d
$ glog -R source-hg
- o 1 "rename a into b, create a, rename c into d" files: a b c d e f
+ o 1@source "rename a into b, create a, rename c into d" files: a b c d e f
|
- o 0 "Initial add: a, c, e" files: a c e
+ o 0@source "Initial add: a, c, e" files: a c e
manifest
@@ -54,7 +54,7 @@
converting...
0 Initial add: a, c, e
$ glog -R source-1-hg
- o 0 "Initial add: a, c, e" files: a c e
+ o 0@source "Initial add: a, c, e" files: a c e
test with filemap
@@ -77,22 +77,12 @@
convert from lightweight checkout
$ bzr checkout --lightweight source source-light
- $ hg convert source-light source-light-hg
+ $ hg convert -s bzr source-light source-light-hg
initializing destination source-light-hg repository
warning: lightweight checkouts may cause conversion failures, try with a regular branch instead.
- scanning source...
- sorting...
- converting...
- 1 Initial add: a, c, e
- 0 rename a into b, create a, rename c into d
-
-lightweight manifest
-
- $ hg manifest -R source-light-hg -r tip
- a
- b
- d
- f
+ $TESTTMP/test-createandrename/source-light does not look like a Bazaar repository
+ abort: source-light: missing or unsupported repository
+ [255]
extract timestamps that look just like hg's {date|isodate}:
yyyy-mm-dd HH:MM zzzz (no seconds!)
@@ -147,13 +137,13 @@
1 Editing b
0 Merged improve branch
$ glog -R source-hg
- o 3 "Merged improve branch" files:
+ o 3@source "Merged improve branch" files:
|\
- | o 2 "Editing b" files: b
+ | o 2@source-improve "Editing b" files: b
| |
- o | 1 "Editing a" files: a
+ o | 1@source "Editing a" files: a
|/
- o 0 "Initial add" files: a b
+ o 0@source "Initial add" files: a b
$ cd ..
@@ -208,3 +198,41 @@
$ hg cat syma; echo
a
+Multiple branches
+
+ $ bzr init-repo -q --no-trees repo
+ $ bzr init -q repo/trunk
+ $ bzr co repo/trunk repo-trunk
+ $ cd repo-trunk
+ $ echo a > a
+ $ bzr add a
+ adding a
+ $ bzr ci -qm adda --commit-time '2012-01-01 00:00:01 +0000'
+ $ bzr switch -b branch
+ Tree is up to date at revision 1.
+ Switched to branch: *repo/branch/ (glob)
+ $ echo b > b
+ $ bzr add b
+ adding b
+ $ bzr ci -qm addb --commit-time '2012-01-01 00:00:02 +0000'
+ $ bzr switch --force ../repo/trunk
+ Updated to revision 1.
+ Switched to branch: */repo/trunk/ (glob)
+ $ echo a >> a
+ $ bzr ci -qm changea --commit-time '2012-01-01 00:00:03 +0000'
+ $ cd ..
+ $ hg convert --datesort repo repo-bzr
+ initializing destination repo-bzr repository
+ scanning source...
+ sorting...
+ converting...
+ 2 adda
+ 1 addb
+ 0 changea
+ $ (cd repo-bzr; glog)
+ o 2@default "changea" files: a
+ |
+ | o 1@branch "addb" files: b
+ |/
+ o 0@default "adda" files: a
+