def __init__(self, ui, path): if svn is None: raise MissingTool(_('Could not load Subversion python bindings')) converter_sink.__init__(self, ui, path) commandline.__init__(self, ui, 'svn') self.delete = [] self.setexec = [] self.delexec = [] self.copies = [] self.wc = None self.cwd = os.getcwd() path = os.path.realpath(path) created = False if os.path.isfile(os.path.join(path, '.svn', 'entries')): self.wc = path self.run0('update') else: wcpath = os.path.join(os.getcwd(), os.path.basename(path) + '-wc') if os.path.isdir(os.path.dirname(path)): if not os.path.exists(os.path.join(path, 'db', 'fs-type')): ui.status( _('initializing svn repository %r\n') % os.path.basename(path)) commandline(ui, 'svnadmin').run0('create', path) created = path path = util.normpath(path) if not path.startswith('/'): path = '/' + path path = 'file://' + path ui.status( _('initializing svn working copy %r\n') % os.path.basename(wcpath)) self.run0('checkout', path, wcpath) self.wc = wcpath self.opener = util.opener(self.wc) self.wopener = util.opener(self.wc) self.childmap = mapfile(ui, self.join('hg-childmap')) self.is_exec = util.checkexec(self.wc) and util.is_exec or None if created: hook = os.path.join(created, 'hooks', 'pre-revprop-change') fp = open(hook, 'w') fp.write(pre_revprop_change) fp.close() util.set_flags(hook, False, True) xport = transport.SvnRaTransport(url=geturl(path)) self.uuid = svn.ra.get_uuid(xport.ra)
def __init__(self, ui, url, rev=None): super(svn_source, self).__init__(ui, url, rev=rev) if not (url.startswith('svn://') or url.startswith('svn+ssh://') or (os.path.exists(url) and os.path.exists( os.path.join(url, '.svn'))) or issvnurl(url)): raise NoRepo("%s does not look like a Subversion repo" % url) try: SubversionException except NameError: raise MissingTool( _('Subversion python bindings could not be loaded')) try: version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR if version < (1, 4): raise MissingTool( _('Subversion python bindings %d.%d found, ' '1.4 or later required') % version) except AttributeError: raise MissingTool( _('Subversion python bindings are too old, 1.4 ' 'or later required')) self.lastrevs = {} latest = None try: # Support file://path@rev syntax. Useful e.g. to convert # deleted branches. at = url.rfind('@') if at >= 0: latest = int(url[at + 1:]) url = url[:at] except ValueError: pass self.url = geturl(url) self.encoding = 'UTF-8' # Subversion is always nominal UTF-8 try: self.transport = transport.SvnRaTransport(url=self.url) self.ra = self.transport.ra self.ctx = self.transport.client self.baseurl = svn.ra.get_repos_root(self.ra) # Module is either empty or a repository path starting with # a slash and not ending with a slash. self.module = urllib.unquote(self.url[len(self.baseurl):]) self.prevmodule = None self.rootmodule = self.module self.commits = {} self.paths = {} self.uuid = svn.ra.get_uuid(self.ra) except SubversionException: ui.traceback() raise NoRepo("%s does not look like a Subversion repo" % self.url) if rev: try: latest = int(rev) except ValueError: raise util.Abort(_('svn: revision %s is not an integer') % rev) self.startrev = self.ui.config('convert', 'svn.startrev', default=0) try: self.startrev = int(self.startrev) if self.startrev < 0: self.startrev = 0 except ValueError: raise util.Abort( _('svn: start revision %s is not an integer') % self.startrev) self.head = self.latest(self.module, latest) if not self.head: raise util.Abort(_('no revision found in module %s') % self.module) self.last_changed = self.revnum(self.head) self._changescache = None if os.path.exists(os.path.join(url, '.svn/entries')): self.wc = url else: self.wc = None self.convertfp = None