Skip to content

Commit d88e377

Browse files
committed
Merge branch 'header-field-multi-improve' of https://github.com/xmo-odoo/gitoxide into xmo-odoo-header-field-multi-improve
2 parents a77d14c + bab9fb5 commit d88e377

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

git-object/src/commit/write.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::io;
22

3-
use bstr::ByteSlice;
4-
53
use crate::{encode, encode::NL, Commit, CommitRef, Kind};
64

75
impl crate::WriteTo for Commit {
@@ -17,12 +15,7 @@ impl crate::WriteTo for Commit {
1715
encode::header_field(b"encoding", encoding, &mut out)?;
1816
}
1917
for (name, value) in &self.extra_headers {
20-
let has_newline = value.find_byte(b'\n').is_some();
21-
if has_newline {
22-
encode::header_field_multi_line(name, value, &mut out)?;
23-
} else {
24-
encode::trusted_header_field(name, value, &mut out)?;
25-
}
18+
encode::header_field_multi_line(name, value, &mut out)?;
2619
}
2720
out.write_all(NL)?;
2821
out.write_all(&self.message)
@@ -46,12 +39,7 @@ impl<'a> crate::WriteTo for CommitRef<'a> {
4639
encode::header_field(b"encoding", encoding, &mut out)?;
4740
}
4841
for (name, value) in &self.extra_headers {
49-
let has_newline = value.find_byte(b'\n').is_some();
50-
if has_newline {
51-
encode::header_field_multi_line(name, value, &mut out)?;
52-
} else {
53-
encode::trusted_header_field(name, value, &mut out)?;
54-
}
42+
encode::header_field_multi_line(name, value, &mut out)?;
5543
}
5644
out.write_all(NL)?;
5745
out.write_all(self.message)

git-object/src/encode.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ impl From<Error> for io::Error {
2222
}
2323

2424
pub fn header_field_multi_line(name: &[u8], value: &[u8], mut out: impl io::Write) -> io::Result<()> {
25-
let mut lines = value.as_bstr().lines();
26-
trusted_header_field(name, lines.next().expect("non-empty value"), &mut out)?;
25+
let mut lines = value.as_bstr().split_str(b"\n");
26+
trusted_header_field(name, lines.next().ok_or(Error::EmptyValue)?, &mut out)?;
2727
for line in lines {
2828
out.write_all(SPACE)?;
2929
out.write_all(line)?;
3030
out.write_all(NL)?;
3131
}
32-
// If the last line ended on a newline, we have to re-add it by force
33-
if let Some(b) = value.last() {
34-
if *b == b'\n' {
35-
out.write_all(SPACE)?;
36-
out.write_all(NL)?;
37-
}
38-
}
3932
Ok(())
4033
}
4134

0 commit comments

Comments
 (0)