Re: RFC: dynamic "auto" date formats
On Thu, May 26, 2016 at 11:53 PM, Linus Torvalds wrote: > > So I think what I really would like to see is more like a reverse > "approxidate" that gives the date in human terms. Yeah, "human" was the word I was looking for while composing my response. I am sure somebody will write the reverse approxidate that utters "tea time" when it is appropriate, if only just for fun. I can't wait ;-) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: RFC: dynamic "auto" date formats
Linus Torvalds writes: > And no, I'm not at all sure that the 24-hour cut-off is the right > thing, but it didn't seem completely crazy either. I tend to like the > relative date format when it is "19 minutes ago" vs "2 hours ago", at > some point it's long enough ago that it's more useful to know "Tuesday > at 3pm" than about how long ago it was. > > (And yes, it would be even better to have the "short term relative > date" turn into a "medium-term 'day of the week at time x'" and then > turn into "full date" when it's more than a week ago, but this patch > only has the two modes of "short term" and "long term" and nothing in > between). While I do not think this has much to do with "auto", other than that it changes the representation depending on how far back the time is to match the taste of Linus automatically, I think the observation you made about the relative uselessness of "relative in the long past" is real. "6 years ago" that does not say if it was in the morning and that does not even say if it was in the summer is losing a bit too much information. Your message made me realize another thing I feel while viewing "relative in the long past" output. In "git log --date=relative" output (especially when the log is "limited" in some way, like with a pathspec, --grep, -S, etc.) that shows multiple commits, all of which are labeled "6 years ago", they make me wonder how they are related to each other chronologically. Perhaps I am seeing 6 commits, but the earlier four was made all within 20 minutes, and the fifth one three days later, and the final one a month later, which may indicate that the first four was the initial round of a topic, with two "oops, this is a fix" follow-up patches that are related in one area. All of them being labeled "6 years ago" would not give such a clue. Which makes me wonder if another variant is useful (or at least "interesting"). What if we chose format according to this rule? 0. Set the "reference time" to the current time. 1. Do get_revision() to grab one commit to show. 2. Show that commit, using timeformat determined as: a. if its time is close to the "reference time", then use "N hours M minues before that" format; b. otherwise, use the default time format; 3. Update the "reference time" to the timestamp of the commit we just showed. 4. Go back to 1. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: RFC: dynamic "auto" date formats
On Thu, May 26, 2016 at 08:36:57PM -0700, Linus Torvalds wrote: > Note that this doesn't add any gitconfig setting to do this, which > would be part of the whole point if this is actually sensible. But I'm > not entirely convinced it's worth it in the first place, thus this > email to see how people react ("That's just stupid" vs "yeah, I didn't > even know I wanted it, but now I need it"). > > And no, I'm not at all sure that the 24-hour cut-off is the right > thing, but it didn't seem completely crazy either. I tend to like the > relative date format when it is "19 minutes ago" vs "2 hours ago", at > some point it's long enough ago that it's more useful to know "Tuesday > at 3pm" than about how long ago it was. Seems like a reasonable idea, though I doubt I'd use it myself. In addition to possibly making the cutoff-time configurable, I'd expect people would want the fallback format to be configurable, too. I wonder if something like: --date=relative:24h:iso would make sense as "relative up to 24 hours, then iso". You could even chain them, so your: > (And yes, it would be even better to have the "short term relative > date" turn into a "medium-term 'day of the week at time x'" and then > turn into "full date" when it's more than a week ago, but this patch > only has the two modes of "short term" and "long term" and nothing in > between). could be something like: --date=relative:24h:short:1w:normal (where "short" actually kind of sucks; we'd introduce a new format for your "Tuesday at 10pm" output). I admit it's a bit baroque to look at, though. -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC: dynamic "auto" date formats
This is a throw-away idea with a simple patch attached, which I don't think anybody should really take all that seriously per se, but I thought I'd throw it out and see if it generates any discussion. I almost never use anything but the default date format (DATE_NORMAL), but every once in a while I will use "--date=relative", typically because I'm looking at my own commits and I'm just checking when I did something. It struck me that I've made the default for most of the logging things be that when I'm just browsing with the pager, git will automatically do the right thing. So I have [color] ui=auto [log] decorate = auto in my ~/.gitconfig, and it shows me all those other things I tench to want to know (like "thar's what I've pushed out" thanks to decorations). So I started thinking about when I care about dates, and decided that maybe I can have a "--date=auto" too. It basically uses relative date formats for the last 24 hours, and then switches over to the default format. I've used it a bit, and like Katy Perry said, I think I might like it. Note that this doesn't add any gitconfig setting to do this, which would be part of the whole point if this is actually sensible. But I'm not entirely convinced it's worth it in the first place, thus this email to see how people react ("That's just stupid" vs "yeah, I didn't even know I wanted it, but now I need it"). And no, I'm not at all sure that the 24-hour cut-off is the right thing, but it didn't seem completely crazy either. I tend to like the relative date format when it is "19 minutes ago" vs "2 hours ago", at some point it's long enough ago that it's more useful to know "Tuesday at 3pm" than about how long ago it was. (And yes, it would be even better to have the "short term relative date" turn into a "medium-term 'day of the week at time x'" and then turn into "full date" when it's more than a week ago, but this patch only has the two modes of "short term" and "long term" and nothing in between). Linus builtin/blame.c | 1 + cache.h | 3 ++- date.c | 10 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 21f42b0b62b8..4d87181dc6cd 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2640,6 +2640,7 @@ parse_done: fewer display columns. */ blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */ break; + case DATE_AUTO: case DATE_NORMAL: blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700"); break; diff --git a/cache.h b/cache.h index 6049f8671138..624817c20414 100644 --- a/cache.h +++ b/cache.h @@ -1223,7 +1223,8 @@ struct date_mode { DATE_ISO8601_STRICT, DATE_RFC2822, DATE_STRFTIME, - DATE_RAW + DATE_RAW, + DATE_AUTO, } type; const char *strftime_fmt; int local; diff --git a/date.c b/date.c index 7c9f76998ac7..c38414a3d968 100644 --- a/date.c +++ b/date.c @@ -184,13 +184,15 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode) return timebuf.buf; } - if (mode->type == DATE_RELATIVE) { + if (mode->type == DATE_RELATIVE || mode->type == DATE_AUTO) { struct timeval now; strbuf_reset(&timebuf); gettimeofday(&now, NULL); - show_date_relative(time, tz, &now, &timebuf); - return timebuf.buf; + if (mode->type != DATE_AUTO || time + 24*60*60 > now.tv_sec) { + show_date_relative(time, tz, &now, &timebuf); + return timebuf.buf; + } } tm = time_to_tm(time, tz); @@ -792,6 +794,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end) return DATE_RAW; if (skip_prefix(format, "format", end)) return DATE_STRFTIME; + if (skip_prefix(format, "auto", end)) + return DATE_AUTO; die("unknown date format %s", format); }