revision.c: the "log" family, except for "show", takes committish

Add a field to setup_revision_opt structure and allow these callers to tell the setup_revisions command parsing machinery that short SHA1 it encounters are meant to name committish. This step does not go all the way to connect the setup_revisions() to sha1_name.c yet. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 2, 2012 at 12:43 UTC d5f6b1d756a29255efedee3cb6e8526aedcfeb00
4 files changed +15 -3
builtin/log.c
+3
@@ -363,6 +363,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
363 rev.simplify_history = 0;
364 memset(&opt, 0, sizeof(opt));
365 opt.def = "HEAD";
366 + opt.revarg_opt = REVARG_COMMITTISH;
367 cmd_log_init(argc, argv, prefix, &rev, &opt);
368 if (!rev.diffopt.output_format)
369 rev.diffopt.output_format = DIFF_FORMAT_RAW;
@@ -543,6 +544,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
544 rev.always_show_header = 1;
545 memset(&opt, 0, sizeof(opt));
546 opt.def = "HEAD";
547 + opt.revarg_opt = REVARG_COMMITTISH;
548 cmd_log_init(argc, argv, prefix, &rev, &opt);
549 return cmd_log_walk(&rev);
550 }
@@ -1144,6 +1146,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1146 rev.subject_prefix = fmt_patch_subject_prefix;
1147 memset(&s_r_opt, 0, sizeof(s_r_opt));
1148 s_r_opt.def = "HEAD";
1149 + s_r_opt.revarg_opt = REVARG_COMMITTISH;
1150
1151 if (default_attach) {
1152 rev.mime_boundary = default_attach;
revision.c
+9 -2
@@ -1102,6 +1102,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
1102 int local_flags;
1103 const char *arg = arg_;
1104 int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
1105 + unsigned get_sha1_flags = 0;
1106
1107 dotdot = strstr(arg, "..");
1108 if (dotdot) {
@@ -1179,7 +1180,11 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
1180 local_flags = UNINTERESTING;
1181 arg++;
1182 }
1182 - if (get_sha1_with_context(arg, 0, sha1, &oc))
1183 +
1184 + if (revarg_opt & REVARG_COMMITTISH)
1185 + get_sha1_flags = GET_SHA1_COMMITTISH;
1186 +
1187 + if (get_sha1_with_context(arg, get_sha1_flags, sha1, &oc))
1188 return revs->ignore_missing ? 0 : -1;
1189 if (!cant_be_filename)
1190 verify_non_filename(revs->prefix, arg);
@@ -1707,7 +1712,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
1712
1713 /* Second, deal with arguments and options */
1714 flags = 0;
1710 - revarg_opt = seen_dashdash ? REVARG_CANNOT_BE_FILENAME : 0;
1715 + revarg_opt = opt ? opt->revarg_opt : 0;
1716 + if (seen_dashdash)
1717 + revarg_opt |= REVARG_CANNOT_BE_FILENAME;
1718 read_from_stdin = 0;
1719 for (left = i = 1; i < argc; i++) {
1720 const char *arg = argv[i];
revision.h
+2
@@ -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 + unsigned revarg_opt;
187 };
188
189 extern void init_revisions(struct rev_info *revs, const char *prefix);
@@ -191,6 +192,7 @@ extern void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ct
192 const struct option *options,
193 const char * const usagestr[]);
194 #define REVARG_CANNOT_BE_FILENAME 01
195 +#define REVARG_COMMITTISH 02
196 extern int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt);
197
198 extern int prepare_revision_walk(struct rev_info *revs);
t/t1512-rev-parse-disambiguation.sh
+1 -1
@@ -117,7 +117,7 @@ test_expect_failure 'rev-parse name1..name2 takes only commit-ishes on both ends
117 git rev-parse 000000000..
118 '
119
120 -test_expect_failure 'git log takes only commit-ish' '
120 +test_expect_success 'git log takes only commit-ish' '
121 git log 000000000
122 '
123