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

patching: rewrite: fully stabilize patch index stanzas as well as From lines #6623

Conversation

rpardini
Copy link
Member

patching: rewrite: fully stabilize patch index stanzas as well as From lines

  • patching: rewrite: fully stabilize patch index stanzas as well as From lines
    • git format-patch --zero-commit doesn't affect index xxx...yyy lines, only From:
      • so use the classy "use a regex with a callback" solution as git format-patch doesn't offer one
    • this will make all patches change when rewritten, but hopefully for the last time !
    • we need to preserve index 000000000000..xxx as zeros, which indicate new file creation, thus:
      • new file creations are rewritten as index 000000000000..111111111111
      • non-creations are rewritten as index 111111111111..222222222222
    • this is the final version of RFC: DO NOT MERGE: patching: rewrite: try to stabilize patch index stanzas as well as From lines #6455

@rpardini
Copy link
Member Author

We've a few malformed patches here and there, which are being handled by other people -- due to this I'm holding back a batch of rewrites of the "big 5" kernels edge patches using this implementation for a while.

@rpardini rpardini force-pushed the pr/patching-rewrite-fully-stabilize-patch-index-stanzas-as-well-as-From-lines branch from f3451c5 to db756b6 Compare May 21, 2024 06:07
@igorpecovnik igorpecovnik added 08 Milestone: Third quarter release Needs review Seeking for review labels May 21, 2024
@rpardini rpardini force-pushed the pr/patching-rewrite-fully-stabilize-patch-index-stanzas-as-well-as-From-lines branch 2 times, most recently from 2f46115 to 842d436 Compare June 3, 2024 06:51
@ColorfulRhino
Copy link
Collaborator

Not quite directly related, but I have discovered that patches created with kernel-patch output patches with 5 additional lines before and after the addition/deletion lines, whereas normal Git patches just have 3 additional lines. While more lines are better to see the patch context, rewrite-kernel-patches does remove/shrink those additional lines, making it basically pointless that kernel-patch added them.

Example:

Patch created with kernel-patch (5 lines before/after the +-):

@@ -400,11 +400,11 @@ $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
 $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
 	$(call if_changed,wrap_S_dtb)
 
 quiet_cmd_dtc = DTC     $@
 cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
-	$(DTC) -o $@ -b 0 \
+	$(DTC) -@ -o $@ -b 0 \
 		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
 		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
 	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
 
 quiet_cmd_fdtoverlay = DTOVL   $@

After doing rewrite-kernel-patches (only 3 lines before/after the +-):

@@ -402,7 +402,7 @@ $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
 
 quiet_cmd_dtc = DTC     $@
 cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
-	$(DTC) -o $@ -b 0 \
+	$(DTC) -@ -o $@ -b 0 \
 		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
 		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
 	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)

BUG:
Also as you can see, the line directly in the hunk line stays the same, which is a bug. The line $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE is not correct anymore after the rewrite.

Maybe I should open an issue about this 😄

@rpardini
Copy link
Member Author

rpardini commented Jun 6, 2024

Not quite directly related, but I have discovered that patches created with kernel-patch output patches with 5 additional lines before and after the addition/deletion lines, whereas normal Git patches just have 3 additional lines.

Yes, because https://github.com/armbian/build/blob/main/lib/functions/compilation/patch/patching.sh#L121 (kernel-patch) and https://github.com/armbian/build/blob/main/lib/tools/common/patching_utils.py#L802 (rewrite-*'s).

Should be easy to fix, eg, make them equal -- but really, what is better, 5 or 3, I dunno.

BUG: Also as you can see, the line directly in the hunk line stays the same, which is a bug. The line $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE is not correct anymore after the rewrite.

Maybe I should open an issue about this 😄

I can't follow; tired eyes. Did this alledged bug happen with this PR or is it on main ?

@ColorfulRhino
Copy link
Collaborator

Should be easy to fix, eg, make them equal -- but really, what is better, 5 or 3, I dunno.

5 is better because more context 👍 This way when rewriting patches, it won't remove lines but will also not be able to add new lines I believe (or can it since it can see the context? that would be nice, although would cause lots of commit diff).

I can't follow; tired eyes. Did this alledged bug happen with this PR or is it on main ?

Apologies, I discovered it in main without this PR applied.

…rom lines

- `git format-patch --zero-commit` doesn't affect `index xxx...yyy` lines, only `From: `
  - so use the _classy_ "use a regex with a callback" solution as git format-patch doesn't offer one
- this will make _all_ patches change when rewritten, but hopefully _for the last time_ !
- we need to preserve `index 000000000000..xxx` as zeros, which indicate new file creation, thus:
  - new file creations are rewritten as `index 000000000000..111111111111`
  - non-creations are rewritten as `index 111111111111..222222222222`
- this is the final version of armbian#6455
@rpardini rpardini force-pushed the pr/patching-rewrite-fully-stabilize-patch-index-stanzas-as-well-as-From-lines branch from 842d436 to 4894ceb Compare June 6, 2024 20:14
Copy link
Collaborator

@ColorfulRhino ColorfulRhino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work as it should.
Maybe the regex magic could have been avoided using git diff --no-index instead when creating or rewriting patches, but at this point I think your solution is totally fine as well 👍

@rpardini
Copy link
Member Author

rpardini commented Jun 9, 2024

git diff --no-index

Hmm. Is there a git format-patch version of this I missed?

@rpardini rpardini merged commit 282fb96 into armbian:main Jun 9, 2024
7 checks passed
@ColorfulRhino
Copy link
Collaborator

ColorfulRhino commented Jun 9, 2024

git diff --no-index

Hmm. Is there a git format-patch version of this I missed?

I don't think so, but actually I think I finally found out how!

Try using the environmental variable: GIT_EXTERNAL_DIFF='git diff --no-index "$2" "$5"' to set how git format-patch uses the diff tool :)
"$2" and "$5" refer to the paths to the temporary files that git creates for the diff.

@rpardini
Copy link
Member Author

rpardini commented Jun 9, 2024

Try using the environmental variable: GIT_EXTERNAL_DIFF='git diff --no-index "$2" "$5"' to set how git format-patch uses the diff tool :)
"$2" and "$5" refer to the paths to the temporary files that git creates for the diff.

Oh wow. Will check this out soon, as it's high-hackage but better than regex-replacing index stanzas! Thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08 Milestone: Third quarter release Needs review Seeking for review size/small PR with less then 50 lines
Development

Successfully merging this pull request may close these issues.

None yet

3 participants