Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: DO NOT MERGE: patching: rewrite: try to stabilize patch index stanzas as well as From lines #6455

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions lib/tools/common/patching_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
REGEX_PATCH_FILENAMES = r"^patching file \"(.+)\""
log: logging.Logger = logging.getLogger("patching_utils")

# Magic strings and regex for rewriting patches' "index xxx....yyyy" lines
index_zero = f"{'0' * 12}"
index_from_zero = f"index {'0' * 12}..{'1' * 12}"
index_not_zero = f"index {'1' * 12}..{'2' * 12}"
index_rewrite_regexp: re.Pattern = re.compile(r"index ([0-9a-f]{12})\.\.([0-9a-f]{12})")


# Callback used for rewriting index lines.
def rewrite_indexes_callback(x: re.Match): # Preserve zero from's for new file creations.
if x.group(1) == index_zero:
return index_from_zero
return index_not_zero


class PatchRootDir:
def __init__(self, abs_dir, root_type, patch_type, root_dir):
Expand Down Expand Up @@ -808,7 +821,7 @@ def export_commit_as_patch(repo: git.Repo, commit: str):
'--zero-commit', # do not use the git revision, instead 000000...0000
'--stat=120', # 'wider' stat output; default is 80
'--stat-graph-width=10', # shorten the diffgraph graph part, it's too long
'--abbrev=12', # force index length to 12
'--abbrev=12', # force index length to 12 - essential for the regex below to work
"-1", "--stdout", commit
],
cwd=repo.working_tree_dir,
Expand All @@ -823,7 +836,17 @@ def export_commit_as_patch(repo: git.Repo, commit: str):
raise Exception(f"Failed to export commit {commit} to patch: {stderr_output}")
if stdout_output == "":
raise Exception(f"Failed to export commit {commit} to patch: no output")
return stdout_output

# Now, massage the output. We don't want the "index 08c33ec7e9f1..528741fcc0ec 100644" lines changing every time.
# We do need to preserve "0000000000.." ones as that indicates new file creation.
# Use a regular expression and a callback to decide. Check the top of this file for the regex and callback.
rewritten_indexes = re.sub(index_rewrite_regexp, rewrite_indexes_callback, stdout_output)

# If rewritten is same as original this didn't work, surely.
if rewritten_indexes == stdout_output:
raise Exception(f"Failed to rewrite indexes in patch output: {stdout_output}")

return rewritten_indexes


# Hack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Subject: Sync `rk3308_codec` to BSP tree

diff --git a/Documentation/devicetree/bindings/sound/rockchip,rk3308-codec.txt b/Documentation/devicetree/bindings/sound/rockchip,rk3308-codec.txt
new file mode 100644
index 000000000000..e20bbd73e37e
index 000000000000..111111111111
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/rockchip,rk3308-codec.txt
@@ -0,0 +1,78 @@
Expand Down Expand Up @@ -95,7 +95,7 @@ index 000000000000..e20bbd73e37e
+ status = "okay";
+};
diff --git a/sound/soc/codecs/rk3308_codec.c b/sound/soc/codecs/rk3308_codec.c
index 106f09738dd0..815e22fc346c 100644
index 111111111111..222222222222 100644
--- a/sound/soc/codecs/rk3308_codec.c
+++ b/sound/soc/codecs/rk3308_codec.c
@@ -29,1420 +29,4699 @@
Expand Down Expand Up @@ -6251,7 +6251,7 @@ index 106f09738dd0..815e22fc346c 100644
},
.probe = rk3308_platform_probe,
diff --git a/sound/soc/codecs/rk3308_codec.h b/sound/soc/codecs/rk3308_codec.h
index 6cfa69157785..93e089dae081 100644
index 111111111111..222222222222 100644
--- a/sound/soc/codecs/rk3308_codec.h
+++ b/sound/soc/codecs/rk3308_codec.h
@@ -26,7 +26,8 @@
Expand Down Expand Up @@ -6701,7 +6701,7 @@ index 6cfa69157785..93e089dae081 100644
#endif /* __RK3308_CODEC_H__ */
diff --git a/sound/soc/codecs/rk3308_codec_provider.h b/sound/soc/codecs/rk3308_codec_provider.h
new file mode 100644
index 000000000000..68042b1328dc
index 000000000000..111111111111
--- /dev/null
+++ b/sound/soc/codecs/rk3308_codec_provider.h
@@ -0,0 +1,28 @@
Expand Down