hgext/convert/__init__.py
changeset 4754 7c8cd400e86a
parent 4753 07efcce17d28
child 4756 8e9d3faec270
equal deleted inserted replaced
4753:07efcce17d28 4754:7c8cd400e86a
     8 from common import NoRepo
     8 from common import NoRepo
     9 from cvs import convert_cvs
     9 from cvs import convert_cvs
    10 from git import convert_git
    10 from git import convert_git
    11 from hg import convert_mercurial
    11 from hg import convert_mercurial
    12 
    12 
    13 import os
    13 import os, shutil
    14 from mercurial import hg, ui, util, commands
    14 from mercurial import hg, ui, util, commands
    15 
    15 
    16 commands.norepo += " convert"
    16 commands.norepo += " convert"
    17 
    17 
    18 converters = [convert_cvs, convert_git, convert_mercurial]
    18 converters = [convert_cvs, convert_git, convert_mercurial]
   272     that use unix logins to identify authors (eg: CVS). One line per author
   272     that use unix logins to identify authors (eg: CVS). One line per author
   273     mapping and the line format is:
   273     mapping and the line format is:
   274     srcauthor=whatever string you want
   274     srcauthor=whatever string you want
   275     '''
   275     '''
   276 
   276 
   277     srcc = converter(ui, src, rev=opts.get('rev'))
       
   278     if not hasattr(srcc, "getcommit"):
       
   279         raise util.Abort("%s: can't read from this repo type" % src)
       
   280 
       
   281     if not dest:
   277     if not dest:
   282         dest = src + "-hg"
   278         dest = src + "-hg"
   283         ui.status("assuming destination %s\n" % dest)
   279         ui.status("assuming destination %s\n" % dest)
   284 
   280 
   285     # Try to be smart and initalize things when required
   281     # Try to be smart and initalize things when required
       
   282     created = False
   286     if os.path.isdir(dest):
   283     if os.path.isdir(dest):
   287         if len(os.listdir(dest)) > 0:
   284         if len(os.listdir(dest)) > 0:
   288             try:
   285             try:
   289                 hg.repository(ui, dest)
   286                 hg.repository(ui, dest)
   290                 ui.status("destination %s is a Mercurial repository\n" % dest)
   287                 ui.status("destination %s is a Mercurial repository\n" % dest)
   295                     "or an already initialized mercurial repository"
   292                     "or an already initialized mercurial repository"
   296                     % dest)
   293                     % dest)
   297         else:
   294         else:
   298             ui.status("initializing destination %s repository\n" % dest)
   295             ui.status("initializing destination %s repository\n" % dest)
   299             hg.repository(ui, dest, create=True)
   296             hg.repository(ui, dest, create=True)
       
   297             created = True
   300     elif os.path.exists(dest):
   298     elif os.path.exists(dest):
   301         raise util.Abort("destination %s exists and is not a directory" % dest)
   299         raise util.Abort("destination %s exists and is not a directory" % dest)
   302     else:
   300     else:
   303         ui.status("initializing destination %s repository\n" % dest)
   301         ui.status("initializing destination %s repository\n" % dest)
   304         hg.repository(ui, dest, create=True)
   302         hg.repository(ui, dest, create=True)
       
   303         created = True
   305 
   304 
   306     destc = converter(ui, dest)
   305     destc = converter(ui, dest)
   307     if not hasattr(destc, "putcommit"):
   306     if not hasattr(destc, "putcommit"):
   308         raise util.Abort("%s: can't write to this repo type" % src)
   307         raise util.Abort("%s: can't write to this repo type" % src)
       
   308 
       
   309     try:
       
   310         srcc = converter(ui, src, rev=opts.get('rev'))
       
   311         if not hasattr(srcc, "getcommit"):
       
   312             raise util.Abort("%s: can't read from this repo type" % src)
       
   313     except Exception:
       
   314         if created:
       
   315             shutil.rmtree(dest, True)
       
   316         raise
   309 
   317 
   310     if not mapfile:
   318     if not mapfile:
   311         try:
   319         try:
   312             mapfile = destc.mapfile()
   320             mapfile = destc.mapfile()
   313         except:
   321         except: