Debian Codegraph @

src/handlers/hunk_header.rs

raw symbols SCIP
1 // A module for constructing and writing the hunk header.
2 //
3 // The structure of the hunk header output by delta is
4 // ```
5 // (file):(line-number): (code-fragment)
6 // ```
7 //
8 // The code fragment and line number derive from a line of git/diff output that looks like
9 // ```
10 // @@ -119,12 +119,7 @@ fn write_to_output_buffer(
11 // ```
12 //
13 // Whether or not file and line-number are included is controlled by the presence of the special
14 // style attributes 'file' and 'line-number' in the hunk-header-style string. For example, delta
15 // might output the above hunk header as
16 // ```
17 // ───────────────────────────────────────────────────┐
18 // src/hunk_header.rs:119: fn write_to_output_buffer( │
19 // ───────────────────────────────────────────────────┘
20 // ```
21 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#;
22 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# as FmtWriterust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
23
24 use superrust-analyzer cargo git-delta 0.19.2 handlers/::drawrust-analyzer cargo git-delta 0.19.2 handlers/draw/;
25 use craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/::{
26 Configrust-analyzer cargo git-delta 0.19.2 config/Config#, HunkHeaderIncludeCodeFragmentrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeCodeFragment#, HunkHeaderIncludeFilePathrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeFilePath#, HunkHeaderIncludeLineNumberrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeLineNumber#,
27 };
28 use craterust-analyzer cargo git-delta 0.19.2 crate/::deltarust-analyzer cargo git-delta 0.19.2 delta/::{selfrust-analyzer cargo git-delta 0.19.2 delta/, DiffTyperust-analyzer cargo git-delta 0.19.2 delta/DiffType#, InMergeConflictrust-analyzer cargo git-delta 0.19.2 delta/InMergeConflict#, MergeParentsrust-analyzer cargo git-delta 0.19.2 delta/MergeParents#, Staterust-analyzer cargo git-delta 0.19.2 delta/State#, StateMachinerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#};
29 use craterust-analyzer cargo git-delta 0.19.2 crate/::paintrust-analyzer cargo git-delta 0.19.2 paint/::{selfrust-analyzer cargo git-delta 0.19.2 paint/, BgShouldFillrust-analyzer cargo git-delta 0.19.2 paint/BgShouldFill#, Painterrust-analyzer cargo git-delta 0.19.2 paint/Painter#, StyleSectionSpecifierrust-analyzer cargo git-delta 0.19.2 paint/StyleSectionSpecifier#};
30 use craterust-analyzer cargo git-delta 0.19.2 crate/::stylerust-analyzer cargo git-delta 0.19.2 style/::{DecorationStylerust-analyzer cargo git-delta 0.19.2 style/DecorationStyle#, Stylerust-analyzer cargo git-delta 0.19.2 style/Style#};
31 use lazy_staticrust-analyzer cargo lazy_static 1.4.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!;
32 use regexrust-analyzer cargo regex 1.12.3 crate/::Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#;
33
34 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
35 pub struct ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
36 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
37 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(usize, usize)>,
38 }
39
40 pub enum HunkHeaderIncludeHunkLabelrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel# {
41 Yesrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#Yes#,
42 Norust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#No#,
43 }
44
45 // The output of `diff -u file1 file2` does not contain a header before the
46 // `--- old.lua` / `+++ new.lua` block, and the hunk can of course contain lines
47 // starting with '-- '. To avoid interpreting '--- lua comment' as a new header,
48 // count the minus lines in a hunk (provided by the '@@ -1,4 +1,3 @@' header).
49 // `diff` itself can not generate two diffs in this ambiguous format, so a second header
50 // could just be ignored. But concatenated diffs exist and are accepted by `patch`.
51 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
52 pub struct AmbiguousDiffMinusCounterrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/AmbiguousDiffMinusCounter#(isize);
53
54 impl AmbiguousDiffMinusCounterrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/AmbiguousDiffMinusCounter# {
55 // The internal isize representation avoids calling `if let Some(..)` on every line. For
56 // nearly all input the counter is not needed, in this case it is decremented but ignored.
57 // [min, COUNTER_RELEVANT_IF_GT] unambiguous diff
58 // (COUNTER_RELEVANT_IF_GT, 0] handle next '--- ' like a header, and set counter in next @@ block
59 // [1, max] counting minus lines in ambiguous header
60 const COUNTER_RELEVANT_IF_GREATER_THANrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]COUNTER_RELEVANT_IF_GREATER_THAN.: isize = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().4096; // -1 works too, but be defensive
61 const EXPECT_DIFF_3DASH_HEADERrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]EXPECT_DIFF_3DASH_HEADER.: isize = 0;
62
63 pub fn not_neededrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]not_needed().() -> Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter] {
64 Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter](Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]::COUNTER_RELEVANT_IF_GREATER_THANrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]COUNTER_RELEVANT_IF_GREATER_THAN.)
65 }
66 pub fn prepare_to_countrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]prepare_to_count().() -> Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter] {
67 Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter](Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]::EXPECT_DIFF_3DASH_HEADERrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]EXPECT_DIFF_3DASH_HEADER.)
68 }
69 pub fn three_dashes_expectedrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]three_dashes_expected().(&self) -> bool {
70 if self.0rust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/AmbiguousDiffMinusCounter#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt().Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]::COUNTER_RELEVANT_IF_GREATER_THANrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]COUNTER_RELEVANT_IF_GREATER_THAN. {
71 self.0rust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/AmbiguousDiffMinusCounter#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]::EXPECT_DIFF_3DASH_HEADERrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]EXPECT_DIFF_3DASH_HEADER.
72 } else {
73 true
74 }
75 }
76 pub fn count_linerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]count_line().(&mut self) {
77 self.0rust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/AmbiguousDiffMinusCounter#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().1;
78 }
79 fn count_fromrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]count_from().(lines: usize) -> Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter] {
80 Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter](
81 lines
82 .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()
83 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]::COUNTER_RELEVANT_IF_GREATER_THANrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]COUNTER_RELEVANT_IF_GREATER_THAN.),
84 )
85 }
86 #[allow(clippy::needless_bool)]
87 fn must_countrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]must_count().(&mut self) -> bool {
88 let relevant = self.0rust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/AmbiguousDiffMinusCounter#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt().Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]::COUNTER_RELEVANT_IF_GREATER_THANrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]COUNTER_RELEVANT_IF_GREATER_THAN.;
89 if relevant {
90 true
91 } else {
92 #[cfg(target_pointer_width = "32")]
93 {
94 self.0 = Selfrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]::COUNTER_RELEVANT_IF_GREATER_THAN;
95 }
96 false
97 }
98 }
99 }
100
101 impl StateMachinerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#<'_> {
102 #[inline]
103 fn test_hunk_header_linerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[`StateMachine<'_>`]test_hunk_header_line().(&self) -> bool {
104 self.linerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#line..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("@@") &&
105 // A hunk header can occur within a merge conflict region, but we don't attempt to handle
106 // that. See #822.
107 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.staterust-analyzer cargo git-delta 0.19.2 delta/StateMachine#state., Staterust-analyzer cargo git-delta 0.19.2 delta/State#::MergeConflictrust-analyzer cargo git-delta 0.19.2 delta/State#MergeConflict#(_, _))
108 }
109
110 pub fn handle_hunk_header_linerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[`StateMachine<'_>`]handle_hunk_header_line().(&mut self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<bool> {
111 use DiffTyperust-analyzer cargo git-delta 0.19.2 delta/DiffType#::*;
112 use Staterust-analyzer cargo git-delta 0.19.2 delta/State#::*;
113 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.test_hunk_header_linerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[`StateMachine<'_>`]test_hunk_header_line().() {
114 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
115 }
116 let mut handled_line = false;
117 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parsed_hunk_header) = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().(&self.linerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#line.) {
118 let diff_type = match &self.staterust-analyzer cargo git-delta 0.19.2 delta/StateMachine#state. {
119 DiffHeaderrust-analyzer cargo git-delta 0.19.2 delta/State#DiffHeader#(Combinedrust-analyzer cargo git-delta 0.19.2 delta/DiffType#Combined#(MergeParentsrust-analyzer cargo git-delta 0.19.2 delta/MergeParents#::Unknownrust-analyzer cargo git-delta 0.19.2 delta/MergeParents#Unknown#, InMergeConflictrust-analyzer cargo git-delta 0.19.2 delta/InMergeConflict#::Norust-analyzer cargo git-delta 0.19.2 delta/InMergeConflict#No#)) => {
120 // https://git-scm.com/docs/git-diff#_combined_diff_format
121 let n_parents = self.linerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#line..charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&'@').countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1;
122 Combinedrust-analyzer cargo git-delta 0.19.2 delta/DiffType#Combined#(MergeParentsrust-analyzer cargo git-delta 0.19.2 delta/MergeParents#::Numberrust-analyzer cargo git-delta 0.19.2 delta/MergeParents#Number#(n_parents), InMergeConflictrust-analyzer cargo git-delta 0.19.2 delta/InMergeConflict#::Norust-analyzer cargo git-delta 0.19.2 delta/InMergeConflict#No#)
123 }
124 DiffHeaderrust-analyzer cargo git-delta 0.19.2 delta/State#DiffHeader#(diff_type)
125 | HunkMinusrust-analyzer cargo git-delta 0.19.2 delta/State#HunkMinus#(diff_type, _)
126 | HunkZerorust-analyzer cargo git-delta 0.19.2 delta/State#HunkZero#(diff_type, _)
127 | HunkPlusrust-analyzer cargo git-delta 0.19.2 delta/State#HunkPlus#(diff_type, _) => diff_type.clonerust-analyzer cargo git-delta 0.19.2 delta/impl#[DiffType][Clone]clone().(),
128 _ => Unifiedrust-analyzer cargo git-delta 0.19.2 delta/DiffType#Unified#,
129 };
130
131 if self.minus_line_counterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#minus_line_counter..must_countrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]must_count().() {
132 if let &[(_, minus_lines), (_, _plus_lines), ..] =
133 parsed_hunk_header.line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths..as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()
134 {
135 self.minus_line_counterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#minus_line_counter. = AmbiguousDiffMinusCounterrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/AmbiguousDiffMinusCounter#::count_fromrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[AmbiguousDiffMinusCounter]count_from().(minus_lines);
136 }
137 }
138
139 self.staterust-analyzer cargo git-delta 0.19.2 delta/StateMachine#state. = HunkHeaderrust-analyzer cargo git-delta 0.19.2 delta/State#HunkHeader#(
140 diff_type,
141 parsed_hunk_header,
142 self.linerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#line..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(),
143 self.raw_linerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#raw_line..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(),
144 );
145 handled_line = true;
146 }
147 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(handled_line)
148 }
149
150 /// Emit the hunk header, with any requested decoration.
151 pub fn emit_hunk_header_linerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[`StateMachine<'_>`]emit_hunk_header_line().(
152 &mut self,
153 parsed_hunk_header: &ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#,
154 line: &str,
155 raw_line: &str,
156 ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<bool> {
157 self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter..paint_buffered_minus_and_plus_linesrust-analyzer cargo git-delta 0.19.2 paint/impl#[`Painter<'p>`]paint_buffered_minus_and_plus_lines().();
158 self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter..set_highlighterrust-analyzer cargo git-delta 0.19.2 paint/impl#[`Painter<'p>`]set_highlighter().();
159 self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter..emitrust-analyzer cargo git-delta 0.19.2 paint/impl#[`Painter<'p>`]emit().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
160
161 let ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
162 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
163 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
164 } = parsed_hunk_header;
165
166 if self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..line_numbersrust-analyzer cargo git-delta 0.19.2 config/Config#line_numbers. {
167 self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter.
168 .line_numbers_datarust-analyzer cargo git-delta 0.19.2 paint/Painter#line_numbers_data.
169 .as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().()
170 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
171 .initialize_hunkrust-analyzer cargo git-delta 0.19.2 features/line_numbers/impl#[`LineNumbersData<'a>`]initialize_hunk().(line_numbers_and_hunk_lengths, self.plus_filerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#plus_file..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
172 }
173
174 if self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style..is_rawrust-analyzer cargo git-delta 0.19.2 style/Style#is_raw. {
175 write_hunk_header_rawrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/write_hunk_header_raw().(&mut self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter., line, raw_line, self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
176 } else if self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style..is_omittedrust-analyzer cargo git-delta 0.19.2 style/Style#is_omitted. {
177 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter..writerrust-analyzer cargo git-delta 0.19.2 paint/Painter#writer.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
178 } else {
179 // Add a blank line below the hunk-header-line for readability, unless
180 // color_only mode is active.
181 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..color_onlyrust-analyzer cargo git-delta 0.19.2 config/Config#color_only. {
182 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter..writerrust-analyzer cargo git-delta 0.19.2 paint/Painter#writer.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
183 }
184
185 write_line_of_code_with_optional_path_and_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/write_line_of_code_with_optional_path_and_line_number().(
186 code_fragment,
187 line_numbers_and_hunk_lengths,
188 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
189 &mut self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter.,
190 line,
191 if self.plus_filerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#plus_file. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."/dev/null" {
192 &self.minus_filerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#minus_file.
193 } else {
194 &self.plus_filerust-analyzer cargo git-delta 0.19.2 delta/StateMachine#plus_file.
195 },
196 self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style..decoration_stylerust-analyzer cargo git-delta 0.19.2 style/Style#decoration_style.,
197 &self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_file_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_file_style.,
198 &self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_line_number_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_line_number_style.,
199 &self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_style_include_file_pathrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_file_path.,
200 &self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_style_include_line_numberrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_line_number.,
201 &HunkHeaderIncludeHunkLabelrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#::Yesrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#Yes#,
202 &self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config..hunk_header_style_include_code_fragmentrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_code_fragment.,
203 ":",
204 self.configrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#config.,
205 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
206 };
207 self.painterrust-analyzer cargo git-delta 0.19.2 delta/StateMachine#painter..set_highlighterrust-analyzer cargo git-delta 0.19.2 paint/impl#[`Painter<'p>`]set_highlighter().();
208 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true)
209 }
210 }
211
212 lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!! {
213 static ref HUNK_HEADER_REGEXrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HUNK_HEADER_REGEX#: Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex# = Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#::newrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]new().(r"@+ ([^@]+)@+(.*\s?)").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
214 }
215
216 // Parse unified diff hunk header format. See
217 // https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
218 // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
219 lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!! {
220 static ref HUNK_HEADER_FILE_COORDINATE_REGEXrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HUNK_HEADER_FILE_COORDINATE_REGEX#: Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex# = Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#::newrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]new().(
221 r"(?x)
222 [-+]
223 (\d+) # 1. Hunk start line number
224 (?: # Start optional hunk length section (non-capturing)
225 , # Literal comma
226 (\d+) # 2. Optional hunk length (defaults to 1)
227 )?"
228 )
229 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
230 }
231
232 /// Given input like
233 /// "@@ -74,15 +74,14 @@ pub fn delta("
234 /// Return " pub fn delta(" and a vector of (line_number, hunk_length) tuples.
235 fn parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().(line: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#> {
236 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = HUNK_HEADER_REGEXrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HUNK_HEADER_REGEX..capturesrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]captures().(line) {
237 let file_coordinates = &caps[rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index().1]rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index().;
238 let line_numbers_and_hunk_lengths: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(usize, usize)> = HUNK_HEADER_FILE_COORDINATE_REGEXrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HUNK_HEADER_FILE_COORDINATE_REGEX.
239 .captures_iterrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]captures_iter().(file_coordinates)
240 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|caps| {
241 (
242 caps[rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index().1]rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<usize>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
243 caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(2)
244 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().())
245 // Per the specs linked above, if the hunk length is absent then it is 1.
246 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("1")
247 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<usize>()
248 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
249 )
250 })
251 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
252 if line_numbers_and_hunk_lengths.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
253 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
254 } else {
255 let code_fragment = caps[rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index().2]rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
256 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
257 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
258 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
259 })
260 }
261 } else {
262 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
263 }
264 }
265
266 fn write_hunk_header_rawrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/write_hunk_header_raw().(
267 painter: &mut Painterrust-analyzer cargo git-delta 0.19.2 paint/Painter#,
268 line: &str,
269 raw_line: &str,
270 config: &Configrust-analyzer cargo git-delta 0.19.2 config/Config#,
271 ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
272 let (mut draw_fn, pad, decoration_ansi_term_style) =
273 drawrust-analyzer cargo git-delta 0.19.2 handlers/draw/::get_draw_functionrust-analyzer cargo git-delta 0.19.2 handlers/draw/get_draw_function().(config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style..decoration_stylerust-analyzer cargo git-delta 0.19.2 style/Style#decoration_style.);
274 if config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style..decoration_stylerust-analyzer cargo git-delta 0.19.2 style/Style#decoration_style. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().DecorationStylerust-analyzer cargo git-delta 0.19.2 style/DecorationStyle#::NoDecorationrust-analyzer cargo git-delta 0.19.2 style/DecorationStyle#NoDecoration# {
275 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(painter.writerrust-analyzer cargo git-delta 0.19.2 paint/Painter#writer.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
276 }
277 draw_fn(
278 painter.writerrust-analyzer cargo git-delta 0.19.2 paint/Painter#writer.,
279 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", line, if pad { " " } else { "" }),
280 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", raw_line, if pad { " " } else { "" }),
281 "",
282 &config.decorations_widthrust-analyzer cargo git-delta 0.19.2 config/Config#decorations_width.,
283 config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style.,
284 decoration_ansi_term_style,
285 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
286 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
287 }
288
289 #[allow(clippy::too_many_arguments)]
290 pub fn write_line_of_code_with_optional_path_and_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/write_line_of_code_with_optional_path_and_line_number().(
291 code_fragment: &str,
292 line_numbers_and_hunk_lengths: &[(usize, usize)],
293 style_sections: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<StyleSectionSpecifierrust-analyzer cargo git-delta 0.19.2 paint/StyleSectionSpecifier#>,
294 painter: &mut Painterrust-analyzer cargo git-delta 0.19.2 paint/Painter#,
295 line: &str,
296 plus_file: &str,
297 decoration_style: DecorationStylerust-analyzer cargo git-delta 0.19.2 style/DecorationStyle#,
298 file_style: &Stylerust-analyzer cargo git-delta 0.19.2 style/Style#,
299 line_number_style: &Stylerust-analyzer cargo git-delta 0.19.2 style/Style#,
300 include_file_path: &HunkHeaderIncludeFilePathrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeFilePath#,
301 include_line_number: &HunkHeaderIncludeLineNumberrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeLineNumber#,
302 include_hunk_label: &HunkHeaderIncludeHunkLabelrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#,
303 include_code_fragment: &HunkHeaderIncludeCodeFragmentrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeCodeFragment#,
304 file_path_separator: &str,
305 config: &Configrust-analyzer cargo git-delta 0.19.2 config/Config#,
306 ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
307 let (mut draw_fn, _, decoration_ansi_term_style) = drawrust-analyzer cargo git-delta 0.19.2 handlers/draw/::get_draw_functionrust-analyzer cargo git-delta 0.19.2 handlers/draw/get_draw_function().(decoration_style);
308 let line = match (config.color_onlyrust-analyzer cargo git-delta 0.19.2 config/Config#color_only., include_code_fragment) {
309 (true, _) => line.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
310 // When called from a ripgrep json context: No " " added, as this would prevent
311 // identifying that a newline already exists, and so another would be added.
312 (_, HunkHeaderIncludeCodeFragmentrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeCodeFragment#::YesNoSpacerust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeCodeFragment#YesNoSpace#) => code_fragment.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
313 (_, HunkHeaderIncludeCodeFragmentrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeCodeFragment#::Yesrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeCodeFragment#Yes#) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().code_fragment.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() => {
314 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{code_fragment} ")
315 }
316 _ => "".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
317 };
318
319 let plus_line_number = line_numbers_and_hunk_lengths[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().line_numbers_and_hunk_lengths.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..0;
320 let file_with_line_number = paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/paint_file_path_with_line_number().(
321 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(plus_line_number),
322 plus_file,
323 file_style,
324 line_number_style,
325 include_file_path,
326 include_line_number,
327 file_path_separator,
328 config,
329 );
330
331 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().line.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().file_with_line_number.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
332 write_to_output_bufferrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/write_to_output_buffer().(
333 &file_with_line_number,
334 file_path_separator,
335 line,
336 style_sections,
337 include_hunk_label,
338 painter,
339 config,
340 );
341 draw_fn(
342 painter.writerrust-analyzer cargo git-delta 0.19.2 paint/Painter#writer.,
343 &painter.output_bufferrust-analyzer cargo git-delta 0.19.2 paint/Painter#output_buffer.,
344 &painter.output_bufferrust-analyzer cargo git-delta 0.19.2 paint/Painter#output_buffer.,
345 "",
346 &config.decorations_widthrust-analyzer cargo git-delta 0.19.2 config/Config#decorations_width.,
347 config.null_stylerust-analyzer cargo git-delta 0.19.2 config/Config#null_style.,
348 decoration_ansi_term_style,
349 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
350 painter.output_bufferrust-analyzer cargo git-delta 0.19.2 paint/Painter#output_buffer..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]clear().();
351 }
352
353 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
354 }
355
356 #[allow(clippy::too_many_arguments)]
357 fn paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/paint_file_path_with_line_number().(
358 line_number: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
359 plus_file: &str,
360 file_style: &Stylerust-analyzer cargo git-delta 0.19.2 style/Style#,
361 line_number_style: &Stylerust-analyzer cargo git-delta 0.19.2 style/Style#,
362 include_file_path: &HunkHeaderIncludeFilePathrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeFilePath#,
363 include_line_number: &HunkHeaderIncludeLineNumberrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeLineNumber#,
364 separator: &str,
365 config: &Configrust-analyzer cargo git-delta 0.19.2 config/Config#,
366 ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
367 let file_style = match include_file_path {
368 HunkHeaderIncludeFilePathrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeFilePath#::Yesrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeFilePath#Yes# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().file_style),
369 HunkHeaderIncludeFilePathrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeFilePath#::Norust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeFilePath#No# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
370 };
371 let line_number_style = if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(include_line_number, HunkHeaderIncludeLineNumberrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeLineNumber#::Yesrust-analyzer cargo git-delta 0.19.2 config/HunkHeaderIncludeLineNumber#Yes#)
372 && line_number.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()
373 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style..is_rawrust-analyzer cargo git-delta 0.19.2 style/Style#is_raw.
374 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().config.color_onlyrust-analyzer cargo git-delta 0.19.2 config/Config#color_only.
375 {
376 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().line_number_style)
377 } else {
378 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
379 };
380
381 paintrust-analyzer cargo git-delta 0.19.2 paint/::paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 paint/paint_file_path_with_line_number().(
382 line_number,
383 plus_file,
384 false,
385 separator,
386 false,
387 file_style,
388 line_number_style,
389 config,
390 )
391 }
392
393 fn write_to_output_bufferrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/write_to_output_buffer().(
394 file_with_line_number: &str,
395 file_path_separator: &str,
396 line: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
397 style_sections: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<StyleSectionSpecifierrust-analyzer cargo git-delta 0.19.2 paint/StyleSectionSpecifier#>,
398 include_hunk_label: &HunkHeaderIncludeHunkLabelrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#,
399 painter: &mut Painterrust-analyzer cargo git-delta 0.19.2 paint/Painter#,
400 config: &Configrust-analyzer cargo git-delta 0.19.2 config/Config#,
401 ) {
402 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(include_hunk_label, HunkHeaderIncludeHunkLabelrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#::Yesrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/HunkHeaderIncludeHunkLabel#Yes#)
403 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().config.hunk_labelrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_label..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().()
404 {
405 let _ = writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
406 &mut painter.output_bufferrust-analyzer cargo git-delta 0.19.2 paint/Painter#output_buffer.,
407 "{} ",
408 config.hunk_header_file_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_file_style..paintrust-analyzer cargo git-delta 0.19.2 style/impl#[Style]paint().(&config.hunk_labelrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_label.)
409 );
410 }
411 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().file_with_line_number.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
412 // The code fragment in "line" adds whitespace, but if only a line number is printed
413 // then the trailing space must be added.
414 let space = if line.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { " " } else { "" };
415 let _ = writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
416 &mut painter.output_bufferrust-analyzer cargo git-delta 0.19.2 paint/Painter#output_buffer.,
417 "{file_with_line_number}{file_path_separator}{space}",
418 );
419 }
420 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().line.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
421 painter.syntax_highlight_and_paint_linerust-analyzer cargo git-delta 0.19.2 paint/impl#[`Painter<'p>`]syntax_highlight_and_paint_line().(
422 &line,
423 style_sections.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(StyleSectionSpecifierrust-analyzer cargo git-delta 0.19.2 paint/StyleSectionSpecifier#::Stylerust-analyzer cargo git-delta 0.19.2 paint/StyleSectionSpecifier#Style#(config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style.)),
424 deltarust-analyzer cargo git-delta 0.19.2 delta/::Staterust-analyzer cargo git-delta 0.19.2 delta/State#::HunkHeaderrust-analyzer cargo git-delta 0.19.2 delta/State#HunkHeader#(
425 DiffTyperust-analyzer cargo git-delta 0.19.2 delta/DiffType#::Unifiedrust-analyzer cargo git-delta 0.19.2 delta/DiffType#Unified#,
426 ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#::defaultrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/impl#[ParsedHunkHeader][Default]default().(),
427 "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
428 "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
429 ),
430 BgShouldFillrust-analyzer cargo git-delta 0.19.2 paint/BgShouldFill#::Norust-analyzer cargo git-delta 0.19.2 paint/BgShouldFill#No#,
431 );
432 painter.output_bufferrust-analyzer cargo git-delta 0.19.2 paint/Painter#output_buffer..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]pop().(); // trim newline
433 }
434 }
435
436 #[cfg(test)]
437 pub mod testsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/ {
438 use superrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/::*;
439 use craterust-analyzer cargo git-delta 0.19.2 crate/::ansirust-analyzer cargo git-delta 0.19.2 ansi/::strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().;
440 use craterust-analyzer cargo git-delta 0.19.2 crate/::testsrust-analyzer cargo git-delta 0.19.2 tests/::integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/;
441
442 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
443 fn test_parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_parse_hunk_header().() {
444 let ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
445 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
446 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
447 } = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().("@@ -74,15 +75,14 @@ pub fn delta(\n").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
448 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code_fragment, " pub fn delta(\n");
449 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (74, 15),);
450 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (75, 14),);
451 }
452
453 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
454 fn test_parse_hunk_header_with_omitted_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_parse_hunk_header_with_omitted_hunk_lengths().() {
455 let ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
456 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
457 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
458 } = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().("@@ -74 +75,2 @@ pub fn delta(\n").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
459 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code_fragment, " pub fn delta(\n");
460 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (74, 1),);
461 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (75, 2),);
462 }
463
464 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
465 fn test_parse_hunk_header_with_no_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_parse_hunk_header_with_no_hunk_lengths().() {
466 let result = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().("@@ @@\n");
467 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
468 }
469
470 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
471 fn test_parse_hunk_header_added_filerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_parse_hunk_header_added_file().() {
472 let ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
473 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
474 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
475 } = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().("@@ -1,22 +0,0 @@").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
476 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code_fragment, "",);
477 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (1, 22),);
478 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (0, 0),);
479 }
480
481 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
482 fn test_parse_hunk_header_deleted_filerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_parse_hunk_header_deleted_file().() {
483 let ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
484 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
485 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
486 } = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().("@@ -0,0 +1,3 @@").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
487 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code_fragment, "",);
488 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (0, 0),);
489 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (1, 3),);
490 }
491
492 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
493 fn test_parse_hunk_header_mergerust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_parse_hunk_header_merge().() {
494 let ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
495 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
496 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
497 } = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().("@@@ -293,11 -358,15 +358,16 @@@ dependencies =").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
498 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code_fragment, " dependencies =");
499 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (293, 11),);
500 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (358, 15),);
501 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (358, 16),);
502 }
503
504 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
505 fn test_parse_hunk_header_cthulhurust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_parse_hunk_header_cthulhu().() {
506 let ParsedHunkHeaderrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader# {
507 code_fragmentrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#code_fragment.,
508 line_numbers_and_hunk_lengthsrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/ParsedHunkHeader#line_numbers_and_hunk_lengths.,
509 } = parse_hunk_headerrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/parse_hunk_header().("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -444,17 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 -446,6 +444,17 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ int snd_soc_jack_add_gpios(struct snd_s").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
510 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code_fragment, " int snd_soc_jack_add_gpios(struct snd_s");
511 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (446, 6),);
512 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (446, 6),);
513 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (446, 6),);
514 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line_numbers_and_hunk_lengths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().65]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., (446, 6),);
515 }
516
517 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
518 fn test_paint_file_path_with_line_number_defaultrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_paint_file_path_with_line_number_default().() {
519 // hunk-header-style (by default) includes 'line-number' but not 'file'.
520 // This test confirms that `paint_file_path_with_line_number` returns a painted line number.
521 let config = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(&[]);
522
523 let result = paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/paint_file_path_with_line_number().(
524 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3),
525 "some-file",
526 &config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style.,
527 &config.hunk_header_line_number_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_line_number_style.,
528 &config.hunk_header_style_include_file_pathrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_file_path.,
529 &config.hunk_header_style_include_line_numberrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_line_number.,
530 ":",
531 &config,
532 );
533
534 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "\u{1b}[34m3\u{1b}[0m");
535 }
536
537 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
538 fn test_paint_file_path_with_line_number_hyperlinksrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_paint_file_path_with_line_number_hyperlinks().() {
539 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#, pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#};
540
541 use craterust-analyzer cargo git-delta 0.19.2 crate/::utilsrust-analyzer cargo git-delta 0.19.2 utils/;
542
543 // hunk-header-style (by default) includes 'line-number' but not 'file'.
544 // Normally, `paint_file_path_with_line_number` would return a painted line number.
545 // But in this test hyperlinks are activated, and the test ensures that delta.__workdir__ is
546 // present in git_config_entries.
547 // This test confirms that, under those circumstances, `paint_file_path_with_line_number`
548 // returns a hyperlinked file path with line number.
549
550 let config = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(&["--features", "hyperlinks"]);
551 let relative_path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::from_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`FromIterator<P>`]from_iter().(["some-dir", "some-file"]);
552
553 let result = paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/paint_file_path_with_line_number().(
554 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3),
555 &relative_path.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().(),
556 &config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style.,
557 &config.hunk_header_line_number_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_line_number_style.,
558 &config.hunk_header_style_include_file_pathrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_file_path.,
559 &config.hunk_header_style_include_line_numberrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_line_number.,
560 ":",
561 &config,
562 );
563
564 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
565 result,
566 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
567 "\u{1b}]8;;file://{}\u{1b}\\\u{1b}[34m3\u{1b}[0m\u{1b}]8;;\u{1b}\\",
568 utilsrust-analyzer cargo git-delta 0.19.2 utils/::pathrust-analyzer cargo git-delta 0.19.2 utils/path/::fake_delta_cwd_for_testsrust-analyzer cargo git-delta 0.19.2 utils/path/fake_delta_cwd_for_tests().()
569 .joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(relative_path)
570 .to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().()
571 )
572 );
573 }
574
575 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
576 fn test_paint_file_path_with_line_number_emptyrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_paint_file_path_with_line_number_empty().() {
577 // hunk-header-style includes neither 'file' nor 'line-number'.
578 // This causes `paint_file_path_with_line_number` to return empty string.
579 let config = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(&[
580 "--hunk-header-style",
581 "syntax bold",
582 "--hunk-header-decoration-style",
583 "omit",
584 ]);
585
586 let result = paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/paint_file_path_with_line_number().(
587 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3),
588 "some-file",
589 &config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style.,
590 &config.hunk_header_line_number_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_line_number_style.,
591 &config.hunk_header_style_include_file_pathrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_file_path.,
592 &config.hunk_header_style_include_line_numberrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_line_number.,
593 ":",
594 &config,
595 );
596
597 // result is
598 // "\u{1b}[1msome-file\u{1b}[0m:\u{1b}[34m3\u{1b}[0m"
599 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "");
600 }
601
602 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
603 fn test_paint_file_path_with_line_number_empty_hyperlinksrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_paint_file_path_with_line_number_empty_hyperlinks().() {
604 // hunk-header-style includes neither 'file' nor 'line-number'.
605 // This causes `paint_file_path_with_line_number` to return empty string.
606 // This test confirms that this remains true even when we are requesting hyperlinks.
607
608 let config = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(&[
609 "--hunk-header-style",
610 "syntax bold",
611 "--hunk-header-decoration-style",
612 "omit",
613 "--features",
614 "hyperlinks",
615 ]);
616
617 let result = paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/paint_file_path_with_line_number().(
618 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3),
619 "some-file",
620 &config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style.,
621 &config.hunk_header_line_number_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_line_number_style.,
622 &config.hunk_header_style_include_file_pathrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_file_path.,
623 &config.hunk_header_style_include_line_numberrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_line_number.,
624 ":",
625 &config,
626 );
627
628 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "");
629 }
630
631 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
632 fn test_paint_file_path_with_line_number_empty_navigaterust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_paint_file_path_with_line_number_empty_navigate().() {
633 let config = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(&[
634 "--hunk-header-style",
635 "syntax bold",
636 "--hunk-header-decoration-style",
637 "omit",
638 "--navigate",
639 ]);
640
641 let result = paint_file_path_with_line_numberrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/paint_file_path_with_line_number().(
642 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3),
643 "δ some-file",
644 &config.hunk_header_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style.,
645 &config.hunk_header_line_number_stylerust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_line_number_style.,
646 &config.hunk_header_style_include_file_pathrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_file_path.,
647 &config.hunk_header_style_include_line_numberrust-analyzer cargo git-delta 0.19.2 config/Config#hunk_header_style_include_line_number.,
648 ":",
649 &config,
650 );
651
652 // result is
653 // "\u{1b}[1mδ some-file\u{1b}[0m:\u{1b}[34m3\u{1b}[0m"
654 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "");
655 }
656
657 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
658 fn test_not_a_hunk_header_is_handled_gracefullyrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/test_not_a_hunk_header_is_handled_gracefully().() {
659 let config = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(&[]);
660 let output =
661 integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::run_deltarust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/run_delta().(GIT_LOG_OUTPUT_WITH_NOT_A_HUNK_HEADERrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/GIT_LOG_OUTPUT_WITH_NOT_A_HUNK_HEADER., &config);
662 let output = strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().(&output);
663 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("@@@2021-12-05"));
664 }
665
666 const GIT_LOG_OUTPUT_WITH_NOT_A_HUNK_HEADERrust-analyzer cargo git-delta 0.19.2 handlers/hunk_header/tests/GIT_LOG_OUTPUT_WITH_NOT_A_HUNK_HEADER.: &str = "\
667 @@@2021-12-05
668
669 src/config.rs | 2 +-
670 src/delta.rs | 3 ++-
671 src/handlers/hunk.rs | 12 ++++++------
672 src/handlers/hunk_header.rs | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------
673 src/handlers/merge_conflict.rs | 2 +-
674 src/handlers/submodule.rs | 4 ++--
675 src/paint.rs | 2 +-
676 7 files changed, 90 insertions(+), 54 deletions(-)
677 ";
678 }