Skip to content

Commit 11877b9

Browse files
committed
Merge branch 'nd/the-index'
Various codepaths in the core-ish part learn to work on an arbitrary in-core index structure, not necessarily the default instance "the_index". * nd/the-index: (23 commits) revision.c: reduce implicit dependency the_repository revision.c: remove implicit dependency on the_index ws.c: remove implicit dependency on the_index tree-diff.c: remove implicit dependency on the_index submodule.c: remove implicit dependency on the_index line-range.c: remove implicit dependency on the_index userdiff.c: remove implicit dependency on the_index rerere.c: remove implicit dependency on the_index sha1-file.c: remove implicit dependency on the_index patch-ids.c: remove implicit dependency on the_index merge.c: remove implicit dependency on the_index merge-blobs.c: remove implicit dependency on the_index ll-merge.c: remove implicit dependency on the_index diff-lib.c: remove implicit dependency on the_index read-cache.c: remove implicit dependency on the_index diff.c: remove implicit dependency on the_index grep.c: remove implicit dependency on the_index diff.c: remove the_index dependency in textconv() functions blame.c: rename "repo" argument to "r" combine-diff.c: remove implicit dependency on the_index ...
2 parents aef8e71 + b3c7eef commit 11877b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+751
-552
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

Documentation/technical/api-revision-walking.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ revision list.
1515
Functions
1616
---------
1717

18-
`init_revisions`::
18+
`repo_init_revisions`::
1919

20-
Initialize a rev_info structure with default values. The second
20+
Initialize a rev_info structure with default values. The third
2121
parameter may be NULL or can be prefix path, and then the `.prefix`
2222
variable will be set to it. This is typically the first function you
2323
want to call when you want to deal with a revision list. After calling

apply.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,10 +2131,12 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si
21312131

21322132
if (!use_patch(state, patch))
21332133
patch->ws_rule = 0;
2134+
else if (patch->new_name)
2135+
patch->ws_rule = whitespace_rule(state->repo->index,
2136+
patch->new_name);
21342137
else
2135-
patch->ws_rule = whitespace_rule(patch->new_name
2136-
? patch->new_name
2137-
: patch->old_name);
2138+
patch->ws_rule = whitespace_rule(state->repo->index,
2139+
patch->old_name);
21382140

21392141
patchsize = parse_single_patch(state,
21402142
buffer + offset + hdrsize,
@@ -3467,7 +3469,8 @@ static int load_preimage(struct apply_state *state,
34673469
return 0;
34683470
}
34693471

3470-
static int three_way_merge(struct image *image,
3472+
static int three_way_merge(struct apply_state *state,
3473+
struct image *image,
34713474
char *path,
34723475
const struct object_id *base,
34733476
const struct object_id *ours,
@@ -3483,7 +3486,9 @@ static int three_way_merge(struct image *image,
34833486
status = ll_merge(&result, path,
34843487
&base_file, "base",
34853488
&our_file, "ours",
3486-
&their_file, "theirs", NULL);
3489+
&their_file, "theirs",
3490+
state->repo->index,
3491+
NULL);
34873492
free(base_file.ptr);
34883493
free(our_file.ptr);
34893494
free(their_file.ptr);
@@ -3595,7 +3600,7 @@ static int try_threeway(struct apply_state *state,
35953600
clear_image(&tmp_image);
35963601

35973602
/* in-core three-way merge between post and our using pre as base */
3598-
status = three_way_merge(image, patch->new_name,
3603+
status = three_way_merge(state, image, patch->new_name,
35993604
&pre_oid, &our_oid, &post_oid);
36003605
if (status < 0) {
36013606
if (state->apply_verbosity > verbosity_silent)
@@ -4627,7 +4632,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)
46274632
}
46284633
string_list_clear(&cpath, 0);
46294634

4630-
rerere(0);
4635+
repo_rerere(state->repo, 0);
46314636
}
46324637

46334638
return errs;

archive-zip.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ static int has_only_ascii(const char *s)
264264
}
265265
}
266266

267-
static int entry_is_binary(const char *path, const void *buffer, size_t size)
267+
static int entry_is_binary(struct index_state *istate, const char *path,
268+
const void *buffer, size_t size)
268269
{
269-
struct userdiff_driver *driver = userdiff_find_by_path(path);
270+
struct userdiff_driver *driver = userdiff_find_by_path(istate, path);
270271
if (!driver)
271272
driver = userdiff_find_by_name("default");
272273
if (driver->binary != -1)
@@ -352,7 +353,8 @@ static int write_zip_entry(struct archiver_args *args,
352353
return error(_("cannot read %s"),
353354
oid_to_hex(oid));
354355
crc = crc32(crc, buffer, size);
355-
is_binary = entry_is_binary(path_without_prefix,
356+
is_binary = entry_is_binary(args->repo->index,
357+
path_without_prefix,
356358
buffer, size);
357359
out = buffer;
358360
}
@@ -428,7 +430,8 @@ static int write_zip_entry(struct archiver_args *args,
428430
break;
429431
crc = crc32(crc, buf, readlen);
430432
if (is_binary == -1)
431-
is_binary = entry_is_binary(path_without_prefix,
433+
is_binary = entry_is_binary(args->repo->index,
434+
path_without_prefix,
432435
buf, readlen);
433436
write_or_die(1, buf, readlen);
434437
}
@@ -460,7 +463,8 @@ static int write_zip_entry(struct archiver_args *args,
460463
break;
461464
crc = crc32(crc, buf, readlen);
462465
if (is_binary == -1)
463-
is_binary = entry_is_binary(path_without_prefix,
466+
is_binary = entry_is_binary(args->repo->index,
467+
path_without_prefix,
464468
buf, readlen);
465469

466470
zstream.next_in = buf;

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static void parse_treeish_arg(const char **argv,
392392
if (get_oid(name, &oid))
393393
die("Not a valid object name");
394394

395-
commit = lookup_commit_reference_gently(the_repository, &oid, 1);
395+
commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
396396
if (commit) {
397397
commit_sha1 = commit->object.oid.hash;
398398
archive_time = commit->date;

bisect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
633633
struct argv_array rev_argv = ARGV_ARRAY_INIT;
634634
int i;
635635

636-
init_revisions(revs, prefix);
636+
repo_init_revisions(the_repository, revs, prefix);
637637
revs->abbrev = 0;
638638
revs->commit_format = CMIT_FMT_UNSPECIFIED;
639639

@@ -890,7 +890,7 @@ static void show_diff_tree(const char *prefix, struct commit *commit)
890890
struct rev_info opt;
891891

892892
/* diff-tree init */
893-
init_revisions(&opt, prefix);
893+
repo_init_revisions(the_repository, &opt, prefix);
894894
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
895895
opt.abbrev = 0;
896896
opt.diff = 1;

blame.c

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
9090

9191

9292

93-
static void verify_working_tree_path(struct repository *repo,
93+
static void verify_working_tree_path(struct repository *r,
9494
struct commit *work_tree, const char *path)
9595
{
9696
struct commit_list *parents;
@@ -102,15 +102,15 @@ static void verify_working_tree_path(struct repository *repo,
102102
unsigned mode;
103103

104104
if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
105-
oid_object_info(repo, &blob_oid, NULL) == OBJ_BLOB)
105+
oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
106106
return;
107107
}
108108

109-
pos = index_name_pos(repo->index, path, strlen(path));
109+
pos = index_name_pos(r->index, path, strlen(path));
110110
if (pos >= 0)
111111
; /* path is in the index */
112-
else if (-1 - pos < repo->index->cache_nr &&
113-
!strcmp(repo->index->cache[-1 - pos]->name, path))
112+
else if (-1 - pos < r->index->cache_nr &&
113+
!strcmp(r->index->cache[-1 - pos]->name, path))
114114
; /* path is in the index, unmerged */
115115
else
116116
die("no such path '%s' in HEAD", path);
@@ -166,7 +166,7 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
166166
* Prepare a dummy commit that represents the work tree (or staged) item.
167167
* Note that annotating work tree item never works in the reverse.
168168
*/
169-
static struct commit *fake_working_tree_commit(struct repository *repo,
169+
static struct commit *fake_working_tree_commit(struct repository *r,
170170
struct diff_options *opt,
171171
const char *path,
172172
const char *contents_from)
@@ -183,7 +183,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
183183
unsigned mode;
184184
struct strbuf msg = STRBUF_INIT;
185185

186-
read_index(repo->index);
186+
read_index(r->index);
187187
time(&now);
188188
commit = alloc_commit_node(the_repository);
189189
commit->object.parsed = 1;
@@ -195,7 +195,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
195195

196196
parent_tail = append_parent(parent_tail, &head_oid);
197197
append_merge_parents(parent_tail);
198-
verify_working_tree_path(repo, commit, path);
198+
verify_working_tree_path(r, commit, path);
199199

200200
origin = make_origin(commit, path);
201201

@@ -234,7 +234,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
234234
switch (st.st_mode & S_IFMT) {
235235
case S_IFREG:
236236
if (opt->flags.allow_textconv &&
237-
textconv_object(read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
237+
textconv_object(r, read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
238238
strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
239239
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
240240
die_errno("cannot open or read '%s'", read_from);
@@ -253,7 +253,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
253253
if (strbuf_read(&buf, 0, 0) < 0)
254254
die_errno("failed to read from stdin");
255255
}
256-
convert_to_git(repo->index, path, buf.buf, buf.len, &buf, 0);
256+
convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
257257
origin->file.ptr = buf.buf;
258258
origin->file.size = buf.len;
259259
pretend_object_file(buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
@@ -264,28 +264,28 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
264264
* bits; we are not going to write this index out -- we just
265265
* want to run "diff-index --cached".
266266
*/
267-
discard_index(repo->index);
268-
read_index(repo->index);
267+
discard_index(r->index);
268+
read_index(r->index);
269269

270270
len = strlen(path);
271271
if (!mode) {
272-
int pos = index_name_pos(repo->index, path, len);
272+
int pos = index_name_pos(r->index, path, len);
273273
if (0 <= pos)
274-
mode = repo->index->cache[pos]->ce_mode;
274+
mode = r->index->cache[pos]->ce_mode;
275275
else
276276
/* Let's not bother reading from HEAD tree */
277277
mode = S_IFREG | 0644;
278278
}
279-
ce = make_empty_cache_entry(repo->index, len);
279+
ce = make_empty_cache_entry(r->index, len);
280280
oidcpy(&ce->oid, &origin->blob_oid);
281281
memcpy(ce->name, path, len);
282282
ce->ce_flags = create_ce_flags(0);
283283
ce->ce_namelen = len;
284284
ce->ce_mode = create_ce_mode(mode);
285-
add_index_entry(repo->index, ce,
285+
add_index_entry(r->index, ce,
286286
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
287287

288-
cache_tree_invalidate_path(repo->index, path);
288+
cache_tree_invalidate_path(r->index, path);
289289

290290
return commit;
291291
}
@@ -318,7 +318,8 @@ static void fill_origin_blob(struct diff_options *opt,
318318

319319
(*num_read_blob)++;
320320
if (opt->flags.allow_textconv &&
321-
textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
321+
textconv_object(opt->repo, o->path, o->mode,
322+
&o->blob_oid, 1, &file->ptr, &file_size))
322323
;
323324
else
324325
file->ptr = read_object_file(&o->blob_oid, &type,
@@ -520,14 +521,14 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
520521
*
521522
* This also fills origin->mode for corresponding tree path.
522523
*/
523-
static int fill_blob_sha1_and_mode(struct repository *repo,
524+
static int fill_blob_sha1_and_mode(struct repository *r,
524525
struct blame_origin *origin)
525526
{
526527
if (!is_null_oid(&origin->blob_oid))
527528
return 0;
528529
if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
529530
goto error_out;
530-
if (oid_object_info(repo, &origin->blob_oid, NULL) != OBJ_BLOB)
531+
if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
531532
goto error_out;
532533
return 0;
533534
error_out:
@@ -540,8 +541,9 @@ static int fill_blob_sha1_and_mode(struct repository *repo,
540541
* We have an origin -- check if the same path exists in the
541542
* parent and return an origin structure to represent it.
542543
*/
543-
static struct blame_origin *find_origin(struct commit *parent,
544-
struct blame_origin *origin)
544+
static struct blame_origin *find_origin(struct repository *r,
545+
struct commit *parent,
546+
struct blame_origin *origin)
545547
{
546548
struct blame_origin *porigin;
547549
struct diff_options diff_opts;
@@ -561,7 +563,7 @@ static struct blame_origin *find_origin(struct commit *parent,
561563
* and origin first. Most of the time they are the
562564
* same and diff-tree is fairly efficient about this.
563565
*/
564-
diff_setup(&diff_opts);
566+
repo_diff_setup(r, &diff_opts);
565567
diff_opts.flags.recursive = 1;
566568
diff_opts.detect_rename = 0;
567569
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -628,14 +630,15 @@ static struct blame_origin *find_origin(struct commit *parent,
628630
* We have an origin -- find the path that corresponds to it in its
629631
* parent and return an origin structure to represent it.
630632
*/
631-
static struct blame_origin *find_rename(struct commit *parent,
632-
struct blame_origin *origin)
633+
static struct blame_origin *find_rename(struct repository *r,
634+
struct commit *parent,
635+
struct blame_origin *origin)
633636
{
634637
struct blame_origin *porigin = NULL;
635638
struct diff_options diff_opts;
636639
int i;
637640

638-
diff_setup(&diff_opts);
641+
repo_diff_setup(r, &diff_opts);
639642
diff_opts.flags.recursive = 1;
640643
diff_opts.detect_rename = DIFF_DETECT_RENAME;
641644
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1259,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12591262
if (!unblamed)
12601263
return; /* nothing remains for this target */
12611264

1262-
diff_setup(&diff_opts);
1265+
repo_diff_setup(sb->repo, &diff_opts);
12631266
diff_opts.flags.recursive = 1;
12641267
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
12651268

@@ -1441,7 +1444,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
14411444
* common cases, then we look for renames in the second pass.
14421445
*/
14431446
for (pass = 0; pass < 2 - sb->no_whole_file_rename; pass++) {
1444-
struct blame_origin *(*find)(struct commit *, struct blame_origin *);
1447+
struct blame_origin *(*find)(struct repository *, struct commit *, struct blame_origin *);
14451448
find = pass ? find_rename : find_origin;
14461449

14471450
for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
@@ -1454,7 +1457,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
14541457
continue;
14551458
if (parse_commit(p))
14561459
continue;
1457-
porigin = find(p, origin);
1460+
porigin = find(sb->repo, p, origin);
14581461
if (!porigin)
14591462
continue;
14601463
if (oideq(&porigin->blob_oid, &origin->blob_oid)) {
@@ -1857,7 +1860,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
18571860
die(_("no such path %s in %s"), path, final_commit_name);
18581861

18591862
if (sb->revs->diffopt.flags.allow_textconv &&
1860-
textconv_object(path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
1863+
textconv_object(sb->repo, path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
18611864
&sb->final_buf_size))
18621865
;
18631866
else

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int add_files_to_cache(const char *prefix,
110110
memset(&data, 0, sizeof(data));
111111
data.flags = flags;
112112

113-
init_revisions(&rev, prefix);
113+
repo_init_revisions(the_repository, &rev, prefix);
114114
setup_revisions(0, NULL, &rev, NULL);
115115
if (pathspec)
116116
copy_pathspec(&rev.prune_data, pathspec);
@@ -232,7 +232,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
232232
if (read_cache() < 0)
233233
die(_("Could not read the index"));
234234

235-
init_revisions(&rev, prefix);
235+
repo_init_revisions(the_repository, &rev, prefix);
236236
rev.diffopt.context = 7;
237237

238238
argc = setup_revisions(argc, argv, &rev, NULL);

0 commit comments

Comments
 (0)