-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: Use git_object::commit::MessageRef::summary()… (#198)
…which removes `commit::summary()` and alters the signature of ``
- Loading branch information
Showing
7 changed files
with
21 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,2 @@ | ||
use std::borrow::Cow; | ||
|
||
use bstr::{BStr, BString, ByteSlice, ByteVec}; | ||
|
||
/// An empty array of a type usable with the `git::easy` API to help declaring no parents should be used | ||
pub const NO_PARENT_IDS: [git_hash::ObjectId; 0] = []; | ||
|
||
/// Produce a short commit summary for the given `message`. | ||
/// | ||
/// This means the following | ||
/// | ||
/// * Take the subject line which is delimited by two newlines (\n\n) | ||
/// * transform intermediate consecutive whitespace including \r into one space | ||
/// | ||
/// The resulting summary will have folded whitespace before a newline into spaces and stopped that process | ||
/// once two consecutive newlines are encountered. | ||
pub fn summary(message: &BStr) -> Cow<'_, BStr> { | ||
let message = message.trim(); | ||
match message.find_byte(b'\n') { | ||
Some(mut pos) => { | ||
let mut out = BString::default(); | ||
let mut previous_pos = None; | ||
loop { | ||
if let Some(previous_pos) = previous_pos { | ||
if previous_pos + 1 == pos { | ||
let len_after_trim = out.trim_end().len(); | ||
out.resize(len_after_trim, 0); | ||
break out.into(); | ||
} | ||
} | ||
let message_to_newline = &message[previous_pos.map(|p| p + 1).unwrap_or(0)..pos]; | ||
|
||
if let Some(pos_before_whitespace) = message_to_newline.rfind_not_byteset(b"\t\n\x0C\r ") { | ||
out.extend_from_slice(&message_to_newline[..pos_before_whitespace + 1]); | ||
} | ||
out.push_byte(b' '); | ||
previous_pos = Some(pos); | ||
match message.get(pos + 1..).and_then(|i| i.find_byte(b'\n')) { | ||
Some(next_nl_pos) => pos += next_nl_pos + 1, | ||
None => { | ||
if let Some(slice) = message.get((pos + 1)..) { | ||
out.extend_from_slice(slice); | ||
} | ||
break out.into(); | ||
} | ||
} | ||
} | ||
} | ||
None => message.as_bstr().into(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters