threads / patch / 23524

patch, 2 partsreflog: remove 'show' from 'expire's usage string

Subject: [PATCH 2/2] reflog: remove 'show' from 'expire's usage string

## tl;dr

6 messages between Apr 19, 2010 and Apr 22, 2010. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

SZEDER Gábor· Apr 19, 2010, 09:52 UTC · lore

[PATCH 1/2] reflog: make the 'show' subcommand really the default

Since the introduction of the 'show' subcommand in cf39f54e (git reflog show, 2007-02-08), 'git reflog's documentation states that in the absence of any subcommands 'show' is the default. Although 'git reflog <log-options>' works as described, i.e. it defaults to 'show', the command 'git reflog <ref>' errors out showing the usage instead of showing the specified ref's reflog. Fix this by treating an unknown subcommand as a ref for 'show'.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 builtin/reflog.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
Show changes to builtin/reflog.c +1 −2
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 64e45bd..d4d4409 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -712,6 +712,5 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
 	if (!strcmp(argv[1], "delete"))
 		return cmd_reflog_delete(argc - 1, argv + 1, prefix);
 
-	/* Not a recognized reflog command..*/
-	usage(reflog_usage);
+	return cmd_log_reflog(argc, argv, prefix);
 }
-- 
1.7.1.rc1.43.gf0841
SZEDER Gábor· Apr 19, 2010, 09:52 UTC · re: SZEDER Gábor · lore

Most of 'expire's options are not recognized by the 'show' subcommand, hence it errors out.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 builtin/reflog.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to builtin/reflog.c +1 −1
diff --git a/builtin/reflog.c b/builtin/reflog.c
index d4d4409..fe8b36d 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -13,7 +13,7 @@
  */
 
 static const char reflog_expire_usage[] =
-"git reflog (show|expire) [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
+"git reflog expire [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
 static const char reflog_delete_usage[] =
 "git reflog delete [--verbose] [--dry-run] [--rewrite] [--updateref] <refs>...";
 
-- 
1.7.1.rc1.43.gf0841
Junio C Hamano· Apr 20, 2010, 00:46 UTC · re: SZEDER Gábor · lore

Re: [PATCH 1/2] reflog: make the 'show' subcommand really the default

SZEDER Gábor <szeder@ira.uka.de> writes:
Show 11 quoted lines
> diff --git a/builtin/reflog.c b/builtin/reflog.c
> index 64e45bd..d4d4409 100644
> --- a/builtin/reflog.c
> +++ b/builtin/reflog.c
> @@ -712,6 +712,5 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
>  	if (!strcmp(argv[1], "delete"))
>  		return cmd_reflog_delete(argc - 1, argv + 1, prefix);
>  
> -	/* Not a recognized reflog command..*/
> -	usage(reflog_usage);
> +	return cmd_log_reflog(argc, argv, prefix);
I am not convinced that this is a good change.

It may be that show/expire/delete happens to be the _only_ subcommands today, but if we had this patch, the command will change the behaviour when we add a new subcommand (the name of that subcommand may happen to be also a refname).

I'd rather see a fix for the documentation.
Your [PATCH 2/2] looks very sane, though.
Thanks.
Jeff King· Apr 20, 2010, 11:37 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/2] reflog: make the 'show' subcommand really the default

On Mon, Apr 19, 2010 at 05:46:02PM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> SZEDER Gábor <szeder@ira.uka.de> writes:
> 
> > diff --git a/builtin/reflog.c b/builtin/reflog.c
> > index 64e45bd..d4d4409 100644
> > --- a/builtin/reflog.c
> > +++ b/builtin/reflog.c
> > @@ -712,6 +712,5 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
> >  	if (!strcmp(argv[1], "delete"))
> >  		return cmd_reflog_delete(argc - 1, argv + 1, prefix);
> >  
> > -	/* Not a recognized reflog command..*/
> > -	usage(reflog_usage);
> > +	return cmd_log_reflog(argc, argv, prefix);
> 
> I am not convinced that this is a good change.
> 
> It may be that show/expire/delete happens to be the _only_ subcommands
> today, but if we had this patch, the command will change the behaviour
> when we add a new subcommand (the name of that subcommand may happen to be
> also a refname).

I don't think it is that big a deal. Scripts should always use the explicit "git reflog show <ref>" form, which will remain safe. "git reflog <ref>" is handy for humans.

That being said, we tried this same experiment with "git stash [show] <msg>" and ended up rejecting it. However, the main complaint with that was the failure mode for typos. Typing "git stash sohw" would make a new stash. In this case, typing "git reflog exipre" would get you:

  fatal: ambiguous argument 'exipre': unknown revision or path not in
  the working tree.
  Use '--' to separate paths from revisions

and you would repeat the command with the typo fixed, which is perhaps not as bad. And unlike stash, "show" is really the dominant command (I don't think I have ever manually used 'delete' or 'expire'), so it is more likely to be right than not.

The current behavior is also weirdly inconsistent:
  git reflog ;# works, shows HEAD
  git reflog -p ;# works, shows HEAD with -p
  git reflog -p foo ;# works, shows foo with -p
  git reflog foo ;# does not work

I can see allowing the first two, but the fact that the third works and the fourth doesn't seems odd to me.

So I don't think the patch is a huge mistake (at least not as huge as the stash one). However, I personally "git log -g [--oneline]" to be much easier to remember to use and to type.

-Peff
SZEDER Gábor· Apr 22, 2010, 13:57 UTC · re: Jeff King · lore

Re: [PATCH 1/2] reflog: make the 'show' subcommand really the default

Hi,
On Tue, Apr 20, 2010 at 07:37:36AM -0400, Jeff King wrote:
Show 17 quoted lines
> On Mon, Apr 19, 2010 at 05:46:02PM -0700, Junio C Hamano wrote:
> 
> > I am not convinced that this is a good change.
> > 
> > It may be that show/expire/delete happens to be the _only_ subcommands
> > today, but if we had this patch, the command will change the behaviour
> > when we add a new subcommand (the name of that subcommand may happen to be
> > also a refname).
> 
> I don't think it is that big a deal. Scripts should always use the
> explicit "git reflog show <ref>" form, which will remain safe. "git
> reflog <ref>" is handy for humans.
> 
> That being said, we tried this same experiment with "git stash [show]
> <msg>" and ended up rejecting it. However, the main complaint with that
> was the failure mode for typos. Typing "git stash sohw" would make a new
> stash.
I think you meant "git stash [save] <msg>" here, right?
http://thread.gmane.org/gmane.comp.version-control.git/63566/focus=63645
Show 10 quoted lines
> In this case, typing "git reflog exipre" would get you:
> 
>   fatal: ambiguous argument 'exipre': unknown revision or path not in
>   the working tree.
>   Use '--' to separate paths from revisions
> 
> and you would repeat the command with the typo fixed, which is perhaps
> not as bad. And unlike stash, "show" is really the dominant command (I
> don't think I have ever manually used 'delete' or 'expire'), so it is
> more likely to be right than not.

If I understood Junio correctly, he is concerned about a different case.

With my patch "git reflog foo" would show foo's reflog, assuming there is a branch named "foo". This is what people would expect according to the documentation. However, once we implement the subcommand "foo", "git reflog foo" will no longer print foo's reflog but instead will perform whatever the subcommand "foo" is supposed to do by default, which might be difficult to recover from.

Show 9 quoted lines
> The current behavior is also weirdly inconsistent:
> 
>   git reflog ;# works, shows HEAD
>   git reflog -p ;# works, shows HEAD with -p
>   git reflog -p foo ;# works, shows foo with -p
>   git reflog foo ;# does not work
> 
> I can see allowing the first two, but the fact that the third works and
> the fourth doesn't seems odd to me.

Indeed. I tried to whip up a patch to fix the documentation to match the current behaviour, but my first attempt failed because of these inconsistencies.

> However, I personally "git log -g [--oneline]" to be
> much easier to remember to use and to type.

Just as sidenote: I rarely use reflog, but then for me it's easier to remember to "reflog" than "-g". But even then I never remember "show" for the first time, that's why I wrote this patch.

Best, Gábor

Jeff King· Apr 22, 2010, 14:40 UTC · re: SZEDER Gábor · lore

Re: [PATCH 1/2] reflog: make the 'show' subcommand really the default

On Thu, Apr 22, 2010 at 03:57:31PM +0200, SZEDER Gábor wrote:
Show 8 quoted lines
> > That being said, we tried this same experiment with "git stash [show]
> > <msg>" and ended up rejecting it. However, the main complaint with that
> > was the failure mode for typos. Typing "git stash sohw" would make a new
> > stash.
> 
> I think you meant "git stash [save] <msg>" here, right?
> 
> http://thread.gmane.org/gmane.comp.version-control.git/63566/focus=63645
Er, yeah, that is what I meant. Sorry, thinko on my part.
Show 20 quoted lines
> > In this case, typing "git reflog exipre" would get you:
> > 
> >   fatal: ambiguous argument 'exipre': unknown revision or path not in
> >   the working tree.
> >   Use '--' to separate paths from revisions
> > 
> > and you would repeat the command with the typo fixed, which is perhaps
> > not as bad. And unlike stash, "show" is really the dominant command (I
> > don't think I have ever manually used 'delete' or 'expire'), so it is
> > more likely to be right than not.
> 
> If I understood Junio correctly, he is concerned about a different
> case.
> 
> With my patch "git reflog foo" would show foo's reflog, assuming there
> is a branch named "foo".  This is what people would expect according
> to the documentation.  However, once we implement the subcommand
> "foo", "git reflog foo" will no longer print foo's reflog but instead
> will perform whatever the subcommand "foo" is supposed to do by
> default, which might be difficult to recover from.

Right, what you quoted from me was not Junio's concern. But I argued against Junio's concern earlier in the mail. Basically, it is a corner case. _If_ we add a new command to "git reflog", and _if_ that command is the same as the name of your ref, you must stop using the short form for that ref, and instead use "git reflog show $ref".

So for things like scripts that don't know what $ref will be, and want to be on the safe side, they should continue to use the explicit "git reflog show $ref" form. But there is no reason that humans typing a command need to be bound by that restriction when it is unlikely to happen (and even if it did, they would recover from it easily).

Personally, I don't care either way whether the documentation is updated to match the behavior of vice versa. But I just don't see what your original patch did as very harmful, and I can see how it would be helpful (on the few occassions when I did use "git reflog show", I first typed it forgetting the "show").

-Peff

← back to recent threads