コード例 #1
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
コード例 #2
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
コード例 #3
0
ファイル: hg-fast-export.py プロジェクト: daolis/fast-export
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
コード例 #4
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
コード例 #5
0
ファイル: hg-fast-export.py プロジェクト: certik/fast-export
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
コード例 #6
0
ファイル: hg-fast-export.py プロジェクト: devintm/fast-export
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
コード例 #7
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
コード例 #8
0
ファイル: hg-fast-export.py プロジェクト: fbucek/fast-export
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
コード例 #9
0
            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

if __name__=='__main__':
  def bail(parser,opt):
    sys.stderr.write('Error: No %s option given\n' % opt)
    parser.print_help()
    sys.exit(2)

  parser=OptionParser()