Ejemplo n.º 1
0
 def rev_list(self, ref_or_refs, count=None, parse=None, format=None):
     # TODO: maybe we should refactor this to not have all of bup rely
     # on the git format ... it's ugly that we have to produce it here
     #
     # TODO: also, this is weird, I'm using existing bup functionality
     # to pretend I'm git, and then bup uses that again, really it stands
     # to reason that bup should do this itself without even *having* a
     # rev_list() method that calls out to git - and it'll probably be
     # faster too since we have the bloom/midx.
     assert count is None
     assert format in (b'%T %at', None)
     # TODO: ugh, this is a messy API ...
     if isinstance(ref_or_refs, compat.str_type):
         ref = ref_or_refs
     else:
         assert len(ref_or_refs) == 1
         ref = ref_or_refs[0]
     while True:
         commit = git.parse_commit(
             git.get_cat_data(self.cat(ref), b'commit'))
         if format is None:
             yield ref
         else:
             if format == b'%T %at':
                 data = BytesIO(b'%s %d\n' %
                                (commit.tree, commit.author_sec))
             yield (ref, parse(data))
         if not commit.parents:
             break
         ref = commit.parents[0]
Ejemplo n.º 2
0
def handle_replace(item, src_repo, writer, opt):
    assert(item.spec.method == 'replace')
    if item.dest.path.startswith(b'/.tag/'):
        get_random_item(item.spec.src, hexlify(item.src.hash),
                        src_repo, writer, opt)
        return (item.src.hash,)
    assert(item.dest.type == 'branch' or not item.dest.type)
    src_oidx = hexlify(item.src.hash)
    get_random_item(item.spec.src, src_oidx, src_repo, writer, opt)
    commit_items = parse_commit(get_cat_data(src_repo.cat(src_oidx), b'commit'))
    return item.src.hash, unhexlify(commit_items.tree)
Ejemplo n.º 3
0
def handle_replace(item, src_repo, writer, opt):
    assert (item.spec.method == 'replace')
    if item.dest.path.startswith('/.tag/'):
        get_random_item(item.spec.src, item.src.hash.encode('hex'), src_repo,
                        writer, opt)
        return (item.src.hash, )
    assert (item.dest.type == 'branch' or not item.dest.type)
    src_oidx = item.src.hash.encode('hex')
    get_random_item(item.spec.src, src_oidx, src_repo, writer, opt)
    commit_items = parse_commit(get_cat_data(src_repo.cat(src_oidx), 'commit'))
    return item.src.hash, commit_items.tree.decode('hex')
Ejemplo n.º 4
0
def handle_ff(item, src_repo, writer, opt):
    assert item.spec.method == 'ff'
    assert item.src.type in ('branch', 'save', 'commit')
    src_oidx = hexlify(item.src.hash)
    dest_oidx = hexlify(item.dest.hash) if item.dest.hash else None
    if not dest_oidx or dest_oidx in src_repo.rev_list(src_oidx):
        # Can fast forward.
        get_random_item(item.spec.src, src_oidx, src_repo, writer, opt)
        commit_items = parse_commit(get_cat_data(src_repo.cat(src_oidx), b'commit'))
        return item.src.hash, unhexlify(commit_items.tree)
    misuse('destination is not an ancestor of source for %s'
           % spec_msg(item.spec))
Ejemplo n.º 5
0
def append_commit(name, hash, parent, src_repo, writer, opt):
    now = time.time()
    items = parse_commit(get_cat_data(src_repo.cat(hash), 'commit'))
    tree = items.tree.decode('hex')
    author = '%s <%s>' % (items.author_name, items.author_mail)
    author_time = (items.author_sec, items.author_offset)
    committer = '%s <%s@%s>' % (userfullname(), username(), hostname())
    get_random_item(name, tree.encode('hex'), src_repo, writer, opt)
    c = writer.new_commit(tree, parent, author, items.author_sec,
                          items.author_offset, committer, now, None,
                          items.message)
    return c, tree
Ejemplo n.º 6
0
def append_commit(name, hash, parent, src_repo, dest_repo, opt):
    now = time.time()
    items = parse_commit(get_cat_data(src_repo.cat(hash), b'commit'))
    tree = unhexlify(items.tree)
    author = b'%s <%s>' % (items.author_name, items.author_mail)
    author_time = (items.author_sec, items.author_offset)
    committer = b'%s <%s@%s>' % (userfullname(), username(), hostname())
    get_random_item(name, hexlify(tree), src_repo, dest_repo, opt)
    c = dest_repo.write_commit(tree, parent, author, items.author_sec,
                               items.author_offset, committer, now, None,
                               items.message)
    return c, tree
Ejemplo n.º 7
0
def handle_ff(item, src_repo, writer, opt):
    assert item.spec.method == 'ff'
    assert item.src.type in ('branch', 'save', 'commit')
    src_oidx = item.src.hash.encode('hex')
    dest_oidx = item.dest.hash.encode('hex') if item.dest.hash else None
    if not dest_oidx or dest_oidx in src_repo.rev_list(src_oidx):
        # Can fast forward.
        get_random_item(item.spec.src, src_oidx, src_repo, writer, opt)
        commit_items = parse_commit(get_cat_data(src_repo.cat(src_oidx), 'commit'))
        return item.src.hash, commit_items.tree.decode('hex')
    spec_args = '%s %s' % (item.spec.argopt, item.spec.argval)
    misuse('destination is not an ancestor of source for %r' % spec_args)
Ejemplo n.º 8
0
def get_commit_items(id, cp):
    return git.parse_commit(git.get_cat_data(cp.get(id), b'commit'))
Ejemplo n.º 9
0
def get_commit_items(repo, hash):
    data = git.get_cat_data(repo.cat(hash), b'commit')
    return git.parse_commit(data)