cherry-pick: do not expect file arguments

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed Apr 14, 2012 at 21:04 UTC 6d5b93f29f5362b9b84954d87684705227984f9e
3 files changed +19 -11
builtin/revert.c
+4 -1
@@ -181,12 +181,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
181 if (opts->subcommand != REPLAY_NONE) {
182 opts->revs = NULL;
183 } else {
184 + struct setup_revision_opt s_r_opt;
185 opts->revs = xmalloc(sizeof(*opts->revs));
186 init_revisions(opts->revs, NULL);
187 opts->revs->no_walk = 1;
188 if (argc < 2)
189 usage_with_options(usage_str, options);
189 - argc = setup_revisions(argc, argv, opts->revs, NULL);
190 + memset(&s_r_opt, 0, sizeof(s_r_opt));
191 + s_r_opt.assume_dashdash = 1;
192 + argc = setup_revisions(argc, argv, opts->revs, &s_r_opt);
193 }
194
195 if (argc > 1)
revision.c
+14 -10
@@ -1715,17 +1715,21 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
1715 submodule = opt->submodule;
1716
1717 /* First, search for "--" */
1718 - seen_dashdash = 0;
1719 - for (i = 1; i < argc; i++) {
1720 - const char *arg = argv[i];
1721 - if (strcmp(arg, "--"))
1722 - continue;
1723 - argv[i] = NULL;
1724 - argc = i;
1725 - if (argv[i + 1])
1726 - append_prune_data(&prune_data, argv + i + 1);
1718 + if (opt && opt->assume_dashdash) {
1719 seen_dashdash = 1;
1728 - break;
1720 + } else {
1721 + seen_dashdash = 0;
1722 + for (i = 1; i < argc; i++) {
1723 + const char *arg = argv[i];
1724 + if (strcmp(arg, "--"))
1725 + continue;
1726 + argv[i] = NULL;
1727 + argc = i;
1728 + if (argv[i + 1])
1729 + append_prune_data(&prune_data, argv + i + 1);
1730 + seen_dashdash = 1;
1731 + break;
1732 + }
1733 }
1734
1735 /* Second, deal with arguments and options */
revision.h
+1
@@ -183,6 +183,7 @@ struct setup_revision_opt {
183 const char *def;
184 void (*tweak)(struct rev_info *, struct setup_revision_opt *);
185 const char *submodule;
186 + int assume_dashdash;
187 };
188
189 extern void init_revisions(struct rev_info *revs, const char *prefix);