Skip to content

Conversation

@Fishrock123
Copy link
Contributor

I know @chrisdickinson said it would have been better to have the repl save in plain text, and that doing so would require a semver-major change.

I'd like to get it into 3.0 if possible, and I'm willing to do whatever if it looks good to people.

This also effectively enables it by default, by using os.homedir() to get an appropriate location (I think?). Perhaps I should be handling more errors if it can't exist?

The first commit is the important one.

R= @chrisdickinson or @rvagg since he's doing 3.0?

@Fishrock123 Fishrock123 added repl Issues and PRs related to the REPL subsystem. semver-major PRs that contain breaking changes and should be released in the next major version. labels Jul 22, 2015
@Fishrock123 Fishrock123 added this to the 3.0.0 milestone Jul 22, 2015
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop this check.
With the new condition at lines 99-100, we are sure it is an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, haha, true.

I didn't really know how else to check that it was probably JSON is an reasonable and quick way.

@Fishrock123 Fishrock123 force-pushed the repl-history-nojson branch from a440565 to 8664f5e Compare July 22, 2015 17:36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't touch it but this line has no effect. It should be repl.history = repl.history.slice(-repl.historySize);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw it feels wrong to slice it here. Why isn't it done before saving the file in flushHistory ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

flushHistory() could probably use some fixes/improvements. It always appends to the file no matter what the current file size is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be permanently appending, since we're using this variant of fs.write, with position set to 0. The existing repl logic should be handling the trimming of history.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but yes, we should assign repl.history = repl.history.slice(...) here.)

@Fishrock123
Copy link
Contributor Author

Updated based off on this length discussion with @chrisdickinson on IRC: http://logs.libuv.org/io.js/2015-07-22#18:19:50.744

We now prefer a new NODE_REPL_HISTORY env variable, and only try to parse JSON the first time if NODE_REPL_HISTORY_FILE is specified.

Still needs some extra log messages about all of this, especially if people are still afterwards specifying a NODE_REPL_HISTORY_FILE.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible for os.homedir() to throw, it would be very uncommon but there are some scenarios beyond ENOMEM, ENOBUFS, ENOENT, EMFILE etc. that might be useful to report rather than just crash. I wonder if we should try/catch this and early return ready()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, whoops, I had forgotten about that, thanks.

It'd probably depend on the error what we may want to do; there a difference between say ENOMEM and ENOENT. :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not really so sure what I meant with this last night! I guess we should just log the error stack and then call ready?

@mscdex
Copy link
Contributor

mscdex commented Jul 24, 2015

I haven't been following the repl history discussion, but what about keeping JSON and just using exclusive locks on the history file?

@Fishrock123
Copy link
Contributor Author

I haven't been following the repl history discussion, but what about keeping JSON and just using exclusive locks on the history file?

Doing thing atomically is another must-do sometime soon. (But I currently don't know how to do that at all.)

This however is more about moving off of json for thoughts of of general stability and API going forward, especially as we near a converged release. It just seems like a better option future-wise, so I felt it was best not to delay it; might as well do it now rather than when people might actually rely on it being json for one reason or other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone wants to share history files across platforms, maybe on a network drive? I think we'd be better off just using \n here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should save using os.EOL, and split liberally on either line ending.

@Fishrock123
Copy link
Contributor Author

I think I've addressed basically everything. We don't really have tests for this, right?

I just need to improve the "converting" info message.

Also it now only tries to load the old history if there isn't any new history.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should split with /[\r\n]+/ for Windows compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or os.EOL?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefourtheye see above comment from @silverwind .
The idea is to be able to share the history file between different platforms.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, thanks for pointing out :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/\n|\r/ will result in empty lines when reading \r\n files. better use /\r?\n/ or even /\r?\n|\n?\r/ if you want to be totally safe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/\r\n|\r|\n/ would be more explicit, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't catch a \n\r case, if such a platform exists, so you'd need /\r\n|\n\r|\r|\n/ but I really have no preference here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on os.EOL, /\r?\n/ would suffice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW the regex I suggested has an interesting side-effect: empty lines will be ignored.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@targos oh indeed. That might be a nice 'feature' ;)

@Fishrock123
Copy link
Contributor Author

Updated with everything, PTAL. + cc @chrisdickinson & @rvagg again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this line when squashing

@chrisdickinson
Copy link
Contributor

Tiny nit re: message, but LGTM.

@Fishrock123
Copy link
Contributor Author

Now includes some doc updates. Should I mention that NODE_REPL_HISTORY_FILE is deprecated, or not at all?

... I'll try to add that bit in later tonight.

Fishrock123 added a commit that referenced this pull request Aug 4, 2015
PR-URL: #2224
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
@rvagg rvagg mentioned this pull request Aug 4, 2015
@targos
Copy link
Member

targos commented Aug 5, 2015

landed in d200932...ed6c249

@targos targos closed this Aug 5, 2015
@arty-name
Copy link

would be nice to support XDG Base Directory Specification for the default path

@akiva
Copy link

akiva commented Oct 22, 2015

+1 @arty-name on the XDG spec standard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

repl Issues and PRs related to the REPL subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.