Пример #1
0
def get_changeset(ui, repo, revision, authors={}):
    node = repo.lookup(revision)
    (manifest, user, (time, timezone), files, desc,
     extra) = repo.changelog.read(node)
    tz = "%+03d%02d" % (-timezone / 3600, ((-timezone % 3600) / 60))
    branch = get_branch(extra.get('branch', 'master'))
    return (node, manifest, fixup_user(user, authors), (time, tz), files, desc,
            branch, extra)
Пример #2
0
def get_changeset(ui,repo,revision,authors={}):
  node=repo.lookup(revision)
  (manifest,user,(time,timezone),files,desc,extra)=repo.changelog.read(node)
  tz="%+03d%02d" % (-timezone / 3600, ((-timezone % 3600) / 60))
  branch=get_branch(extra.get('branch','master'))
  return (node,manifest,fixup_user(user,authors),(time,tz),files,desc,branch,extra)
Пример #3
0
def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap):
  def get_branchname(name):
    if brmap.has_key(name):
      return brmap[name]
    n=sanitize_name(name)
    brmap[name]=n
    return n

  (revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors)

  branch=get_branchname(branch)

  parents = [p for p in repo.changelog.parentrevs(revision) if p >= 0]

  if len(parents)==0 and revision != 0:
    wr('reset refs/heads/%s' % branch)

  wr('commit refs/heads/%s' % branch)
  wr('mark :%d' % (revision+1))
  if sob:
    wr('author %s %d %s' % (get_author(desc,user,authors),time,timezone))
  wr('committer %s %d %s' % (user,time,timezone))
  wr('data %d' % (len(desc)+1)) # wtf?
  wr(desc)
  wr()


  # Sort the parents based on revision ids so that we always get the
  # same resulting git repo, no matter how the revisions were
  # numbered.
  parents.sort(key=repo.changelog.node, reverse=True)

  ctx=repo.changectx(str(revision))
  man=ctx.manifest()
  added,changed,removed,type=[],[],[],''

  if len(parents) == 0:
    # first revision: feed in full manifest
    added=man.keys()
    added.sort()
    type='full'
  else:
    wr('from %s' % revnum_to_revref(parents[0], old_marks))
    if len(parents) == 1:
      # later non-merge revision: feed in changed manifest
      # if we have exactly one parent, just take the changes from the
      # manifest without expensively comparing checksums
      f=repo.status(repo.lookup(parents[0]),revnode)[:3]
      added,changed,removed=f[1],f[0],f[2]
      type='simple delta'
    else: # a merge with two parents
      wr('merge %s' % revnum_to_revref(parents[1], old_marks))
      # later merge revision: feed in changed manifest
      # for many files comparing checksums is expensive so only do it for
      # merges where we really need it due to hg's revlog logic
      added,changed,removed=get_filechanges(repo,revision,parents,man)
      type='thorough delta'

  sys.stderr.write('%s: Exporting %s revision %d/%d with %d/%d/%d added/changed/removed files\n' %
      (branch,type,revision+1,max,len(added),len(changed),len(removed)))

  map(lambda r: wr('D %s' % r),removed)
  export_file_contents(ctx,man,added)
  export_file_contents(ctx,man,changed)
  wr()

  return checkpoint(count)
Пример #4
0
def export_commit(ui,repo,revision,marks,mapping,heads,last,max,count,authors,sob,brmap):
  def get_branchname(name):
    if brmap.has_key(name):
      return brmap[name]
    n=sanitize_name(name)
    brmap[name]=n
    return n

  (revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors)
  parents=repo.changelog.parentrevs(revision)

  branch=get_branchname(branch)

  wr('commit refs/heads/%s' % branch)
  wr('mark :%d' % (revision+1))
  if sob:
    wr('author %s %d %s' % (get_author(desc,user,authors),time,timezone))
  wr('committer %s %d %s' % (user,time,timezone))
  wr('data %d' % (len(desc)+1)) # wtf?
  wr(desc)
  wr()

  pidx1, pidx2 = 0, 1
  if parents[0] < parents[1]:
    pidx1, pidx2 = 1, 0

  src=heads.get(branch,'')
  link=''
  if src!='':
    # if we have a cached head, this is an incremental import: initialize it
    # and kill reference so we won't init it again
    wr('from %s' % src)
    heads[branch]=''
    sys.stderr.write('%s: Initializing to parent [%s]\n' %
        (branch,src))
    link=src # avoid making a merge commit for incremental import
  elif link=='' and not heads.has_key(branch) and revision>0:
    # newly created branch and not the first one: connect to parent
    tmp=get_parent_mark(parents[0],marks)
    wr('from %s' % tmp)
    sys.stderr.write('%s: Link new branch to parent [%s]\n' %
        (branch,tmp))
    link=tmp # avoid making a merge commit for branch fork
  elif last.get(branch,revision) != parents[pidx1] and parents[pidx1] > 0 and revision > 0:
    pm=get_parent_mark(parents[pidx1],marks)
    sys.stderr.write('%s: Placing commit [r%d] in branch [%s] on top of [r%d]\n' %
        (branch,revision,branch,parents[pidx1]));
    wr('from %s' % pm)

  if parents[pidx2] > 0:
    pm=get_parent_mark(parents[pidx2],marks)
    sys.stderr.write('%s: Merging with parent [%s] from [r%d]\n' %
        (branch,pm,parents[pidx2]))
    wr('merge %s' % pm)

  last[branch]=revision
  heads[branch]=''
  # we need this later to write out tags
  marks[str(revision)]=':%d'%(revision+1)

  ctx=repo.changectx(str(revision))
  man=ctx.manifest()
  added,changed,removed,type=[],[],[],''

  if revision==0:
    # first revision: feed in full manifest
    added=man.keys()
    added.sort()
    type='full'
  elif is_merge(parents):
    # later merge revision: feed in changed manifest
    # for many files comparing checksums is expensive so only do it for
    # merges where we really need it due to hg's revlog logic
    added,changed,removed=get_filechanges(repo,revision,parents,man)
    type='thorough delta'
  else:
    # later non-merge revision: feed in changed manifest
    # if we have exactly one parent, just take the changes from the
    # manifest without expensively comparing checksums
    f=repo.status(repo.lookup(parents[0]),revnode)[:3]
    added,changed,removed=f[1],f[0],f[2]
    type='simple delta'

  sys.stderr.write('%s: Exporting %s revision %d/%d with %d/%d/%d added/changed/removed files\n' %
      (branch,type,revision+1,max,len(added),len(changed),len(removed)))

  map(lambda r: wr('D %s' % r),removed)
  export_file_contents(ctx,man,added)
  export_file_contents(ctx,man,changed)
  wr()

  return checkpoint(count)
Пример #5
0
def export_commit(ui,repo,revision,marks,heads,last,max,count,authors,sob):
  (revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors)
  parents=repo.changelog.parentrevs(revision)

  wr('commit refs/heads/%s' % branch)
  wr('mark :%d' % (revision+1))
  if sob:
    wr('author %s %d %s' % (get_author(desc,user,authors),time,timezone))
  wr('committer %s %d %s' % (user,time,timezone))
  wr('data %d' % (len(desc)+1)) # wtf?
  wr(desc)
  wr()

  src=heads.get(branch,'')
  link=''
  if src!='':
    # if we have a cached head, this is an incremental import: initialize it
    # and kill reference so we won't init it again
    wr('from %s' % src)
    heads[branch]=''
    sys.stderr.write('Initializing branch [%s] to parent [%s]\n' %
        (branch,src))
    link=src # avoid making a merge commit for incremental import
  elif link=='' and not heads.has_key(branch) and revision>0:
    # newly created branch and not the first one: connect to parent
    tmp=get_parent_mark(parents[0],marks)
    wr('from %s' % tmp)
    sys.stderr.write('Link new branch [%s] to parent [%s]\n' %
        (branch,tmp))
    link=tmp # avoid making a merge commit for branch fork

  if parents:
    l=last.get(branch,revision)
    for p in parents:
      # 1) as this commit implicitely is the child of the most recent
      #    commit of this branch, ignore this parent
      # 2) ignore nonexistent parents
      # 3) merge otherwise
      if p==l or p==revision or p<0:
        continue
      tmp=get_parent_mark(p,marks)
      # if we fork off a branch, don't merge with our parent via 'merge'
      # as we have 'from' already above
      if tmp==link:
        continue
      sys.stderr.write('Merging branch [%s] with parent [%s] from [r%d]\n' %
          (branch,tmp,p))
      wr('merge %s' % tmp)

  last[branch]=revision
  heads[branch]=''
  # we need this later to write out tags
  marks[str(revision)]=':%d'%(revision+1)

  ctx=repo.changectx(str(revision))
  man=ctx.manifest()
  added,changed,removed,type=[],[],[],''

  if revision==0:
    # first revision: feed in full manifest
    added=man.keys()
    type='full'
  elif is_merge(parents):
    # later merge revision: feed in changed manifest
    # for many files comparing checksums is expensive so only do it for
    # merges where we really need it due to hg's revlog logic
    added,changed,removed=get_filechanges(repo,revision,parents,man)
    type='thorough delta'
  else:
    # later non-merge revision: feed in changed manifest
    # if we have exactly one parent, just take the changes from the
    # manifest without expensively comparing checksums
    f=repo.status(repo.lookup(parents[0]),revnode)[:3]
    added,changed,removed=f[1],f[0],f[2]
    type='simple delta'

  sys.stderr.write('Exporting %s revision %d/%d with %d/%d/%d added/changed/removed files\n' %
      (type,revision+1,max,len(added),len(changed),len(removed)))

  map(lambda r: wr('D %s' % r),removed)
  export_file_contents(ctx,man,added+changed)
  wr()

  return checkpoint(count)
Пример #6
0
def export_commit(ui, repo, revision, marks, heads, last, max, count, authors,
                  sob):
    (revnode, _, user, (time, timezone), files, desc, branch,
     _) = get_changeset(ui, repo, revision, authors)
    parents = repo.changelog.parentrevs(revision)

    wr('commit refs/heads/%s' % branch)
    wr('mark :%d' % (revision + 1))
    if sob:
        wr('author %s %d %s' %
           (get_author(desc, user, authors), time, timezone))
    wr('committer %s %d %s' % (user, time, timezone))
    wr('data %d' % (len(desc) + 1))  # wtf?
    wr(desc)
    wr()

    src = heads.get(branch, '')
    link = ''
    if src != '':
        # if we have a cached head, this is an incremental import: initialize it
        # and kill reference so we won't init it again
        wr('from %s' % src)
        heads[branch] = ''
        sys.stderr.write('Initializing branch [%s] to parent [%s]\n' %
                         (branch, src))
        link = src  # avoid making a merge commit for incremental import
    elif link == '' and not heads.has_key(branch) and revision > 0:
        # newly created branch and not the first one: connect to parent
        tmp = get_parent_mark(parents[0], marks)
        wr('from %s' % tmp)
        sys.stderr.write('Link new branch [%s] to parent [%s]\n' %
                         (branch, tmp))
        link = tmp  # avoid making a merge commit for branch fork

    if parents:
        l = last.get(branch, revision)
        for p in parents:
            # 1) as this commit implicitely is the child of the most recent
            #    commit of this branch, ignore this parent
            # 2) ignore nonexistent parents
            # 3) merge otherwise
            if p == l or p == revision or p < 0:
                continue
            tmp = get_parent_mark(p, marks)
            # if we fork off a branch, don't merge with our parent via 'merge'
            # as we have 'from' already above
            if tmp == link:
                continue
            sys.stderr.write(
                'Merging branch [%s] with parent [%s] from [r%d]\n' %
                (branch, tmp, p))
            wr('merge %s' % tmp)

    last[branch] = revision
    heads[branch] = ''
    # we need this later to write out tags
    marks[str(revision)] = ':%d' % (revision + 1)

    ctx = repo.changectx(str(revision))
    man = ctx.manifest()
    added, changed, removed, type = [], [], [], ''

    if revision == 0:
        # first revision: feed in full manifest
        added = man.keys()
        type = 'full'
    elif is_merge(parents):
        # later merge revision: feed in changed manifest
        # for many files comparing checksums is expensive so only do it for
        # merges where we really need it due to hg's revlog logic
        added, changed, removed = get_filechanges(repo, revision, parents, man)
        type = 'thorough delta'
    else:
        # later non-merge revision: feed in changed manifest
        # if we have exactly one parent, just take the changes from the
        # manifest without expensively comparing checksums
        f = repo.status(repo.lookup(parents[0]), revnode)[:3]
        added, changed, removed = f[1], f[0], f[2]
        type = 'simple delta'

    sys.stderr.write(
        'Exporting %s revision %d/%d with %d/%d/%d added/changed/removed files\n'
        % (type, revision + 1, max, len(added), len(changed), len(removed)))

    map(lambda r: wr('D %s' % r), removed)
    export_file_contents(ctx, man, added + changed)
    wr()

    return checkpoint(count)