diff.c: remove implicit dependency on the_index
A new variant repo_diff_setup() is added that takes 'struct repository *' and diff_setup() becomes a thin macro around it that is protected by NO_THE_REPOSITORY_COMPATIBILITY_MACROS, similar to NO_THE_INDEX_.... The plan is these macros will always be defined for all library files and the macros are only accessible in builtin/ Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Sep 21, 2018 at 17:57 UTC
e675765235001c382ba30d336bb69618296c012b
15 files changed
+38
-28
Documentation/technical/api-diff.txt
+2
-2
@@ -18,8 +18,8 @@ Calling sequence
18
----------------
19
20
* Prepare `struct diff_options` to record the set of diff options, and
21
- then call `diff_setup()` to initialize this structure. This sets up
22
- the vanilla default.
21
+ then call `repo_diff_setup()` to initialize this structure. This
22
+ sets up the vanilla default.
23
24
* Fill in the options structure to specify desired output format, rename
25
detection, etc. `diff_opt_parse()` can be used to parse options given
blame.c
+11
-9
@@ -541,8 +541,9 @@ static int fill_blob_sha1_and_mode(struct repository *r,
541
* We have an origin -- check if the same path exists in the
542
* parent and return an origin structure to represent it.
543
*/
544
-static struct blame_origin *find_origin(struct commit *parent,
545
- struct blame_origin *origin)
544
+static struct blame_origin *find_origin(struct repository *r,
545
+ struct commit *parent,
546
+ struct blame_origin *origin)
547
{
548
struct blame_origin *porigin;
549
struct diff_options diff_opts;
@@ -562,7 +563,7 @@ static struct blame_origin *find_origin(struct commit *parent,
563
* and origin first. Most of the time they are the
564
* same and diff-tree is fairly efficient about this.
565
*/
565
- diff_setup(&diff_opts);
566
+ repo_diff_setup(r, &diff_opts);
567
diff_opts.flags.recursive = 1;
568
diff_opts.detect_rename = 0;
569
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -629,14 +630,15 @@ static struct blame_origin *find_origin(struct commit *parent,
630
* We have an origin -- find the path that corresponds to it in its
631
* parent and return an origin structure to represent it.
632
*/
632
-static struct blame_origin *find_rename(struct commit *parent,
633
- struct blame_origin *origin)
633
+static struct blame_origin *find_rename(struct repository *r,
634
+ struct commit *parent,
635
+ struct blame_origin *origin)
636
{
637
struct blame_origin *porigin = NULL;
638
struct diff_options diff_opts;
639
int i;
640
639
- diff_setup(&diff_opts);
641
+ repo_diff_setup(r, &diff_opts);
642
diff_opts.flags.recursive = 1;
643
diff_opts.detect_rename = DIFF_DETECT_RENAME;
644
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1260,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
1262
if (!unblamed)
1263
return; /* nothing remains for this target */
1264
1263
- diff_setup(&diff_opts);
1265
+ repo_diff_setup(sb->repo, &diff_opts);
1266
diff_opts.flags.recursive = 1;
1267
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1268
@@ -1442,7 +1444,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
1444
* common cases, then we look for renames in the second pass.
1445
*/
1446
for (pass = 0; pass < 2 - sb->no_whole_file_rename; pass++) {
1445
- struct blame_origin *(*find)(struct commit *, struct blame_origin *);
1447
+ struct blame_origin *(*find)(struct repository *, struct commit *, struct blame_origin *);
1448
find = pass ? find_rename : find_origin;
1449
1450
for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
@@ -1455,7 +1457,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
1457
continue;
1458
if (parse_commit(p))
1459
continue;
1458
- porigin = find(p, origin);
1460
+ porigin = find(sb->repo, p, origin);
1461
if (!porigin)
1462
continue;
1463
if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {
builtin/diff.c
+1
-1
@@ -339,7 +339,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
339
}
340
if (no_index)
341
/* If this is a no-index diff, just run it and exit there. */
342
- diff_no_index(&rev, argc, argv);
342
+ diff_no_index(the_repository, &rev, argc, argv);
343
344
/* Otherwise, we are doing the usual "git" diff */
345
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
builtin/log.c
+1
-1
@@ -1361,7 +1361,7 @@ static void prepare_bases(struct base_tree_info *bases,
1361
return;
1362
1363
init_commit_base(&commit_base);
1364
- diff_setup(&diffopt);
1364
+ repo_diff_setup(the_repository, &diffopt);
1365
diffopt.flags.recursive = 1;
1366
diff_setup_done(&diffopt);
1367
builtin/merge.c
+1
-1
@@ -452,7 +452,7 @@ static void finish(struct commit *head_commit,
452
}
453
if (new_head && show_diffstat) {
454
struct diff_options opts;
455
- diff_setup(&opts);
455
+ repo_diff_setup(the_repository, &opts);
456
opts.stat_width = -1; /* use full terminal width */
457
opts.stat_graph_width = -1; /* respect statGraphWidth config */
458
opts.output_format |=
builtin/range-diff.c
+1
-1
@@ -34,7 +34,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
34
35
git_config(git_diff_ui_config, NULL);
36
37
- diff_setup(&diffopt);
37
+ repo_diff_setup(the_repository, &diffopt);
38
diffopt.output_format = DIFF_FORMAT_PATCH;
39
diffopt.flags.suppress_diff_headers = 1;
40
diffopt.output_prefix = output_prefix_cb;
diff-no-index.c
+7
-2
@@ -233,7 +233,8 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
233
}
234
}
235
236
-void diff_no_index(struct rev_info *revs,
236
+void diff_no_index(struct repository *r,
237
+ struct rev_info *revs,
238
int argc, const char **argv)
239
{
240
int i;
@@ -241,7 +242,11 @@ void diff_no_index(struct rev_info *revs,
242
struct strbuf replacement = STRBUF_INIT;
243
const char *prefix = revs->prefix;
244
244
- diff_setup(&revs->diffopt);
245
+ /*
246
+ * FIXME: --no-index should not look at index and we should be
247
+ * able to pass NULL repo. Maybe later.
248
+ */
249
+ repo_diff_setup(r, &revs->diffopt);
250
for (i = 1; i < argc - 2; ) {
251
int j;
252
if (!strcmp(argv[i], "--no-index"))
diff.c
+2
-2
@@ -4390,12 +4390,12 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
4390
builtin_checkdiff(name, other, attr_path, p->one, p->two, o);
4391
}
4392
4393
-void diff_setup(struct diff_options *options)
4393
+void repo_diff_setup(struct repository *r, struct diff_options *options)
4394
{
4395
memcpy(options, &default_diff_options, sizeof(*options));
4396
4397
options->file = stdout;
4398
- options->repo->index = &the_index;
4398
+ options->repo = r;
4399
4400
options->abbrev = DEFAULT_ABBREV;
4401
options->line_termination = '\n';
diff.h
+5
-2
@@ -336,7 +336,10 @@ int git_diff_basic_config(const char *var, const char *value, void *cb);
336
int git_diff_heuristic_config(const char *var, const char *value, void *cb);
337
void init_diff_ui_defaults(void);
338
int git_diff_ui_config(const char *var, const char *value, void *cb);
339
-void diff_setup(struct diff_options *);
339
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
340
+#define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts)
341
+#endif
342
+void repo_diff_setup(struct repository *, struct diff_options *);
343
int diff_opt_parse(struct diff_options *, const char **, int, const char *);
344
void diff_setup_done(struct diff_options *);
345
int git_config_rename(const char *var, const char *value);
@@ -426,7 +429,7 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
429
430
int diff_result_code(struct diff_options *, int);
431
429
-void diff_no_index(struct rev_info *, int, const char **);
432
+void diff_no_index(struct repository *, struct rev_info *, int, const char **);
433
434
int index_differs_from(const char *def, const struct diff_flags *flags,
435
int ita_invisible_in_index);
merge-recursive.c
+1
-1
@@ -1812,7 +1812,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
1812
struct diff_queue_struct *ret;
1813
struct diff_options opts;
1814
1815
- diff_setup(&opts);
1815
+ repo_diff_setup(the_repository, &opts);
1816
opts.flags.recursive = 1;
1817
opts.flags.rename_empty = 0;
1818
opts.detect_rename = merge_detect_rename(o);
notes-merge.c
+2
-2
@@ -126,7 +126,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
126
trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n",
127
oid_to_hex(base), oid_to_hex(remote));
128
129
- diff_setup(&opt);
129
+ repo_diff_setup(the_repository, &opt);
130
opt.flags.recursive = 1;
131
opt.output_format = DIFF_FORMAT_NO_OUTPUT;
132
diff_setup_done(&opt);
@@ -189,7 +189,7 @@ static void diff_tree_local(struct notes_merge_options *o,
189
trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n",
190
len, oid_to_hex(base), oid_to_hex(local));
191
192
- diff_setup(&opt);
192
+ repo_diff_setup(the_repository, &opt);
193
opt.flags.recursive = 1;
194
opt.output_format = DIFF_FORMAT_NO_OUTPUT;
195
diff_setup_done(&opt);
patch-ids.c
+1
-1
@@ -59,7 +59,7 @@ static int patch_id_cmp(const void *cmpfn_data,
59
int init_patch_ids(struct patch_ids *ids)
60
{
61
memset(ids, 0, sizeof(*ids));
62
- diff_setup(&ids->diffopts);
62
+ repo_diff_setup(the_repository, &ids->diffopts);
63
ids->diffopts.detect_rename = 0;
64
ids->diffopts.flags.recursive = 1;
65
diff_setup_done(&ids->diffopts);
read-cache.c
+1
-1
@@ -2137,7 +2137,7 @@ int index_has_changes(struct index_state *istate,
2137
if (tree || !get_oid_tree("HEAD", &cmp)) {
2138
struct diff_options opt;
2139
2140
- diff_setup(&opt);
2140
+ repo_diff_setup(the_repository, &opt);
2141
opt.flags.exit_with_status = 1;
2142
if (!sb)
2143
opt.flags.quick = 1;
revision.c
+1
-1
@@ -1468,7 +1468,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
1468
grep_init(&revs->grep_filter, the_repository, prefix);
1469
revs->grep_filter.status_only = 1;
1470
1471
- diff_setup(&revs->diffopt);
1471
+ repo_diff_setup(the_repository, &revs->diffopt);
1472
if (prefix && !revs->diffopt.prefix) {
1473
revs->diffopt.prefix = prefix;
1474
revs->diffopt.prefix_length = strlen(prefix);
tree-diff.c
+1
-1
@@ -605,7 +605,7 @@ static void try_to_follow_renames(const struct object_id *old_oid,
605
choice = q->queue[0];
606
q->nr = 0;
607
608
- diff_setup(&diff_opts);
608
+ repo_diff_setup(the_repository, &diff_opts);
609
diff_opts.flags.recursive = 1;
610
diff_opts.flags.find_copies_harder = 1;
611
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;