Commit Graph

4 Commits

Author SHA1 Message Date
Miguel Ojeda
8f8d4be9fb .gitattributes: set diff driver for Rust source code files
Git supports a builtin Rust diff driver [1] since v2.23.0 (2019).

It improves the choice of hunk headers in some cases, such as
diffs within methods, since those are indented in Rust within
an `impl` block, and therefore the default diff driver would
pick the outer `impl` block instead (rather than the method
where the changed code is).

For instance, with the default diff driver:

    @@ -455,6 +455,8 @@ impl fmt::Write for RawFormatter {
             // Amount that we can copy. `saturating_sub` ensures we get 0 if `pos` goes past `end`.
             let len_to_copy = core::cmp::min(pos_new, self.end).saturating_sub(self.pos);

    +        test_diff_driver();
    +
             if len_to_copy > 0 {
                 // SAFETY: If `len_to_copy` is non-zero, then we know `pos` has not gone past `end`
                 // yet, so it is valid for write per the type invariants.

With the Rust diff driver:

    @@ -455,6 +455,8 @@ fn write_str(&mut self, s: &str) -> fmt::Result {
             // Amount that we can copy. `saturating_sub` ensures we get 0 if `pos` goes past `end`.
             let len_to_copy = core::cmp::min(pos_new, self.end).saturating_sub(self.pos);

    +        test_diff_driver();
    +
             if len_to_copy > 0 {
                 // SAFETY: If `len_to_copy` is non-zero, then we know `pos` has not gone past `end`
                 // yet, so it is valid for write per the type invariants.

Thus set the `rust` diff driver for `*.rs` source files.

The Rust repository also does so since 2020 [2].

Link: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header [1]
Link: https://github.com/rust-lang/rust/pull/78882 [2]
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20230418233048.335281-1-ojeda@kernel.org
[ Added link to Rust repository ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-05-31 17:48:25 +02:00
Masahiro Yamada
ae41e0e41b .gitattributes: use 'dts' diff driver for *.dtso files
Now we have the third extension for DT source files (overlay).
Give the diff=dts attribute to *.dtso as well.

While I was here, I merged *.c and *.o into *.[ch] and added the
SPDX-License-Identifier.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2023-02-26 15:28:23 +09:00
Stephen Boyd
a512ae54ce .gitattributes: use 'dts' diff driver for dts files
Git is gaining support to display the closest node to the diff in the
hunk header via the 'dts' diff driver.  Use that driver for all dts and
dtsi files so we can gain some more context on where the diff is.
Taking a recent commit in the kernel dts files you can see the
difference.

With this patch and an updated git

: diff --git a/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi b/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi
:  index 62e07e1197cc..4c38426a6969 100644
:  --- a/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi
:  +++ b/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi
:  @@ -289,5 +289,29 @@ vdd_hdmi: regulator@1 {
:                          gpio = <&gpio TEGRA194_MAIN_GPIO(A, 3) GPIO_ACTIVE_HIGH>;
:                          enable-active-high;
:                  };
:  +
:  +               vdd_3v3_pcie: regulator@2 {
:  +                       compatible = "regulator-fixed";

vs. without this patch

:  diff --git a/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi b/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi
:  index 62e07e1197cc..4c38426a6969 100644
:  --- a/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi
:  +++ b/arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi
:  @@ -289,5 +289,29 @@
:                          gpio = <&gpio TEGRA194_MAIN_GPIO(A, 3) GPIO_ACTIVE_HIGH>;
:                          enable-active-high;
:                  };
:  +
:  +               vdd_3v3_pcie: regulator@2 {
:  +                       compatible = "regulator-fixed";

You can see that we don't know what the context node is because it isn't
shown after the '@@'.

dts is not released yet but it is staged to be in the next release[1].
One can probably build git from source and try it out.

[1] https://git.kernel.org/pub/scm/git/git.git/commit/?id=d49c2c3466d2c8cb0b3d0a43e6b406b07078fdb1

Link: http://lkml.kernel.org/r/20191004212311.141538-1-swboyd@chromium.org
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Acked-by: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-12-04 19:44:11 -08:00
Jean Delvare
218dd85887 .gitattributes: set git diff driver for C source code files
Git can be told to apply language-specific rules when generating diffs.
Enable this for C source code files (*.c and *.h) so that function names
are printed right.  Specifically, doing so prevents "git diff" from
mistakenly considering unindented goto labels as function names.

Link: http://lkml.kernel.org/r/20160907143403.1449324f@endymion
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Joe Perches <joe@perches.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-07 18:46:30 -07:00