Beispiel #1
0
def verify_heads(ui,repo,cache,force):
  branches=repo.branchtags()
  l=[(-repo.changelog.rev(n), n, t) for t, n in branches.items()]
  l.sort()

  # get list of hg's branches to verify, don't take all git has
  for _,_,b in l:
    b=get_branch(b)
    sha1=get_git_sha1(b)
    c=cache.get(b)
    if sha1!=c:
      sys.stderr.write('Error: Branch [%s] modified outside hg-fast-export:'
        '\n%s (repo) != %s (cache)\n' % (b,sha1,c))
      if not force: return False

  # verify that branch has exactly one head
  t={}
  for h in repo.heads():
    (_,_,_,_,_,_,branch,_)=get_changeset(ui,repo,h)
    if t.get(branch,False):
      sys.stderr.write('Error: repository has at least one unnamed head: hg r%s\n' %
          repo.changelog.rev(h))
      if not force: return False
    t[branch]=True

  return True
Beispiel #2
0
def verify_heads(ui, repo, cache, force):
    def getsha1(branch):
        try:
            f = open(
                os.getenv('GIT_DIR', '/dev/null') + '/refs/heads/' + branch)
            sha1 = f.readlines()[0].split('\n')[0]
            f.close()
            return sha1
        except IOError:
            return None

    branches = repo.branchtags()
    l = [(-repo.changelog.rev(n), n, t) for t, n in branches.items()]
    l.sort()

    # get list of hg's branches to verify, don't take all git has
    for _, _, b in l:
        b = get_branch(b)
        sha1 = getsha1(b)
        c = cache.get(b)
        if sha1 != None and c != None:
            sys.stderr.write('Verifying branch [%s]\n' % b)
        if sha1 != c:
            sys.stderr.write('Error: Branch [%s] modified outside hg2git:'
                             '\n%s (repo) != %s (cache)\n' % (b, sha1, c))
            if not force: return False

    # verify that branch has exactly one head
    t = {}
    for h in repo.heads():
        (_, _, _, _, _, _, branch, _) = get_changeset(ui, repo, h)
        if t.get(branch, False):
            sys.stderr.write(
                'Error: repository has at least one unnamed head: hg r%s\n' %
                repo.changelog.rev(h))
            if not force: return False
        t[branch] = True

    return True
Beispiel #3
0
def verify_heads(ui,repo,cache,force):
  def getsha1(branch):
    try:
      f=open(os.getenv('GIT_DIR','/dev/null')+'/refs/heads/'+branch)
      sha1=f.readlines()[0].split('\n')[0]
      f.close()
      return sha1
    except IOError:
      return None

  branches=repo.branchtags()
  l=[(-repo.changelog.rev(n), n, t) for t, n in branches.items()]
  l.sort()

  # get list of hg's branches to verify, don't take all git has
  for _,_,b in l:
    b=get_branch(b)
    sha1=getsha1(b)
    c=cache.get(b)
    if sha1!=None and c!=None:
      sys.stderr.write('Verifying branch [%s]\n' % b)
    if sha1!=c:
      sys.stderr.write('Error: Branch [%s] modified outside hg2git:'
        '\n%s (repo) != %s (cache)\n' % (b,sha1,c))
      if not force: return False

  # verify that branch has exactly one head
  t={}
  for h in repo.heads():
    (_,_,_,_,_,_,branch,_)=get_changeset(ui,repo,h)
    if t.get(branch,False):
      sys.stderr.write('Error: repository has at least one unnamed head: hg r%s\n' %
          repo.changelog.rev(h))
      if not force: return False
    t[branch]=True

  return True