Skip to content

Commit e675765

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 38bbc2e commit e675765

File tree

15 files changed

+38
-28
lines changed

15 files changed

+38
-28
lines changed

Documentation/technical/api-diff.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Calling sequence
1818
----------------
1919

2020
* 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.
2323

2424
* Fill in the options structure to specify desired output format, rename
2525
detection, etc. `diff_opt_parse()` can be used to parse options given

blame.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,9 @@ static int fill_blob_sha1_and_mode(struct repository *r,
541541
* We have an origin -- check if the same path exists in the
542542
* parent and return an origin structure to represent it.
543543
*/
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)
546547
{
547548
struct blame_origin *porigin;
548549
struct diff_options diff_opts;
@@ -562,7 +563,7 @@ static struct blame_origin *find_origin(struct commit *parent,
562563
* and origin first. Most of the time they are the
563564
* same and diff-tree is fairly efficient about this.
564565
*/
565-
diff_setup(&diff_opts);
566+
repo_diff_setup(r, &diff_opts);
566567
diff_opts.flags.recursive = 1;
567568
diff_opts.detect_rename = 0;
568569
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -629,14 +630,15 @@ static struct blame_origin *find_origin(struct commit *parent,
629630
* We have an origin -- find the path that corresponds to it in its
630631
* parent and return an origin structure to represent it.
631632
*/
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)
634636
{
635637
struct blame_origin *porigin = NULL;
636638
struct diff_options diff_opts;
637639
int i;
638640

639-
diff_setup(&diff_opts);
641+
repo_diff_setup(r, &diff_opts);
640642
diff_opts.flags.recursive = 1;
641643
diff_opts.detect_rename = DIFF_DETECT_RENAME;
642644
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1260,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12601262
if (!unblamed)
12611263
return; /* nothing remains for this target */
12621264

1263-
diff_setup(&diff_opts);
1265+
repo_diff_setup(sb->repo, &diff_opts);
12641266
diff_opts.flags.recursive = 1;
12651267
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
12661268

@@ -1442,7 +1444,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
14421444
* common cases, then we look for renames in the second pass.
14431445
*/
14441446
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 *);
14461448
find = pass ? find_rename : find_origin;
14471449

14481450
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,
14551457
continue;
14561458
if (parse_commit(p))
14571459
continue;
1458-
porigin = find(p, origin);
1460+
porigin = find(sb->repo, p, origin);
14591461
if (!porigin)
14601462
continue;
14611463
if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
339339
}
340340
if (no_index)
341341
/* 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);
343343

344344
/* Otherwise, we are doing the usual "git" diff */
345345
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ static void prepare_bases(struct base_tree_info *bases,
13611361
return;
13621362

13631363
init_commit_base(&commit_base);
1364-
diff_setup(&diffopt);
1364+
repo_diff_setup(the_repository, &diffopt);
13651365
diffopt.flags.recursive = 1;
13661366
diff_setup_done(&diffopt);
13671367

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ static void finish(struct commit *head_commit,
452452
}
453453
if (new_head && show_diffstat) {
454454
struct diff_options opts;
455-
diff_setup(&opts);
455+
repo_diff_setup(the_repository, &opts);
456456
opts.stat_width = -1; /* use full terminal width */
457457
opts.stat_graph_width = -1; /* respect statGraphWidth config */
458458
opts.output_format |=

builtin/range-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
3434

3535
git_config(git_diff_ui_config, NULL);
3636

37-
diff_setup(&diffopt);
37+
repo_diff_setup(the_repository, &diffopt);
3838
diffopt.output_format = DIFF_FORMAT_PATCH;
3939
diffopt.flags.suppress_diff_headers = 1;
4040
diffopt.output_prefix = output_prefix_cb;

diff-no-index.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,20 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
233233
}
234234
}
235235

236-
void diff_no_index(struct rev_info *revs,
236+
void diff_no_index(struct repository *r,
237+
struct rev_info *revs,
237238
int argc, const char **argv)
238239
{
239240
int i;
240241
const char *paths[2];
241242
struct strbuf replacement = STRBUF_INIT;
242243
const char *prefix = revs->prefix;
243244

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);
245250
for (i = 1; i < argc - 2; ) {
246251
int j;
247252
if (!strcmp(argv[i], "--no-index"))

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4390,12 +4390,12 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
43904390
builtin_checkdiff(name, other, attr_path, p->one, p->two, o);
43914391
}
43924392

4393-
void diff_setup(struct diff_options *options)
4393+
void repo_diff_setup(struct repository *r, struct diff_options *options)
43944394
{
43954395
memcpy(options, &default_diff_options, sizeof(*options));
43964396

43974397
options->file = stdout;
4398-
options->repo->index = &the_index;
4398+
options->repo = r;
43994399

44004400
options->abbrev = DEFAULT_ABBREV;
44014401
options->line_termination = '\n';

diff.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ int git_diff_basic_config(const char *var, const char *value, void *cb);
336336
int git_diff_heuristic_config(const char *var, const char *value, void *cb);
337337
void init_diff_ui_defaults(void);
338338
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 *);
340343
int diff_opt_parse(struct diff_options *, const char **, int, const char *);
341344
void diff_setup_done(struct diff_options *);
342345
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);
426429

427430
int diff_result_code(struct diff_options *, int);
428431

429-
void diff_no_index(struct rev_info *, int, const char **);
432+
void diff_no_index(struct repository *, struct rev_info *, int, const char **);
430433

431434
int index_differs_from(const char *def, const struct diff_flags *flags,
432435
int ita_invisible_in_index);

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
18121812
struct diff_queue_struct *ret;
18131813
struct diff_options opts;
18141814

1815-
diff_setup(&opts);
1815+
repo_diff_setup(the_repository, &opts);
18161816
opts.flags.recursive = 1;
18171817
opts.flags.rename_empty = 0;
18181818
opts.detect_rename = merge_detect_rename(o);

0 commit comments

Comments
 (0)