comparison hgext/convert/subversion.py @ 4906:2642726b61b6

convert/subversion.py: fix bad assumptions about SVN path naming The SVN converter assumed that the trunk and branches paths were fixed, and immediately under the base of the SVN URL. Fix the second assumption, and allow the trunk and branches paths to be reconfigured.
author Bryan O'Sullivan <bos@serpentine.com>
date Tue, 17 Jul 2007 15:24:59 -0700
parents 28b23b9073a8
children 5e89b0dafce5
comparison
equal deleted inserted replaced
4905:ad09ce1d393c 4906:2642726b61b6
1 # Subversion 1.4/1.5 Python API backend 1 # Subversion 1.4/1.5 Python API backend
2 # 2 #
3 # Copyright(C) 2007 Daniel Holth et al 3 # Copyright(C) 2007 Daniel Holth et al
4 #
5 # Configuration options:
6 #
7 # convert.svn.trunk
8 # Relative path to the trunk (default: "trunk")
9 # convert.svn.branches
10 # Relative path to tree of branches (default: "branches")
11 #
12 # Set these in a hgrc, or on the command line as follows:
13 #
14 # hg convert --config convert.svn.trunk=wackoname [...]
4 15
5 import pprint 16 import pprint
6 import locale 17 import locale
7 18
8 from mercurial import util 19 from mercurial import util
86 lastrevnum = lastrevs.setdefault(module, revnum) 97 lastrevnum = lastrevs.setdefault(module, revnum)
87 if revnum > lastrevnum: 98 if revnum > lastrevnum:
88 lastrevs[module] = revnum 99 lastrevs[module] = revnum
89 self.lastrevs = lastrevs 100 self.lastrevs = lastrevs
90 101
102 def exists(self, path, optrev):
103 try:
104 return svn.client.ls(self.url.rstrip('/') + '/' + path,
105 optrev, False, self.ctx)
106 except SubversionException, err:
107 return []
108
91 def getheads(self): 109 def getheads(self):
92 # detect standard /branches, /tags, /trunk layout 110 # detect standard /branches, /tags, /trunk layout
93 optrev = svn.core.svn_opt_revision_t() 111 optrev = svn.core.svn_opt_revision_t()
94 optrev.kind = svn.core.svn_opt_revision_number 112 optrev.kind = svn.core.svn_opt_revision_number
95 optrev.value.number = self.last_changed 113 optrev.value.number = self.last_changed
96 rpath = self.url.strip('/') 114 rpath = self.url.strip('/')
97 paths = svn.client.ls(rpath, optrev, False, self.ctx) 115 cfgtrunk = self.ui.config('convert', 'svn.trunk')
98 if 'branches' in paths and 'trunk' in paths: 116 cfgbranches = self.ui.config('convert', 'svn.branches')
99 self.module += '/trunk' 117 trunk = (cfgtrunk or 'trunk').strip('/')
118 branches = (cfgbranches or 'branches').strip('/')
119 if self.exists(trunk, optrev) and self.exists(branches, optrev):
120 self.ui.note('found trunk at %r and branches at %r\n' %
121 (trunk, branches))
122 oldmodule = self.module
123 self.module += '/' + trunk
100 lt = self.latest(self.module, self.last_changed) 124 lt = self.latest(self.module, self.last_changed)
101 self.head = self.revid(lt) 125 self.head = self.revid(lt)
102 self.heads = [self.head] 126 self.heads = [self.head]
103 branches = svn.client.ls(rpath + '/branches', optrev, False, self.ctx) 127 branchnames = svn.client.ls(rpath + '/' + branches, optrev, False,
104 for branch in branches.keys(): 128 self.ctx)
105 module = '/branches/' + branch 129 for branch in branchnames.keys():
130 if oldmodule:
131 module = '/' + oldmodule + '/' + branches + '/' + branch
132 else:
133 module = '/' + branches + '/' + branch
106 brevnum = self.latest(module, self.last_changed) 134 brevnum = self.latest(module, self.last_changed)
107 brev = self.revid(brevnum, module) 135 brev = self.revid(brevnum, module)
108 self.ui.note('found branch %s at %d\n' % (branch, brevnum)) 136 self.ui.note('found branch %s at %d\n' % (branch, brevnum))
109 self.heads.append(brev) 137 self.heads.append(brev)
138 elif cfgtrunk or cfgbranches:
139 raise util.Abort(_('trunk/branch layout expected, '
140 'but not found'))
110 else: 141 else:
142 self.ui.note('working with one branch\n')
111 self.heads = [self.head] 143 self.heads = [self.head]
112 return self.heads 144 return self.heads
113 145
114 def getfile(self, file, rev): 146 def getfile(self, file, rev):
115 data, mode = self._getfile(file, rev) 147 data, mode = self._getfile(file, rev)
191 dirent = svn.ra.stat(self.ra, path.strip('/'), stop) 223 dirent = svn.ra.stat(self.ra, path.strip('/'), stop)
192 self.reparent(self.module) 224 self.reparent(self.module)
193 except SubversionException: 225 except SubversionException:
194 dirent = None 226 dirent = None
195 if not dirent: 227 if not dirent:
196 raise util.Abort('%s not found up to revision %d' \ 228 print self.base, path
197 % (path, stop)) 229 raise util.Abort('%s not found up to revision %d' % (path, stop))
198 230
199 return dirent.created_rev 231 return dirent.created_rev
200 232
201 def get_blacklist(self): 233 def get_blacklist(self):
202 """Avoid certain revision numbers. 234 """Avoid certain revision numbers.