import bzrlib.errors
import bzrlib.ui
import bzrlib.urlutils
+import bzrlib.branch
import sys
import os
return self.marks[rev]
def to_rev(self, mark):
- return self.rev_marks[mark]
+ return str(self.rev_marks[mark])
def next_mark(self):
self.last_mark += 1
ref = '%s/heads/%s' % (prefix, name)
tip = marks.get_tip(name)
- branch = branches[name]
+ branch = bzrlib.branch.Branch.open(branches[name])
repo = branch.repository
branch.lock_read()
revs = branch.iter_merge_sorted_revisions(None, tip, 'exclude', 'forward')
- tip_revno = branch.revision_id_to_revno(tip)
- last_revno, _ = branch.last_revision_info()
- total = last_revno - tip_revno
+ try:
+ tip_revno = branch.revision_id_to_revno(tip)
+ last_revno, _ = branch.last_revision_info()
+ total = last_revno - tip_revno
+ except bzrlib.errors.NoSuchRevision:
+ tip_revno = 0
+ total = 0
- revs = [revid, seq for revid, _, seq, _ in revs if not marks.is_marked(revid)]
+ for revid, _, seq, _ in revs:
- for revid, seq in revs:
+ if marks.is_marked(revid):
+ continue
rev = repo.get_revision(revid)
revno = seq[0]
progress = (revno - tip_revno)
if (progress % 100 == 0):
- print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
+ if total:
+ print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
+ else:
+ print "progress revision %d '%s' (%d)" % (revno, name, progress)
branch.unlock()
if ref.startswith('refs/heads/'):
name = ref[len('refs/heads/'):]
- branch = branches[name]
+ branch = bzrlib.branch.Branch.open(branches[name])
else:
die('unknown ref')
files[path] = f
committer, date, tz = committer
- parents = [str(mark_to_rev(p)) for p in parents]
+ parents = [mark_to_rev(p) for p in parents]
revid = bzrlib.generate_ids.gen_revision_id(committer, date)
props = {}
props['branch-nick'] = branch.nick
die('unhandled export command: %s' % line)
for ref, revid in parsed_refs.iteritems():
- name = ref[len('refs/heads/'):]
- branch = branches[name]
- branch.generate_revision_history(revid, marks.get_tip(name))
+ if ref.startswith('refs/heads/'):
+ name = ref[len('refs/heads/'):]
+ branch = bzrlib.branch.Branch.open(branches[name])
+ branch.generate_revision_history(revid, marks.get_tip(name))
- if name in peers:
- peer = peers[name]
- try:
- peer.bzrdir.push_branch(branch, revision_id=revid)
- except bzrlib.errors.DivergedBranches:
- print "error %s non-fast forward" % ref
- continue
+ if name in peers:
+ peer = bzrlib.branch.Branch.open(peers[name])
+ try:
+ peer.bzrdir.push_branch(branch, revision_id=revid)
+ except bzrlib.errors.DivergedBranches:
+ print "error %s non-fast forward" % ref
+ continue
- try:
- wt = branch.bzrdir.open_workingtree()
- wt.update()
- except bzrlib.errors.NoWorkingTree:
- pass
+ try:
+ wt = branch.bzrdir.open_workingtree()
+ wt.update()
+ except bzrlib.errors.NoWorkingTree:
+ pass
+ elif ref.startswith('refs/tags/'):
+ # TODO: implement tag push
+ print "error %s pushing tags not supported" % ref
+ continue
+ else:
+ # transport-helper/fast-export bugs
+ continue
print "ok %s" % ref
master_branch = name
print "? refs/heads/%s" % name
- branch = branches[master_branch]
+ branch = bzrlib.branch.Branch.open(branches[master_branch])
branch.lock_read()
for tag, revid in branch.tags.get_tag_dict().items():
try:
return branch
def find_branches(repo, wanted):
- transport = repo.user_transport
+ transport = repo.bzrdir.root_transport
for fn in transport.iter_files_recursive():
if not fn.endswith('.bzr/branch-format'):
clone_path = os.path.join(dirname, 'clone')
if not os.path.exists(clone_path):
os.mkdir(clone_path)
+ else:
+ # check and remove old organization
+ try:
+ bdir = bzrlib.bzrdir.BzrDir.open(clone_path)
+ bdir.destroy_repository()
+ except bzrlib.errors.NotBranchError:
+ pass
+ except bzrlib.errors.NoRepositoryPresent:
+ pass
try:
repo = origin.open_repository()
+ if not repo.user_transport.listable():
+ # this repository is not usable for us
+ raise bzrlib.errors.NoRepositoryPresent(repo.bzrdir)
except bzrlib.errors.NoRepositoryPresent:
# branch
name = 'master'
- branch = origin.open_branch()
+ remote_branch = origin.open_branch()
if not is_local:
- peers[name] = branch
- branches[name] = get_remote_branch(origin, branch, name)
+ peers[name] = remote_branch.base
+ branch = get_remote_branch(origin, remote_branch, name)
else:
- branches[name] = branch
+ branch = remote_branch
+
+ branches[name] = branch.base
return branch.repository
else:
# stupid python
wanted = [e for e in wanted if e]
- for name, branch in find_branches(repo, wanted):
+ for name, remote_branch in find_branches(repo, wanted):
if not is_local:
- peers[name] = branch
- branches[name] = get_remote_branch(origin, branch, name)
+ peers[name] = remote_branch.base
+ branch = get_remote_branch(origin, remote_branch, name)
else:
- branches[name] = branch
+ branch = remote_branch
+
+ branches[name] = branch.base
return repo
if not os.path.exists(dirname):
os.makedirs(dirname)
- bzrlib.ui.ui_factory.be_quiet(True)
+ if hasattr(bzrlib.ui.ui_factory, 'be_quiet'):
+ bzrlib.ui.ui_factory.be_quiet(True)
repo = get_repo(url, alias)