Skip to content

Commit

Permalink
Make the diff_options bitfields be an unsigned with explicit masks.
Browse files Browse the repository at this point in the history
reverse_diff was a bit-value in disguise, it's merged in the flags now.

Signed-off-by: Pierre Habouzit <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
MadCoder authored and gitster committed Nov 12, 2007
1 parent 68dce6e commit 8f67f8a
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 149 deletions.
10 changes: 5 additions & 5 deletions builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static struct origin *find_origin(struct scoreboard *sb,
* same and diff-tree is fairly efficient about this.
*/
diff_setup(&diff_opts);
diff_opts.recursive = 1;
DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.detect_rename = 0;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
paths[0] = origin->path;
Expand Down Expand Up @@ -409,7 +409,7 @@ static struct origin *find_rename(struct scoreboard *sb,
const char *paths[2];

diff_setup(&diff_opts);
diff_opts.recursive = 1;
DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.detect_rename = DIFF_DETECT_RENAME;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_opts.single_follow = origin->path;
Expand Down Expand Up @@ -1075,7 +1075,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
return 1; /* nothing remains for this target */

diff_setup(&diff_opts);
diff_opts.recursive = 1;
DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;

paths[0] = NULL;
Expand All @@ -1093,7 +1093,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
if ((opt & PICKAXE_BLAME_COPY_HARDEST)
|| ((opt & PICKAXE_BLAME_COPY_HARDER)
&& (!porigin || strcmp(target->path, porigin->path))))
diff_opts.find_copies_harder = 1;
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);

if (is_null_sha1(target->commit->object.sha1))
do_diff_cache(parent->tree->object.sha1, &diff_opts);
Expand All @@ -1102,7 +1102,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
target->commit->tree->object.sha1,
"", &diff_opts);

if (!diff_opts.find_copies_harder)
if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
diffcore_std(&diff_opts);

retval = 0;
Expand Down
4 changes: 3 additions & 1 deletion builtin-diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
result = run_diff_files_cmd(&rev, argc, argv);
return rev.diffopt.exit_with_status ? rev.diffopt.has_changes: result;
if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
return DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
return result;
}
4 changes: 3 additions & 1 deletion builtin-diff-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
return -1;
}
result = run_diff_index(&rev, cached);
return rev.diffopt.exit_with_status ? rev.diffopt.has_changes: result;
if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
return DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
return result;
}
7 changes: 4 additions & 3 deletions builtin-diff-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
}

if (!read_stdin)
return opt->diffopt.exit_with_status ?
opt->diffopt.has_changes: 0;
return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS)
&& DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES);

if (opt->diffopt.detect_rename)
opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
Expand All @@ -134,5 +134,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
else
diff_tree_stdin(line);
}
return opt->diffopt.exit_with_status ? opt->diffopt.has_changes: 0;
return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS)
&& DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES);
}
12 changes: 6 additions & 6 deletions builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void stuff_change(struct diff_options *opt,
!hashcmp(old_sha1, new_sha1) && (old_mode == new_mode))
return;

if (opt->reverse_diff) {
if (DIFF_OPT_TST(opt, REVERSE_DIFF)) {
unsigned tmp;
const unsigned char *tmp_u;
const char *tmp_c;
Expand Down Expand Up @@ -253,13 +253,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
if (diff_setup_done(&rev.diffopt) < 0)
die("diff_setup_done failed");
}
rev.diffopt.allow_external = 1;
rev.diffopt.recursive = 1;
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);

/* If the user asked for our exit code then don't start a
* pager or we would end up reporting its exit code instead.
*/
if (!rev.diffopt.exit_with_status)
if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
setup_pager();

/* Do we have --cached and not have a pending object, then
Expand Down Expand Up @@ -363,8 +363,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
else
result = builtin_diff_combined(&rev, argc, argv,
ent, ents);
if (rev.diffopt.exit_with_status)
result = rev.diffopt.has_changes;
if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
result = DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;

if (1 < rev.diffopt.skip_stat_unmatch)
refresh_index_quietly();
Expand Down
24 changes: 10 additions & 14 deletions builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
rev->abbrev = DEFAULT_ABBREV;
rev->commit_format = CMIT_FMT_DEFAULT;
rev->verbose_header = 1;
rev->diffopt.recursive = 1;
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
rev->show_root_diff = default_show_root;
rev->subject_prefix = fmt_patch_subject_prefix;
argc = setup_revisions(argc, argv, rev, "HEAD");
if (rev->diffopt.pickaxe || rev->diffopt.filter)
rev->always_show_header = 0;
if (rev->diffopt.follow_renames) {
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
rev->always_show_header = 0;
if (rev->diffopt.nr_paths != 1)
usage("git logs can only follow renames on one pathname at a time");
Expand Down Expand Up @@ -185,23 +185,19 @@ int cmd_show(int argc, const char **argv, const char *prefix)
struct tag *t = (struct tag *)o;

printf("%stag %s%s\n\n",
diff_get_color(rev.diffopt.color_diff,
DIFF_COMMIT),
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
t->tag,
diff_get_color(rev.diffopt.color_diff,
DIFF_RESET));
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
ret = show_object(o->sha1, 1);
objects[i].item = (struct object *)t->tagged;
i--;
break;
}
case OBJ_TREE:
printf("%stree %s%s\n\n",
diff_get_color(rev.diffopt.color_diff,
DIFF_COMMIT),
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
name,
diff_get_color(rev.diffopt.color_diff,
DIFF_RESET));
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
show_tree_object);
break;
Expand Down Expand Up @@ -487,7 +483,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
rev.combine_merges = 0;
rev.ignore_merges = 1;
rev.diffopt.msg_sep = "";
rev.diffopt.recursive = 1;
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);

rev.subject_prefix = fmt_patch_subject_prefix;
rev.extra_headers = extra_headers;
Expand Down Expand Up @@ -590,8 +586,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;

if (!rev.diffopt.text)
rev.diffopt.binary = 1;
if (!DIFF_OPT_TST(&rev.diffopt, TEXT))
DIFF_OPT_SET(&rev.diffopt, BINARY);

if (!output_directory && !use_stdout)
output_directory = prefix;
Expand Down Expand Up @@ -747,7 +743,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
revs.diff = 1;
revs.combine_merges = 0;
revs.ignore_merges = 1;
revs.diffopt.recursive = 1;
DIFF_OPT_SET(&revs.diffopt, RECURSIVE);

if (add_pending_commit(head, &revs, 0))
die("Unknown commit %s", head);
Expand Down
10 changes: 5 additions & 5 deletions combine-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
int mode_differs = 0;
int i, show_hunks;
int working_tree_file = is_null_sha1(elem->sha1);
int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;
int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
mmfile_t result_file;

context = opt->context;
Expand Down Expand Up @@ -784,7 +784,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,

if (show_hunks || mode_differs || working_tree_file) {
const char *abb;
int use_color = opt->color_diff;
int use_color = DIFF_OPT_TST(opt, COLOR_DIFF);
const char *c_meta = diff_get_color(use_color, DIFF_METAINFO);
const char *c_reset = diff_get_color(use_color, DIFF_RESET);
int added = 0;
Expand Down Expand Up @@ -836,7 +836,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
dump_quoted_path("+++ /dev/", "null", c_meta, c_reset);
else
dump_quoted_path("+++ b/", elem->path, c_meta, c_reset);
dump_sline(sline, cnt, num_parent, opt->color_diff);
dump_sline(sline, cnt, num_parent, DIFF_OPT_TST(opt, COLOR_DIFF));
}
free(result);

Expand Down Expand Up @@ -929,8 +929,8 @@ void diff_tree_combined(const unsigned char *sha1,

diffopts = *opt;
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
diffopts.recursive = 1;
diffopts.allow_external = 0;
DIFF_OPT_SET(&diffopts, RECURSIVE);
DIFF_OPT_CLR(&diffopts, ALLOW_EXTERNAL);

show_log_first = !!rev->loginfo && !rev->no_commit_id;
needsep = 0;
Expand Down
24 changes: 13 additions & 11 deletions diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int queue_diff(struct diff_options *o,
} else {
struct diff_filespec *d1, *d2;

if (o->reverse_diff) {
if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
unsigned tmp;
const char *tmp_c;
tmp = mode1; mode1 = mode2; mode2 = tmp;
Expand Down Expand Up @@ -188,8 +188,8 @@ static int handle_diff_files_args(struct rev_info *revs,
else if (!strcmp(argv[1], "-n") ||
!strcmp(argv[1], "--no-index")) {
revs->max_count = -2;
revs->diffopt.exit_with_status = 1;
revs->diffopt.no_index = 1;
DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);
DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
}
else if (!strcmp(argv[1], "-q"))
*silent = 1;
Expand All @@ -207,7 +207,7 @@ static int handle_diff_files_args(struct rev_info *revs,
if (!is_in_index(revs->diffopt.paths[0]) ||
!is_in_index(revs->diffopt.paths[1])) {
revs->max_count = -2;
revs->diffopt.no_index = 1;
DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
}
}

Expand Down Expand Up @@ -258,7 +258,7 @@ int setup_diff_no_index(struct rev_info *revs,
break;
} else if (i < argc - 3 && !strcmp(argv[i], "--no-index")) {
i = argc - 3;
revs->diffopt.exit_with_status = 1;
DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);
break;
}
if (argc != i + 2 || (!is_outside_repo(argv[i + 1], nongit, prefix) &&
Expand Down Expand Up @@ -296,7 +296,7 @@ int setup_diff_no_index(struct rev_info *revs,
else
revs->diffopt.paths = argv + argc - 2;
revs->diffopt.nr_paths = 2;
revs->diffopt.no_index = 1;
DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
revs->max_count = -2;
if (diff_setup_done(&revs->diffopt) < 0)
die("diff_setup_done failed");
Expand All @@ -310,7 +310,7 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
if (handle_diff_files_args(revs, argc, argv, &silent_on_removed))
return -1;

if (revs->diffopt.no_index) {
if (DIFF_OPT_TST(&revs->diffopt, NO_INDEX)) {
if (revs->diffopt.nr_paths != 2)
return error("need two files/directories with --no-index");
if (queue_diff(&revs->diffopt, revs->diffopt.paths[0],
Expand Down Expand Up @@ -346,7 +346,8 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
struct cache_entry *ce = active_cache[i];
int changed;

if (revs->diffopt.quiet && revs->diffopt.has_changes)
if (DIFF_OPT_TST(&revs->diffopt, QUIET) &&
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
break;

if (!ce_path_match(ce, revs->prune_data))
Expand Down Expand Up @@ -442,7 +443,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
continue;
}
changed = ce_match_stat(ce, &st, 0);
if (!changed && !revs->diffopt.find_copies_harder)
if (!changed && !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
continue;
oldmode = ntohl(ce->ce_mode);
newmode = ntohl(ce_mode_from_stat(ce, st.st_mode));
Expand Down Expand Up @@ -561,7 +562,7 @@ static int show_modified(struct rev_info *revs,

oldmode = old->ce_mode;
if (mode == oldmode && !hashcmp(sha1, old->sha1) &&
!revs->diffopt.find_copies_harder)
!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
return 0;

mode = ntohl(mode);
Expand All @@ -581,7 +582,8 @@ static int diff_cache(struct rev_info *revs,
struct cache_entry *ce = *ac;
int same = (entries > 1) && ce_same_name(ce, ac[1]);

if (revs->diffopt.quiet && revs->diffopt.has_changes)
if (DIFF_OPT_TST(&revs->diffopt, QUIET) &&
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
break;

if (!ce_path_match(ce, pathspec))
Expand Down
Loading

0 comments on commit 8f67f8a

Please sign in to comment.