Python pygit2.GIT_SORT_TOPOLOGICAL Examples

The following are 6 code examples of pygit2.GIT_SORT_TOPOLOGICAL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygit2 , or try the search function .
Example #1
Source File: git.py    From PySpice with GNU General Public License v3.0 5 votes vote down vote up
def get_commits(ctx):

    path = '.'
    repository_path = git.discover_repository(path)
    # print(repository_path)
    repository = git.Repository(repository_path)

    head = repository.head
    head_commit = repository[head.target]

    # GIT_SORT_TOPOLOGICAL. Sort the repository contents in topological order (parents before children);
    # this sorting mode can be combined with time sorting.
    sorting = git.GIT_SORT_TOPOLOGICAL # git.GIT_SORT_TIME
    commits = [commit for commit in repository.walk(head_commit.id, sorting)]

    template = '''
====================================================================================================
{message}

  -------------------------------------------------
  {name} <{email}> / {timestamp}
  {id}
'''

    for commit in commits:
        fields = {
            'message': commit.message.strip(),
            'id': commit.hex,
            'timestamp': fromtimestamp(commit.commit_time).strftime('%Y-%m-%d %H:%M:%S'),
            'name': commit.committer.name, # author
            'email': commit.committer.email,
        }
        if 'salvaire' not in fields['name'].lower():
            print(template.lstrip().format(**fields)) 
Example #2
Source File: genrelease.py    From ibis with Apache License 2.0 5 votes vote down vote up
def iter_release_notes(repo, from_ref, to_ref, default_role):
    """Yield release notes from `from_ref` to `to_ref`."""
    pattern = re.compile(
        r'^(?:{})\s+#(\d+)\s+from'.format('|'.join(GITHUB_CLOSE_KEYWORDS)),
        flags=re.MULTILINE | re.IGNORECASE,
    )
    for commit in commits_between(
        repo, from_ref, to_ref, options=pygit2.GIT_SORT_TOPOLOGICAL
    ):
        message = commit.message.strip()
        subject, *lines = map(str.strip, message.splitlines())
        tag, *rest = subject.split(':', 1)
        tag = tag.lower()
        lineitem = ''.join(rest) or subject
        role = KEYWORD_MAP.get(tag, default_role)
        modifier = ' major' if role == 'bug' else ''
        try:
            issue_number, *_ = pattern.findall(message)
        except ValueError:
            issue_number = '-'
        yield "* :{role}:`{issue_number}{modifier}` {lineitem}".format(
            role=role,
            issue_number=issue_number,
            modifier=modifier,
            lineitem=lineitem.strip(),
        ) 
Example #3
Source File: meta.py    From EmoteCollector with GNU Affero General Public License v3.0 5 votes vote down vote up
def _current_revision(*, default='master'):
		repo = pygit2.Repository('.git')
		c = next(repo.walk(repo.head.target, pygit2.GIT_SORT_TOPOLOGICAL))
		return c.hex[:10] 
Example #4
Source File: git.py    From Gitmails with MIT License 5 votes vote down vote up
def get_authors(self, repo_path):
        try:
            if self.args.verbose:
                Helpers.print_success("Collecting authors in {}".format(repo_path))
            authors_set = set()
            repo = Repository(repo_path)
            for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
                authors_set.add(Author(commit.author.name, commit.author.email))
            return authors_set

        except Exception as e:
            Helpers.print_error("{}: Could not collect authors".format(repo_path))
            return None 
Example #5
Source File: gitdata.py    From repostat with GNU General Public License v3.0 5 votes vote down vote up
def commits_walker(self):
        return self.repo.walk(self.repo.head.target, git.GIT_SORT_TOPOLOGICAL) 
Example #6
Source File: gitdata.py    From repostat with GNU General Public License v3.0 5 votes vote down vote up
def fetch(self):
        # TODO: this should perhaps be a part of WholeHistory
        tag_refs = {refobj.peel().oid: refobj
                    for refobj in self.repo.listall_reference_objects() if refobj.name.startswith('refs/tags')}

        result = []
        tag_ref = None
        is_symbolic_reference = False
        for commit in self.repo.walk(self.repo.head.target, git.GIT_SORT_TOPOLOGICAL):
            author_name, _ = map_signature(self.mailmap, commit.author)
            if commit.oid in tag_refs:
                tag_ref: git.Reference = tag_refs[commit.oid]
                is_symbolic_reference = tag_ref.target.hex == commit.hex

            if tag_ref is not None:
                if not is_symbolic_reference:
                    tag = self.repo[tag_ref.target]
                    tagger_name, _ = map_signature(self.mailmap, tag.tagger)
                    tag_metadata = {
                        "tag_name": tag.name,
                        "tagger_name": tagger_name,
                        "tagger_time": tag.tagger.time,
                    }
                else:
                    tag_metadata = {
                        "tag_name": tag_ref.shorthand,
                        "tagger_name": None,
                        "tagger_time": -1,
                    }
            else:
                tag_metadata = {
                    "tag_name": None,
                    "tagger_name": None,
                    "tagger_time": -1,
                }
            tag_metadata["commit_author"] = author_name
            tag_metadata["commit_time"] = commit.author.time
            tag_metadata["is_merge"] = len(commit.parents) > 1
            result.append(tag_metadata)

        return result