diff --git a/hgext/convert/bzr.py b/hgext/convert/bzr.py --- a/hgext/convert/bzr.py +++ b/hgext/convert/bzr.py @@ -23,7 +23,7 @@ from common import NoRepo, commit, conve 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 @@ class bzr_source(converter_source): 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 @@ class bzr_source(converter_source): 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 @@ class bzr_source(converter_source): 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): diff --git a/tests/bzr-definitions b/tests/bzr-definitions --- a/tests/bzr-definitions +++ b/tests/bzr-definitions @@ -9,7 +9,7 @@ echo 'hgext.graphlog = ' >> $HGRCPATH glog() { - hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@" + hg glog --template '{rev}@{branch} "{desc|firstline}" files: {files}\n' "$@" } manifest() diff --git a/tests/test-convert-bzr-ghosts.t b/tests/test-convert-bzr-ghosts.t --- a/tests/test-convert-bzr-ghosts.t +++ b/tests/test-convert-bzr-ghosts.t @@ -30,7 +30,7 @@ ghost revisions 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 diff --git a/tests/test-convert-bzr-merges.t b/tests/test-convert-bzr-merges.t --- a/tests/test-convert-bzr-merges.t +++ b/tests/test-convert-bzr-merges.t @@ -48,17 +48,17 @@ test multiple merges at once 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 diff --git a/tests/test-convert-bzr.t b/tests/test-convert-bzr.t --- a/tests/test-convert-bzr.t +++ b/tests/test-convert-bzr.t @@ -32,9 +32,9 @@ create and rename on the same file in th 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 @@ test --rev option 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 @@ test with filemap 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 @@ merge 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 @@ test the symlinks can be recreated $ 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 +