66
77import git
88
9+ from ciq_helpers import get_backport_commit_data
10+
911FIPS_PROTECTED_DIRECTORIES = [
1012 b"arch/x86/crypto/" ,
1113 b"crypto/asymmetric_keys/" ,
@@ -25,6 +27,55 @@ def find_common_tag(old_tags, new_tags):
2527 return None
2628
2729
30+ def get_commit_maps_from_backport_data (repo_path , branch , common_tag ):
31+ """Get commit maps using get_backport_commit_data from ciq_helpers.
32+
33+ This function properly parses all commits and extracts upstream references
34+ from 'commit <sha>' lines in commit bodies. This ensures we correctly identify
35+ duplicates even when different CIQ commits reference the same upstream commit.
36+
37+ Returns:
38+ commit_map: dict mapping CIQ commit SHA -> upstream commit SHA (or "" if no upstream)
39+ commit_map_rev: dict mapping upstream commit SHA -> CIQ commit SHA
40+ """
41+ # get_backport_commit_data returns:
42+ # { "upstream_sha": { "repo_commit": "ciq_sha", "upstream_subject": "...", ... } }
43+ backport_data , success = get_backport_commit_data (
44+ repo_path ,
45+ branch ,
46+ common_tag .decode () if isinstance (common_tag , bytes ) else common_tag ,
47+ allow_duplicates = True
48+ )
49+
50+ if not success :
51+ print ("[rolling release update] WARNING: Duplicate upstream commits detected in backport data" )
52+ print ("[rolling release update] Continuing with allow_duplicates=True" )
53+
54+ # Transform to the format expected by the rest of the script
55+ commit_map = {}
56+ commit_map_rev = {}
57+
58+ for upstream_sha , data in backport_data .items ():
59+ ciq_sha = data ["repo_commit" ]
60+ commit_map [ciq_sha ] = upstream_sha
61+ commit_map_rev [upstream_sha ] = ciq_sha
62+
63+ # Also get all commits (including those without upstream references)
64+ # to ensure we have a complete list
65+ repo = git .Repo (repo_path )
66+ repo .git .checkout (branch )
67+ common_tag_str = common_tag .decode () if isinstance (common_tag , bytes ) else common_tag
68+ all_commits = repo .git .log ("--pretty=%H" , f"{ common_tag_str } ..HEAD" ).split ("\n " )
69+
70+ # Add commits without upstream references (CIQ-specific commits)
71+ for commit_sha in all_commits :
72+ commit_sha = commit_sha .strip ()
73+ if commit_sha and commit_sha not in commit_map :
74+ commit_map [commit_sha ] = ""
75+
76+ return commit_map , commit_map_rev
77+
78+
2879def get_branch_tag_sha_list (repo , branch , minor_version = False ):
2980 print ("[rolling release update] Checking out branch: " , branch )
3081 repo .git .checkout (branch )
@@ -224,17 +275,9 @@ def check_for_fips_protected_changes(repo, branch, common_tag):
224275 "[rolling release update] Finding the CIQ Kernel and Associated Upstream commits between the last resf tag and HEAD"
225276 )
226277 print (f"[rolling release update] Getting SHAS { old_rolling_resf_tag_sha .decode ()} ..HEAD" )
227- rolling_commit_map = {}
228- rollint_commit_map_rev = {}
229- rolling_commits = repo .git .log (f"{ old_rolling_resf_tag_sha .decode ()} ..HEAD" )
230- for line in rolling_commits .split ("\n " ):
231- if line .startswith ("commit " ):
232- ciq_commit = line .split ("commit " )[1 ]
233- rolling_commit_map [ciq_commit ] = ""
234- if line .startswith (" commit " ):
235- upstream_commit = line .split (" commit " )[1 ]
236- rolling_commit_map [ciq_commit ] = upstream_commit
237- rollint_commit_map_rev [upstream_commit ] = ciq_commit
278+ rolling_commit_map , rolling_commit_map_rev = get_commit_maps_from_backport_data (
279+ args .repo , args .old_rolling_branch , old_rolling_resf_tag_sha
280+ )
238281
239282 print ("[rolling release update] Last RESF tag sha: " , common_sha )
240283
@@ -309,17 +352,9 @@ def check_for_fips_protected_changes(repo, branch, common_tag):
309352 exit (1 )
310353
311354 print ("[rolling release update] Creating Map of all new commits from last rolling release fork" )
312- new_base_commit_map = {}
313- new_base_commit_map_rev = {}
314- new_base_commits = repo .git .log (f"{ common_sha .decode ()} ..HEAD" )
315- for line in new_base_commits .split ("\n " ):
316- if line .startswith ("commit " ):
317- ciq_commit = line .split ("commit " )[1 ]
318- new_base_commit_map [ciq_commit ] = ""
319- if line .startswith (" commit " ):
320- upstream_commit = line .split (" commit " )[1 ]
321- new_base_commit_map [ciq_commit ] = upstream_commit
322- new_base_commit_map_rev [upstream_commit ] = ciq_commit
355+ new_base_commit_map , new_base_commit_map_rev = get_commit_maps_from_backport_data (
356+ args .repo , f"{ os .getlogin ()} _{ new_rolling_branch_kernel } " , common_sha
357+ )
323358
324359 print (f"[rolling release update] Total commits in new branch: { len (new_base_commit_map )} " )
325360 if DEBUG :
@@ -336,14 +371,18 @@ def check_for_fips_protected_changes(repo, branch, common_tag):
336371 )
337372 commits_to_remove = {}
338373 for ciq_commit , upstream_commit in rolling_commit_map .items ():
339- if upstream_commit in new_base_commit_map_rev :
374+ if upstream_commit and upstream_commit in new_base_commit_map_rev :
375+ new_base_ciq_commit = new_base_commit_map_rev [upstream_commit ]
376+ print (
377+ f"- Old commit { ciq_commit [:12 ]} backported upstream { upstream_commit [:12 ]} "
378+ )
340379 print (
341- f"- Commit { ciq_commit } already present in new base branch: { repo .git .show ('--pretty=oneline ' , '-s' , ciq_commit )} "
380+ f" Already in new base as { new_base_ciq_commit [: 12 ] } : { repo .git .show ('--pretty=%s ' , '-s' , new_base_ciq_commit )} "
342381 )
343382 commits_to_remove [ciq_commit ] = upstream_commit
344- if ciq_commit in new_base_commit_map :
383+ elif ciq_commit in new_base_commit_map :
345384 print (
346- f"- CIQ Commit { ciq_commit } already present in new base branch: { repo .git .show ('--pretty=oneline' , '-s' , ciq_commit )} "
385+ f"- CIQ Commit { ciq_commit [: 12 ] } already present in new base branch: { repo .git .show ('--pretty=oneline' , '-s' , ciq_commit )} "
347386 )
348387 commits_to_remove [ciq_commit ] = upstream_commit
349388
0 commit comments