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
history: Add option to show timestamps #3175
Conversation
Cool! I wonder how difficult it would be to modify It'd be important to maintain compatibility with the history files (preferably both ways). |
@@ -301,6 +301,7 @@ AC_CHECK_FUNCS( futimes ) | |||
AC_CHECK_FUNCS( wcslcpy lrand48_r killpg ) | |||
AC_CHECK_FUNCS( backtrace_symbols getifaddrs ) | |||
AC_CHECK_FUNCS( futimens clock_gettime ) | |||
AC_CHECK_FUNCS( localtime_r ) |
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.
What is the point of this configure check? This change calls localtime()
unconditionally. Which is reasonable since no OS fish runs on should not have an implementation for that function.
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.
It's not localtime
, it's localtime_r
which is sometimes not available on Win32 IIRC.
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.
AC_CHECK_FUNCS
defines a preprocessor symbol if the function is available, but there is no check for this in the code (and no alternative handling).
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.
@zanchey: Do we need to support platforms which don’t define localtime_r
? I’m really not wild about using localtime
, since it’s not thread-safe. Would it be acceptable for configure
to just halt with an error if localtime_r
is undefined?
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.
Somewhat surprisingly we don't currently have a single localtime()
call in the code so it's use in this change would be thread-safe since it is the only thread that would ever call it. However, that's putting down a land mine. So this is a case where a fallback function needs to be defined if the platform doesn't provide it. The fallback should just use a simple global lock around the call to localtime()
to ensure the single internal result buffer isn't overwritten before it's contents are copied into the user supplied result buffer. Look in the code for instances of scoped_lock locker(lock); //!OCLINT(side-effect)
for how to do that.
I should also note that you change has another bug: You don't call tzset()
(and neither does the current fish code). It's possible the internal timezone state is being set indirectly via some other call but you shouldn't rely on that.
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.
It looks like it's going to be mingw that may not have this - seems like it can be expected on Cygwin? Perhaps it's not an issue?
Would it perhaps be better to implement some of this in the classes in history.cpp rather than builtin.cpp? I notice we are not calling |
@floam: Since the timestamp format is a property of the |
I've confirmed the configure check for Thanks for doing this, @bbarenblat. In the future remember to update documentation and unit tests. |
I've merged this change, minus the configure.ac change as commit 7e08679. I'm not going to close this until my change to update the documentation and share/functions/history.fish script is also merged. |
I fixed the history function issues with commit cbee315. |
Closes #677.