Exemplo n.º 1
0
def refresh_hg_submodule(name, subrepo_info):
    gitRepoLocation = submodule_mappings[name] + b"/.git"

    # Populate the cache to map mercurial revision to git revision
    if not name in subrepo_cache:
        subrepo_cache[name] = (load_cache(gitRepoLocation +
                                          b"/hg2git-mapping"),
                               load_cache(gitRepoLocation + b"/hg2git-marks",
                                          lambda s: int(s) - 1))

    (mapping_cache, marks_cache) = subrepo_cache[name]
    subrepo_hash = subrepo_info[1]
    if subrepo_hash in mapping_cache:
        revnum = mapping_cache[subrepo_hash]
        gitSha = marks_cache[int(revnum)]
        wr(b'M 160000 %s %s' % (gitSha, name))
        stderr_buffer.write(
            b"Adding/updating submodule %s, revision %s->%s\n" %
            (name, subrepo_hash, gitSha))
        return b'[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (
            name, name, submodule_mappings[name])
    else:
        stderr_buffer.write(
            b"Warning: Could not find hg revision %s for %s in git %s\n" % (
                subrepo_hash,
                name,
                gitRepoLocation,
            ))
        return b''
Exemplo n.º 2
0
def refresh_hg_submodule(name, subrepo_info):
    gitRepoLocation = submodule_mappings[name] + "/.git"

    # Populate the cache to map mercurial revision to git revision
    if not name in subrepo_cache:
        subrepo_cache[name] = (load_cache(gitRepoLocation + "/hg2git-mapping"),
                               load_cache(gitRepoLocation + "/hg2git-marks",
                                          lambda s: int(s) - 1))
        sys.stderr.write("Printing out subrepo_cache for %s\n" % (name))
        sys.stderr.write(json.dumps(subrepo_cache))
        # for k in subrepo_cache[name]:
        #   sys.stderr.write("  %s -> %s\n" % (k, subrepo_cache[name][k]))
        sys.stderr.write("subrepo_cache contains %d entries\n" %
                         (len(subrepo_cache[name])))

    (mapping_cache, marks_cache) = subrepo_cache[name]
    subrepo_hash = subrepo_info[1]
    if subrepo_hash in mapping_cache:
        revnum = mapping_cache[subrepo_hash]
        gitSha = marks_cache[int(revnum)]
        wr('M 160000 %s %s' % (gitSha, name))
        sys.stderr.write("Adding/updating submodule %s, revision %s->%s\n" %
                         (name, subrepo_hash, gitSha))
        return '[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (
            name, name, submodule_mappings[name])
    else:
        sys.stderr.write(
            "Warning: Could not find hg revision %s for %s in git %s\n" %
            (subrepo_hash, name, gitRepoLocation))
        return ''
Exemplo n.º 3
0
def refresh_gitmodules(ctx):
  """Updates list of ctx submodules according to .hgsubstate file"""
  remove_gitmodules(ctx)
  gitmodules=""
  # Create the .gitmodules file and all submodules
  for name,subrepo_info in ctx.substate.items():
    gitRepoLocation=submodule_mappings[name] + "/.git"

    # Populate the cache to map mercurial revision to git revision
    if not name in subrepo_cache:
      subrepo_cache[name]=(load_cache(gitRepoLocation+"/hg2git-mapping"),
                           load_cache(gitRepoLocation+"/hg2git-marks",
                                      lambda s: int(s)-1))

    (mapping_cache,marks_cache)=subrepo_cache[name]
    subrepo_hash=subrepo_info[1]
    if subrepo_hash in mapping_cache:
      revnum=mapping_cache[subrepo_hash]
      gitSha=marks_cache[int(revnum)]
      wr('M 160000 %s %s' % (gitSha,name))
      sys.stderr.write("Adding/updating submodule %s, revision %s->%s\n"
                       % (name,subrepo_hash,gitSha))
      gitmodules+='[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name,name,
        submodule_mappings[name])
    else:
      sys.stderr.write("Warning: Could not find hg revision %s for %s in git %s\n" %
        (subrepo_hash,name,gitRepoLocation))

  if len(gitmodules):
    wr('M 100644 inline .gitmodules')
    wr('data %d' % (len(gitmodules)+1))
    wr(gitmodules)
Exemplo n.º 4
0
def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,
           authors={},branchesmap={},tagsmap={},
           sob=False,force=False,hgtags=False,notes=False,encoding='',fn_encoding=''):
  def check_cache(filename, contents):
    if len(contents) == 0:
      sys.stderr.write('Warning: %s does not contain any data, this will probably make an incremental import fail\n' % filename)

  _max=int(m)

  old_marks=load_cache(marksfile,lambda s: int(s)-1)
  mapping_cache=load_cache(mappingfile)
  heads_cache=load_cache(headsfile)
  state_cache=load_cache(tipfile)

  if len(state_cache) != 0:
    for (name, data) in [(marksfile, old_marks),
                         (mappingfile, mapping_cache),
                         (headsfile, state_cache)]:
      check_cache(name, data)

  ui,repo=setup_repo(repourl)

  if not verify_heads(ui,repo,heads_cache,force,branchesmap):
    return 1

  try:
    tip=repo.changelog.count()
  except AttributeError:
    tip=len(repo)

  min=int(state_cache.get('tip',0))
  max=_max
  if _max<0 or max>tip:
    max=tip

  for rev in range(0,max):
  	(revnode,_,_,_,_,_,_,_)=get_changeset(ui,repo,rev,authors)
  	mapping_cache[revnode.encode('hex_codec')] = str(rev)


  c=0
  brmap={}
  for rev in range(min,max):
    c=export_commit(ui,repo,rev,old_marks,max,c,authors,branchesmap,
                    sob,brmap,hgtags,encoding,fn_encoding)
  if notes:
    for rev in range(min,max):
      c=export_note(ui,repo,rev,c,authors, encoding, rev == min and min != 0)

  state_cache['tip']=max
  state_cache['repo']=repourl
  save_cache(tipfile,state_cache)
  save_cache(mappingfile,mapping_cache)

  c=export_tags(ui,repo,old_marks,mapping_cache,c,authors,tagsmap)

  sys.stderr.write('Issued %d commands\n' % c)

  return 0
Exemplo n.º 5
0
def hg2git(repourl,
           m,
           marksfile,
           mappingfile,
           headsfile,
           tipfile,
           authors={},
           branchesmap={},
           tagsmap={},
           sob=False,
           force=False,
           hgtags=False,
           notes=False,
           encoding='',
           fn_encoding=''):
    _max = int(m)

    old_marks = load_cache(marksfile, lambda s: int(s) - 1)
    mapping_cache = load_cache(mappingfile)
    heads_cache = load_cache(headsfile)
    state_cache = load_cache(tipfile)

    ui, repo = setup_repo(repourl)

    if not verify_heads(ui, repo, heads_cache, force):
        return 1

    try:
        tip = repo.changelog.count()
    except AttributeError:
        tip = len(repo)

    min = int(state_cache.get('tip', 0))
    max = _max
    if _max < 0 or max > tip:
        max = tip

    for rev in range(0, max):
        (revnode, _, _, _, _, _, _, _) = get_changeset(ui, repo, rev, authors)
        mapping_cache[revnode.encode('hex_codec')] = str(rev)

    c = 0
    brmap = {}
    for rev in range(min, max):
        c = export_commit(ui, repo, rev, old_marks, max, c, authors,
                          branchesmap, sob, brmap, hgtags, notes, encoding,
                          fn_encoding)

    state_cache['tip'] = max
    state_cache['repo'] = repourl
    save_cache(tipfile, state_cache)
    save_cache(mappingfile, mapping_cache)

    c = export_tags(ui, repo, old_marks, mapping_cache, c, authors, tagsmap)

    sys.stderr.write('Issued %d commands\n' % c)

    return 0
Exemplo n.º 6
0
def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=False,force=False,hgtags=False,notes=False,ignoreSub=False,fixBranch=False,encoding=''):
  _max=int(m)

  old_marks=load_cache(marksfile,lambda s: int(s)-1)
  mapping_cache=load_cache(mappingfile)
  heads_cache=load_cache(headsfile)
  state_cache=load_cache(tipfile)

  ui,repo=setup_repo(repourl)

  if not verify_heads(ui,repo,heads_cache,force):
    return 1

  try:
    tip=repo.changelog.count()
  except AttributeError:
    tip=len(repo)

  min=int(state_cache.get('tip',0))
  max=_max
  if _max<0 or max>tip:
    max=tip

  subRepoWarnings = {}
  for rev in range(0,max):
    if not ignoreSub:
      # check if repository uses unconverted subrepos
      ctx=repo.changectx(str(rev))
      if (ctx.substate):
        subRepoWarnings=verify_subrepo(repourl, ctx, subRepoWarnings)
    (revnode,_,_,_,_,_,_,_)=get_changeset(ui,repo,rev,authors)
    mapping_cache[revnode.encode('hex_codec')] = str(rev)

  if subRepoWarnings:
    sys.stderr.write("\n")
    for key in subRepoWarnings.keys():
      sys.stderr.write(subRepoWarnings[key])
    sys.stderr.write("\n")
    return 1
  c=0
  brmap={}
  for rev in range(min,max):
    c=export_commit(ui,repo,rev,old_marks,max,c,authors,sob,brmap,hgtags,notes,repourl,ignoreSub,fixBranch,encoding)

  state_cache['tip']=max
  state_cache['repo']=repourl
  save_cache(tipfile,state_cache)
  save_cache(mappingfile,mapping_cache)

  c=export_tags(ui,repo,old_marks,mapping_cache,c,authors)

  sys.stderr.write('Issued %d commands\n' % c)

  return 0
Exemplo n.º 7
0
def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,
           authors={},branchesmap={},tagsmap={},
           sob=False,force=False,hgtags=False,notes=False,encoding='',fn_encoding=''):
  _max=int(m)

  old_marks=load_cache(marksfile,lambda s: int(s)-1)
  mapping_cache=load_cache(mappingfile)
  heads_cache=load_cache(headsfile)
  state_cache=load_cache(tipfile)

  ui,repo=setup_repo(repourl)

  if not verify_heads(ui,repo,heads_cache,force):
    return 1

  try:
    tip=repo.changelog.count()
  except AttributeError:
    tip=len(repo)

  min=int(state_cache.get('tip',0))
  max=_max
  if _max<0 or max>tip:
    max=tip

  for rev in range(0,max):
  	(revnode,_,_,_,_,_,_,_)=get_changeset(ui,repo,rev,authors)
  	mapping_cache[revnode.encode('hex_codec')] = str(rev)


  c=0
  brmap={}
  for rev in range(min,max):
    c=export_commit(ui,repo,rev,old_marks,max,c,authors,branchesmap,
                    sob,brmap,hgtags,encoding,fn_encoding)
  if notes:
    for rev in range(min,max):
      c=export_note(ui,repo,rev,c,authors, encoding, rev == min and min != 0)

  state_cache['tip']=max
  state_cache['repo']=repourl
  save_cache(tipfile,state_cache)
  save_cache(mappingfile,mapping_cache)

  c=export_tags(ui,repo,old_marks,mapping_cache,c,authors,tagsmap)

  sys.stderr.write('Issued %d commands\n' % c)

  return 0
Exemplo n.º 8
0
def export_file_contents(ctx,
                         manifest,
                         files,
                         hgtags,
                         repourl,
                         revnode,
                         ignoreSub,
                         encoding=''):
    count = 0
    max = len(files)
    for file in files:
        # create submodule file istead of .hgsubstate file
        if not ignoreSub and ctx.substate and file == ".hgsubstate":
            smContent = ""
            for name in ctx.substate:
                subRepoDir = ctx.substate[name][0]
                linkFileName = repourl + "/" + name + "/.hg/link2git"
                if (os.path.isfile(linkFileName)):
                    gitRepoLocation = open(linkFileName, "r").read()
                    if not name in subrepo_cache:
                        subrepo_cache[name] = load_cache(gitRepoLocation +
                                                         "/hg2git-revisions")
                    gitRepo = Repo(gitRepoLocation)
                    smContent += '[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (
                        name, name, gitRepo.remotes.origin.url)
            wr('M 100644 inline .gitmodules')
            wr('data %d' % (len(smContent) + 1))
            wr(smContent)
            # read .hgsubstate file
            data = ctx.filectx(file).data()
            subHashes = {}
            for line in data.split('\n'):
                if line.strip() == "":
                    continue
                cols = line.split(' ')
                subHashes[cols[1]] = cols[0]
            for name in ctx.substate:
                if subHashes[name] in subrepo_cache[name]:
                    gitSha = subrepo_cache[name][subHashes[name]]
                    wr('M 160000 %s %s' % (gitSha, name))
            continue
        # Skip .hgtags files. They only get us in trouble.
        if not hgtags and file == ".hgtags":
            sys.stderr.write('Skip %s\n' % (file))
            continue
        d = ctx.filectx(file).data()
        if encoding:
            filename = file.decode(encoding).encode('utf8')
        else:
            filename = file
        wr('M %s inline %s' % (gitmode(manifest.flags(file)), filename))
        wr('data %d' % len(d))  # had some trouble with size()
        wr(d)
        count += 1
        if count % cfg_export_boundary == 0:
            sys.stderr.write('Exported %d/%d files\n' % (count, max))
    if max > cfg_export_boundary:
        sys.stderr.write('Exported %d/%d files\n' % (count, max))
Exemplo n.º 9
0
def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=False,force=False):
  _max=int(m)

  marks_cache=load_cache(marksfile,mangle_mark)
  mapping_cache=load_cache(mappingfile)
  heads_cache=load_cache(headsfile)
  state_cache=load_cache(tipfile)

  ui,repo=setup_repo(repourl)

  if not verify_heads(ui,repo,heads_cache,force):
    return 1

  try:
    tip=repo.changelog.count()
  except AttributeError:
    tip=len(repo)

  min=int(state_cache.get('tip',0))
  max=_max
  if _max<0 or max>tip:
    max=tip

  for rev in range(0,max):
  	(revnode,_,_,_,_,_,_,_)=get_changeset(ui,repo,rev,authors)
  	mapping_cache[revnode.encode('hex_codec')] = str(rev)


  c=0
  last={}
  brmap={}
  for rev in range(min,max):
    c=export_commit(ui,repo,rev,marks_cache,mapping_cache,heads_cache,last,max,c,authors,sob,brmap)

  state_cache['tip']=max
  state_cache['repo']=repourl
  save_cache(tipfile,state_cache)
  save_cache(mappingfile,mapping_cache)

  c=export_tags(ui,repo,marks_cache,mapping_cache,c,authors)

  sys.stderr.write('Issued %d commands\n' % c)

  return 0
Exemplo n.º 10
0
def export_file_contents(ctx,manifest,files,hgtags,repourl,revnode,ignoreSub,encoding=''):
  count=0
  max=len(files)
  for file in files:
    # create submodule file istead of .hgsubstate file
    if not ignoreSub and ctx.substate and file == ".hgsubstate":
      smContent=""
      for name in ctx.substate:
        subRepoDir=ctx.substate[name][0]
        linkFileName=repourl+"/"+name+"/.hg/link2git"
        if (os.path.isfile(linkFileName)):
          gitRepoLocation=open(linkFileName, "r").read()
          if not name in subrepo_cache:
            subrepo_cache[name] = load_cache(gitRepoLocation+"/hg2git-revisions")
          gitRepo = Repo(gitRepoLocation)
          smContent += '[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name, name, gitRepo.remotes.origin.url)
      wr('M 100644 inline .gitmodules')
      wr('data %d' % (len(smContent)+1))
      wr(smContent)
      # read .hgsubstate file
      data = ctx.filectx(file).data()
      subHashes = {}
      for line in data.split('\n'):
        if line.strip() == "":
          continue
        cols= line.split(' ')
        subHashes[cols[1]]=cols[0]
      for name in ctx.substate:
        if subHashes[name] in subrepo_cache[name]:
          gitSha = subrepo_cache[name][subHashes[name]]
          wr('M 160000 %s %s' % (gitSha, name))
      continue
    # Skip .hgtags files. They only get us in trouble.
    if not hgtags and file == ".hgtags":
      sys.stderr.write('Skip %s\n' % (file))
      continue
    # Skip .git files. They only get us in trouble.
    if '.git' in file:
      sys.stderr.write('Skip %s\n' % (file))
      continue
    d=ctx.filectx(file).data()
    if encoding:
      filename=file.decode(encoding).encode('utf8')
    else:
      filename=file
    wr('M %s inline %s' % (gitmode(manifest.flags(file)),filename))
    wr('data %d' % len(d)) # had some trouble with size()
    wr(d)
    count+=1
    if count%cfg_export_boundary==0:
      sys.stderr.write('Exported %d/%d files\n' % (count,max))
  if max>cfg_export_boundary:
    sys.stderr.write('Exported %d/%d files\n' % (count,max))
Exemplo n.º 11
0
def hg2git(repourl,
           m,
           marksfile,
           mappingfile,
           headsfile,
           tipfile,
           authors={},
           branchesmap={},
           tagsmap={},
           sob=False,
           force=False,
           ignore_unnamed_heads=False,
           hgtags=False,
           notes=False,
           encoding='',
           fn_encoding='',
           plugins={}):
    def check_cache(filename, contents):
        if len(contents) == 0:
            sys.stderr.write(
                'Warning: %s does not contain any data, this will probably make an incremental import fail\n'
                % filename)

    _max = int(m)

    old_marks = load_cache(marksfile, lambda s: int(s) - 1)
    mapping_cache = load_cache(mappingfile)
    heads_cache = load_cache(headsfile)
    state_cache = load_cache(tipfile)

    if len(state_cache) != 0:
        for (name, data) in [(marksfile, old_marks),
                             (mappingfile, mapping_cache),
                             (headsfile, state_cache)]:
            check_cache(name, data)

    ui, repo = setup_repo(repourl)

    if not verify_heads(ui, repo, heads_cache, force, ignore_unnamed_heads,
                        branchesmap):
        return 1

    try:
        tip = repo.changelog.count()
    except AttributeError:
        tip = len(repo)

    min = int(state_cache.get('tip', 0))
    max = _max
    if _max < 0 or max > tip:
        max = tip

    for rev in range(0, max):
        (revnode, _, _, _, _, _, _, _) = get_changeset(ui, repo, rev, authors)
        if repo[revnode].hidden():
            continue
        mapping_cache[hexlify(revnode)] = b"%d" % rev

    if submodule_mappings:
        # Make sure that all mercurial submodules are registered in the submodule-mappings file
        for rev in range(0, max):
            ctx = revsymbol(repo, b"%d" % rev)
            if ctx.hidden():
                continue
            if ctx.substate:
                for key in ctx.substate:
                    if ctx.substate[key][
                            2] == 'hg' and key not in submodule_mappings:
                        sys.stderr.write(
                            "Error: %s not found in submodule-mappings\n" %
                            (key))
                        return 1

    c = 0
    brmap = {}
    for rev in range(min, max):
        c = export_commit(ui, repo, rev, old_marks, max, c, authors,
                          branchesmap, sob, brmap, hgtags, encoding,
                          fn_encoding, plugins)
    if notes:
        for rev in range(min, max):
            c = export_note(ui, repo, rev, c, authors, encoding, rev == min
                            and min != 0)

    state_cache['tip'] = max
    state_cache['repo'] = repourl
    save_cache(tipfile, state_cache)
    save_cache(mappingfile, mapping_cache)

    c = export_tags(ui, repo, old_marks, mapping_cache, c, authors, tagsmap)

    sys.stderr.write('Issued %d commands\n' % c)

    return 0
Exemplo n.º 12
0
    parser.add_option("-R",
                      "--revision",
                      type=int,
                      dest="revision",
                      help="Revision to reset to")

    (options, args) = parser.parse_args()

    if options.marksfile == None: bail(parser, '--marks option')
    if options.mappingfile == None: bail(parser, '--mapping option')
    if options.headsfile == None: bail(parser, '--heads option')
    if options.statusfile == None: bail(parser, '--status option')
    if options.repourl == None: bail(parser, '--repo option')
    if options.revision == None: bail(parser, '-R/--revision')

    heads_cache = load_cache(options.headsfile)
    marks_cache = load_cache(options.marksfile, mangle_mark)
    state_cache = load_cache(options.statusfile)
    mapping_cache = load_cache(options.mappingfile)

    l = int(state_cache.get('tip', options.revision))
    if options.revision + 1 > l:
        sys.stderr.write('Revision is beyond last revision imported: %d>%d\n' %
                         (options.revision, l))
        sys.exit(1)

    ui, repo = setup_repo(options.repourl)

    stale, changed, unchanged = get_branches(ui, repo, heads_cache,
                                             marks_cache, mapping_cache,
                                             options.revision + 1)
Exemplo n.º 13
0
def hg2git(repourl,
           m,
           marksfile,
           mappingfile,
           headsfile,
           tipfile,
           authors={},
           sob=False,
           force=False,
           hgtags=False,
           notes=False,
           ignoreSub=False,
           fixBranch=False,
           encoding=''):
    _max = int(m)

    old_marks = load_cache(marksfile, lambda s: int(s) - 1)
    mapping_cache = load_cache(mappingfile)
    heads_cache = load_cache(headsfile)
    state_cache = load_cache(tipfile)

    ui, repo = setup_repo(repourl)

    if not verify_heads(ui, repo, heads_cache, force):
        return 1

    try:
        tip = repo.changelog.count()
    except AttributeError:
        tip = len(repo)

    min = int(state_cache.get('tip', 0))
    max = _max
    if _max < 0 or max > tip:
        max = tip

    subRepoWarnings = {}
    for rev in range(0, max):
        if not ignoreSub:
            # check if repository uses unconverted subrepos
            ctx = repo.changectx(str(rev))
            if (ctx.substate):
                subRepoWarnings = verify_subrepo(repourl, ctx, subRepoWarnings)
        (revnode, _, _, _, _, _, _, _) = get_changeset(ui, repo, rev, authors)
        mapping_cache[revnode.encode('hex_codec')] = str(rev)

    if subRepoWarnings:
        sys.stderr.write("\n")
        for key in subRepoWarnings.keys():
            sys.stderr.write(subRepoWarnings[key])
        sys.stderr.write("\n")
        return 1
    c = 0
    brmap = {}
    for rev in range(min, max):
        c = export_commit(ui, repo, rev, old_marks, max, c, authors, sob,
                          brmap, hgtags, notes, repourl, ignoreSub, fixBranch,
                          encoding)

    state_cache['tip'] = max
    state_cache['repo'] = repourl
    save_cache(tipfile, state_cache)
    save_cache(mappingfile, mapping_cache)

    c = export_tags(ui, repo, old_marks, mapping_cache, c, authors)

    sys.stderr.write('Issued %d commands\n' % c)

    return 0
Exemplo n.º 14
0
  parser.add_option("--status",dest="statusfile",
      help="File to read status from")
  parser.add_option("-r","--repo",dest="repourl",
      help="URL of repo to import")
  parser.add_option("-R","--revision",type=int,dest="revision",
      help="Revision to reset to")

  (options,args)=parser.parse_args()

  if options.marksfile==None: bail(parser,'--marks option')
  if options.headsfile==None: bail(parser,'--heads option')
  if options.statusfile==None: bail(parser,'--status option')
  if options.repourl==None: bail(parser,'--repo option')
  if options.revision==None: bail(parser,'-R/--revision')

  heads_cache=load_cache(options.headsfile)
  marks_cache=load_cache(options.marksfile,mangle_mark)
  state_cache=load_cache(options.statusfile)

  l=int(state_cache.get('tip',options.revision))
  if options.revision+1>l:
    sys.stderr.write('Revision is beyond last revision imported: %d>%d\n' % (options.revision,l))
    sys.exit(1)

  ui,repo=setup_repo(options.repourl)

  stale,changed,unchanged=get_branches(ui,repo,heads_cache,marks_cache,mapping_cache,options.revision+1)
  good,bad=get_tags(ui,repo,marks_cache,mapping_cache,options.revision+1)

  print "Possibly stale branches:"
  map(lambda b: sys.stdout.write('\t%s\n' % b),stale.keys())
Exemplo n.º 15
0
def export_file_contents(ctx,
                         manifest,
                         files,
                         hgtags,
                         encoding='',
                         plugins={}):
    count = 0
    max = len(files)
    for file in files:
        if submodule_mappings and ctx.substate and file == ".hgsubstate":
            # Remove all submodules as we don't detect deleted submodules properly
            # in any other way. We will add the ones not deleted back again below.
            for module in submodule_mappings.keys():
                wr('D %s' % module)

            # Read .hgsubstate file in order to find the revision of each subrepo
            data = ctx.filectx(file).data()
            subHashes = {}
            for line in data.split('\n'):
                if line.strip() == "":
                    continue
                cols = line.split(' ')
                subHashes[cols[1]] = cols[0]

            gitmodules = ""
            # Create the .gitmodules file and all submodules
            for name in ctx.substate:
                gitRepoLocation = submodule_mappings[name] + "/.git"

                # Populate the cache to map mercurial revision to git revision
                if not name in subrepo_cache:
                    subrepo_cache[name] = (load_cache(gitRepoLocation +
                                                      "/hg2git-mapping"),
                                           load_cache(
                                               gitRepoLocation +
                                               "/hg2git-marks",
                                               lambda s: int(s) - 1))

                (mapping_cache, marks_cache) = subrepo_cache[name]
                if subHashes[name] in mapping_cache:
                    revnum = mapping_cache[subHashes[name]]
                    gitSha = marks_cache[int(revnum)]
                    wr('M 160000 %s %s' % (gitSha, name))
                    sys.stderr.write("Adding submodule %s, revision %s->%s\n" %
                                     (name, subHashes[name], gitSha))
                    gitmodules += '[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (
                        name, name, submodule_mappings[name])
                else:
                    sys.stderr.write(
                        "Warning: Could not find hg revision %s for %s in git %s\n"
                        % (subHashes[name], name, gitRepoLocation))

            if len(gitmodules):
                wr('M 100644 inline .gitmodules')
                wr('data %d' % (len(gitmodules) + 1))
                wr(gitmodules)

        # Skip .hgtags files. They only get us in trouble.
        if not hgtags and file == ".hgtags":
            sys.stderr.write('Skip %s\n' % (file))
            continue
        if encoding:
            filename = file.decode(encoding).encode('utf8')
        else:
            filename = file
        file_ctx = ctx.filectx(file)
        d = file_ctx.data()

        if plugins and plugins['file_data_filters']:
            file_data = {'filename': filename, 'file_ctx': file_ctx, 'data': d}
            for filter in plugins['file_data_filters']:
                filter(file_data)
            d = file_data['data']
            filename = file_data['filename']
            file_ctx = file_data['file_ctx']

        wr('M %s inline %s' %
           (gitmode(manifest.flags(file)), strip_leading_slash(filename)))
        wr('data %d' % len(d))  # had some trouble with size()
        wr(d)
        count += 1
        if count % cfg_export_boundary == 0:
            sys.stderr.write('Exported %d/%d files\n' % (count, max))
    if max > cfg_export_boundary:
        sys.stderr.write('Exported %d/%d files\n' % (count, max))
Exemplo n.º 16
0
      if not force: return False
    t[branch]=True

  return True

def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,
           authors={},branchesmap={},tagsmap={},
           sob=False,force=False,hgtags=False,notes=False,encoding='',fn_encoding='',
           plugins={}):
  def check_cache(filename, contents):
    if len(contents) == 0:
      sys.stderr.write('Warning: %s does not contain any data, this will probably make an incremental import fail\n' % filename)

  _max=int(m)

  old_marks=load_cache(marksfile,lambda s: int(s)-1)
  mapping_cache=load_cache(mappingfile)
  heads_cache=load_cache(headsfile)
  state_cache=load_cache(tipfile)

  if len(state_cache) != 0:
    for (name, data) in [(marksfile, old_marks),
                         (mappingfile, mapping_cache),
                         (headsfile, state_cache)]:
      check_cache(name, data)

  ui,repo=setup_repo(repourl)

  if not verify_heads(ui,repo,heads_cache,force,branchesmap):
    return 1
Exemplo n.º 17
0
def hg2git(
    repourl,
    m,
    marksfile,
    mappingfile,
    headsfile,
    tipfile,
    authors={},
    branchesmap={},
    tagsmap={},
    sob=False,
    force=False,
    hgtags=False,
    notes=False,
    encoding="",
    fn_encoding="",
):
    def check_cache(filename, contents):
        if len(contents) == 0:
            sys.stderr.write(
                "Warning: %s does not contain any data, this will probably make an incremental import fail\n" % filename
            )

    _max = int(m)

    old_marks = load_cache(marksfile, lambda s: int(s) - 1)
    mapping_cache = load_cache(mappingfile)
    heads_cache = load_cache(headsfile)
    state_cache = load_cache(tipfile)

    if len(state_cache) != 0:
        for (name, data) in [(marksfile, old_marks), (mappingfile, mapping_cache), (headsfile, state_cache)]:
            check_cache(name, data)

    ui, repo = setup_repo(repourl)

    if not verify_heads(ui, repo, heads_cache, force, branchesmap):
        return 1

    try:
        tip = repo.changelog.count()
    except AttributeError:
        tip = len(repo)

    min = int(state_cache.get("tip", 0))
    max = _max
    if _max < 0 or max > tip:
        max = tip

    for rev in range(0, max):
        (revnode, _, _, _, _, _, _, _) = get_changeset(ui, repo, rev, authors)
        mapping_cache[revnode.encode("hex_codec")] = str(rev)

    c = 0
    brmap = {}
    for rev in range(min, max):
        c = export_commit(
            ui, repo, rev, old_marks, max, c, authors, branchesmap, sob, brmap, hgtags, encoding, fn_encoding
        )
    if notes:
        for rev in range(min, max):
            c = export_note(ui, repo, rev, c, authors, encoding, rev == min and min != 0)

    state_cache["tip"] = max
    state_cache["repo"] = repourl
    save_cache(tipfile, state_cache)
    save_cache(mappingfile, mapping_cache)

    c = export_tags(ui, repo, old_marks, mapping_cache, c, authors, tagsmap)

    sys.stderr.write("Issued %d commands\n" % c)

    return 0