Skip to content

Commit 8cc6332

Browse files
committed
Merge branch 'bw/diff-opt-impl-to-bitfields'
A single-word "unsigned flags" in the diff options is being split into a structure with many bitfields. * bw/diff-opt-impl-to-bitfields: diff: make struct diff_flags members lowercase diff: remove DIFF_OPT_CLR macro diff: remove DIFF_OPT_SET macro diff: remove DIFF_OPT_TST macro diff: remove touched flags diff: add flag to indicate textconv was set via cmdline diff: convert flags to be stored in bitfields add, reset: use DIFF_OPT_SET macro to set a diff flag
2 parents bde1370 + 0d1e0e7 commit 8cc6332

27 files changed

+260
-246
lines changed

blame.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
209209

210210
switch (st.st_mode & S_IFMT) {
211211
case S_IFREG:
212-
if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
212+
if (opt->flags.allow_textconv &&
213213
textconv_object(read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
214214
strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
215215
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
@@ -293,7 +293,7 @@ static void fill_origin_blob(struct diff_options *opt,
293293
unsigned long file_size;
294294

295295
(*num_read_blob)++;
296-
if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
296+
if (opt->flags.allow_textconv &&
297297
textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
298298
;
299299
else
@@ -541,7 +541,7 @@ static struct blame_origin *find_origin(struct commit *parent,
541541
* same and diff-tree is fairly efficient about this.
542542
*/
543543
diff_setup(&diff_opts);
544-
DIFF_OPT_SET(&diff_opts, RECURSIVE);
544+
diff_opts.flags.recursive = 1;
545545
diff_opts.detect_rename = 0;
546546
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
547547
paths[0] = origin->path;
@@ -615,7 +615,7 @@ static struct blame_origin *find_rename(struct commit *parent,
615615
int i;
616616

617617
diff_setup(&diff_opts);
618-
DIFF_OPT_SET(&diff_opts, RECURSIVE);
618+
diff_opts.flags.recursive = 1;
619619
diff_opts.detect_rename = DIFF_DETECT_RENAME;
620620
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
621621
diff_opts.single_follow = origin->path;
@@ -1238,7 +1238,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12381238
return; /* nothing remains for this target */
12391239

12401240
diff_setup(&diff_opts);
1241-
DIFF_OPT_SET(&diff_opts, RECURSIVE);
1241+
diff_opts.flags.recursive = 1;
12421242
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
12431243

12441244
diff_setup_done(&diff_opts);
@@ -1253,7 +1253,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12531253
if ((opt & PICKAXE_BLAME_COPY_HARDEST)
12541254
|| ((opt & PICKAXE_BLAME_COPY_HARDER)
12551255
&& (!porigin || strcmp(target->path, porigin->path))))
1256-
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
1256+
diff_opts.flags.find_copies_harder = 1;
12571257

12581258
if (is_null_oid(&target->commit->object.oid))
12591259
do_diff_cache(&parent->tree->object.oid, &diff_opts);
@@ -1262,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12621262
&target->commit->tree->object.oid,
12631263
"", &diff_opts);
12641264

1265-
if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
1265+
if (!diff_opts.flags.find_copies_harder)
12661266
diffcore_std(&diff_opts);
12671267

12681268
do {
@@ -1825,7 +1825,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
18251825
if (fill_blob_sha1_and_mode(o))
18261826
die(_("no such path %s in %s"), path, final_commit_name);
18271827

1828-
if (DIFF_OPT_TST(&sb->revs->diffopt, ALLOW_TEXTCONV) &&
1828+
if (sb->revs->diffopt.flags.allow_textconv &&
18291829
textconv_object(path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
18301830
&sb->final_buf_size))
18311831
;

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int add_files_to_cache(const char *prefix,
116116
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
117117
rev.diffopt.format_callback = update_callback;
118118
rev.diffopt.format_callback_data = &data;
119-
rev.diffopt.flags |= DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG;
119+
rev.diffopt.flags.override_submodule_config = 1;
120120
rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
121121
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
122122
clear_pathspec(&rev.prune_data);
@@ -218,7 +218,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
218218
argc = setup_revisions(argc, argv, &rev, NULL);
219219
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
220220
rev.diffopt.use_color = 0;
221-
DIFF_OPT_SET(&rev.diffopt, IGNORE_DIRTY_SUBMODULES);
221+
rev.diffopt.flags.ignore_dirty_submodules = 1;
222222
out = open(file, O_CREAT | O_WRONLY, 0666);
223223
if (out < 0)
224224
die(_("Could not open '%s' for writing."), file);

builtin/am.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,9 +1157,9 @@ static int index_has_changes(struct strbuf *sb)
11571157
struct diff_options opt;
11581158

11591159
diff_setup(&opt);
1160-
DIFF_OPT_SET(&opt, EXIT_WITH_STATUS);
1160+
opt.flags.exit_with_status = 1;
11611161
if (!sb)
1162-
DIFF_OPT_SET(&opt, QUICK);
1162+
opt.flags.quick = 1;
11631163
do_diff_cache(&head, &opt);
11641164
diffcore_std(&opt);
11651165
for (i = 0; sb && i < diff_queued_diff.nr; i++) {
@@ -1168,7 +1168,7 @@ static int index_has_changes(struct strbuf *sb)
11681168
strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
11691169
}
11701170
diff_flush(&opt);
1171-
return DIFF_OPT_TST(&opt, HAS_CHANGES) != 0;
1171+
return opt.flags.has_changes != 0;
11721172
} else {
11731173
for (i = 0; sb && i < active_nr; i++) {
11741174
if (i)
@@ -1409,8 +1409,8 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm
14091409
rev_info.show_root_diff = 1;
14101410
rev_info.diffopt.output_format = DIFF_FORMAT_PATCH;
14111411
rev_info.no_commit_id = 1;
1412-
DIFF_OPT_SET(&rev_info.diffopt, BINARY);
1413-
DIFF_OPT_SET(&rev_info.diffopt, FULL_INDEX);
1412+
rev_info.diffopt.flags.binary = 1;
1413+
rev_info.diffopt.flags.full_index = 1;
14141414
rev_info.diffopt.use_color = 0;
14151415
rev_info.diffopt.file = fp;
14161416
rev_info.diffopt.close_file = 1;

builtin/blame.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
708708
git_config(git_blame_config, &output_option);
709709
init_revisions(&revs, NULL);
710710
revs.date_mode = blame_date_mode;
711-
DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV);
712-
DIFF_OPT_SET(&revs.diffopt, FOLLOW_RENAMES);
711+
revs.diffopt.flags.allow_textconv = 1;
712+
revs.diffopt.flags.follow_renames = 1;
713713

714714
save_commit_buffer = 0;
715715
dashdash_pos = 0;
@@ -734,9 +734,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
734734
parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
735735
}
736736
parse_done:
737-
no_whole_file_rename = !DIFF_OPT_TST(&revs.diffopt, FOLLOW_RENAMES);
737+
no_whole_file_rename = !revs.diffopt.flags.follow_renames;
738738
xdl_opts |= revs.diffopt.xdl_opts & XDF_INDENT_HEURISTIC;
739-
DIFF_OPT_CLR(&revs.diffopt, FOLLOW_RENAMES);
739+
revs.diffopt.flags.follow_renames = 0;
740740
argc = parse_options_end(&ctx);
741741

742742
if (incremental || (output_option & OUTPUT_PORCELAIN)) {
@@ -803,7 +803,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
803803
}
804804
blame_date_width -= 1; /* strip the null */
805805

806-
if (DIFF_OPT_TST(&revs.diffopt, FIND_COPIES_HARDER))
806+
if (revs.diffopt.flags.find_copies_harder)
807807
opt |= (PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE |
808808
PICKAXE_BLAME_COPY_HARDER);
809809

builtin/commit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
912912
* submodules which were manually staged, which would
913913
* be really confusing.
914914
*/
915-
int diff_flags = DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG;
915+
struct diff_flags flags = DIFF_FLAGS_INIT;
916+
flags.override_submodule_config = 1;
916917
if (ignore_submodule_arg &&
917918
!strcmp(ignore_submodule_arg, "all"))
918-
diff_flags |= DIFF_OPT_IGNORE_SUBMODULES;
919-
commitable = index_differs_from(parent, diff_flags, 1);
919+
flags.ignore_submodules = 1;
920+
commitable = index_differs_from(parent, &flags, 1);
920921
}
921922
}
922923
strbuf_release(&committer_ident);

builtin/diff.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void stuff_change(struct diff_options *opt,
4444
!oidcmp(old_oid, new_oid) && (old_mode == new_mode))
4545
return;
4646

47-
if (DIFF_OPT_TST(opt, REVERSE_DIFF)) {
47+
if (opt->flags.reverse_diff) {
4848
SWAP(old_mode, new_mode);
4949
SWAP(old_oid, new_oid);
5050
SWAP(old_path, new_path);
@@ -349,8 +349,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
349349
rev.diffopt.stat_graph_width = -1;
350350

351351
/* Default to let external and textconv be used */
352-
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
353-
DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
352+
rev.diffopt.flags.allow_external = 1;
353+
rev.diffopt.flags.allow_textconv = 1;
354354

355355
if (nongit)
356356
die(_("Not a git repository"));
@@ -360,7 +360,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
360360
diff_setup_done(&rev.diffopt);
361361
}
362362

363-
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
363+
rev.diffopt.flags.recursive = 1;
364364

365365
setup_diff_pager(&rev.diffopt);
366366

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
10661066
die("revision walk setup failed");
10671067
revs.diffopt.format_callback = show_filemodify;
10681068
revs.diffopt.format_callback_data = &paths_of_changed_objects;
1069-
DIFF_OPT_SET(&revs.diffopt, RECURSIVE);
1069+
revs.diffopt.flags.recursive = 1;
10701070
while ((commit = get_revision(&revs))) {
10711071
if (has_unshown_parent(commit)) {
10721072
add_object_array(&commit->object, NULL, &commits);

builtin/log.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,19 @@ static void cmd_log_init_defaults(struct rev_info *rev)
121121
if (fmt_pretty)
122122
get_commit_format(fmt_pretty, rev);
123123
if (default_follow)
124-
DIFF_OPT_SET(&rev->diffopt, DEFAULT_FOLLOW_RENAMES);
124+
rev->diffopt.flags.default_follow_renames = 1;
125125
rev->verbose_header = 1;
126-
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
126+
rev->diffopt.flags.recursive = 1;
127127
rev->diffopt.stat_width = -1; /* use full terminal width */
128128
rev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */
129129
rev->abbrev_commit = default_abbrev_commit;
130130
rev->show_root_diff = default_show_root;
131131
rev->subject_prefix = fmt_patch_subject_prefix;
132132
rev->show_signature = default_show_signature;
133-
DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
133+
rev->diffopt.flags.allow_textconv = 1;
134134

135135
if (default_date_mode)
136136
parse_date_format(default_date_mode, &rev->date_mode);
137-
rev->diffopt.touched_flags = 0;
138137
}
139138

140139
static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
@@ -182,7 +181,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
182181
init_display_notes(&rev->notes_opt);
183182

184183
if (rev->diffopt.pickaxe || rev->diffopt.filter ||
185-
DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES))
184+
rev->diffopt.flags.follow_renames)
186185
rev->always_show_header = 0;
187186

188187
if (source)
@@ -392,7 +391,7 @@ static int cmd_log_walk(struct rev_info *rev)
392391
fclose(rev->diffopt.file);
393392

394393
if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
395-
DIFF_OPT_TST(&rev->diffopt, CHECK_FAILED)) {
394+
rev->diffopt.flags.check_failed) {
396395
return 02;
397396
}
398397
return diff_result_code(&rev->diffopt, 0);
@@ -484,8 +483,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
484483
unsigned long size;
485484

486485
fflush(rev->diffopt.file);
487-
if (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||
488-
!DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
486+
if (!rev->diffopt.flags.textconv_set_via_cmdline ||
487+
!rev->diffopt.flags.allow_textconv)
489488
return stream_blob_to_fd(1, oid, NULL, 0);
490489

491490
if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
@@ -667,9 +666,9 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
667666
static void log_setup_revisions_tweak(struct rev_info *rev,
668667
struct setup_revision_opt *opt)
669668
{
670-
if (DIFF_OPT_TST(&rev->diffopt, DEFAULT_FOLLOW_RENAMES) &&
669+
if (rev->diffopt.flags.default_follow_renames &&
671670
rev->prune_data.nr == 1)
672-
DIFF_OPT_SET(&rev->diffopt, FOLLOW_RENAMES);
671+
rev->diffopt.flags.follow_renames = 1;
673672

674673
/* Turn --cc/-c into -p --cc/-c when -p was not given */
675674
if (!rev->diffopt.output_format && rev->combine_merges)
@@ -1341,7 +1340,7 @@ static void prepare_bases(struct base_tree_info *bases,
13411340
return;
13421341

13431342
diff_setup(&diffopt);
1344-
DIFF_OPT_SET(&diffopt, RECURSIVE);
1343+
diffopt.flags.recursive = 1;
13451344
diff_setup_done(&diffopt);
13461345

13471346
oidcpy(&bases->base_commit, &base->object.oid);
@@ -1512,7 +1511,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
15121511
rev.verbose_header = 1;
15131512
rev.diff = 1;
15141513
rev.max_parents = 1;
1515-
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
1514+
rev.diffopt.flags.recursive = 1;
15161515
rev.subject_prefix = fmt_patch_subject_prefix;
15171516
memset(&s_r_opt, 0, sizeof(s_r_opt));
15181517
s_r_opt.def = "HEAD";
@@ -1613,8 +1612,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
16131612

16141613
rev.zero_commit = zero_commit;
16151614

1616-
if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
1617-
DIFF_OPT_SET(&rev.diffopt, BINARY);
1615+
if (!rev.diffopt.flags.text && !no_binary_diff)
1616+
rev.diffopt.flags.binary = 1;
16181617

16191618
if (rev.show_notes)
16201619
init_display_notes(&rev.notes_opt);

builtin/merge-ours.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)
2626
*/
2727
if (read_cache() < 0)
2828
die_errno("read_cache failed");
29-
if (index_differs_from("HEAD", 0, 0))
29+
if (index_differs_from("HEAD", NULL, 0))
3030
exit(2);
3131
exit(0);
3232
}

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int read_from_tree(const struct pathspec *pathspec,
166166
opt.output_format = DIFF_FORMAT_CALLBACK;
167167
opt.format_callback = update_index_from_diff;
168168
opt.format_callback_data = &intent_to_add;
169-
opt.flags |= DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG;
169+
opt.flags.override_submodule_config = 1;
170170

171171
if (do_diff_cache(tree_oid, &opt))
172172
return 1;

0 commit comments

Comments
 (0)