public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] .gitattributes: set diff driver for Rust source code files
@ 2023-04-18 23:30 Miguel Ojeda
  2023-04-19  2:45 ` Martin Rodriguez Reboredo
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Miguel Ojeda @ 2023-04-18 23:30 UTC (permalink / raw)
  To: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Masahiro Yamada, Stephen Boyd, Jean Delvare, rust-for-linux,
	linux-kernel, patches

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.

Link: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header [1]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 .gitattributes | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitattributes b/.gitattributes
index c9ba5bfc4036..2325c529e185 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2,3 +2,4 @@
 *.[ch] diff=cpp
 *.dts diff=dts
 *.dts[io] diff=dts
+*.rs diff=rust

base-commit: 09a9639e56c01c7a00d6c0ca63f4c7c41abe075d
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] .gitattributes: set diff driver for Rust source code files
  2023-04-18 23:30 [PATCH] .gitattributes: set diff driver for Rust source code files Miguel Ojeda
@ 2023-04-19  2:45 ` Martin Rodriguez Reboredo
  2023-04-19 12:11 ` Gary Guo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-04-19  2:45 UTC (permalink / raw)
  To: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Masahiro Yamada, Stephen Boyd, Jean Delvare, rust-for-linux,
	linux-kernel, patches

On 4/18/23 20:30, Miguel Ojeda wrote:
> Git supports a builtin Rust diff driver [1] since v2.23.0 (2019).
> 
> [...]

At this stage in the game such an improvement in diffs is required.

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] .gitattributes: set diff driver for Rust source code files
  2023-04-18 23:30 [PATCH] .gitattributes: set diff driver for Rust source code files Miguel Ojeda
  2023-04-19  2:45 ` Martin Rodriguez Reboredo
@ 2023-04-19 12:11 ` Gary Guo
  2023-04-19 12:30 ` Benno Lossin
  2023-05-31 17:03 ` Miguel Ojeda
  3 siblings, 0 replies; 5+ messages in thread
From: Gary Guo @ 2023-04-19 12:11 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Wedson Almeida Filho, Alex Gaynor, Boqun Feng,
	Björn Roy Baron, Benno Lossin, Masahiro Yamada, Stephen Boyd,
	Jean Delvare, rust-for-linux, linux-kernel, patches

On Wed, 19 Apr 2023 01:30:48 +0200
Miguel Ojeda <ojeda@kernel.org> wrote:

> 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.
> 
> Link: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header [1]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

This is also done in rustc repo:
https://github.com/rust-lang/rust/blob/master/.gitattributes

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
>  .gitattributes | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/.gitattributes b/.gitattributes
> index c9ba5bfc4036..2325c529e185 100644
> --- a/.gitattributes
> +++ b/.gitattributes
> @@ -2,3 +2,4 @@
>  *.[ch] diff=cpp
>  *.dts diff=dts
>  *.dts[io] diff=dts
> +*.rs diff=rust
> 
> base-commit: 09a9639e56c01c7a00d6c0ca63f4c7c41abe075d


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] .gitattributes: set diff driver for Rust source code files
  2023-04-18 23:30 [PATCH] .gitattributes: set diff driver for Rust source code files Miguel Ojeda
  2023-04-19  2:45 ` Martin Rodriguez Reboredo
  2023-04-19 12:11 ` Gary Guo
@ 2023-04-19 12:30 ` Benno Lossin
  2023-05-31 17:03 ` Miguel Ojeda
  3 siblings, 0 replies; 5+ messages in thread
From: Benno Lossin @ 2023-04-19 12:30 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Wedson Almeida Filho, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Masahiro Yamada, Stephen Boyd, Jean Delvare,
	rust-for-linux, linux-kernel, patches

On 19.04.23 01:30, Miguel Ojeda wrote:
> 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.
> 
> Link: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header [1]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Benno Lossin <benno.lossin@proton.me>

> ---
>   .gitattributes | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/.gitattributes b/.gitattributes
> index c9ba5bfc4036..2325c529e185 100644
> --- a/.gitattributes
> +++ b/.gitattributes
> @@ -2,3 +2,4 @@
>   *.[ch] diff=cpp
>   *.dts diff=dts
>   *.dts[io] diff=dts
> +*.rs diff=rust
> 
> base-commit: 09a9639e56c01c7a00d6c0ca63f4c7c41abe075d
> --
> 2.40.0
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] .gitattributes: set diff driver for Rust source code files
  2023-04-18 23:30 [PATCH] .gitattributes: set diff driver for Rust source code files Miguel Ojeda
                   ` (2 preceding siblings ...)
  2023-04-19 12:30 ` Benno Lossin
@ 2023-05-31 17:03 ` Miguel Ojeda
  3 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2023-05-31 17:03 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Wedson Almeida Filho, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Masahiro Yamada, Stephen Boyd,
	Jean Delvare, rust-for-linux, linux-kernel, patches

On Wed, Apr 19, 2023 at 1:31 AM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> Thus set the `rust` diff driver for `*.rs` source files.
>
> Link: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header [1]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Applied to `rust-next` (with an extra link based on Gary's) -- thanks
everyone for reviewing!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-31 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-18 23:30 [PATCH] .gitattributes: set diff driver for Rust source code files Miguel Ojeda
2023-04-19  2:45 ` Martin Rodriguez Reboredo
2023-04-19 12:11 ` Gary Guo
2023-04-19 12:30 ` Benno Lossin
2023-05-31 17:03 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox