From 74476ac47584d3b416a74c1cb70a723b25692c01 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 15 Apr 2006 23:44:12 +0200 Subject: [PATCH] Properly recognize branch paths (uses svn.client.info) --- README | 3 ++- TODO | 6 ++++++ branch.py | 23 ++++++++++++++--------- format.py | 4 +++- repository.py | 28 ++++++++++++++++------------ 5 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 TODO diff --git a/README b/README index 7b0428e4..da5fcd10 100644 --- a/README +++ b/README @@ -5,7 +5,8 @@ Bazaar (http://www.bazaar-vcs.org/) You will need a recent version of Bazaar-NG, at least 0.8 (or one of the 0.8 pre releases). -You also need the Subversion bindings for python. +You also need the Subversion bindings for python, with my patch for svn_info_t (available at +http://jelmer.vernstok.nl/files/patches/svn-client-info-python.diff) Simply place this directory in ~/.bazaar/plugins and you should be able to check out branches from Subversion using bzr. diff --git a/TODO b/TODO new file mode 100644 index 00000000..6e554079 --- /dev/null +++ b/TODO @@ -0,0 +1,6 @@ +- support tracking of moves +- support SVN working trees +- support svn:executable +- support svn:ignore +- support svn:externals +- integrate DumpFile support (e.g. svn2bzr) ? diff --git a/branch.py b/branch.py index 502c9b04..9df17c3a 100644 --- a/branch.py +++ b/branch.py @@ -82,18 +82,23 @@ class SvnRevisionTree(Tree): return Stream(stream).read() class SvnBranch(Branch): - def __init__(self,repos,base,kind): + def __init__(self,repos,base): self.repository = repos + + if not base.startswith(repos.url): + raise CorruptRepository(repos) + + self.branch_path = base[len(repos.url):] self.base = base - self.base_revno = svn.core.svn_opt_revision_t() - self.base_revno.kind = svn.core.svn_opt_revision_head - self._generate_revnum_map('trunk',self.base_revno) + self.base_revt = svn.core.svn_opt_revision_t() + self.base_revt.kind = svn.core.svn_opt_revision_head + self._generate_revnum_map() def url_from_file_id(self,revision_id,file_id): """Generate a full Subversion URL from a bzr file id.""" return self.base+"/"+self.filename_from_file_id(revision_id,file_id) - def _generate_revnum_map(self,relpath,revt_end): + def _generate_revnum_map(self): #FIXME: Revids should be globally unique, so we should include the # branch path somehow. If we don't do this there might be revisions # that have the same id because they were created in the same commit. @@ -107,13 +112,13 @@ class SvnBranch(Branch): revt_begin.value.number = 0 def rcvr(paths,rev,author,date,message,pool): - revid = "%d@%s-%s" % (rev,self.repository.uuid,relpath) + revid = "%d@%s-%s" % (rev,self.repository.uuid,self.branch_path) self._revision_history.append(revid) - url = "%s/%s" % (self.repository.url, relpath) + url = "%s/%s" % (self.repository.url, self.branch_path) - svn.client.log3([url.encode('utf8')], revt_end, revt_begin, \ - revt_end, 0, False, False, rcvr, + svn.client.log3([url.encode('utf8')], self.base_revt, revt_begin, \ + self.base_revt, 0, False, False, rcvr, self.repository.client, self.repository.pool) def set_root_id(self, file_id): diff --git a/format.py b/format.py index 18c033b5..598dee96 100644 --- a/format.py +++ b/format.py @@ -3,6 +3,7 @@ from repository import SvnRepository from branch import SvnBranch import svn.client from libsvn._core import SubversionException +from bzrlib.errors import NotBranchError from bzrlib.lockable_files import TransportLock class SvnRemoteAccess(BzrDir): @@ -33,7 +34,7 @@ class SvnRemoteAccess(BzrDir): def open_branch(self, unsupported=True): try: - branch = SvnBranch(self.find_repository(),self.url,svn.core.svn_opt_revision_head) + branch = SvnBranch(self.find_repository(),self.url) except SubversionException, (msg, num): if num == svn.core.SVN_ERR_RA_ILLEGAL_URL or \ num == svn.core.SVN_ERR_WC_NOT_DIRECTORY or \ @@ -57,3 +58,4 @@ class SvnFormat(BzrDirFormat): def get_format_string(self): return 'SVN Repository' + diff --git a/repository.py b/repository.py index e6e609ab..b6508998 100644 --- a/repository.py +++ b/repository.py @@ -25,18 +25,14 @@ class SvnFileWeave(VersionedFile): self.file = weave_name def get_lines(self, version_id): - return [] if version_id is None: - path = "trunk" # FIXME + return [] - revt = svn.core.svn_opt_revision_t() - revt.kind = svn.core.svn_opt_revision_head - else: - (path,revnum) = self.repository.parse_revision_id(version_id) + (path,revnum) = self.repository.parse_revision_id(version_id) - revt = svn.core.svn_opt_revision_t() - revt.kind = svn.core.svn_opt_revision_number - revt.value.number = revnum + revt = svn.core.svn_opt_revision_t() + revt.kind = svn.core.svn_opt_revision_number + revt.value.number = revnum file_url = "%s/%s/%s" % (self.repository.url,path,self.file) @@ -61,7 +57,6 @@ class SvnRepository(Repository): branch_paths = [".","branches","tags"] def __init__(self, bzrdir, url): - self.url = url _revision_store = None control_store = None @@ -75,8 +70,17 @@ class SvnRepository(Repository): self.client.config = svn.core.svn_config_get_config(None) self.client.auth_baton = auth_baton - self.uuid = svn.client.uuid_from_url(self.url.encode('utf8'), - self.client, self.pool) + def rcvr(path,info,pool): + self.url = info.repos_root_URL + self.uuid = info.repos_UUID + + revt = svn.core.svn_opt_revision_t() + revt.kind = svn.core.svn_opt_revision_head + + svn.client.info(url.encode('utf8'), revt, revt, rcvr, False, self.client, self.pool) + + assert self.url + assert self.uuid mutter("Connected to repository at %s, UUID %s" % (self.url, self.uuid)) -- 2.34.1