threads / patch / 20259

patch, 3 partsbash completion: log --date, --no-date and --date=normal

Subject: [PATCH 3/3] bash completion: log --date, --no-date and --date=normal

## tl;dr

10 messages between Jul 28, 2009 and Jul 28, 2009. Diffs are folded; open one to read it.

replies: 9people: 3as markdown or json

Thomas Rast· Jul 28, 2009, 08:40 UTC · lore

[PATCH 1/3] log: Show reflog date with --date=normal

The reflog case special-cases --date=default (internally DATE_NORMAL) to show the entry number instead of a date. This means it is impossible to show the default date format for the reflog entries.

Introduce a new state DATE_DEFAULT (for the existing --date=default) that takes over the special value 0, and have DATE_NORMAL (for the new --date=normal) act the same except in the reflog code where we still special-case the value 0. This means that 'git log -g --date=normal' shows the date, whereas 'git log -g --date=default' shows the reflog entry number.

Thanks to Johannes Schindelin for IRC help.
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 Documentation/git-rev-list.txt     |    2 +-
 Documentation/rev-list-options.txt |    7 +++++--
 builtin-blame.c                    |    1 +
 cache.h                            |    3 ++-
 date.c                             |    2 ++
 5 files changed, 11 insertions(+), 4 deletions(-)
Show changes to 5 files +11 −3

Documentation/git-rev-list.txt, Documentation/rev-list-options.txt, builtin-blame.c, cache.h, date.c

diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index a765cfa..6f2013b 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -36,7 +36,7 @@ SYNOPSIS
 	     [ \--regexp-ignore-case | -i ]
 	     [ \--extended-regexp | -E ]
 	     [ \--fixed-strings | -F ]
-	     [ \--date={local|relative|default|iso|rfc|short} ]
+	     [ \--date={local|relative|normal|default|iso|rfc|short} ]
 	     [ [\--objects | \--objects-edge] [ \--unpacked ] ]
 	     [ \--pretty | \--header ]
 	     [ \--bisect ]
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index bf66116..2a106bd 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -13,7 +13,7 @@ include::pretty-options.txt[]
 
 	Synonym for `--date=relative`.
 
---date={relative,local,default,iso,rfc,short,raw}::
+--date={relative,local,normal,default,iso,rfc,short,raw}::
 
 	Only takes effect for dates shown in human-readable format, such
 	as when using "--pretty". `log.date` config variable sets a default
@@ -33,8 +33,11 @@ format, often found in E-mail messages.
 +
 `--date=raw` shows the date in the internal raw git format `%s %z` format.
 +
-`--date=default` shows timestamps in the original timezone
+`--date=normal` shows timestamps in the original timezone
 (either committer's or author's).
++
+`--date=default` is like `normal`, except for reflog entries where the
+entry number is shown instead.
 
 ifdef::git-rev-list[]
 --header::
diff --git a/builtin-blame.c b/builtin-blame.c
index fd6ca51..9671c20 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -2288,6 +2288,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 		/* "normal" is used as the fallback for "relative" */
 	case DATE_LOCAL:
 	case DATE_NORMAL:
+	case DATE_DEFAULT:
 		blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
 		break;
 	}
diff --git a/cache.h b/cache.h
index e6c7f33..a62ce78 100644
--- a/cache.h
+++ b/cache.h
@@ -712,7 +712,8 @@ static inline unsigned int hexval(unsigned char c)
 				   struct object *o, enum object_type);
 
 enum date_mode {
-	DATE_NORMAL = 0,
+	DATE_DEFAULT = 0,
+	DATE_NORMAL,
 	DATE_RELATIVE,
 	DATE_SHORT,
 	DATE_LOCAL,
diff --git a/date.c b/date.c
index 409a17d..661dd24 100644
--- a/date.c
+++ b/date.c
@@ -637,6 +637,8 @@ enum date_mode parse_date_format(const char *format)
 	else if (!strcmp(format, "local"))
 		return DATE_LOCAL;
 	else if (!strcmp(format, "default"))
+		return DATE_DEFAULT;
+	else if (!strcmp(format, "normal"))
 		return DATE_NORMAL;
 	else if (!strcmp(format, "raw"))
 		return DATE_RAW;
-- 
1.6.4.rc3.218.gb7ac
Thomas Rast· Jul 28, 2009, 08:40 UTC · re: Thomas Rast · lore

[PATCH 2/3] log: --date and --no-date to toggle reflog dates

Introduce two new options that help the user, especially in the case where log.date is set to some value other than "normal":

--date: equivalent to --date=normal if it was previously "default" --no-date: equivalent to --date=default

This means that 'git reflog --date' will always show reflog entries by date, and 'git reflog --no-date' won't even if log.date is set.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 Documentation/git-rev-list.txt     |    2 +-
 Documentation/rev-list-options.txt |   11 ++++++++++-
 revision.c                         |    5 +++++
 3 files changed, 16 insertions(+), 2 deletions(-)
Show changes to 3 files +16 −1

Documentation/git-rev-list.txt, Documentation/rev-list-options.txt, revision.c

diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index 6f2013b..023a595 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -36,7 +36,7 @@ SYNOPSIS
 	     [ \--regexp-ignore-case | -i ]
 	     [ \--extended-regexp | -E ]
 	     [ \--fixed-strings | -F ]
-	     [ \--date={local|relative|normal|default|iso|rfc|short} ]
+	     [ \--date[={local|relative|normal|default|iso|rfc|short}] ]
 	     [ [\--objects | \--objects-edge] [ \--unpacked ] ]
 	     [ \--pretty | \--header ]
 	     [ \--bisect ]
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 2a106bd..e83e8bd 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -13,7 +13,7 @@ include::pretty-options.txt[]
 
 	Synonym for `--date=relative`.
 
---date={relative,local,normal,default,iso,rfc,short,raw}::
+--date[={relative,local,normal,default,iso,rfc,short,raw}]::
 
 	Only takes effect for dates shown in human-readable format, such
 	as when using "--pretty". `log.date` config variable sets a default
@@ -38,6 +38,15 @@ format, often found in E-mail messages.
 +
 `--date=default` is like `normal`, except for reflog entries where the
 entry number is shown instead.
++
+`--date` sets the date display to `normal` if it was previously
+`default`, so it serves as a shorthand to display reflog entries with
+date instead of number.
+
+--no-date::
+
+	Synonym for `--date=default`, so named because it causes
+	reflog entries to be shown by number instead of date.
 
 ifdef::git-rev-list[]
 --header::
diff --git a/revision.c b/revision.c
index 9f5dac5..941f631 100644
--- a/revision.c
+++ b/revision.c
@@ -1159,6 +1159,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->simplify_history = 0;
 	} else if (!strcmp(arg, "--relative-date")) {
 		revs->date_mode = DATE_RELATIVE;
+	} else if (!strcmp(arg, "--date")) {
+		if (!revs->date_mode)
+			revs->date_mode = DATE_NORMAL;
+	} else if (!strcmp(arg, "--no-date")) {
+		revs->date_mode = DATE_DEFAULT;
 	} else if (!strncmp(arg, "--date=", 7)) {
 		revs->date_mode = parse_date_format(arg + 7);
 	} else if (!strcmp(arg, "--log-size")) {
-- 
1.6.4.rc3.218.gb7ac
Thomas Rast· Jul 28, 2009, 08:40 UTC · re: Thomas Rast · lore

The preceding patches made the argument to --date optional and introduced --date=normal and --no-date. Teach the bash completion about this.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 contrib/completion/git-completion.bash |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Show changes to contrib/completion/git-completion.bash +2 −2
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 745b5fb..4ddeacf 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1143,7 +1143,7 @@ __git_log_shortlog_options="
 "
 
 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
-__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
+__git_log_date_formats="relative iso8601 rfc2822 short local default raw normal"
 
 _git_log ()
 {
@@ -1178,7 +1178,7 @@ _git_log ()
 			--root --topo-order --date-order --reverse
 			--follow --full-diff
 			--abbrev-commit --abbrev=
-			--relative-date --date=
+			--relative-date --date= --date --no-date
 			--pretty= --format= --oneline
 			--cherry-pick
 			--graph
-- 
1.6.4.rc3.218.gb7ac
Johannes Schindelin· Jul 28, 2009, 10:49 UTC · re: Thomas Rast · lore

Re: [PATCH 1/3] log: Show reflog date with --date=normal

Hi,
On Tue, 28 Jul 2009, Thomas Rast wrote:
> This means that 'git log -g --date=normal' shows the date, whereas 'git 
> log -g --date=default' shows the reflog entry number.

I find this highly unintuitive, sorry. I'd prefer it if it showed the date whenever I specify a date format. And I'd prefer not to have a distinction between "default" and "normal".

Sorry, Dscho

Johannes Schindelin· Jul 28, 2009, 10:51 UTC · re: Johannes Schindelin · lore

Re: [PATCH 1/3] log: Show reflog date with --date=normal

Hi,
On Tue, 28 Jul 2009, Johannes Schindelin wrote:
> And I'd prefer not to have a distinction between "default" and "normal".
IOW I like the DATE_UNSPECIFIED idea (that we talked about on IRC) better.

Ciao, Dscho

Thomas Rast· Jul 28, 2009, 11:53 UTC · re: Johannes Schindelin · lore

Re: [PATCH 1/3] log: Show reflog date with --date=normal

Johannes Schindelin wrote:
Show 9 quoted lines
> Hi,
> 
> On Tue, 28 Jul 2009, Thomas Rast wrote:
> 
> > This means that 'git log -g --date=normal' shows the date, whereas 'git 
> > log -g --date=default' shows the reflog entry number.
> 
> I find this highly unintuitive, sorry.  I'd prefer it if it showed the 
> date whenever I specify a date format.

So you'd rather have a toggle --[no-]reflog-date? Which would make a lot of sense, but probably not be backwards compatible in the sense that log.date suddenly stops affecting the reflog date display.

> And I'd prefer not to have a distinction between "default" and
> "normal".

I actually had to change that because I wanted to allow the user to override the log.date config. Saying --date=unspecified doesn't make a lot of sense :-)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Johannes Schindelin· Jul 28, 2009, 12:31 UTC · re: Thomas Rast · lore

Re: [PATCH 1/3] log: Show reflog date with --date=normal

Hi,
On Tue, 28 Jul 2009, Thomas Rast wrote:
Show 13 quoted lines
> Johannes Schindelin wrote:
> 
> > On Tue, 28 Jul 2009, Thomas Rast wrote:
> > 
> > > This means that 'git log -g --date=normal' shows the date, whereas 
> > > 'git log -g --date=default' shows the reflog entry number.
> > 
> > I find this highly unintuitive, sorry.  I'd prefer it if it showed the 
> > date whenever I specify a date format.
> 
> So you'd rather have a toggle --[no-]reflog-date?  Which would make a
> lot of sense, but probably not be backwards compatible in the sense
> that log.date suddenly stops affecting the reflog date display.

No, I do not see any sense in doing this kind of sophistication. If I ask for a date format, it should show me the dates. If I don't ask for a date format, it should show me the reflog number.

Inspecting reflogs is an interactive task, and I do not think that this justifies the complications you suggested. I can _easily_ say "git log -g" and then "git show --date=relative <commit>". Not that I _ever_ needed such a thing.

Show 6 quoted lines
> > And I'd prefer not to have a distinction between "default" and 
> > "normal".
> 
> I actually had to change that because I wanted to allow the user to 
> override the log.date config.  Saying --date=unspecified doesn't make a 
> lot of sense :-)

And what exactly does "--no-date" mean? Does it not say _exactly_ what "--date=unspecified" would _intuitively_ mean?

I am getting more and more the feeling that this patch series is in search of a problem it can solve.

Ciao, Dscho

Thomas Rast· Jul 28, 2009, 13:11 UTC · re: Johannes Schindelin · lore

Re: [PATCH 1/3] log: Show reflog date with --date=normal

Johannes Schindelin wrote:
Show 5 quoted lines
> 
> Inspecting reflogs is an interactive task, and I do not think that this 
> justifies the complications you suggested.  I can _easily_ say "git log 
> -g" and then "git show --date=relative <commit>".  Not that I _ever_ 
> needed such a thing.

That's something entirely different. This series is about the date of *reflog entries*; the git-show will give you the dates associated with the *commit*. The latter act naturally w.r.t. --date and are of no concern to this discussion (other than not breaking them of course).

The reflog entries, OTOH, show numbers instead in "default" date mode, leading people to do things like

  git reflog show HEAD@{now}
  git reflog --date=local

to see the reflog with dates instead of numbers. (AFAICT 'reflog' in this usage is equivalent to 'log -g --oneline' which is even more typing, so I'm usually assuming 'reflog'.)

So the discussion on IRC was about making a shorthand like --date that triggers display of the reflog dates. This much can be solved by the DATE_UNSPECIFIED value alone.

I just wasn't happy to leave it at that because that means people who do set log.date now always get dates instead of numbers in the reflog.

> And what exactly does "--no-date" mean?  Does it not say _exactly_ what 
> "--date=unspecified" would _intuitively_ mean?

Maybe to someone who knows the implementation details. To a user, specifying --date=unspecified is probably a contradiction in terms, and even if not, it does not show the date in some unspecified format -- it hides it (again, for reflog dates).

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Johannes Schindelin· Jul 28, 2009, 13:27 UTC · re: Thomas Rast · lore

Re: [PATCH 1/3] log: Show reflog date with --date=normal

Hi,
On Tue, 28 Jul 2009, Thomas Rast wrote:
Show 8 quoted lines
> Johannes Schindelin wrote:
> > 
> > Inspecting reflogs is an interactive task, and I do not think that 
> > this justifies the complications you suggested.  I can _easily_ say 
> > "git log -g" and then "git show --date=relative <commit>".  Not that I 
> > _ever_ needed such a thing.
> 
> That's something entirely different.

No, it's not. The '--date=<format>' option was always about the commit dates. It was just DWIMed in the context of '--reflog' to mean "show me the dates in the reflogs, too".

As such, I think having '--no-date' switch that DWIM off (and reverting to default date format for the commit dates) is perfectly acceptable and consistent.

Having DATE_NORMAL and DATE_DEFAULT do exactly the same thing -- except in the presence of '--reflog' -- is nothing I want to see in Git. It is inconsistent, unintuitive and confusing.

I could live with switching off the DWIMery and introducing '--reflog-date=<format', though but the whole point of our IRC discussion was to make it less painful to switch on the date-based reflogs, no?

Now, it often happened that Junio just ignored such comments of mine, and I had to live with the consequences. I just hope it does not happen here.

Ciao, Dscho

Junio C Hamano· Jul 28, 2009, 17:05 UTC · re: Thomas Rast · lore

Re: [PATCH 1/3] log: Show reflog date with --date=normal

Thomas Rast <trast@student.ethz.ch> writes:
> The reflog case special-cases --date=default (internally DATE_NORMAL)
> to show the entry number instead of a date.  This means it is
> impossible to show the default date format for the reflog entries.
Isn't it the other way around?  Traditionally you wrote
    $ git show -g @{0}
    $ git show -g @{now}

to explicitly ask for either time or number, but without @{which}, the presense of --date=<foo> for some unknown reason declares that you want time for reflogs, too. I personally think that is an insane behaviour, but that is probably already stuck in people's fingers.

    $ git show -g --date=short master
    $ git show -g --date=short master@{0}
    $ git show -g --date=short master@{now}
    
I think what is broken, if anything, is the second case (i.e. with --date,
you cannot even ask for entry numbers).
You can get times in default date formats just fine.

← back to recent threads