Merge branch 'cb/cherry-pick-rev-path-confusion'
authorJunio C Hamano <gitster@pobox.com>
Fri, 27 Apr 2012 20:58:02 +0000 (13:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Apr 2012 20:58:02 +0000 (13:58 -0700)
The command line parser choked "git cherry-pick $name" when $name can be
both revision name and a pathname, even though $name can never be a path
in the context of the command.

The issue the patch addresses is real, but the way it is implemented felt
unnecessarily invasive a bit. It may be cleaner for this caller to add
the "--" to the end of the argv_array it passes to setup_revisions().

By Clemens Buchacher
* cb/cherry-pick-rev-path-confusion:
cherry-pick: do not expect file arguments

1  2 
builtin/revert.c
revision.c
revision.h
diff --combined builtin/revert.c
index e4ed0239ca7cbc0f33f2cf02d6287e681ca535bf,92f3fa5f57f289dbc966f5a49c7aedf2ee87e547..5462e676e2151452adae8fe5b0cb42b1a5edff31
@@@ -86,7 -86,6 +86,7 @@@ static void verify_opt_mutually_compati
                                break;
                }
        }
 +      va_end(ap);
  
        if (opt1 && opt2)
                die(_("%s: %s cannot be used with %s"), me, opt1, opt2);
@@@ -182,12 -181,15 +182,15 @@@ static void parse_args(int argc, const 
        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 --combined revision.c
index edb225d1fa2e572cacf467f1706f203ee02ddda7,9a0d9c7de2af43c7ae082a892a2a9cfd6f4b4761..e0e80f13ef12c28e7f791e4c7ca9519e3c5aecc0
@@@ -1715,17 -1715,21 +1715,21 @@@ int setup_revisions(int argc, const cha
                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 */
@@@ -2062,11 -2066,6 +2066,11 @@@ static void set_children(struct rev_inf
        }
  }
  
 +void reset_revision_walk(void)
 +{
 +      clear_object_flags(SEEN | ADDED | SHOWN);
 +}
 +
  int prepare_revision_walk(struct rev_info *revs)
  {
        int nr = revs->pending.nr;
                if (commit) {
                        if (!(commit->object.flags & SEEN)) {
                                commit->object.flags |= SEEN;
 -                              commit_list_insert_by_date(commit, &revs->commits);
 +                              commit_list_insert(commit, &revs->commits);
                        }
                }
                e++;
        }
 +      commit_list_reverse(&revs->commits);
 +      commit_list_sort_by_date(&revs->commits);
        if (!revs->leak_pending)
                free(list);
  
diff --combined revision.h
index eb87fd1e2f5d16032cb92d96c4bae9e2397f2978,1a0838473f41edad56014f63629dcb0820c9e216..863f4f64543bd9f9e830e7c9567def23e906c7d9
@@@ -183,6 -183,7 +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);
@@@ -192,7 -193,6 +193,7 @@@ extern void parse_revision_opt(struct r
                                 const char * const usagestr[]);
  extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename);
  
 +extern void reset_revision_walk(void);
  extern int prepare_revision_walk(struct rev_info *revs);
  extern struct commit *get_revision(struct rev_info *revs);
  extern char *get_revision_mark(const struct rev_info *revs, const struct commit *commit);