-
Notifications
You must be signed in to change notification settings - Fork 3k
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
console.lua: allow persisting the command history #14681
base: master
Are you sure you want to change the base?
Conversation
49d11c5
to
9033060
Compare
player/lua/console.lua
Outdated
end | ||
|
||
local error | ||
history_file, error = io.open(history_path, 'w') |
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.
Why not just append and avoid all the read logic?
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.
We don't know whether history commands are new or were read from the history file on startup. Even if we kept track of it that would break history deduplication.
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.
Why history deduplication is needed?
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.
To avoid duplicate lines? We even have an option for it.
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.
Well, bit too bloated for my taste, but whatever.
Download the artifacts for this pull request: |
An issue with doing a full file write instead of appending is that it will end up overwriting history with a zero-byte file if we're out of disk space. Many existing history scripts suffer from this same issue and shrug it off when they lose your history. Don't want this behavior in a builtin script. I personally think deduplication on write is overkill, but don't skip over the huge block of text since some stuff still applies. |
That's better than duplicating history lines.
What? New lines from the current instance are appended to the end.
The file is reread to save lines from other mpv instances as written in the comment. Rereading it is not necessary to deduplicate entries or reordering. Saving the last cursor position would break if the beginning of the history file has been modified by other mpv instances.
Deduplication is performed every time a line is added to the history. On write it only deduplicates lines written by other mpv instasnces. |
8b5a133
to
7ee4c39
Compare
7ee4c39
to
db59907
Compare
8d91fd9
to
9951305
Compare
9951305
to
771c465
Compare
771c465
to
1dd24d6
Compare
1dd24d6
to
5b84f22
Compare
Disabled by default.