-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: Reverses order of .node_repl_history #4313
Conversation
@@ -119,7 +119,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { | |||
} | |||
|
|||
if (data) { | |||
repl.history = data.split(/[\n\r]+/, repl.historySize); | |||
repl.history = data.split(/[\n\r]+/).slice(repl.historySize * -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how large history files can get, but maybe it'd be more efficient to limit the input to the last repl.historySize
lines first and then split on that? For example:
var reLastLines = new RegExp('(?:.*[\r\n]+){0,' + repl.historySize + '}$');
repl.history = reLastLines.exec(data)[0].match(/[^\r\n]+/g) || [];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it would be an issue large enough to necessitate that unless some manually edited in a way-too-big history file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code may not be correct though, I think it should probably keep the original logic, and then call .reverse()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fishrock123 Since the history file is going to be arranged from least recent to most (most being at the bottom), doing data.split(/[\n\r]+/, repl.historySize)
will end up losing the latest history elements if data.length > repl.historySize
. The latest history elements will end up getting dropped/truncated as they are at a higher index in data
array than the less recent ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh good catch.
(Actually, on second thought, this is semver-major anyways) |
assert.strictEqual(historyCopy, '\'you look fabulous today\'' + os.EOL + | ||
'\'Stay Fresh~\'' + os.EOL); | ||
assert.strictEqual(historyCopy, '\'Stay Fresh~\'' + os.EOL + | ||
'\'you look fabulous today\''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these are being reversed, something is probably not correct. :)
@zeusdeux Instead of changing |
Welcome @zeusdeux, I believe this would be your first commit to core if it gets in, thanks for contributing! Even if this doesn't get in, we appreciate the time you've spent discussing and working on this with us. I'm labelling this one |
@rvagg I do have a commit in actually. Got one in quite recently with help from @Fishrock123. I love this community! :) As for this PR, should I continue working on this then or wait till I hear more? |
@zeusdeux we'll cover this in our CTC meeting tomorrow, no promises on actually getting anywhere with it. Will let you know. |
This is kind of a general idea: if we want to start making changes like this, perhaps we should consider versioning history files (e.g. add some version identifier at the top of the file)? That way we can more easily know how to parse a history file (in the future)? |
This was discussed on the CTC call today. Overall consensus is that there is currently no pressing reason to adopt this change currently and we'd rather keep the history ordering consistent with what's currently in v4 and v5. Unless there is a compelling new reason to make this change, we'd prefer to keep things as they are currently. |
@jasnell fair enough. Should I go ahead and just close this then? |
If that's what you wish. If you close but not delete the branch, we can at
|
I don't mind leaving it open but I fear that might just add unnecessary cognitive load for anyone going through the PRs. On the flipside, the issue (#3928) that prompted this PR is still open so closing this might make for a weird history later on. So, yeah, I am not sure. As for the branch, sure, we can keep it around. |
Let's close it for now. Like you say, it unclutters the open PRs view. |
Rationale -> #3928.
A few tests are still broken for this and I am kinda confused as to why. Could use some help to ready this PR up.
Thanks!