Skip to content

Commit 5ea6bcf

Browse files
committed
wip: new implementation of _latest_git_version_tag()
1 parent 2251170 commit 5ea6bcf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

version_query/git_query.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ def _latest_git_version_tag_on_branches(
7373
MAX_COMMIT_DISTANCE = 999
7474

7575

76+
def _latest_git_version_tag_new(
77+
repo: git.Repo, assume_if_none: bool = False, base_commit: git.Commit = None,
78+
commit_distance: int = 0, skip_commits: t.Set[git.Commit] = None) -> t.Tuple[
79+
git.Commit, t.Optional[git.TagReference], Version, int]:
80+
version_tags = _git_version_tags(repo)
81+
version_tag_commits = set()
82+
divergence_points = []
83+
if skip_commits is None:
84+
skip_commits = set()
85+
while True:
86+
commit = None
87+
for commit in repo.iter_commits(rev=base_commit):
88+
if commit in skip_commits:
89+
return None, None, None, -1
90+
_LOG.log(logging.NOTSET, 'iterating over commit %s', commit)
91+
current_version_tags = {tag: version for tag, version in version_tags.items()
92+
if tag.commit == commit}
93+
commit_distance += 1
94+
skip_commits.add(commit)
95+
if len(commit.parents) > 1:
96+
divergence_points.append(commit)
97+
break
98+
base_commit = divergence_points.pop()
99+
return commit, tag, version, commit_distance
100+
101+
76102
def _latest_git_version_tag(
77103
repo: git.Repo, assume_if_none: bool = False,
78104
base_commit: t.Optional[git.objects.Commit] = None, commit_distance: int = 0,
@@ -122,6 +148,9 @@ def _latest_git_version_tag(
122148
return commit, tag, version, commit_distance
123149

124150

151+
_latest_git_version_tag = _latest_git_version_tag_new
152+
153+
125154
def _upcoming_git_version_tag(repo: git.Repo, ignore_untracked_files: bool = True) -> t.Tuple[
126155
t.Optional[git.objects.Commit], t.Optional[git.TagReference], t.Optional[Version], int,
127156
bool]:

0 commit comments

Comments
 (0)