From ff80e0d444579c72dfab755b98bc79da1b1a4ffe Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 16 Sep 2024 16:26:33 +0100 Subject: fix(remote): fetch report join remote lines when they are sent via multiple messages --- src/bin/git_remote_nostr/fetch.rs | 69 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'src/bin') diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index 9a891b2..9c2b0a2 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs @@ -288,13 +288,28 @@ impl<'a> FetchReporter<'a> { let existing_lines = self.count_all_existing_lines(); let msg = data.to_string(); if let Some(last) = self.remote_msgs.last() { - if (last.contains('%') && !last.contains("100%")) + // if previous line begins with x but doesnt finish with y then its part of the + // same msg + if (last.starts_with("Enume") && !last.ends_with(", done.")) + || ((last.starts_with("Compre") || last.starts_with("Count")) + && !last.contains(')')) + { + let last = self.remote_msgs.pop().unwrap(); + self.remote_msgs.push(format!("{last}{msg}")); + // if previous msg contains % and its not 100% then it + // should be overwritten + } else if (last.contains('%') && !last.contains("100%")) + // but also if the next message is identical with "", done." appended || last == &msg.replace(", done.", "") { self.remote_msgs.pop(); + self.remote_msgs.push(msg); + } else { + self.remote_msgs.push(msg); } + } else { + self.remote_msgs.push(msg); } - self.remote_msgs.push(msg); self.write_all(existing_lines); } } @@ -453,6 +468,56 @@ mod tests { } } + mod joins_lines_sent_over_multiple_msgs { + use super::*; + + #[test] + fn enumerating() { + assert_eq!( + pass_through_fetch_reporter_proces_remote_msg(vec![ + "Enumerat", + "ing objec", + "ts: 23716, done.", + "Counting objects: 0% (1/2195)", + ]), + vec![ + "Enumerating objects: 23716, done.", + "Counting objects: 0% (1/2195)", + ] + ); + } + #[test] + fn counting() { + assert_eq!( + pass_through_fetch_reporter_proces_remote_msg(vec![ + "Enumerating objects: 23716, done.", + "Counting obj", + "ects: 0% (1/2195)", + "Count", + "ing objects: 1% (22/", + "2195)", + ]), + vec![ + "Enumerating objects: 23716, done.", + "Counting objects: 1% (22/2195)", + ] + ); + } + #[test] + fn compressing() { + assert_eq!( + pass_through_fetch_reporter_proces_remote_msg(vec![ + "Compress", + "ing obj", + "ect", + "s: 0% (1/56", + "0)" + ]), + vec!["Compressing objects: 0% (1/560)"] + ); + } + } + #[test] fn msgs_with_pc_and_not_100pc_are_replaced() { assert_eq!( -- cgit v1.2.3