def rev_list(repository, to_ref, from_ref=None, path=None, skip=0, max_count=0, author=None, query=None, first_parent=None, since=0, no_merges=None): """git rev-list command, pygit2 wrapper. But this returns a commit list""" if repository.is_empty: return [] commits_index_list = [] commits_dict = {} # TODO: use resolve_version to_commit = repository.revparse_single(to_ref) walk_order = GIT_SORT_TOPOLOGICAL if first_parent else GIT_SORT_TIME if to_commit.type == GIT_OBJ_TAG: to_commit = repository[to_commit.target] next_commit = None walker = repository.walk(to_commit.id, walk_order) if from_ref: try: from_commit = repository.revparse_single(from_ref) if from_commit.type == GIT_OBJ_TAG: from_commit = repository[from_commit.target] walker.hide(from_commit.id) except (KeyError, ValueError): from_commit = None if max_count: length = max_count + skip if skip else max_count else: length = 0 for c in walker: if all([_check_author(c, author), _check_file_change(c, path), _check_message(c, query), _check_date(c, since), _check_no_merges(c, no_merges)]): index = c.hex if first_parent: if next_commit and next_commit.hex != c.hex: continue if len(c.parents) == 0: next_commit = None elif len(c.parents) >= 1: next_commit = c.parents[0] else: continue if index not in commits_index_list: commits_index_list.append(index) commits_dict[index] = c if length and len(commits_index_list) >= length: break if skip: commits_index_list = commits_index_list[skip:] return [format_commit(commits_dict[i], repository) for i in commits_index_list]
def _format_with_last_commit(repository, ret_tree, to_commit): walker = repository.walk(to_commit.oid, GIT_SORT_TOPOLOGICAL) paths = [k for k, v in ret_tree.iteritems()] ret = {} for commit in walker: for path in paths: _calc_is_changed(commit, path, ret, ret_tree[path]['type']) if not ret: continue fc = format_commit(commit, None) for path, r in ret.iteritems(): ret_tree[path]['commit'] = fc paths.remove(path) if not paths: break ret = {}
def _format_with_last_commit(repository, ret_tree, to_commit): walker = repository.walk(to_commit.id, GIT_SORT_TOPOLOGICAL) paths = [k for k, v in ret_tree.iteritems()] ret = {} for commit in walker: for path in paths: _calc_is_changed(commit, path, ret, ret_tree[path]['type']) if not ret: continue fc = format_commit(commit, None) for path, r in ret.iteritems(): ret_tree[path]['commit'] = fc paths.remove(path) if not paths: break ret = {}