@@ -40,6 +40,30 @@ def _git_version_tags(repo: git.Repo) -> t.Mapping[git.Tag, Version]:
4040 return versions
4141
4242
43+ def _latest_git_version_tag_on_branches (
44+ repo : git .Repo , assume_if_none : bool , commit : git .Commit , commit_distance : int ,
45+ skip_commits : t .Set [git .Commit ]):
46+ _LOG .log (logging .NOTSET , 'entering %i branches...' , len (commit .parents ))
47+ results = []
48+ main_commit_distance = None
49+ for parent in commit .parents :
50+ try :
51+ result = _latest_git_version_tag (
52+ repo , assume_if_none , parent , commit_distance , skip_commits )
53+ if main_commit_distance is None :
54+ main_commit_distance = result [3 ]
55+ except ValueError :
56+ continue
57+ if result [2 ] is not None :
58+ results .append (result )
59+ if not results :
60+ return main_commit_distance
61+ final_result = sorted (results , key = lambda _ : _ [2 ])[- 1 ]
62+ _LOG .log (logging .NOTSET , 'result from %i branches is %s and %s' ,
63+ len (commit .parents ), * final_result [1 :3 ])
64+ return final_result
65+
66+
4367MAX_COMMIT_DISTANCE = 999
4468
4569
@@ -76,31 +100,35 @@ def _latest_git_version_tag(
76100 commit_distance += 1
77101 if len (commit .parents ) <= 1 :
78102 continue
79- _LOG .log (logging .NOTSET , 'entering %i branches...' , len (commit .parents ))
80- results = []
81- main_commit_distance = None
82- for parent in commit .parents :
83- try :
84- result = _latest_git_version_tag (
85- repo , assume_if_none , parent , commit_distance , skip_commits )
86- if main_commit_distance is None :
87- main_commit_distance = result [3 ]
88- except ValueError :
89- continue
90- if result [2 ] is not None :
91- results .append (result )
92- if not results :
93- commit_distance = main_commit_distance
103+ result = _latest_git_version_tag_on_branches (
104+ repo , assume_if_none , commit , commit_distance , skip_commits )
105+ if not isinstance (result , tuple ):
106+ commit_distance = result # main_commit_distance
94107 break
95- result = sorted (results , key = lambda _ : _ [2 ])[- 1 ]
96- _LOG .log (logging .NOTSET , 'result from %i branches is %s and %s' ,
97- len (commit .parents ), * result [1 :3 ])
108+ # _LOG.log(logging.NOTSET, 'entering %i branches...', len(commit.parents))
109+ # results = []
110+ # main_commit_distance = None
111+ # for parent in commit.parents:
112+ # try:
113+ # result = _latest_git_version_tag(
114+ # repo, assume_if_none, parent, commit_distance, skip_commits)
115+ # if main_commit_distance is None:
116+ # main_commit_distance = result[3]
117+ # except ValueError:
118+ # continue
119+ # if result[2] is not None:
120+ # results.append(result)
121+ # if not results:
122+ # commit_distance = main_commit_distance
123+ # break
124+ # result = sorted(results, key=lambda _: _[2])[-1]
125+ # _LOG.log(logging.NOTSET, 'result from %i branches is %s and %s',
126+ # len(commit.parents), *result[1:3])
98127 return result
99128 if not current_version_tags :
100129 if assume_if_none :
101130 return commit , None , Version .from_str ('0.1.0.dev0' ), commit_distance
102- else :
103- raise ValueError ('the given repo {} has no version tags' .format (repo ))
131+ raise ValueError ('the given repo {} has no version tags' .format (repo ))
104132 tag , version = sorted (current_version_tags .items (), key = lambda _ : _ [1 ])[- 1 ]
105133 _LOG .log (logging .NOTSET , 'result is %s and %s' , tag , version )
106134 return commit , tag , version , commit_distance
0 commit comments