[PATCH] repos: add --whitespace=fix to git apply command

270 views
Skip to first unread message

Claudius Heine

unread,
May 12, 2022, 6:47:14 AM5/12/22
to kas-devel, Claudius Heine
Patches generated by git-format-patch have a space after each `+` or `-`
when an empty line is added or removed.

Applying those patches with git-apply will cause git to print out
warnings, but still applies the patch. Those warnings will be picked up
by kas, and since they are coming from stderr, print them out as ERRORS.

To solve this, either `--whitespace=nowarn` or `--whitespace=fix` can be
used to either suppress those warnings or to actually fix them before
applying them.

Fixing those issues instead of ignoring them is probably better, but
both options would be an improvement over the current state. At the end
it probably does not matter much which one of those is chosen.

Signed-off-by: Claudius Heine <c...@denx.de>
---
kas/repos.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kas/repos.py b/kas/repos.py
index 448d723..ed3ad89 100644
--- a/kas/repos.py
+++ b/kas/repos.py
@@ -393,7 +393,7 @@ class GitRepo(RepoImpl):
format(refspec=self.remove_ref_prefix(self.refspec))]

def apply_patches_file_cmd(self, path):
- return ['git', 'apply', path]
+ return ['git', 'apply', '--whitespace=fix', path]

def set_remote_url_cmd(self):
return ['git', 'remote', 'set-url', 'origin', self.effective_url]
--
2.33.3

Jan Kiszka

unread,
May 12, 2022, 7:06:41 AM5/12/22
to Claudius Heine, kas-devel
On 12.05.22 12:47, Claudius Heine wrote:
> Patches generated by git-format-patch have a space after each `+` or `-`
> when an empty line is added or removed.
>
> Applying those patches with git-apply will cause git to print out
> warnings, but still applies the patch. Those warnings will be picked up
> by kas, and since they are coming from stderr, print them out as ERRORS.
>
> To solve this, either `--whitespace=nowarn` or `--whitespace=fix` can be
> used to either suppress those warnings or to actually fix them before
> applying them.
>
> Fixing those issues instead of ignoring them is probably better, but
> both options would be an improvement over the current state. At the end
> it probably does not matter much which one of those is chosen.

Won't "fix" remove those whitespaces from the patch of the patch, thus
rendering the patched-in patch broken?

Jan

>
> Signed-off-by: Claudius Heine <c...@denx.de>
> ---
> kas/repos.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kas/repos.py b/kas/repos.py
> index 448d723..ed3ad89 100644
> --- a/kas/repos.py
> +++ b/kas/repos.py
> @@ -393,7 +393,7 @@ class GitRepo(RepoImpl):
> format(refspec=self.remove_ref_prefix(self.refspec))]
>
> def apply_patches_file_cmd(self, path):
> - return ['git', 'apply', path]
> + return ['git', 'apply', '--whitespace=fix', path]
>
> def set_remote_url_cmd(self):
> return ['git', 'remote', 'set-url', 'origin', self.effective_url]

--
Siemens AG, Technology
Competence Center Embedded Linux

Bezdeka, Florian

unread,
May 12, 2022, 7:15:33 AM5/12/22
to c...@denx.de, kas-...@googlegroups.com
On Thu, 2022-05-12 at 12:47 +0200, Claudius Heine wrote:
> Patches generated by git-format-patch have a space after each `+` or `-`
> when an empty line is added or removed.

I can't confirm that. If you're adding an empty line you get "+", a new
line with one whitespace delivers "+ ".

git warns me about new empty lines at EOF, but not when they appear
somewhere else.

Claudius Heine

unread,
May 12, 2022, 7:19:46 AM5/12/22
to Jan Kiszka, kas-devel
On 2022-05-12 13:06, Jan Kiszka wrote:
> On 12.05.22 12:47, Claudius Heine wrote:
>> Patches generated by git-format-patch have a space after each `+` or `-`
>> when an empty line is added or removed.
>>
>> Applying those patches with git-apply will cause git to print out
>> warnings, but still applies the patch. Those warnings will be picked up
>> by kas, and since they are coming from stderr, print them out as ERRORS.
>>
>> To solve this, either `--whitespace=nowarn` or `--whitespace=fix` can be
>> used to either suppress those warnings or to actually fix them before
>> applying them.
>>
>> Fixing those issues instead of ignoring them is probably better, but
>> both options would be an improvement over the current state. At the end
>> it probably does not matter much which one of those is chosen.
>
> Won't "fix" remove those whitespaces from the patch of the patch, thus
> rendering the patched-in patch broken?

Hmm.. No those inception patches seems to still work in my tests.

However I found that `fix` still prints out messages about it. So I
guess this issue should just be silenced via `nowarn`...

I am not sure why `git-format-patch` behaves this way and adds those
AFAIK unnecessary whitespaces...

Claudius Heine

unread,
May 12, 2022, 7:39:56 AM5/12/22
to Bezdeka, Florian, kas-...@googlegroups.com
Hi Florian,

On 2022-05-12 13:15, Bezdeka, Florian wrote:
> On Thu, 2022-05-12 at 12:47 +0200, Claudius Heine wrote:
>> Patches generated by git-format-patch have a space after each `+` or `-`
>> when an empty line is added or removed.
>
> I can't confirm that. If you're adding an empty line you get "+", a new
> line with one whitespace delivers "+ ".
>
> git warns me about new empty lines at EOF, but not when they appear
> somewhere else.

Hm... It seems to happen with creating a patch that contains patches...

The I get a `+ ` for every empty like that was already in around where
the inner patch changed something:

Example:

```
--- /dev/null
+++
b/meta-filesystems/recipes-utils/btrfsmaintenance/files/0001-change-sysconfig-path-to-etc-default.patch
[...]
+--- a/btrfsmaintenance-refresh.service
++++ b/btrfsmaintenance-refresh.service
+@@ -1,5 +1,5 @@
+ [Unit]
+-Description=Update cron periods from /etc/sysconfig/btrfsmaintenance
++Description=Update cron periods from /etc/default/btrfsmaintenance
+ <--------------------------------- empty space here
+ [Service]
+ ExecStart=/usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh
systemd-timer
+-- <------------------------------- empty space here
+2.33.3
+
```

Odd...

regards,
Claudius

Claudius Heine

unread,
May 12, 2022, 8:12:57 AM5/12/22
to kas-devel, Claudius Heine
Patches contain tailing white space in empty lines around a change, those
are generally expected by git-apply and cause no issue.

However in cases where a patch file is added, removed or modified
in a patch, that patch would necessarily include `- ` or `+ ` lines,
since they operate on patch files.

Applying those patches with git-apply will cause git to print out
warnings about tailing white spaces per default, but still applies the
patch. Those warnings will be picked up by kas, and since they are
coming from stderr, print them out as `ERRORS`.

To solve this add `--whitespace=nowarn` as a parameter to the git-apply
call to silence those warnings.

In case of kas, it is to be expected that patches are added, removed or
changed in meta layers, so those supposedly errors will cause confusion.

Signed-off-by: Claudius Heine <c...@denx.de>
---
changes from v1:
- replace `fix` with `nowarn` because `fix` would still issue messages
about it.
- clarify commit message about the issue
---
kas/repos.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kas/repos.py b/kas/repos.py
index 448d723..8921bb4 100644
--- a/kas/repos.py
+++ b/kas/repos.py
@@ -393,7 +393,7 @@ class GitRepo(RepoImpl):
format(refspec=self.remove_ref_prefix(self.refspec))]

def apply_patches_file_cmd(self, path):
- return ['git', 'apply', path]
+ return ['git', 'apply', '--whitespace=nowarn', path]

Jan Kiszka

unread,
May 16, 2022, 3:13:03 AM5/16/22
to Claudius Heine, kas-devel
Thanks, applied.

Jan
Reply all
Reply to author
Forward
0 new messages