Truncate `s` to at most `max_bytes`, rounding down to the nearest UTF-8 character boundary to keep the result a valid `&str`.
(s: &str, max_bytes: usize)
| 721 | /// Truncate `s` to at most `max_bytes`, rounding down to the nearest UTF-8 |
| 722 | /// character boundary to keep the result a valid `&str`. |
| 723 | fn safe_utf8_truncate(s: &str, max_bytes: usize) -> usize { |
| 724 | if s.len() <= max_bytes { |
| 725 | return s.len(); |
| 726 | } |
| 727 | let mut idx = max_bytes; |
| 728 | while idx > 0 && !s.is_char_boundary(idx) { |
| 729 | idx -= 1; |
| 730 | } |
| 731 | idx |
| 732 | } |
| 733 | |
| 734 | /// Map a non-2xx response to an `anyhow::Error`, attaching a typed |
| 735 | /// [`RemoteGitConflict`] when the server returned a recoverable code under |