@matheusbsbs / matheus-bagliano / commits / 32962c9bd5
Fork 0

revision: introduce setup_revision_opt

So far the last parameter to setup_revisions() was to specify the default ref when the command line did not give any (typically "HEAD"). This changes it to take a pointer to a structure so that we can add other information without touching too many codepaths in later patches. There is no functionality change. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 8, 2010 at 22:58 UTC 32962c9bd5149005b163dff230670872eb99286a
5 files changed +44 -16
builtin-log.c
+22 -8
@@ -32,7 +32,7 @@ static const char * const builtin_log_usage =
32 " or: git show [options] <object>...";
33
34 static void cmd_log_init(int argc, const char **argv, const char *prefix,
35 - struct rev_info *rev)
35 + struct rev_info *rev, struct setup_revision_opt *opt)
36 {
37 int i;
38 int decoration_style = 0;
@@ -56,7 +56,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
56 */
57 if (argc == 2 && !strcmp(argv[1], "-h"))
58 usage(builtin_log_usage);
59 - argc = setup_revisions(argc, argv, rev, "HEAD");
59 + argc = setup_revisions(argc, argv, rev, opt);
60
61 if (!rev->show_notes_given && !rev->pretty_given)
62 rev->show_notes = 1;
@@ -262,6 +262,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
262 int cmd_whatchanged(int argc, const char **argv, const char *prefix)
263 {
264 struct rev_info rev;
265 + struct setup_revision_opt opt;
266
267 git_config(git_log_config, NULL);
268
@@ -271,7 +272,9 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
272 init_revisions(&rev, prefix);
273 rev.diff = 1;
274 rev.simplify_history = 0;
274 - cmd_log_init(argc, argv, prefix, &rev);
275 + memset(&opt, 0, sizeof(opt));
276 + opt.def = "HEAD";
277 + cmd_log_init(argc, argv, prefix, &rev, &opt);
278 if (!rev.diffopt.output_format)
279 rev.diffopt.output_format = DIFF_FORMAT_RAW;
280 return cmd_log_walk(&rev);
@@ -328,6 +331,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
331 {
332 struct rev_info rev;
333 struct object_array_entry *objects;
334 + struct setup_revision_opt opt;
335 int i, count, ret = 0;
336
337 git_config(git_log_config, NULL);
@@ -342,7 +346,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
346 rev.always_show_header = 1;
347 rev.ignore_merges = 0;
348 rev.no_walk = 1;
345 - cmd_log_init(argc, argv, prefix, &rev);
349 + memset(&opt, 0, sizeof(opt));
350 + opt.def = "HEAD";
351 + cmd_log_init(argc, argv, prefix, &rev, &opt);
352
353 count = rev.pending.nr;
354 objects = rev.pending.objects;
@@ -405,6 +411,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
411 int cmd_log_reflog(int argc, const char **argv, const char *prefix)
412 {
413 struct rev_info rev;
414 + struct setup_revision_opt opt;
415
416 git_config(git_log_config, NULL);
417
@@ -415,7 +422,9 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
422 init_reflog_walk(&rev.reflog_info);
423 rev.abbrev_commit = 1;
424 rev.verbose_header = 1;
418 - cmd_log_init(argc, argv, prefix, &rev);
425 + memset(&opt, 0, sizeof(opt));
426 + opt.def = "HEAD";
427 + cmd_log_init(argc, argv, prefix, &rev, &opt);
428
429 /*
430 * This means that we override whatever commit format the user gave
@@ -438,6 +447,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
447 int cmd_log(int argc, const char **argv, const char *prefix)
448 {
449 struct rev_info rev;
450 + struct setup_revision_opt opt;
451
452 git_config(git_log_config, NULL);
453
@@ -446,7 +456,9 @@ int cmd_log(int argc, const char **argv, const char *prefix)
456
457 init_revisions(&rev, prefix);
458 rev.always_show_header = 1;
449 - cmd_log_init(argc, argv, prefix, &rev);
459 + memset(&opt, 0, sizeof(opt));
460 + opt.def = "HEAD";
461 + cmd_log_init(argc, argv, prefix, &rev, &opt);
462 return cmd_log_walk(&rev);
463 }
464
@@ -887,6 +899,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
899 struct commit *commit;
900 struct commit **list = NULL;
901 struct rev_info rev;
902 + struct setup_revision_opt s_r_opt;
903 int nr = 0, total, i;
904 int use_stdout = 0;
905 int start_number = -1;
@@ -964,8 +977,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
977 rev.combine_merges = 0;
978 rev.ignore_merges = 1;
979 DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
967 -
980 rev.subject_prefix = fmt_patch_subject_prefix;
981 + memset(&s_r_opt, 0, sizeof(s_r_opt));
982 + s_r_opt.def = "HEAD";
983
984 if (default_attach) {
985 rev.mime_boundary = default_attach;
@@ -1037,7 +1051,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1051 if (keep_subject && subject_prefix)
1052 die ("--subject-prefix and -k are mutually exclusive.");
1053
1040 - argc = setup_revisions(argc, argv, &rev, "HEAD");
1054 + argc = setup_revisions(argc, argv, &rev, &s_r_opt);
1055 if (argc > 1)
1056 die ("unrecognized argument: %s", argv[1]);
1057
diff-lib.c
+4 -1
@@ -510,9 +510,12 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
510 int index_differs_from(const char *def, int diff_flags)
511 {
512 struct rev_info rev;
513 + struct setup_revision_opt opt;
514
515 init_revisions(&rev, NULL);
515 - setup_revisions(0, NULL, &rev, def);
516 + memset(&opt, 0, sizeof(opt));
517 + opt.def = def;
518 + setup_revisions(0, NULL, &rev, &opt);
519 DIFF_OPT_SET(&rev.diffopt, QUICK);
520 DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
521 rev.diffopt.flags |= diff_flags;
revision.c
+2 -2
@@ -1328,7 +1328,7 @@ static void append_prune_data(const char ***prune_data, const char **av)
1328 * Returns the number of arguments left that weren't recognized
1329 * (which are also moved to the head of the argument list)
1330 */
1331 -int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def)
1331 +int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt)
1332 {
1333 int i, flags, left, seen_dashdash, read_from_stdin;
1334 const char **prune_data = NULL;
@@ -1462,7 +1462,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1462 revs->prune_data = get_pathspec(revs->prefix, prune_data);
1463
1464 if (revs->def == NULL)
1465 - revs->def = def;
1465 + revs->def = opt ? opt->def : NULL;
1466 if (revs->show_merge)
1467 prepare_show_merge(revs);
1468 if (revs->def && !revs->pending.nr) {
revision.h
+5 -1
@@ -137,8 +137,12 @@ struct rev_info {
137 typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
138 extern volatile show_early_output_fn_t show_early_output;
139
140 +struct setup_revision_opt {
141 + const char *def;
142 +};
143 +
144 extern void init_revisions(struct rev_info *revs, const char *prefix);
141 -extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);
145 +extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *);
146 extern void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
147 const struct option *options,
148 const char * const usagestr[]);
wt-status.c
+11 -4
@@ -290,10 +290,13 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
290 static void wt_status_collect_changes_index(struct wt_status *s)
291 {
292 struct rev_info rev;
293 + struct setup_revision_opt opt;
294
295 init_revisions(&rev, NULL);
295 - setup_revisions(0, NULL, &rev,
296 - s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
296 + memset(&opt, 0, sizeof(opt));
297 + opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
298 + setup_revisions(0, NULL, &rev, &opt);
299 +
300 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
301 rev.diffopt.format_callback = wt_status_collect_updated_cb;
302 rev.diffopt.format_callback_data = s;
@@ -512,11 +515,15 @@ static void wt_status_print_untracked(struct wt_status *s)
515 static void wt_status_print_verbose(struct wt_status *s)
516 {
517 struct rev_info rev;
518 + struct setup_revision_opt opt;
519
520 init_revisions(&rev, NULL);
521 DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
518 - setup_revisions(0, NULL, &rev,
519 - s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
522 +
523 + memset(&opt, 0, sizeof(opt));
524 + opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
525 + setup_revisions(0, NULL, &rev, &opt);
526 +
527 rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
528 rev.diffopt.detect_rename = 1;
529 rev.diffopt.file = s->fp;