Repository navigation
Remove redundant progress text from Git error messages - #9945
Conversation
rafeca
left a comment
There was a problem hiding this comment.
I can't express how much I ❤️ this PR! I've stumbled across clone errors that display all the percentage lines and the experience was quite bad. This will help users a lot!
Just added a few comments, nothing major
Co-Authored-By: Rafael Oleza <[email protected]>
Unless we decide to support the backspace character at some point I don't believe we ever have to care about the head of the existing line, it's all about whether there's anything remaining after we've applied the new text or not
This is the most common scenario in Git, they add white space up to the max line length they expect in order to ensure they erase the previous lines
|
@rafeca I realized when looking at the code with a fresh set of eyes that the I also spotted one more opportunity for optimization to avoid the last |
|
Thanks for doing these optimizations! From your explanations and by looking at the code they make sense. I'm getting a little bit worried that using a RegExp makes the logic of this method a bit hard to understand due to a couple of smart tricks (overriding the Have you considered just splitting the string manually to avoid using a RegExp? It will be less memory efficient but I don't think it would be a big deal in this scenario since we already have the whole string in memory... I'm thinking about something similar to: const lines = text.split('\n')
const cleanLines = lines
.map(line => {
const sublines = line.split('\r')
let out = ''
for (const subline of sublines) {
if (subline.length >= out.length) {
// Happy path, the new line is equal to or longer
// than the previous, we can just use the new one
// without creating any new strings.
out = subline
} else {
const remainder = out.substring(subline.length)
out = `${subline}${remainder}`
}
}
return out
})
return cleanLines.join('\n') |
Co-authored-by: Rafael Oleza <[email protected]>
Co-Authored-By: Rafael Oleza <[email protected]>
Yes, I played around with something similar to that early on but I wasn't feeling great about all the intermediate arrays but I agree that this solution has incrementally evolved into something much more complex than I had originally envisioned. While there are cases when the clone output become ridiculously long we do have a cap at 10Mb in dugite for I took your proposed change and tweaked it just a little bit since I think a reduce operation fits in really nicely here. |
| expect(parseCarriageReturn('foo\r\r\r\r\rbar')).toBe('bar') | ||
| }) | ||
|
|
||
| it('treats unicode line separator and paragraph separator as flow text', () => { |
There was a problem hiding this comment.
@rafeca This test is kinda pointless now that we're not using a regex but I think it's a fair test still in case we alter course in the future and turn it into a regex again. I'll drop it if you want though
rafeca
left a comment
There was a problem hiding this comment.
Nice!!! Let's merge this one 🚢
🌵 This depends on #9944, please review that first 🌵Description
When looking at #9944 I was struck once again by how bad our error messages from Git commands that show some sort of progress are:
While somewhat improved in #8964...
There's still a whole lot of redundant text in there that users don't care about and which often times ends up making it really hard to find the actual error message.
The reason for all of this is that Git (and many other CLI tools) leverage an old trick from the typewriter era called the carriage return character to make it seem like they're just updating a single character in the users' terminal.
When the users sees something like
Progress: 1%that then changes toProgress: 2%what Git actually does is it writesProgress: 1%followed by a carriage return character (\r) which sends the "carriage" back to the leftmost position and then it overwrites the existing text withProgress: 2%. Since we didn't handle carriage returns we got, and displayed each of those updates which for clones and fetches of large repositories could be enormous.This PR changes that by introducing a parser that emulates how a terminal would interpret carriage returns so now we only show the last progress line for each type of progress reported.
Screenshots
Before
After
Release notes
Notes: [Improved] Removed redundant progress text in Git error messages