Skip to content

Commit 9a9a206

Browse files
committed
Remove newline and header_buf
1 parent 09c6f21 commit 9a9a206

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

gix-diff/src/blob/unified_diff.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,8 @@ pub(super) mod _impl {
166166

167167
/// Symmetrical context before and after the changed hunk.
168168
ctx_size: u32,
169-
// TODO:
170-
// Is there a way to remove `newline` from `UnifiedDiffSink` as it is purely
171-
// formatting-related?
172-
// One option would be to introduce `HunkHeader` with a method `format_header` that could
173-
// then be called outside `UnifiedDiffSink`, potentially taking `newline` as an argument.
174-
newline: NewlineSeparator<'a>,
175169

176170
buffer: Vec<(DiffLineType, Vec<u8>)>,
177-
header_buf: String,
178171
delegate: D,
179172

180173
err: Option<std::io::Error>,
@@ -191,12 +184,7 @@ pub(super) mod _impl {
191184
/// to the sink.
192185
///
193186
/// The sink's `consume_hunk` method is called for each hunk with structured type information.
194-
pub fn new(
195-
input: &'a InternedInput<T>,
196-
consume_hunk: D,
197-
newline_separator: NewlineSeparator<'a>,
198-
context_size: ContextSize,
199-
) -> Self {
187+
pub fn new(input: &'a InternedInput<T>, consume_hunk: D, context_size: ContextSize) -> Self {
200188
Self {
201189
interner: &input.interner,
202190
before: &input.before,
@@ -209,10 +197,8 @@ pub(super) mod _impl {
209197
ctx_pos: None,
210198

211199
ctx_size: context_size.symmetrical,
212-
newline: newline_separator,
213200

214201
buffer: Vec::with_capacity(8),
215-
header_buf: String::new(),
216202
delegate: consume_hunk,
217203

218204
err: None,
@@ -237,23 +223,6 @@ pub(super) mod _impl {
237223

238224
let hunk_start = self.before_hunk_start + 1;
239225
let hunk_end = self.after_hunk_start + 1;
240-
self.header_buf.clear();
241-
std::fmt::Write::write_fmt(
242-
&mut self.header_buf,
243-
format_args!(
244-
"@@ -{},{} +{},{} @@{nl}",
245-
hunk_start,
246-
self.before_hunk_len,
247-
hunk_end,
248-
self.after_hunk_len,
249-
nl = match self.newline {
250-
NewlineSeparator::AfterHeaderAndLine(nl) | NewlineSeparator::AfterHeaderAndWhenNeeded(nl) => {
251-
nl
252-
}
253-
}
254-
),
255-
)
256-
.map_err(|err| std::io::Error::new(ErrorKind::Other, err))?;
257226

258227
// TODO:
259228
// Is this explicit conversion necessary?
@@ -394,7 +363,7 @@ pub(super) mod _impl {
394363
};
395364
// TODO:
396365
// Should this return a `UnifiedDiff` instead of a `UnifiedDiffSink`?
397-
UnifiedDiffSink::new(input, formatter, newline_separator, context_size)
366+
UnifiedDiffSink::new(input, formatter, context_size)
398367
}
399368

400369
fn format_line(&mut self, line_type: DiffLineType, content: &[u8]) {

gix-diff/tests/diff/blob/unified_diff.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,7 @@ fn removed_modified_added_with_newlines_in_tokens() -> crate::Result {
402402
let actual = gix_diff::blob::diff(
403403
Algorithm::Myers,
404404
&interner,
405-
UnifiedDiffSink::new(
406-
&interner,
407-
TypedRecorder::default(),
408-
NewlineSeparator::AfterHeaderAndWhenNeeded("\r\n"),
409-
ContextSize::symmetrical(1),
410-
),
405+
UnifiedDiffSink::new(&interner, TypedRecorder::default(), ContextSize::symmetrical(1)),
411406
)?;
412407
assert_eq!(
413408
actual,

0 commit comments

Comments
 (0)