@@ -99,27 +99,72 @@ def main():
9999 # Fallback for initial version if no previous version found
100100 if not prev_commit :
101101 print (
102- f"Previous version not found in history for module { module } ." , file = sys .stderr
102+ f"Previous version not found in history of versions.txt for module { module } . Trying pom.xml history.. ." , file = sys .stderr
103103 )
104- # Find the first commit affecting that directory
105- first_commit_cmd = [
104+
105+ pom_path = f"{ directory } /pom.xml"
106+ pom_log_cmd = [
106107 "git" ,
107108 "log" ,
108- "--reverse" ,
109109 "--oneline" ,
110110 "--" ,
111- directory ,
111+ pom_path ,
112112 ]
113113 try :
114- first_commit_output = run_cmd (first_commit_cmd )
115- if first_commit_output :
116- prev_commit = None
117- print (f"No previous version found. Generating notes from the beginning of history for { directory } ." , file = sys .stderr )
114+ pom_log_output = run_cmd (pom_log_cmd )
115+ pom_commits = [line .split ()[0 ] for line in pom_log_output .splitlines () if line ]
116+
117+ prev_commit_in_loop = None
118+ target_end_commit = None
119+ prev_start_commit = None
120+
121+ for commit in pom_commits :
122+ show_cmd = ["git" , "show" , f"{ commit } :{ pom_path } " ]
123+ try :
124+ content = run_cmd (show_cmd )
125+ except SystemExit :
126+ continue
127+
128+ match = re .search (r"<version>([^<]+)</version>" , content )
129+ if match :
130+ ver = match .group (1 )
131+
132+ if ver == target_version and not target_end_commit :
133+ # Moving backwards, this is the first commit with target version!
134+ # The previous commit in loop was the one that changed it AWAY from target version!
135+ target_end_commit = prev_commit_in_loop
136+ print (
137+ f"Found commit changing away from { target_version } at { target_end_commit } " ,
138+ file = sys .stderr ,
139+ )
140+
141+ elif (
142+ target_end_commit
143+ and ver != target_version
144+ and "-SNAPSHOT" not in ver
145+ ):
146+ # This is the commit where the previous stable version was set!
147+ prev_start_commit = commit
148+ print (
149+ f"Found previous stable version { ver } at { commit } " ,
150+ file = sys .stderr ,
151+ )
152+ break
153+
154+ prev_commit_in_loop = commit
155+
156+ if prev_start_commit and target_end_commit :
157+ prev_commit = prev_start_commit
158+ # Use W~1 to be exclusive of W (the commit that changed it away)
159+ target_commit = f"{ target_end_commit } ~1"
160+ print (f"Using range derived from pom.xml: { prev_commit } ..{ target_commit } " , file = sys .stderr )
118161 else :
119- print (f"No history found for directory { directory } ." , file = sys .stderr )
120- sys .exit (1 )
162+ print (f"Could not find complete range in pom.xml. Falling back to initial release logic." , file = sys .stderr )
163+ prev_commit = None
164+
121165 except SystemExit :
122- sys .exit (1 )
166+ print (f"Failed to read pom.xml history." , file = sys .stderr )
167+ prev_commit = None
123168
124169 range_desc = f"between { prev_commit } and { target_commit } " if prev_commit else f"up to { target_commit } "
125170 print (
0 commit comments