2

I have a .patch file that I want to apply to the android kernel, and I do so via:

patch -p1 < <patch-file>

After running it, I see git binary diffs are not supported print for the following line of the patch:

+PRODUCT_COPY_FILES += \
+     hardware/ril/libquectel-ril/arm64-v8a/dir:system/bin/dir \

whereas dir is a binary defined in a patch file.

Should I be initializing git, adding all the files, and then running git apply patch-file?

Edit:

After running git init, git add, git commit, I ran git apply <patch-file>, and now I get:

warning: device/qcom/common/rootdir/etc/init.class_main.sh has type 100644, expected 100755
error: patch failed: device/qcom/sdm845/sdm845.mk:87
error: device/qcom/sdm845/sdm845.mk: patch does not apply
warning: device/qcom/sepolicy/generic/vendor/common/file_contexts has type 100644, expected 100755
file.patch:37781: new blank line at EOF.
+
warning: system/core/init/selinux.cpp has type 100644, expected 100755
error: patch failed: system/core/init/selinux.cpp:430
error: system/core/init/selinux.cpp: patch does not apply
Jazzy
  • 324
  • 4
  • 15
  • You don't need to create a Git repository first, but it's probably not a bad idea to do so. – torek Mar 02 '21 at 02:14
  • do you see why am I getting this print? (not sure if it's a warning or an error but it's preventing a build to complete since these lines aren't "applied" – Jazzy Mar 02 '21 at 02:19
  • ... because someone provided a binary patch, when `patch` itself doesn't support them? Git added binary patches so that you could turn a commit into a patch even if some of the files in the commit are not printable text. Presumably whoever provided these patches, provided them on the assumption that you have the appropriate Git repository. If you can find the right source repository and clone it, you'll be in great shape. If not, you can find some other repository and clone it and hope, or turn what you have into a repository and wish-and-hope. – torek Mar 02 '21 at 02:27
  • So does that mean I can't do much with the existing binary patch file i.e applying it? – Jazzy Mar 02 '21 at 02:38
  • You can use `git patch apply` to *try* to apply it. A patch only works if you have the right original file as well, though. I can't tell whether you have the right original file for that particular patch. – torek Mar 02 '21 at 03:58
  • ...after `git commit`? – Jazzy Mar 02 '21 at 03:59
  • You can use `git patch apply` at any time: if you run it in a non-Git-repository, it just tries to be an improved version of `patch`. But if you have a full Git repository, it can make use of the `index` lines at the front of each diff. – torek Mar 02 '21 at 04:21
  • where's the patch file in `git patch apply`? From what I looked up online, it's `git apply patch-file`, which upon running errors out `error: device/qcom/sdm845/sdm845.mk: patch does not apply` – Jazzy Mar 02 '21 at 04:28
  • Whoops, I meant `git apply`, not `git patch apply`. The `patch does not apply` error means that the patch is for files you don't have in the first place, which is what I was getting at: a patch is only good if you have the files it patches. You have some other set of files. – torek Mar 02 '21 at 05:38
  • but the `device/qcom/sdm845/sdm845.mk` file does exist though – Jazzy Mar 02 '21 at 05:51
  • If you have a file that says "red green blue" named `file`, and I have a file that says "small medium large" named `file`, do we have the same files? – torek Mar 02 '21 at 05:53
  • You mentioned the patch is for files I don't have in the first place. Isn't that implying that I don't have the files it's complaining about which is referenced in the patch file? – Jazzy Mar 02 '21 at 06:05
  • A file is not just a name. In many ways the *name* is the least interesting part of a file. A file's *content* is what matters. A patch says: *To get the new file named F, look at the old file named F: at line X you'll find existing content oldContent; replace that with newContent.* But what if the file that *you* have that's named F doesn't have that existing content? – torek Mar 02 '21 at 08:46
  • 2
    To put it another way: just because you have a box with the right label on it, does not mean you have the right stuff *in* the box. The patch is an update for the *contents*. It's not a replacement for all the contents: you need to have the right *current* contents before the patch can be applied to it. – torek Mar 02 '21 at 08:48

0 Answers0