diff options
Diffstat (limited to 'src/bin/git_remote_nostr')
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 69 |
1 files changed, 67 insertions, 2 deletions
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> { | |||
| 288 | let existing_lines = self.count_all_existing_lines(); | 288 | let existing_lines = self.count_all_existing_lines(); |
| 289 | let msg = data.to_string(); | 289 | let msg = data.to_string(); |
| 290 | if let Some(last) = self.remote_msgs.last() { | 290 | if let Some(last) = self.remote_msgs.last() { |
| 291 | if (last.contains('%') && !last.contains("100%")) | 291 | // if previous line begins with x but doesnt finish with y then its part of the |
| 292 | // same msg | ||
| 293 | if (last.starts_with("Enume") && !last.ends_with(", done.")) | ||
| 294 | || ((last.starts_with("Compre") || last.starts_with("Count")) | ||
| 295 | && !last.contains(')')) | ||
| 296 | { | ||
| 297 | let last = self.remote_msgs.pop().unwrap(); | ||
| 298 | self.remote_msgs.push(format!("{last}{msg}")); | ||
| 299 | // if previous msg contains % and its not 100% then it | ||
| 300 | // should be overwritten | ||
| 301 | } else if (last.contains('%') && !last.contains("100%")) | ||
| 302 | // but also if the next message is identical with "", done." appended | ||
| 292 | || last == &msg.replace(", done.", "") | 303 | || last == &msg.replace(", done.", "") |
| 293 | { | 304 | { |
| 294 | self.remote_msgs.pop(); | 305 | self.remote_msgs.pop(); |
| 306 | self.remote_msgs.push(msg); | ||
| 307 | } else { | ||
| 308 | self.remote_msgs.push(msg); | ||
| 295 | } | 309 | } |
| 310 | } else { | ||
| 311 | self.remote_msgs.push(msg); | ||
| 296 | } | 312 | } |
| 297 | self.remote_msgs.push(msg); | ||
| 298 | self.write_all(existing_lines); | 313 | self.write_all(existing_lines); |
| 299 | } | 314 | } |
| 300 | } | 315 | } |
| @@ -453,6 +468,56 @@ mod tests { | |||
| 453 | } | 468 | } |
| 454 | } | 469 | } |
| 455 | 470 | ||
| 471 | mod joins_lines_sent_over_multiple_msgs { | ||
| 472 | use super::*; | ||
| 473 | |||
| 474 | #[test] | ||
| 475 | fn enumerating() { | ||
| 476 | assert_eq!( | ||
| 477 | pass_through_fetch_reporter_proces_remote_msg(vec![ | ||
| 478 | "Enumerat", | ||
| 479 | "ing objec", | ||
| 480 | "ts: 23716, done.", | ||
| 481 | "Counting objects: 0% (1/2195)", | ||
| 482 | ]), | ||
| 483 | vec![ | ||
| 484 | "Enumerating objects: 23716, done.", | ||
| 485 | "Counting objects: 0% (1/2195)", | ||
| 486 | ] | ||
| 487 | ); | ||
| 488 | } | ||
| 489 | #[test] | ||
| 490 | fn counting() { | ||
| 491 | assert_eq!( | ||
| 492 | pass_through_fetch_reporter_proces_remote_msg(vec![ | ||
| 493 | "Enumerating objects: 23716, done.", | ||
| 494 | "Counting obj", | ||
| 495 | "ects: 0% (1/2195)", | ||
| 496 | "Count", | ||
| 497 | "ing objects: 1% (22/", | ||
| 498 | "2195)", | ||
| 499 | ]), | ||
| 500 | vec![ | ||
| 501 | "Enumerating objects: 23716, done.", | ||
| 502 | "Counting objects: 1% (22/2195)", | ||
| 503 | ] | ||
| 504 | ); | ||
| 505 | } | ||
| 506 | #[test] | ||
| 507 | fn compressing() { | ||
| 508 | assert_eq!( | ||
| 509 | pass_through_fetch_reporter_proces_remote_msg(vec![ | ||
| 510 | "Compress", | ||
| 511 | "ing obj", | ||
| 512 | "ect", | ||
| 513 | "s: 0% (1/56", | ||
| 514 | "0)" | ||
| 515 | ]), | ||
| 516 | vec!["Compressing objects: 0% (1/560)"] | ||
| 517 | ); | ||
| 518 | } | ||
| 519 | } | ||
| 520 | |||
| 456 | #[test] | 521 | #[test] |
| 457 | fn msgs_with_pc_and_not_100pc_are_replaced() { | 522 | fn msgs_with_pc_and_not_100pc_are_replaced() { |
| 458 | assert_eq!( | 523 | assert_eq!( |