Skip to contentSkip to conversation

"-" and "@{-1}" on various programs

JFF Junio C Hamano 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

JFF stands for just for fun.

This is not meant to give out a model answer and is known to be incomplete, but I was wondering if it would be a better direction to allow "-" as a stand-in for "@{-1}" everywhere we allow a branch name, losing workarounds at the surface level we have for checkout, merge and revert.

The first three paths are to remove the surface workarounds that become unnecessary. The one in sha1_name.c is the central change.

The change in revision.c is to allow a single "-" to be recognized as a potential revision name (without this change, what begins with "-" is either an option or an unknown option).

So you could do things like "git reset - $path" but also things like "git log -" after switching out of a branch.

What does not work are what needs further tweaking in revision.c parser. "git checkout master && git checkout next && git log -.." should show what next has on top of master but I didn't touch the range notation so it does not work, for example.

 builtin/checkout.c |  3 ---
 builtin/merge.c    |  3 +--
 builtin/revert.c   |  2 --
 revision.c         |  2 +-
 sha1_name.c        | 57 +++++++++++++++++++++++++++++++++---------------------
 5 files changed, 37 insertions(+), 30 deletions(-)
builtin/checkout.c +0 -3
index 7e2d144..8f52a92 100644
@@ -1169,9 +1169,6 @@ static int parse_branchname_arg(int argc, const char **argv,
 	else if (dash_dash_pos >= 2)
 		die(_("only one reference expected, %d given."), dash_dash_pos);
 
-	if (!strcmp(arg, "-"))
-		arg = "@{-1}";
-
 	if (get_sha1_mb(arg, rev)) {
 		/*
 		 * Either case (3) or (4), with <something> not being
builtin/merge.c +1 -2
index 90dd5e6..569dda3 100644
@@ -1164,8 +1164,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 				argc = setup_with_upstream(&argv);
 			else
 				die(_("No commit specified and merge.defaultToUpstream not set."));
-		} else if (argc == 1 && !strcmp(argv[0], "-"))
-			argv[0] = "@{-1}";
+		}
 	}
 	if (!argc)
 		usage_with_options(builtin_merge_usage,
builtin/revert.c +0 -2
index 56a2c36..dc98b4e 100644
@@ -170,8 +170,6 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 		opts->revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED;
 		if (argc < 2)
 			usage_with_options(usage_str, options);
-		if (!strcmp(argv[1], "-"))
-			argv[1] = "@{-1}";
 		memset(&s_r_opt, 0, sizeof(s_r_opt));
 		s_r_opt.assume_dashdash = 1;
 		argc = setup_revisions(argc, argv, opts->revs, &s_r_opt);
revision.c +1 -1
index e1321d5..17709a1 100644
@@ -2195,7 +2195,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 	read_from_stdin = 0;
 	for (left = i = 1; i < argc; i++) {
 		const char *arg = argv[i];
-		if (*arg == '-') {
+		if (arg[0] == '-' && arg[1]) {
 			int opts;
 
 			opts = handle_revision_pseudo_opt(submodule,
sha1_name.c +35 -22

89 lines not on this page · raw message

#1 lore raw

Junio C Hamano venit, vidit, dixit 10.03.2015 21:20:

Quoted 23 lines

JFF stands for just for fun.

This is not meant to give out a model answer and is known to be incomplete, but I was wondering if it would be a better direction to allow "-" as a stand-in for "@{-1}" everywhere we allow a branch name, losing workarounds at the surface level we have for checkout, merge and revert.

The first three paths are to remove the surface workarounds that become unnecessary. The one in sha1_name.c is the central change.

The change in revision.c is to allow a single "-" to be recognized as a potential revision name (without this change, what begins with "-" is either an option or an unknown option).

So you could do things like "git reset - $path" but also things like "git log -" after switching out of a branch.

What does not work are what needs further tweaking in revision.c parser. "git checkout master && git checkout next && git log -.." should show what next has on top of master but I didn't touch the range notation so it does not work, for example.

Quoted 6 lines
 builtin/checkout.c |  3 ---
 builtin/merge.c    |  3 +--
 builtin/revert.c   |  2 --
 revision.c         |  2 +-
 sha1_name.c        | 57 +++++++++++++++++++++++++++++++++---------------------
 5 files changed, 37 insertions(+), 30 deletions(-)

Like it :)

It removes the special casing and makes a shorthand available systematically. I'd say it's useful even without extending it to ranges.

Michae

#2 lore raw
Quoted 15 lines · Michael J Gruber

Junio C Hamano venit, vidit, dixit 10.03.2015 21:20:

Quoted 7 lines

JFF stands for just for fun.
...
What does not work are what needs further tweaking in revision.c parser. "git checkout master && git checkout next && git log -.." should show what next has on top of master but I didn't touch the range notation so it does not work, for example.

Quoted 6 lines
 builtin/checkout.c |  3 ---
 builtin/merge.c    |  3 +--
 builtin/revert.c   |  2 --
 revision.c         |  2 +-
 sha1_name.c        | 57 +++++++++++++++++++++++++++++++++---------------------
 5 files changed, 37 insertions(+), 30 deletions(-)
Quoted 4 lines

Like it :)

It removes the special casing and makes a shorthand available systematically. I'd say it's useful even without extending it to ranges.

I wouldn't have done this if I thought it will lead to an unusable blind alley ;-) But I won't be hacking on this any further for now.

Hint hint...