hgext/convert/convcmd.py
changeset 26587 56b2bcea2529
parent 26035 86598f4fe1cf
child 26812 58a309e9cf80
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
    16 from bzr import bzr_source
    16 from bzr import bzr_source
    17 from p4 import p4_source
    17 from p4 import p4_source
    18 import filemap
    18 import filemap
    19 
    19 
    20 import os, shutil, shlex
    20 import os, shutil, shlex
    21 from mercurial import hg, util, encoding
    21 from mercurial import hg, util, encoding, error
    22 from mercurial.i18n import _
    22 from mercurial.i18n import _
    23 
    23 
    24 orig_encoding = 'ascii'
    24 orig_encoding = 'ascii'
    25 
    25 
    26 def recode(s):
    26 def recode(s):
    80     ]
    80     ]
    81 
    81 
    82 def convertsource(ui, path, type, revs):
    82 def convertsource(ui, path, type, revs):
    83     exceptions = []
    83     exceptions = []
    84     if type and type not in [s[0] for s in source_converters]:
    84     if type and type not in [s[0] for s in source_converters]:
    85         raise util.Abort(_('%s: invalid source repository type') % type)
    85         raise error.Abort(_('%s: invalid source repository type') % type)
    86     for name, source, sortmode in source_converters:
    86     for name, source, sortmode in source_converters:
    87         try:
    87         try:
    88             if not type or name == type:
    88             if not type or name == type:
    89                 return source(ui, path, revs), sortmode
    89                 return source(ui, path, revs), sortmode
    90         except (NoRepo, MissingTool) as inst:
    90         except (NoRepo, MissingTool) as inst:
    91             exceptions.append(inst)
    91             exceptions.append(inst)
    92     if not ui.quiet:
    92     if not ui.quiet:
    93         for inst in exceptions:
    93         for inst in exceptions:
    94             ui.write("%s\n" % inst)
    94             ui.write("%s\n" % inst)
    95     raise util.Abort(_('%s: missing or unsupported repository') % path)
    95     raise error.Abort(_('%s: missing or unsupported repository') % path)
    96 
    96 
    97 def convertsink(ui, path, type):
    97 def convertsink(ui, path, type):
    98     if type and type not in [s[0] for s in sink_converters]:
    98     if type and type not in [s[0] for s in sink_converters]:
    99         raise util.Abort(_('%s: invalid destination repository type') % type)
    99         raise error.Abort(_('%s: invalid destination repository type') % type)
   100     for name, sink in sink_converters:
   100     for name, sink in sink_converters:
   101         try:
   101         try:
   102             if not type or name == type:
   102             if not type or name == type:
   103                 return sink(ui, path)
   103                 return sink(ui, path)
   104         except NoRepo as inst:
   104         except NoRepo as inst:
   105             ui.note(_("convert: %s\n") % inst)
   105             ui.note(_("convert: %s\n") % inst)
   106         except MissingTool as inst:
   106         except MissingTool as inst:
   107             raise util.Abort('%s\n' % inst)
   107             raise error.Abort('%s\n' % inst)
   108     raise util.Abort(_('%s: unknown repository type') % path)
   108     raise error.Abort(_('%s: unknown repository type') % path)
   109 
   109 
   110 class progresssource(object):
   110 class progresssource(object):
   111     def __init__(self, ui, source, filecount):
   111     def __init__(self, ui, source, filecount):
   112         self.ui = ui
   112         self.ui = ui
   113         self.source = source
   113         self.source = source
   183                 lex.whitespace_split = True
   183                 lex.whitespace_split = True
   184                 lex.whitespace += ','
   184                 lex.whitespace += ','
   185                 line = list(lex)
   185                 line = list(lex)
   186                 # check number of parents
   186                 # check number of parents
   187                 if not (2 <= len(line) <= 3):
   187                 if not (2 <= len(line) <= 3):
   188                     raise util.Abort(_('syntax error in %s(%d): child parent1'
   188                     raise error.Abort(_('syntax error in %s(%d): child parent1'
   189                                        '[,parent2] expected') % (path, i + 1))
   189                                        '[,parent2] expected') % (path, i + 1))
   190                 for part in line:
   190                 for part in line:
   191                     self.source.checkrevformat(part)
   191                     self.source.checkrevformat(part)
   192                 child, p1, p2 = line[0], line[1:2], line[2:]
   192                 child, p1, p2 = line[0], line[1:2], line[2:]
   193                 if p1 == p2:
   193                 if p1 == p2:
   194                     m[child] = p1
   194                     m[child] = p1
   195                 else:
   195                 else:
   196                     m[child] = p1 + p2
   196                     m[child] = p1 + p2
   197          # if file does not exist or error reading, exit
   197          # if file does not exist or error reading, exit
   198         except IOError:
   198         except IOError:
   199             raise util.Abort(_('splicemap file not found or error reading %s:')
   199             raise error.Abort(_('splicemap file not found or error reading %s:')
   200                                % path)
   200                                % path)
   201         return m
   201         return m
   202 
   202 
   203 
   203 
   204     def walktree(self, heads):
   204     def walktree(self, heads):
   245                 # We do not have to wait for nodes already in dest.
   245                 # We do not have to wait for nodes already in dest.
   246                 if self.dest.hascommitforsplicemap(self.map.get(p, p)):
   246                 if self.dest.hascommitforsplicemap(self.map.get(p, p)):
   247                     continue
   247                     continue
   248                 # Parent is not in dest and not being converted, not good
   248                 # Parent is not in dest and not being converted, not good
   249                 if p not in parents:
   249                 if p not in parents:
   250                     raise util.Abort(_('unknown splice map parent: %s') % p)
   250                     raise error.Abort(_('unknown splice map parent: %s') % p)
   251                 pc.append(p)
   251                 pc.append(p)
   252             parents[c] = pc
   252             parents[c] = pc
   253 
   253 
   254     def toposort(self, parents, sortmode):
   254     def toposort(self, parents, sortmode):
   255         '''Return an ordering such that every uncommitted changeset is
   255         '''Return an ordering such that every uncommitted changeset is
   341         elif sortmode == 'sourcesort':
   341         elif sortmode == 'sourcesort':
   342             picknext = makesourcesorter()
   342             picknext = makesourcesorter()
   343         elif sortmode == 'closesort':
   343         elif sortmode == 'closesort':
   344             picknext = makeclosesorter()
   344             picknext = makeclosesorter()
   345         else:
   345         else:
   346             raise util.Abort(_('unknown sort mode: %s') % sortmode)
   346             raise error.Abort(_('unknown sort mode: %s') % sortmode)
   347 
   347 
   348         children, actives = mapchildren(parents)
   348         children, actives = mapchildren(parents)
   349 
   349 
   350         s = []
   350         s = []
   351         pendings = {}
   351         pendings = {}
   359                 if c not in pendings:
   359                 if c not in pendings:
   360                     pendings[c] = [p for p in parents[c] if p not in self.map]
   360                     pendings[c] = [p for p in parents[c] if p not in self.map]
   361                 try:
   361                 try:
   362                     pendings[c].remove(n)
   362                     pendings[c].remove(n)
   363                 except ValueError:
   363                 except ValueError:
   364                     raise util.Abort(_('cycle detected between %s and %s')
   364                     raise error.Abort(_('cycle detected between %s and %s')
   365                                        % (recode(c), recode(n)))
   365                                        % (recode(c), recode(n)))
   366                 if not pendings[c]:
   366                 if not pendings[c]:
   367                     # Parents are converted, node is eligible
   367                     # Parents are converted, node is eligible
   368                     actives.insert(0, c)
   368                     actives.insert(0, c)
   369                     pendings[c] = None
   369                     pendings[c] = None
   370 
   370 
   371         if len(s) != len(parents):
   371         if len(s) != len(parents):
   372             raise util.Abort(_("not all revisions were sorted"))
   372             raise error.Abort(_("not all revisions were sorted"))
   373 
   373 
   374         return s
   374         return s
   375 
   375 
   376     def writeauthormap(self):
   376     def writeauthormap(self):
   377         authorfile = self.authorfile
   377         authorfile = self.authorfile
   554         raise
   554         raise
   555 
   555 
   556     sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort')
   556     sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort')
   557     sortmode = [m for m in sortmodes if opts.get(m)]
   557     sortmode = [m for m in sortmodes if opts.get(m)]
   558     if len(sortmode) > 1:
   558     if len(sortmode) > 1:
   559         raise util.Abort(_('more than one sort mode specified'))
   559         raise error.Abort(_('more than one sort mode specified'))
   560     if sortmode:
   560     if sortmode:
   561         sortmode = sortmode[0]
   561         sortmode = sortmode[0]
   562     else:
   562     else:
   563         sortmode = defaultsort
   563         sortmode = defaultsort
   564 
   564 
   565     if sortmode == 'sourcesort' and not srcc.hasnativeorder():
   565     if sortmode == 'sourcesort' and not srcc.hasnativeorder():
   566         raise util.Abort(_('--sourcesort is not supported by this data source'))
   566         raise error.Abort(_('--sourcesort is not supported by this data source')
       
   567                          )
   567     if sortmode == 'closesort' and not srcc.hasnativeclose():
   568     if sortmode == 'closesort' and not srcc.hasnativeclose():
   568         raise util.Abort(_('--closesort is not supported by this data source'))
   569         raise error.Abort(_('--closesort is not supported by this data source'))
   569 
   570 
   570     fmap = opts.get('filemap')
   571     fmap = opts.get('filemap')
   571     if fmap:
   572     if fmap:
   572         srcc = filemap.filemap_source(ui, srcc, fmap)
   573         srcc = filemap.filemap_source(ui, srcc, fmap)
   573         destc.setfilemapmode(True)
   574         destc.setfilemapmode(True)