Browse Source

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>
maint
Junio C Hamano 15 years ago
parent
commit
32962c9bd5
  1. 30
      builtin-log.c
  2. 5
      diff-lib.c
  3. 4
      revision.c
  4. 6
      revision.h
  5. 15
      wt-status.c

30
builtin-log.c

@ -32,7 +32,7 @@ static const char * const builtin_log_usage =
" or: git show [options] <object>..."; " or: git show [options] <object>...";


static void cmd_log_init(int argc, const char **argv, const char *prefix, static void cmd_log_init(int argc, const char **argv, const char *prefix,
struct rev_info *rev) struct rev_info *rev, struct setup_revision_opt *opt)
{ {
int i; int i;
int decoration_style = 0; int decoration_style = 0;
@ -56,7 +56,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
*/ */
if (argc == 2 && !strcmp(argv[1], "-h")) if (argc == 2 && !strcmp(argv[1], "-h"))
usage(builtin_log_usage); usage(builtin_log_usage);
argc = setup_revisions(argc, argv, rev, "HEAD"); argc = setup_revisions(argc, argv, rev, opt);


if (!rev->show_notes_given && !rev->pretty_given) if (!rev->show_notes_given && !rev->pretty_given)
rev->show_notes = 1; rev->show_notes = 1;
@ -262,6 +262,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
int cmd_whatchanged(int argc, const char **argv, const char *prefix) int cmd_whatchanged(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
struct setup_revision_opt opt;


git_config(git_log_config, NULL); git_config(git_log_config, NULL);


@ -271,7 +272,9 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
rev.diff = 1; rev.diff = 1;
rev.simplify_history = 0; rev.simplify_history = 0;
cmd_log_init(argc, argv, prefix, &rev); memset(&opt, 0, sizeof(opt));
opt.def = "HEAD";
cmd_log_init(argc, argv, prefix, &rev, &opt);
if (!rev.diffopt.output_format) if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW; rev.diffopt.output_format = DIFF_FORMAT_RAW;
return cmd_log_walk(&rev); return cmd_log_walk(&rev);
@ -328,6 +331,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
struct object_array_entry *objects; struct object_array_entry *objects;
struct setup_revision_opt opt;
int i, count, ret = 0; int i, count, ret = 0;


git_config(git_log_config, NULL); git_config(git_log_config, NULL);
@ -342,7 +346,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
rev.always_show_header = 1; rev.always_show_header = 1;
rev.ignore_merges = 0; rev.ignore_merges = 0;
rev.no_walk = 1; rev.no_walk = 1;
cmd_log_init(argc, argv, prefix, &rev); memset(&opt, 0, sizeof(opt));
opt.def = "HEAD";
cmd_log_init(argc, argv, prefix, &rev, &opt);


count = rev.pending.nr; count = rev.pending.nr;
objects = rev.pending.objects; objects = rev.pending.objects;
@ -405,6 +411,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
int cmd_log_reflog(int argc, const char **argv, const char *prefix) int cmd_log_reflog(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
struct setup_revision_opt opt;


git_config(git_log_config, NULL); git_config(git_log_config, NULL);


@ -415,7 +422,9 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
init_reflog_walk(&rev.reflog_info); init_reflog_walk(&rev.reflog_info);
rev.abbrev_commit = 1; rev.abbrev_commit = 1;
rev.verbose_header = 1; rev.verbose_header = 1;
cmd_log_init(argc, argv, prefix, &rev); memset(&opt, 0, sizeof(opt));
opt.def = "HEAD";
cmd_log_init(argc, argv, prefix, &rev, &opt);


/* /*
* This means that we override whatever commit format the user gave * 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)
int cmd_log(int argc, const char **argv, const char *prefix) int cmd_log(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
struct setup_revision_opt opt;


git_config(git_log_config, NULL); git_config(git_log_config, NULL);


@ -446,7 +456,9 @@ int cmd_log(int argc, const char **argv, const char *prefix)


init_revisions(&rev, prefix); init_revisions(&rev, prefix);
rev.always_show_header = 1; rev.always_show_header = 1;
cmd_log_init(argc, argv, prefix, &rev); memset(&opt, 0, sizeof(opt));
opt.def = "HEAD";
cmd_log_init(argc, argv, prefix, &rev, &opt);
return cmd_log_walk(&rev); return cmd_log_walk(&rev);
} }


@ -887,6 +899,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
struct commit *commit; struct commit *commit;
struct commit **list = NULL; struct commit **list = NULL;
struct rev_info rev; struct rev_info rev;
struct setup_revision_opt s_r_opt;
int nr = 0, total, i; int nr = 0, total, i;
int use_stdout = 0; int use_stdout = 0;
int start_number = -1; int start_number = -1;
@ -964,8 +977,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
rev.combine_merges = 0; rev.combine_merges = 0;
rev.ignore_merges = 1; rev.ignore_merges = 1;
DIFF_OPT_SET(&rev.diffopt, RECURSIVE); DIFF_OPT_SET(&rev.diffopt, RECURSIVE);

rev.subject_prefix = fmt_patch_subject_prefix; rev.subject_prefix = fmt_patch_subject_prefix;
memset(&s_r_opt, 0, sizeof(s_r_opt));
s_r_opt.def = "HEAD";


if (default_attach) { if (default_attach) {
rev.mime_boundary = default_attach; rev.mime_boundary = default_attach;
@ -1037,7 +1051,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (keep_subject && subject_prefix) if (keep_subject && subject_prefix)
die ("--subject-prefix and -k are mutually exclusive."); die ("--subject-prefix and -k are mutually exclusive.");


argc = setup_revisions(argc, argv, &rev, "HEAD"); argc = setup_revisions(argc, argv, &rev, &s_r_opt);
if (argc > 1) if (argc > 1)
die ("unrecognized argument: %s", argv[1]); die ("unrecognized argument: %s", argv[1]);



5
diff-lib.c

@ -510,9 +510,12 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
int index_differs_from(const char *def, int diff_flags) int index_differs_from(const char *def, int diff_flags)
{ {
struct rev_info rev; struct rev_info rev;
struct setup_revision_opt opt;


init_revisions(&rev, NULL); init_revisions(&rev, NULL);
setup_revisions(0, NULL, &rev, def); memset(&opt, 0, sizeof(opt));
opt.def = def;
setup_revisions(0, NULL, &rev, &opt);
DIFF_OPT_SET(&rev.diffopt, QUICK); DIFF_OPT_SET(&rev.diffopt, QUICK);
DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS); DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
rev.diffopt.flags |= diff_flags; rev.diffopt.flags |= diff_flags;

4
revision.c

@ -1328,7 +1328,7 @@ static void append_prune_data(const char ***prune_data, const char **av)
* Returns the number of arguments left that weren't recognized * Returns the number of arguments left that weren't recognized
* (which are also moved to the head of the argument list) * (which are also moved to the head of the argument list)
*/ */
int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def) int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt)
{ {
int i, flags, left, seen_dashdash, read_from_stdin; int i, flags, left, seen_dashdash, read_from_stdin;
const char **prune_data = NULL; const char **prune_data = NULL;
@ -1462,7 +1462,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
revs->prune_data = get_pathspec(revs->prefix, prune_data); revs->prune_data = get_pathspec(revs->prefix, prune_data);


if (revs->def == NULL) if (revs->def == NULL)
revs->def = def; revs->def = opt ? opt->def : NULL;
if (revs->show_merge) if (revs->show_merge)
prepare_show_merge(revs); prepare_show_merge(revs);
if (revs->def && !revs->pending.nr) { if (revs->def && !revs->pending.nr) {

6
revision.h

@ -137,8 +137,12 @@ struct rev_info {
typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *); typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
extern volatile show_early_output_fn_t show_early_output; extern volatile show_early_output_fn_t show_early_output;


struct setup_revision_opt {
const char *def;
};

extern void init_revisions(struct rev_info *revs, const char *prefix); extern void init_revisions(struct rev_info *revs, const char *prefix);
extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def); extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *);
extern void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, extern void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
const struct option *options, const struct option *options,
const char * const usagestr[]); const char * const usagestr[]);

15
wt-status.c

@ -290,10 +290,13 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
static void wt_status_collect_changes_index(struct wt_status *s) static void wt_status_collect_changes_index(struct wt_status *s)
{ {
struct rev_info rev; struct rev_info rev;
struct setup_revision_opt opt;


init_revisions(&rev, NULL); init_revisions(&rev, NULL);
setup_revisions(0, NULL, &rev, memset(&opt, 0, sizeof(opt));
s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
setup_revisions(0, NULL, &rev, &opt);

rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = wt_status_collect_updated_cb; rev.diffopt.format_callback = wt_status_collect_updated_cb;
rev.diffopt.format_callback_data = s; rev.diffopt.format_callback_data = s;
@ -512,11 +515,15 @@ static void wt_status_print_untracked(struct wt_status *s)
static void wt_status_print_verbose(struct wt_status *s) static void wt_status_print_verbose(struct wt_status *s)
{ {
struct rev_info rev; struct rev_info rev;
struct setup_revision_opt opt;


init_revisions(&rev, NULL); init_revisions(&rev, NULL);
DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV); DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
setup_revisions(0, NULL, &rev,
s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); memset(&opt, 0, sizeof(opt));
opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
setup_revisions(0, NULL, &rev, &opt);

rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
rev.diffopt.detect_rename = 1; rev.diffopt.detect_rename = 1;
rev.diffopt.file = s->fp; rev.diffopt.file = s->fp;

Loading…
Cancel
Save