hgext/convert/subversion.py
changeset 4813 744371157212
parent 4812 1fcdf2fe3d7c
child 4814 4cdbaa885d8a
equal deleted inserted replaced
4812:1fcdf2fe3d7c 4813:744371157212
    24     import transport
    24     import transport
    25 except ImportError:
    25 except ImportError:
    26     pass
    26     pass
    27 
    27 
    28 class CompatibilityException(Exception): pass
    28 class CompatibilityException(Exception): pass
    29 
       
    30 class svn_entry(object):
       
    31     """Emulate a Subversion path change."""
       
    32     __slots__ = ['path', 'copyfrom_path', 'copyfrom_rev', 'action']
       
    33     def __init__(self, entry):
       
    34         self.copyfrom_path = entry.copyfrom_path
       
    35         self.copyfrom_rev = entry.copyfrom_rev
       
    36         self.action = entry.action
       
    37 
       
    38     def __str__(self):
       
    39         return "%s %s %s" % (self.action, self.copyfrom_path, self.copyfrom_rev)
       
    40 
       
    41     def __repr__(self):
       
    42         return self.__str__()
       
    43 
       
    44 class svn_paths(object):
       
    45     """Emulate a Subversion ordered dictionary of changed paths."""
       
    46     __slots__ = ['values', 'order']
       
    47     def __init__(self, orig_paths):
       
    48         self.order = []
       
    49         self.values = {}
       
    50         if hasattr(orig_paths, 'keys'):
       
    51             self.order = sorted(orig_paths.keys())
       
    52             self.values.update(orig_paths)
       
    53             return
       
    54         if not orig_paths:
       
    55             return
       
    56         for path in orig_paths:
       
    57             self.order.append(path)
       
    58             self.values[path] = svn_entry(orig_paths[path])
       
    59         self.order.sort() # maybe the order it came in isn't so great...
       
    60 
       
    61     def __iter__(self):
       
    62         return iter(self.order)
       
    63 
       
    64     def __getitem__(self, key):
       
    65         return self.values[key]
       
    66 
       
    67     def __str__(self):
       
    68         s = "{\n"
       
    69         for path in self.order:
       
    70             s += "'%s': %s,\n" % (path, self.values[path])
       
    71         s += "}"
       
    72         return s
       
    73     
       
    74     def __repr__(self):
       
    75         return self.__str__()
       
    76 
    29 
    77 # SVN conversion code stolen from bzr-svn and tailor
    30 # SVN conversion code stolen from bzr-svn and tailor
    78 class convert_svn(converter_source):
    31 class convert_svn(converter_source):
    79     def __init__(self, ui, url, rev=None):
    32     def __init__(self, ui, url, rev=None):
    80         super(convert_svn, self).__init__(ui, url, rev=rev)
    33         super(convert_svn, self).__init__(ui, url, rev=rev)
   211             received.append(arg)
   164             received.append(arg)
   212 
   165 
   213         self.child_cset = None
   166         self.child_cset = None
   214         def parselogentry(*arg, **args):
   167         def parselogentry(*arg, **args):
   215             orig_paths, revnum, author, date, message, pool = arg
   168             orig_paths, revnum, author, date, message, pool = arg
   216             orig_paths = svn_paths(orig_paths)
       
   217 
   169 
   218             if self.is_blacklisted(revnum):
   170             if self.is_blacklisted(revnum):
   219                 self.ui.note('skipping blacklisted revision %d\n' % revnum)
   171                 self.ui.note('skipping blacklisted revision %d\n' % revnum)
   220                 return
   172                 return
   221 
   173 
   241                 if branch == 'trunk':
   193                 if branch == 'trunk':
   242                     branch = ''
   194                     branch = ''
   243             except IndexError:
   195             except IndexError:
   244                 branch = None
   196                 branch = None
   245                 
   197                 
   246             for path in orig_paths:
   198             for path in sorted(orig_paths):
   247                 # self.ui.write("path %s\n" % path)
   199                 # self.ui.write("path %s\n" % path)
   248                 if path == self.module: # Follow branching back in history
   200                 if path == self.module: # Follow branching back in history
   249                     ent = orig_paths[path]
   201                     ent = orig_paths[path]
   250                     if ent:
   202                     if ent:
   251                         if ent.copyfrom_path:
   203                         if ent.copyfrom_path:
   548 
   500 
   549     def gettags(self):
   501     def gettags(self):
   550         tags = {}
   502         tags = {}
   551         def parselogentry(*arg, **args):
   503         def parselogentry(*arg, **args):
   552             orig_paths, revnum, author, date, message, pool = arg
   504             orig_paths, revnum, author, date, message, pool = arg
   553             orig_paths = svn_paths(orig_paths)
       
   554             for path in orig_paths:
   505             for path in orig_paths:
   555                 if not path.startswith('/tags/'):
   506                 if not path.startswith('/tags/'):
   556                     continue
   507                     continue
   557                 ent = orig_paths[path]
   508                 ent = orig_paths[path]
   558                 source = ent.copyfrom_path
   509                 source = ent.copyfrom_path