.gitattributes: set diff driver for Rust source code files
Miguel Ojeda
maintainerPATCH 1/1 .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.
--- .gitattributes | 1 + 1 file changed, 1 insertion(+)
.gitattributes +1 -0
@@ -2,3 +2,4 @@ *.[ch] diff=cpp *.dts diff=dts *.dts[io] diff=dts +*.rs diff=rust
base-commit: 09a9639e56c01c7a00d6c0ca63f4c7c41abe075d
Signature · 1 line
2.40.0
Quoted 3 lines · Miguel Ojeda
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.
Quoted 32 lines · On Wed, 19 Apr 2023 01:30:48 +0200 Miguel Ojeda <[email protected]> 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
implblock, and therefore the default diff driver would pick the outerimplblock 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.
Quoted 4 lines
Thus set the
rustdiff driver for*.rssource files.
This is also done in rustc repo:
https://github.com/rust-lang/rust/blob/master/.gitattributes
Quoted 15 lines
--- .gitattributes | 1 + 1 file changed, 1 insertion(+).gitattributes +1
-0@@ -2,3 +2,4 @@ *.[ch] diff=cpp *.dts diff=dts *.dts[io] diff=dts +*.rs diff=rustbase-commit:
09a9639e56c01c7a00d6c0ca63f4c7c41abe075d
Quoted 32 lines · Miguel Ojeda
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
implblock, and therefore the default diff driver would pick the outerimplblock 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.
Quoted 4 lines
Thus set the
rustdiff driver for*.rssource files.
Quoted 18 lines
--- .gitattributes | 1 + 1 file changed, 1 insertion(+).gitattributes +1
-0@@ -2,3 +2,4 @@ *.[ch] diff=cpp *.dts diff=dts *.dts[io] diff=dts +*.rs diff=rustbase-commit:
09a9639e56c01c7a00d6c0ca63f4c7c41abe075d--
2.40.0
Miguel Ojeda
AppliedQuoted 5 lines · Miguel Ojeda
Thus set the
rustdiff driver for*.rssource files.
Applied to rust-next (with an extra link based on Gary's) -- thanks everyone for reviewing!
Cheers,
Miguel