Skip to content

Improve implementation of _latest_git_version_tag() #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions version_query/git_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ def _latest_git_version_tag_on_branches(
MAX_COMMIT_DISTANCE = 999


def _latest_git_version_tag_new(
repo: git.Repo, assume_if_none: bool = False, base_commit: git.Commit = None,
commit_distance: int = 0, skip_commits: t.Set[git.Commit] = None) -> t.Tuple[
git.Commit, t.Optional[git.TagReference], Version, int]:
version_tags = _git_version_tags(repo)
version_tag_commits = set()
divergence_points = []
if skip_commits is None:
skip_commits = set()
while True:
commit = None
for commit in repo.iter_commits(rev=base_commit):
if commit in skip_commits:
return None, None, None, -1
_LOG.log(logging.NOTSET, 'iterating over commit %s', commit)
current_version_tags = {tag: version for tag, version in version_tags.items()
if tag.commit == commit}
commit_distance += 1
skip_commits.add(commit)
if len(commit.parents) > 1:
divergence_points.append(commit)
break
base_commit = divergence_points.pop()
return commit, tag, version, commit_distance


def _latest_git_version_tag(
repo: git.Repo, assume_if_none: bool = False,
base_commit: t.Optional[git.objects.Commit] = None, commit_distance: int = 0,
Expand Down Expand Up @@ -122,6 +148,9 @@ def _latest_git_version_tag(
return commit, tag, version, commit_distance


_latest_git_version_tag = _latest_git_version_tag_new


def _upcoming_git_version_tag(repo: git.Repo, ignore_untracked_files: bool = True) -> t.Tuple[
t.Optional[git.objects.Commit], t.Optional[git.TagReference], t.Optional[Version], int,
bool]:
Expand Down
Loading