threads / patch / 30244

patchcherry-pick: do not expect file arguments

Subject: [PATCH] cherry-pick: do not expect file arguments

## tl;dr

2 messages between Apr 14, 2012 and Apr 14, 2012. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Clemens Buchacher· Apr 14, 2012, 19:04 UTC · lore

If a commit-ish passed to cherry-pick or revert happens to have a file of the same name, git complains that the argument is ambiguous and advises to use '--'. To make things worse, the '--' argument is removed by parse_options, und so passing '--' has no effect.

Instead, always interpret cherry-pick/revert arguments as revisions.
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
 builtin/revert.c |    5 ++++-
 revision.c       |   24 ++++++++++++++----------
 revision.h       |    1 +
 3 files changed, 19 insertions(+), 11 deletions(-)
Show changes to 3 files +19 −11

builtin/revert.c, revision.c, revision.h

diff --git a/builtin/revert.c b/builtin/revert.c
index e6840f2..92f3fa5 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -181,12 +181,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 	if (opts->subcommand != REPLAY_NONE) {
 		opts->revs = NULL;
 	} else {
+		struct setup_revision_opt s_r_opt;
 		opts->revs = xmalloc(sizeof(*opts->revs));
 		init_revisions(opts->revs, NULL);
 		opts->revs->no_walk = 1;
 		if (argc < 2)
 			usage_with_options(usage_str, options);
-		argc = setup_revisions(argc, argv, opts->revs, NULL);
+		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);
 	}
 
 	if (argc > 1)
diff --git a/revision.c b/revision.c
index b3554ed..9a0d9c7 100644
--- a/revision.c
+++ b/revision.c
@@ -1715,17 +1715,21 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		submodule = opt->submodule;
 
 	/* First, search for "--" */
-	seen_dashdash = 0;
-	for (i = 1; i < argc; i++) {
-		const char *arg = argv[i];
-		if (strcmp(arg, "--"))
-			continue;
-		argv[i] = NULL;
-		argc = i;
-		if (argv[i + 1])
-			append_prune_data(&prune_data, argv + i + 1);
+	if (opt && opt->assume_dashdash) {
 		seen_dashdash = 1;
-		break;
+	} else {
+		seen_dashdash = 0;
+		for (i = 1; i < argc; i++) {
+			const char *arg = argv[i];
+			if (strcmp(arg, "--"))
+				continue;
+			argv[i] = NULL;
+			argc = i;
+			if (argv[i + 1])
+				append_prune_data(&prune_data, argv + i + 1);
+			seen_dashdash = 1;
+			break;
+		}
 	}
 
 	/* Second, deal with arguments and options */
diff --git a/revision.h b/revision.h
index b8e9223..1a08384 100644
--- a/revision.h
+++ b/revision.h
@@ -183,6 +183,7 @@ struct setup_revision_opt {
 	const char *def;
 	void (*tweak)(struct rev_info *, struct setup_revision_opt *);
 	const char *submodule;
+	int assume_dashdash;
 };
 
 extern void init_revisions(struct rev_info *revs, const char *prefix);
-- 
1.7.9.6
Junio C Hamano· Apr 14, 2012, 23:48 UTC · re: Clemens Buchacher · lore

Re: [PATCH] cherry-pick: do not expect file arguments

Clemens Buchacher <drizzd@aon.at> writes:
> If a commit-ish passed to cherry-pick or revert happens to have a file
> of the same name, git complains that the argument is ambiguous and
> advises to use '--'. To make things worse, the '--' argument is removed
> by parse_options, und so passing '--' has no effect.
Thanks.

I can see how this patch is one way to solve it, but if the command knows that it is feedling only revs and no pathspecs, isn't the caller the one that is responsible for adding "--" to the argv_array it is passing to setup_revisions()?

With s/assume_dashdash/no_pathspecs/, the damage to the revision traversal machinery does not look _too_ bad, but I am not convinced (yet) that this patch is the best way to solve the issue.

Show 78 quoted lines
> Instead, always interpret cherry-pick/revert arguments as revisions.
>
> Signed-off-by: Clemens Buchacher <drizzd@aon.at>
> ---
>  builtin/revert.c |    5 ++++-
>  revision.c       |   24 ++++++++++++++----------
>  revision.h       |    1 +
>  3 files changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/builtin/revert.c b/builtin/revert.c
> index e6840f2..92f3fa5 100644
> --- a/builtin/revert.c
> +++ b/builtin/revert.c
> @@ -181,12 +181,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
>  	if (opts->subcommand != REPLAY_NONE) {
>  		opts->revs = NULL;
>  	} else {
> +		struct setup_revision_opt s_r_opt;
>  		opts->revs = xmalloc(sizeof(*opts->revs));
>  		init_revisions(opts->revs, NULL);
>  		opts->revs->no_walk = 1;
>  		if (argc < 2)
>  			usage_with_options(usage_str, options);
> -		argc = setup_revisions(argc, argv, opts->revs, NULL);
> +		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);
>  	}
>  
>  	if (argc > 1)
> diff --git a/revision.c b/revision.c
> index b3554ed..9a0d9c7 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -1715,17 +1715,21 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  		submodule = opt->submodule;
>  
>  	/* First, search for "--" */
> -	seen_dashdash = 0;
> -	for (i = 1; i < argc; i++) {
> -		const char *arg = argv[i];
> -		if (strcmp(arg, "--"))
> -			continue;
> -		argv[i] = NULL;
> -		argc = i;
> -		if (argv[i + 1])
> -			append_prune_data(&prune_data, argv + i + 1);
> +	if (opt && opt->assume_dashdash) {
>  		seen_dashdash = 1;
> -		break;
> +	} else {
> +		seen_dashdash = 0;
> +		for (i = 1; i < argc; i++) {
> +			const char *arg = argv[i];
> +			if (strcmp(arg, "--"))
> +				continue;
> +			argv[i] = NULL;
> +			argc = i;
> +			if (argv[i + 1])
> +				append_prune_data(&prune_data, argv + i + 1);
> +			seen_dashdash = 1;
> +			break;
> +		}
>  	}
>  
>  	/* Second, deal with arguments and options */
> diff --git a/revision.h b/revision.h
> index b8e9223..1a08384 100644
> --- a/revision.h
> +++ b/revision.h
> @@ -183,6 +183,7 @@ struct setup_revision_opt {
>  	const char *def;
>  	void (*tweak)(struct rev_info *, struct setup_revision_opt *);
>  	const char *submodule;
> +	int assume_dashdash;
>  };
>  
>  extern void init_revisions(struct rev_info *revs, const char *prefix);

← back to recent threads