1414 CIQ_fixes_references ,
1515 CIQ_get_full_hash ,
1616 CIQ_original_commit_author_to_tag_string ,
17+ CIQ_raise_or_warn ,
1718 CIQ_reset_HEAD ,
1819 CIQ_run_git ,
1920)
2223MERGE_MSG_BAK = f"{ MERGE_MSG } .bak"
2324
2425
25- def check_fixes (sha ):
26+ def check_fixes (sha , ignore_fixes_check ):
2627 """
2728 Checks if commit has "Fixes:" references and if so, it checks if the
2829 commit(s) that it tries to fix are part of the current branch
@@ -33,9 +34,13 @@ def check_fixes(sha):
3334 logging .warning ("The commit you try to cherry pick has no Fixes: reference; review it carefully" )
3435 return
3536
37+ not_present_fixes = []
3638 for fix in fixes :
3739 if not CIQ_commit_exists_in_current_branch (os .getcwd (), fix ):
38- raise RuntimeError (f"The commit you want to cherry pick references a Fixes: { fix } but this is not here" )
40+ not_present_fixes .append (fix )
41+
42+ err = f"The commit you want to cherry pick has the following Fixes: reference that are not part of the tree { not_present_fixes } "
43+ CIQ_raise_or_warn (cond = not not_present_fixes , error_msg = err , warn = ignore_fixes_check )
3944
4045
4146def manage_commit_message (full_sha , ciq_tags , jira_ticket , commit_successful ):
@@ -80,7 +85,7 @@ def manage_commit_message(full_sha, ciq_tags, jira_ticket, commit_successful):
8085 raise RuntimeError (f"Failed to write commit message to { MERGE_MSG } : { e } " ) from e
8186
8287
83- def cherry_pick (sha , ciq_tags , jira_ticket ):
88+ def cherry_pick (sha , ciq_tags , jira_ticket , ignore_fixes_check ):
8489 """
8590 Cherry picks a commit and it adds the ciq standardized format
8691 In case of error (cherry pick conflict):
@@ -102,7 +107,7 @@ def cherry_pick(sha, ciq_tags, jira_ticket):
102107 except RuntimeError as e :
103108 raise RuntimeError (f"Invalid commit SHA { sha } : { e } " ) from e
104109
105- check_fixes (sha = full_sha )
110+ check_fixes (sha = full_sha , ignore_fixes_check = ignore_fixes_check )
106111
107112 # Commit message is in MERGE_MSG
108113 commit_successful = True
@@ -129,7 +134,7 @@ def cherry_pick(sha, ciq_tags, jira_ticket):
129134 CIQ_run_git (repo_path = os .getcwd (), args = ["commit" , "-F" , MERGE_MSG ])
130135
131136
132- def cherry_pick_fixes (sha , ciq_tags , jira_ticket , upstream_ref ):
137+ def cherry_pick_fixes (sha , ciq_tags , jira_ticket , upstream_ref , ignore_fixes_check ):
133138 """
134139 It checks upstream_ref for commits that have this reference:
135140 Fixes: <sha>. If any, these will also be cherry picked with the ciq
@@ -142,21 +147,33 @@ def cherry_pick_fixes(sha, ciq_tags, jira_ticket, upstream_ref):
142147 bf_ciq_tags = [re .sub (r"^cve " , "cve-bf " , s ) for s in ciq_tags ]
143148 for full_hash , display_str in fixes_in_mainline :
144149 print (f"Extra cherry picking { display_str } " )
145- full_cherry_pick (sha = full_hash , ciq_tags = bf_ciq_tags , jira_ticket = jira_ticket , upstream_ref = upstream_ref )
150+ full_cherry_pick (
151+ sha = full_hash ,
152+ ciq_tags = bf_ciq_tags ,
153+ jira_ticket = jira_ticket ,
154+ upstream_ref = upstream_ref ,
155+ ignore_fixes_check = ignore_fixes_check ,
156+ )
146157
147158
148- def full_cherry_pick (sha , ciq_tags , jira_ticket , upstream_ref ):
159+ def full_cherry_pick (sha , ciq_tags , jira_ticket , upstream_ref , ignore_fixes_check ):
149160 """
150161 It cherry picks a commit from upstream-ref along with its Fixes: references.
151162 If cherry-pick or cherry_pick_fixes fail, the exception is propagated
152163 If one of the cherry picks fails, an exception is returned and the previous
153164 successful cherry picks are left as they are.
154165 """
155166 # Cherry pick the commit
156- cherry_pick (sha = sha , ciq_tags = ciq_tags , jira_ticket = jira_ticket )
167+ cherry_pick (sha = sha , ciq_tags = ciq_tags , jira_ticket = jira_ticket , ignore_fixes_check = ignore_fixes_check )
157168
158169 # Cherry pick the fixed-by dependencies
159- cherry_pick_fixes (sha = sha , ciq_tags = ciq_tags , jira_ticket = jira_ticket , upstream_ref = upstream_ref )
170+ cherry_pick_fixes (
171+ sha = sha ,
172+ ciq_tags = ciq_tags ,
173+ jira_ticket = jira_ticket ,
174+ upstream_ref = upstream_ref ,
175+ ignore_fixes_check = ignore_fixes_check ,
176+ )
160177
161178
162179if __name__ == "__main__" :
@@ -177,6 +194,11 @@ def full_cherry_pick(sha, ciq_tags, jira_ticket, upstream_ref):
177194 default = "origin/kernel-mainline" ,
178195 help = "Reference to upstream mainline branch (default: origin/kernel-mainline)" ,
179196 )
197+ parser .add_argument (
198+ "--ignore-fixes-check" ,
199+ action = "store_true" ,
200+ help = "If the commit(s) this commit is trying to fix are not part of the tree, do not exit" ,
201+ )
180202
181203 args = parser .parse_args ()
182204
@@ -187,7 +209,13 @@ def full_cherry_pick(sha, ciq_tags, jira_ticket, upstream_ref):
187209 tags = args .ciq_tag .split ("," )
188210
189211 try :
190- full_cherry_pick (sha = args .sha , ciq_tags = tags , jira_ticket = args .ticket , upstream_ref = args .upstream_ref )
212+ full_cherry_pick (
213+ sha = args .sha ,
214+ ciq_tags = tags ,
215+ jira_ticket = args .ticket ,
216+ upstream_ref = args .upstream_ref ,
217+ ignore_fixes_check = args .ignore_fixes_check ,
218+ )
191219 except Exception as e :
192220 print (f"full_cherry_pick failed { e } " )
193221 traceback .print_exc ()
0 commit comments