hgext/convert/subversion.py
changeset 10282 08a0f04b56bd
parent 10071 661980567246
child 10618 508fda6b8637
equal deleted inserted replaced
10281:e7d3b509af8b 10282:08a0f04b56bd
   136 
   136 
   137 # Check to see if the given path is a local Subversion repo. Verify this by
   137 # Check to see if the given path is a local Subversion repo. Verify this by
   138 # looking for several svn-specific files and directories in the given
   138 # looking for several svn-specific files and directories in the given
   139 # directory.
   139 # directory.
   140 def filecheck(ui, path, proto):
   140 def filecheck(ui, path, proto):
   141     for x in ('locks', 'hooks', 'format', 'db', ):
   141     for x in ('locks', 'hooks', 'format', 'db'):
   142         if not os.path.exists(os.path.join(path, x)):
   142         if not os.path.exists(os.path.join(path, x)):
   143             return False
   143             return False
   144     return True
   144     return True
   145 
   145 
   146 # Check to see if a given path is the root of an svn repo over http. We verify
   146 # Check to see if a given path is the root of an svn repo over http. We verify
   148 # for the svn-specific "not found" XML.
   148 # for the svn-specific "not found" XML.
   149 def httpcheck(ui, path, proto):
   149 def httpcheck(ui, path, proto):
   150     try:
   150     try:
   151         opener = urllib2.build_opener()
   151         opener = urllib2.build_opener()
   152         rsp = opener.open('%s://%s/!svn/ver/0/.svn' % (proto, path))
   152         rsp = opener.open('%s://%s/!svn/ver/0/.svn' % (proto, path))
   153         data = rsp.read()        
   153         data = rsp.read()
   154     except urllib2.HTTPError, inst:
   154     except urllib2.HTTPError, inst:
   155         if inst.code != 404:
   155         if inst.code != 404:
   156             # Except for 404 we cannot know for sure this is not an svn repo
   156             # Except for 404 we cannot know for sure this is not an svn repo
   157             ui.warn(_('svn: cannot probe remote repository, assume it could '
   157             ui.warn(_('svn: cannot probe remote repository, assume it could '
   158                       'be a subversion repository. Use --source-type if you '
   158                       'be a subversion repository. Use --source-type if you '
   229         try:
   229         try:
   230             # Support file://path@rev syntax. Useful e.g. to convert
   230             # Support file://path@rev syntax. Useful e.g. to convert
   231             # deleted branches.
   231             # deleted branches.
   232             at = url.rfind('@')
   232             at = url.rfind('@')
   233             if at >= 0:
   233             if at >= 0:
   234                 latest = int(url[at+1:])
   234                 latest = int(url[at + 1:])
   235                 url = url[:at]
   235                 url = url[:at]
   236         except ValueError:
   236         except ValueError:
   237             pass
   237             pass
   238         self.url = geturl(url)
   238         self.url = geturl(url)
   239         self.encoding = 'UTF-8' # Subversion is always nominal UTF-8
   239         self.encoding = 'UTF-8' # Subversion is always nominal UTF-8
   361             if len(self.heads) > 1:
   361             if len(self.heads) > 1:
   362                 raise util.Abort(_('svn: start revision is not supported '
   362                 raise util.Abort(_('svn: start revision is not supported '
   363                                    'with more than one branch'))
   363                                    'with more than one branch'))
   364             revnum = self.revnum(self.heads[0])
   364             revnum = self.revnum(self.heads[0])
   365             if revnum < self.startrev:
   365             if revnum < self.startrev:
   366                 raise util.Abort(_('svn: no revision found after start revision %d')
   366                 raise util.Abort(
       
   367                     _('svn: no revision found after start revision %d')
   367                                  % self.startrev)
   368                                  % self.startrev)
   368 
   369 
   369         return self.heads
   370         return self.heads
   370 
   371 
   371     def getfile(self, file, rev):
   372     def getfile(self, file, rev):
   387         else:
   388         else:
   388             # Perform a full checkout on roots
   389             # Perform a full checkout on roots
   389             uuid, module, revnum = self.revsplit(rev)
   390             uuid, module, revnum = self.revsplit(rev)
   390             entries = svn.client.ls(self.baseurl + urllib.quote(module),
   391             entries = svn.client.ls(self.baseurl + urllib.quote(module),
   391                                     optrev(revnum), True, self.ctx)
   392                                     optrev(revnum), True, self.ctx)
   392             files = [n for n,e in entries.iteritems()
   393             files = [n for n, e in entries.iteritems()
   393                      if e.kind == svn.core.svn_node_file]
   394                      if e.kind == svn.core.svn_node_file]
   394             copies = {}
   395             copies = {}
   395 
   396 
   396         files.sort()
   397         files.sort()
   397         files = zip(files, [rev] * len(files))
   398         files = zip(files, [rev] * len(files))
   562             dirent = svn.ra.stat(self.ra, path.strip('/'), stop)
   563             dirent = svn.ra.stat(self.ra, path.strip('/'), stop)
   563             self.reparent(prevmodule)
   564             self.reparent(prevmodule)
   564         except SubversionException:
   565         except SubversionException:
   565             dirent = None
   566             dirent = None
   566         if not dirent:
   567         if not dirent:
   567             raise SvnPathNotFound(_('%s not found up to revision %d') % (path, stop))
   568             raise SvnPathNotFound(_('%s not found up to revision %d')
       
   569                                   % (path, stop))
   568 
   570 
   569         # stat() gives us the previous revision on this line of
   571         # stat() gives us the previous revision on this line of
   570         # development, but it might be in *another module*. Fetch the
   572         # development, but it might be in *another module*. Fetch the
   571         # log and detect renames down to the latest revision.
   573         # log and detect renames down to the latest revision.
   572         stream = self._getlog([path], stop, dirent.created_rev)
   574         stream = self._getlog([path], stop, dirent.created_rev)
   643                 self.ui.debug("entry %s\n" % parentpath)
   645                 self.ui.debug("entry %s\n" % parentpath)
   644 
   646 
   645                 # We can avoid the reparent calls if the module has
   647                 # We can avoid the reparent calls if the module has
   646                 # not changed but it probably does not worth the pain.
   648                 # not changed but it probably does not worth the pain.
   647                 prevmodule = self.reparent('')
   649                 prevmodule = self.reparent('')
   648                 fromkind = svn.ra.check_path(self.ra, parentpath.strip('/'), prevnum)
   650                 fromkind = svn.ra.check_path(self.ra, parentpath.strip('/'),
       
   651                                              prevnum)
   649                 self.reparent(prevmodule)
   652                 self.reparent(prevmodule)
   650 
   653 
   651                 if fromkind == svn.core.svn_node_file:
   654                 if fromkind == svn.core.svn_node_file:
   652                     entries.append(self.recode(entrypath))
   655                     entries.append(self.recode(entrypath))
   653                 elif fromkind == svn.core.svn_node_dir:
   656                 elif fromkind == svn.core.svn_node_dir:
   655                         children = self._find_children(path, prevnum)
   658                         children = self._find_children(path, prevnum)
   656                     else:
   659                     else:
   657                         oroot = parentpath.strip('/')
   660                         oroot = parentpath.strip('/')
   658                         nroot = path.strip('/')
   661                         nroot = path.strip('/')
   659                         children = self._find_children(oroot, prevnum)
   662                         children = self._find_children(oroot, prevnum)
   660                         children = [s.replace(oroot,nroot) for s in children]
   663                         children = [s.replace(oroot, nroot) for s in children]
   661 
   664 
   662                     for child in children:
   665                     for child in children:
   663                         childpath = self.getrelpath("/" + child, pmodule)
   666                         childpath = self.getrelpath("/" + child, pmodule)
   664                         if not childpath:
   667                         if not childpath:
   665                             continue
   668                             continue
   736 
   739 
   737             parents = []
   740             parents = []
   738             # check whether this revision is the start of a branch or part
   741             # check whether this revision is the start of a branch or part
   739             # of a branch renaming
   742             # of a branch renaming
   740             orig_paths = sorted(orig_paths.iteritems())
   743             orig_paths = sorted(orig_paths.iteritems())
   741             root_paths = [(p,e) for p,e in orig_paths if self.module.startswith(p)]
   744             root_paths = [(p, e) for p, e in orig_paths
       
   745                           if self.module.startswith(p)]
   742             if root_paths:
   746             if root_paths:
   743                 path, ent = root_paths[-1]
   747                 path, ent = root_paths[-1]
   744                 if ent.copyfrom_path:
   748                 if ent.copyfrom_path:
   745                     branched = True
   749                     branched = True
   746                     newpath = ent.copyfrom_path + self.module[len(path):]
   750                     newpath = ent.copyfrom_path + self.module[len(path):]
   748                     previd = self.latest(newpath, ent.copyfrom_rev)
   752                     previd = self.latest(newpath, ent.copyfrom_rev)
   749                     if previd is not None:
   753                     if previd is not None:
   750                         prevmodule, prevnum = self.revsplit(previd)[1:]
   754                         prevmodule, prevnum = self.revsplit(previd)[1:]
   751                         if prevnum >= self.startrev:
   755                         if prevnum >= self.startrev:
   752                             parents = [previd]
   756                             parents = [previd]
   753                             self.ui.note(_('found parent of branch %s at %d: %s\n') %
   757                             self.ui.note(
   754                                          (self.module, prevnum, prevmodule))
   758                                 _('found parent of branch %s at %d: %s\n') %
       
   759                                 (self.module, prevnum, prevmodule))
   755                 else:
   760                 else:
   756                     self.ui.debug("no copyfrom path, don't know what to do.\n")
   761                     self.ui.debug("no copyfrom path, don't know what to do.\n")
   757 
   762 
   758             paths = []
   763             paths = []
   759             # filter out unrelated paths
   764             # filter out unrelated paths