Skip to content

Commit

Permalink
Add optional CherryPick and Revert mergeStrategy option for PatchSet …
Browse files Browse the repository at this point in the history
…recipe

CherryPick and Revert in an edkrepo manifest PatchSet can include:
mergeStrategy="ort_ignore-all-space"
mergeStrategy="ort_theirs"
mergeStrategy="ort_ours"

This can help with PatchSet merge issues.
e.g. using Patch followed by CherryPick where the host system's git am.keepcr
setting is unknown during the Patch "git am" step.
tianocore#244

Signed-off-by: Nathaniel Haller <[email protected]>
  • Loading branch information
ndhaller authored and ashedesimone committed Jun 4, 2024
1 parent 5afcd61 commit dbcbb95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 17 additions & 3 deletions edkrepo/common/common_repo_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,27 @@ def apply_patchset_operations(repo, operations_list, global_manifest_path, remot
else:
raise EdkrepoPatchNotFoundException(PATCHFILE_DOES_NOT_EXIST.format(operation.file))
elif operation.type == REVERT:
revert_command = ['git', 'revert', operation.sha, '--no-edit']
if operation.merge_strategy == "ort_ignore-all-space":
revert_command.extend(['--strategy', 'ort', '--strategy-option', 'ignore-all-space'])
elif operation.merge_strategy == "ort_theirs":
revert_command.extend(['--strategy', 'ort', '--strategy-option', 'theirs'])
elif operation.merge_strategy == "ort_ours":
revert_command.extend(['--strategy', 'ort', '--strategy-option', 'ours'])
try:
repo.git.execute(['git', 'revert', operation.sha, '--no-edit'])
repo.git.execute(revert_command)
except:
if is_merge_conflict(repo):
repo.git.execute(['git', 'revert', '--abort'])
raise EdkrepoRevertFailedException(APPLYING_REVERT_FAILED.format(operation.sha))
else:
cherrypick_command = ['git', 'cherry-pick', operation.sha, '-x']
if operation.merge_strategy == "ort_ignore-all-space":
cherrypick_command.extend(['--strategy', 'ort', '--strategy-option', 'ignore-all-space'])
elif operation.merge_strategy == "ort_theirs":
cherrypick_command.extend(['--strategy', 'ort', '--strategy-option', 'theirs'])
elif operation.merge_strategy == "ort_ours":
cherrypick_command.extend(['--strategy', 'ort', '--strategy-option', 'ours'])
if operation.source_remote:
REMOTE_FOUND = False
for remote in remote_list:
Expand All @@ -962,7 +976,7 @@ def apply_patchset_operations(repo, operations_list, global_manifest_path, remot
except:
raise EdkrepoFetchBranchNotFoundException(FETCH_BRANCH_DOES_NOT_EXIST.format(operation.source_branch))
try:
repo.git.execute(['git', 'cherry-pick', operation.sha, '-x'])
repo.git.execute(cherrypick_command)
except:
if is_merge_conflict(repo):
repo.git.execute(['git', 'cherry-pick', '--abort'])
Expand All @@ -979,7 +993,7 @@ def apply_patchset_operations(repo, operations_list, global_manifest_path, remot
except:
raise EdkrepoFetchBranchNotFoundException(FETCH_BRANCH_DOES_NOT_EXIST.format(operation.source_branch))
try:
repo.git.execute(['git', 'cherry-pick', operation.sha, '-x'])
repo.git.execute(cherrypick_command)
except:
if is_merge_conflict(repo):
repo.git.execute(['git', 'cherry-pick', '--abort'])
Expand Down
8 changes: 6 additions & 2 deletions edkrepo_manifest_parser/edk_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
RepoSource = namedtuple('RepoSource', ['root', 'remote_name', 'remote_url', 'branch', 'commit', 'sparse',
'enable_submodule', 'tag', 'venv_cfg', 'patch_set'])
PatchSet = namedtuple('PatchSet', ['remote', 'name', 'parent_sha', 'fetch_branch'])
PatchOperation = namedtuple('PatchOperation',['type', 'file', 'sha', 'source_remote', 'source_branch'])
PatchOperation = namedtuple('PatchOperation',['type', 'file', 'sha', 'source_remote', 'source_branch', 'merge_strategy'])
SparseSettings = namedtuple('SparseSettings', ['sparse_by_default'])
SparseData = namedtuple('SparseData', ['combination', 'remote_name', 'always_include', 'always_exclude'])

Expand Down Expand Up @@ -906,10 +906,14 @@ def __init__(self, element):
self.source_branch = element.attrib['sourceBranch']
except KeyError as k:
self.source_branch = None
try:
self.merge_strategy = element.attrib['mergeStrategy']
except KeyError as k:
self.merge_strategy = None

@property
def tuple(self):
return PatchOperation(self.type, self.file, self.sha, self.source_remote, self.source_branch)
return PatchOperation(self.type, self.file, self.sha, self.source_remote, self.source_branch, self.merge_strategy)

class _ProjectInfo():
def __init__(self, element):
Expand Down

0 comments on commit dbcbb95

Please sign in to comment.