Skip to content

Commit d5f6b1d

Browse files
committed
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 <[email protected]>
1 parent 8e676e8 commit d5f6b1d

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

builtin/log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
363363
rev.simplify_history = 0;
364364
memset(&opt, 0, sizeof(opt));
365365
opt.def = "HEAD";
366+
opt.revarg_opt = REVARG_COMMITTISH;
366367
cmd_log_init(argc, argv, prefix, &rev, &opt);
367368
if (!rev.diffopt.output_format)
368369
rev.diffopt.output_format = DIFF_FORMAT_RAW;
@@ -543,6 +544,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
543544
rev.always_show_header = 1;
544545
memset(&opt, 0, sizeof(opt));
545546
opt.def = "HEAD";
547+
opt.revarg_opt = REVARG_COMMITTISH;
546548
cmd_log_init(argc, argv, prefix, &rev, &opt);
547549
return cmd_log_walk(&rev);
548550
}
@@ -1144,6 +1146,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
11441146
rev.subject_prefix = fmt_patch_subject_prefix;
11451147
memset(&s_r_opt, 0, sizeof(s_r_opt));
11461148
s_r_opt.def = "HEAD";
1149+
s_r_opt.revarg_opt = REVARG_COMMITTISH;
11471150

11481151
if (default_attach) {
11491152
rev.mime_boundary = default_attach;

revision.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
11021102
int local_flags;
11031103
const char *arg = arg_;
11041104
int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
1105+
unsigned get_sha1_flags = 0;
11051106

11061107
dotdot = strstr(arg, "..");
11071108
if (dotdot) {
@@ -1179,7 +1180,11 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
11791180
local_flags = UNINTERESTING;
11801181
arg++;
11811182
}
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))
11831188
return revs->ignore_missing ? 0 : -1;
11841189
if (!cant_be_filename)
11851190
verify_non_filename(revs->prefix, arg);
@@ -1707,7 +1712,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
17071712

17081713
/* Second, deal with arguments and options */
17091714
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;
17111718
read_from_stdin = 0;
17121719
for (left = i = 1; i < argc; i++) {
17131720
const char *arg = argv[i];

revision.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct setup_revision_opt {
183183
const char *def;
184184
void (*tweak)(struct rev_info *, struct setup_revision_opt *);
185185
const char *submodule;
186+
unsigned revarg_opt;
186187
};
187188

188189
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
191192
const struct option *options,
192193
const char * const usagestr[]);
193194
#define REVARG_CANNOT_BE_FILENAME 01
195+
#define REVARG_COMMITTISH 02
194196
extern int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt);
195197

196198
extern int prepare_revision_walk(struct rev_info *revs);

t/t1512-rev-parse-disambiguation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ test_expect_failure 'rev-parse name1..name2 takes only commit-ishes on both ends
117117
git rev-parse 000000000..
118118
'
119119

120-
test_expect_failure 'git log takes only commit-ish' '
120+
test_expect_success 'git log takes only commit-ish' '
121121
git log 000000000
122122
'
123123

0 commit comments

Comments
 (0)