Skip to content

Commit 6042717

Browse files
committed
Merge branch 'en/merge-ort-almost-wo-the-repository' into jch
Mark the marge-ort codebase to prevent more uses of the_repository from getting added. * en/merge-ort-almost-wo-the-repository: replay: prevent the_repository from coming back merge-ort: prevent the_repository from coming back merge-ort: replace the_hash_algo with opt->repo->hash_algo merge-ort: replace the_repository with opt->repo merge-ort: pass repository to write_tree() merge,diff: remove the_repository check before prefetching blobs
2 parents 5e1c06a + 3249d07 commit 6042717

5 files changed

Lines changed: 61 additions & 47 deletions

File tree

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7194,7 +7194,7 @@ void diffcore_std(struct diff_options *options)
71947194
* If no prefetching occurs, diffcore_rename() will prefetch if it
71957195
* decides that it needs inexact rename detection.
71967196
*/
7197-
if (options->repo == the_repository && repo_has_promisor_remote(the_repository) &&
7197+
if (repo_has_promisor_remote(options->repo) &&
71987198
(options->output_format & output_formats_to_prefetch ||
71997199
options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK))
72007200
diff_queued_diff_prefetch(options->repo);

diffcore-break.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int should_break(struct repository *r,
6969
oideq(&src->oid, &dst->oid))
7070
return 0; /* they are the same */
7171

72-
if (r == the_repository && repo_has_promisor_remote(the_repository)) {
72+
if (repo_has_promisor_remote(r)) {
7373
options.missing_object_cb = diff_queued_diff_prefetch;
7474
options.missing_object_data = r;
7575
}

diffcore-rename.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ static int find_basename_matches(struct diff_options *options,
987987
strintmap_set(&dests, base, i);
988988
}
989989

990-
if (options->repo == the_repository && repo_has_promisor_remote(the_repository)) {
990+
if (repo_has_promisor_remote(options->repo)) {
991991
dpf_options.missing_object_cb = basename_prefetch;
992992
dpf_options.missing_object_data = &prefetch_options;
993993
}
@@ -1574,7 +1574,7 @@ void diffcore_rename_extended(struct diff_options *options,
15741574

15751575
/* Finish setting up dpf_options */
15761576
prefetch_options.skip_unmodified = skip_unmodified;
1577-
if (options->repo == the_repository && repo_has_promisor_remote(the_repository)) {
1577+
if (repo_has_promisor_remote(options->repo)) {
15781578
dpf_options.missing_object_cb = inexact_prefetch;
15791579
dpf_options.missing_object_data = &prefetch_options;
15801580
}

merge-ort.c

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
#include "unpack-trees.h"
5454
#include "xdiff-interface.h"
5555

56+
/*
57+
* We technically need USE_THE_REPOSITORY_VARIABLE above for DEFAULT_ABBREV,
58+
* but do not want more uses of the_repository. Prevent them.
59+
*
60+
* opt->repo is available; use it instead.
61+
*/
62+
#define the_repository DO_NOT_USE_THE_REPOSITORY
63+
5664
/*
5765
* We have many arrays of size 3. Whenever we have such an array, the
5866
* indices refer to one of the sides of the three-way merge. This is so
@@ -1732,9 +1740,9 @@ static int collect_merge_info(struct merge_options *opt,
17321740
info.data = opt;
17331741
info.show_all_errors = 1;
17341742

1735-
if (repo_parse_tree(the_repository, merge_base) < 0 ||
1736-
repo_parse_tree(the_repository, side1) < 0 ||
1737-
repo_parse_tree(the_repository, side2) < 0)
1743+
if (repo_parse_tree(opt->repo, merge_base) < 0 ||
1744+
repo_parse_tree(opt->repo, side1) < 0 ||
1745+
repo_parse_tree(opt->repo, side2) < 0)
17381746
return -1;
17391747
init_tree_desc(t + 0, &merge_base->object.oid,
17401748
merge_base->buffer, merge_base->size);
@@ -1857,7 +1865,7 @@ static int merge_submodule(struct merge_options *opt,
18571865
BUG("submodule deleted on one side; this should be handled outside of merge_submodule()");
18581866

18591867
if ((sub_not_initialized = repo_submodule_init(&subrepo,
1860-
opt->repo, path, null_oid(the_hash_algo)))) {
1868+
opt->repo, path, null_oid(opt->repo->hash_algo)))) {
18611869
path_msg(opt, CONFLICT_SUBMODULE_NOT_INITIALIZED, 0,
18621870
path, NULL, NULL, NULL,
18631871
_("Failed to merge submodule %s (not checked out)"),
@@ -2136,9 +2144,9 @@ static int merge_3way(struct merge_options *opt,
21362144
name2 = mkpathdup("%s:%s", opt->branch2, pathnames[2]);
21372145
}
21382146

2139-
read_mmblob(&orig, the_repository->objects, o);
2140-
read_mmblob(&src1, the_repository->objects, a);
2141-
read_mmblob(&src2, the_repository->objects, b);
2147+
read_mmblob(&orig, opt->repo->objects, o);
2148+
read_mmblob(&src1, opt->repo->objects, a);
2149+
read_mmblob(&src2, opt->repo->objects, b);
21422150

21432151
merge_status = ll_merge(result_buf, path, &orig, base,
21442152
&src1, name1, &src2, name2,
@@ -2240,7 +2248,7 @@ static int handle_content_merge(struct merge_options *opt,
22402248
two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode));
22412249

22422250
merge_status = merge_3way(opt, path,
2243-
two_way ? null_oid(the_hash_algo) : &o->oid,
2251+
two_way ? null_oid(opt->repo->hash_algo) : &o->oid,
22442252
&a->oid, &b->oid,
22452253
pathnames, extra_marker_size,
22462254
&result_buf);
@@ -2254,7 +2262,7 @@ static int handle_content_merge(struct merge_options *opt,
22542262
}
22552263

22562264
if (!ret && record_object &&
2257-
odb_write_object(the_repository->objects, result_buf.ptr, result_buf.size,
2265+
odb_write_object(opt->repo->objects, result_buf.ptr, result_buf.size,
22582266
OBJ_BLOB, &result->oid)) {
22592267
path_msg(opt, ERROR_OBJECT_WRITE_FAILED, 0,
22602268
pathnames[0], pathnames[1], pathnames[2], NULL,
@@ -2272,7 +2280,7 @@ static int handle_content_merge(struct merge_options *opt,
22722280
} else if (S_ISGITLINK(a->mode)) {
22732281
int two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode));
22742282
clean = merge_submodule(opt, pathnames[0],
2275-
two_way ? null_oid(the_hash_algo) : &o->oid,
2283+
two_way ? null_oid(opt->repo->hash_algo) : &o->oid,
22762284
&a->oid, &b->oid, &result->oid);
22772285
if (clean < 0)
22782286
return -1;
@@ -2786,7 +2794,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
27862794
assert(!new_ci->match_mask);
27872795
new_ci->dirmask = 0;
27882796
new_ci->stages[1].mode = 0;
2789-
oidcpy(&new_ci->stages[1].oid, null_oid(the_hash_algo));
2797+
oidcpy(&new_ci->stages[1].oid, null_oid(opt->repo->hash_algo));
27902798

27912799
/*
27922800
* Now that we have the file information in new_ci, make sure
@@ -2799,7 +2807,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
27992807
continue;
28002808
/* zero out any entries related to files */
28012809
ci->stages[i].mode = 0;
2802-
oidcpy(&ci->stages[i].oid, null_oid(the_hash_algo));
2810+
oidcpy(&ci->stages[i].oid, null_oid(opt->repo->hash_algo));
28032811
}
28042812

28052813
/* Now we want to focus on new_ci, so reassign ci to it. */
@@ -3214,7 +3222,7 @@ static int process_renames(struct merge_options *opt,
32143222
if (type_changed) {
32153223
/* rename vs. typechange */
32163224
/* Mark the original as resolved by removal */
3217-
memcpy(&oldinfo->stages[0].oid, null_oid(the_hash_algo),
3225+
memcpy(&oldinfo->stages[0].oid, null_oid(opt->repo->hash_algo),
32183226
sizeof(oldinfo->stages[0].oid));
32193227
oldinfo->stages[0].mode = 0;
32203228
oldinfo->filemask &= 0x06;
@@ -3713,7 +3721,7 @@ static int read_oid_strbuf(struct merge_options *opt,
37133721
void *buf;
37143722
enum object_type type;
37153723
unsigned long size;
3716-
buf = odb_read_object(the_repository->objects, oid, &type, &size);
3724+
buf = odb_read_object(opt->repo->objects, oid, &type, &size);
37173725
if (!buf) {
37183726
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
37193727
path, NULL, NULL, NULL,
@@ -3822,15 +3830,16 @@ static int tree_entry_order(const void *a_, const void *b_)
38223830
b->string, strlen(b->string), bmi->result.mode);
38233831
}
38243832

3825-
static int write_tree(struct object_id *result_oid,
3833+
static int write_tree(struct repository *repo,
3834+
struct object_id *result_oid,
38263835
struct string_list *versions,
3827-
unsigned int offset,
3828-
size_t hash_size)
3836+
unsigned int offset)
38293837
{
38303838
size_t maxlen = 0, extra;
38313839
unsigned int nr;
38323840
struct strbuf buf = STRBUF_INIT;
38333841
int i, ret = 0;
3842+
size_t hash_size = repo->hash_algo->rawsz;
38343843

38353844
assert(offset <= versions->nr);
38363845
nr = versions->nr - offset;
@@ -3856,7 +3865,7 @@ static int write_tree(struct object_id *result_oid,
38563865
}
38573866

38583867
/* Write this object file out, and record in result_oid */
3859-
if (odb_write_object(the_repository->objects, buf.buf,
3868+
if (odb_write_object(repo->objects, buf.buf,
38603869
buf.len, OBJ_TREE, result_oid))
38613870
ret = -1;
38623871
strbuf_release(&buf);
@@ -4026,8 +4035,8 @@ static int write_completed_directory(struct merge_options *opt,
40264035
dir_info->is_null = 0;
40274036
dir_info->result.mode = S_IFDIR;
40284037
if (record_tree &&
4029-
write_tree(&dir_info->result.oid, &info->versions, offset,
4030-
opt->repo->hash_algo->rawsz) < 0)
4038+
write_tree(opt->repo, &dir_info->result.oid, &info->versions,
4039+
offset) < 0)
40314040
ret = -1;
40324041
}
40334042

@@ -4101,7 +4110,7 @@ static int process_entry(struct merge_options *opt,
41014110
if (ci->filemask & (1 << i))
41024111
continue;
41034112
ci->stages[i].mode = 0;
4104-
oidcpy(&ci->stages[i].oid, null_oid(the_hash_algo));
4113+
oidcpy(&ci->stages[i].oid, null_oid(opt->repo->hash_algo));
41054114
}
41064115
} else if (ci->df_conflict && ci->merged.result.mode != 0) {
41074116
/*
@@ -4148,7 +4157,7 @@ static int process_entry(struct merge_options *opt,
41484157
continue;
41494158
/* zero out any entries related to directories */
41504159
new_ci->stages[i].mode = 0;
4151-
oidcpy(&new_ci->stages[i].oid, null_oid(the_hash_algo));
4160+
oidcpy(&new_ci->stages[i].oid, null_oid(opt->repo->hash_algo));
41524161
}
41534162

41544163
/*
@@ -4270,23 +4279,23 @@ static int process_entry(struct merge_options *opt,
42704279
new_ci->merged.result.mode = ci->stages[2].mode;
42714280
oidcpy(&new_ci->merged.result.oid, &ci->stages[2].oid);
42724281
new_ci->stages[1].mode = 0;
4273-
oidcpy(&new_ci->stages[1].oid, null_oid(the_hash_algo));
4282+
oidcpy(&new_ci->stages[1].oid, null_oid(opt->repo->hash_algo));
42744283
new_ci->filemask = 5;
42754284
if ((S_IFMT & b_mode) != (S_IFMT & o_mode)) {
42764285
new_ci->stages[0].mode = 0;
4277-
oidcpy(&new_ci->stages[0].oid, null_oid(the_hash_algo));
4286+
oidcpy(&new_ci->stages[0].oid, null_oid(opt->repo->hash_algo));
42784287
new_ci->filemask = 4;
42794288
}
42804289

42814290
/* Leave only a in ci, fixing stages. */
42824291
ci->merged.result.mode = ci->stages[1].mode;
42834292
oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
42844293
ci->stages[2].mode = 0;
4285-
oidcpy(&ci->stages[2].oid, null_oid(the_hash_algo));
4294+
oidcpy(&ci->stages[2].oid, null_oid(opt->repo->hash_algo));
42864295
ci->filemask = 3;
42874296
if ((S_IFMT & a_mode) != (S_IFMT & o_mode)) {
42884297
ci->stages[0].mode = 0;
4289-
oidcpy(&ci->stages[0].oid, null_oid(the_hash_algo));
4298+
oidcpy(&ci->stages[0].oid, null_oid(opt->repo->hash_algo));
42904299
ci->filemask = 2;
42914300
}
42924301

@@ -4414,7 +4423,7 @@ static int process_entry(struct merge_options *opt,
44144423
/* Deleted on both sides */
44154424
ci->merged.is_null = 1;
44164425
ci->merged.result.mode = 0;
4417-
oidcpy(&ci->merged.result.oid, null_oid(the_hash_algo));
4426+
oidcpy(&ci->merged.result.oid, null_oid(opt->repo->hash_algo));
44184427
assert(!ci->df_conflict);
44194428
ci->merged.clean = !ci->path_conflict;
44204429
}
@@ -4438,7 +4447,7 @@ static void prefetch_for_content_merges(struct merge_options *opt,
44384447
struct string_list_item *e;
44394448
struct oid_array to_fetch = OID_ARRAY_INIT;
44404449

4441-
if (opt->repo != the_repository || !repo_has_promisor_remote(the_repository))
4450+
if (!repo_has_promisor_remote(opt->repo))
44424451
return;
44434452

44444453
for (e = &plist->items[plist->nr-1]; e >= plist->items; --e) {
@@ -4573,8 +4582,7 @@ static int process_entries(struct merge_options *opt,
45734582
BUG("dir_metadata accounting completely off; shouldn't happen");
45744583
}
45754584
if (record_tree &&
4576-
write_tree(result_oid, &dir_metadata.versions, 0,
4577-
opt->repo->hash_algo->rawsz) < 0)
4585+
write_tree(opt->repo, result_oid, &dir_metadata.versions, 0) < 0)
45784586
ret = -1;
45794587
cleanup:
45804588
string_list_clear(&plist, 0);
@@ -4619,10 +4627,10 @@ static int checkout(struct merge_options *opt,
46194627
unpack_opts.verbose_update = (opt->verbosity > 2);
46204628
unpack_opts.fn = twoway_merge;
46214629
unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */
4622-
if (repo_parse_tree(the_repository, prev) < 0)
4630+
if (repo_parse_tree(opt->repo, prev) < 0)
46234631
return -1;
46244632
init_tree_desc(&trees[0], &prev->object.oid, prev->buffer, prev->size);
4625-
if (repo_parse_tree(the_repository, next) < 0)
4633+
if (repo_parse_tree(opt->repo, next) < 0)
46264634
return -1;
46274635
init_tree_desc(&trees[1], &next->object.oid, next->buffer, next->size);
46284636

@@ -5280,7 +5288,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
52805288

52815289
if (result->clean >= 0) {
52825290
if (!opt->mergeability_only) {
5283-
result->tree = repo_parse_tree_indirect(the_repository,
5291+
result->tree = repo_parse_tree_indirect(opt->repo,
52845292
&working_tree_oid);
52855293
if (!result->tree)
52865294
die(_("unable to read tree (%s)"),
@@ -5309,7 +5317,7 @@ static void merge_ort_internal(struct merge_options *opt,
53095317
struct strbuf merge_base_abbrev = STRBUF_INIT;
53105318

53115319
if (!merge_bases) {
5312-
if (repo_get_merge_bases(the_repository, h1, h2,
5320+
if (repo_get_merge_bases(opt->repo, h1, h2,
53135321
&merge_bases) < 0) {
53145322
result->clean = -1;
53155323
goto out;
@@ -5440,20 +5448,20 @@ static void merge_recursive_config(struct merge_options *opt, int ui)
54405448
{
54415449
char *value = NULL;
54425450
int renormalize = 0;
5443-
repo_config_get_int(the_repository, "merge.verbosity", &opt->verbosity);
5444-
repo_config_get_int(the_repository, "diff.renamelimit", &opt->rename_limit);
5445-
repo_config_get_int(the_repository, "merge.renamelimit", &opt->rename_limit);
5446-
repo_config_get_bool(the_repository, "merge.renormalize", &renormalize);
5451+
repo_config_get_int(opt->repo, "merge.verbosity", &opt->verbosity);
5452+
repo_config_get_int(opt->repo, "diff.renamelimit", &opt->rename_limit);
5453+
repo_config_get_int(opt->repo, "merge.renamelimit", &opt->rename_limit);
5454+
repo_config_get_bool(opt->repo, "merge.renormalize", &renormalize);
54475455
opt->renormalize = renormalize;
5448-
if (!repo_config_get_string(the_repository, "diff.renames", &value)) {
5456+
if (!repo_config_get_string(opt->repo, "diff.renames", &value)) {
54495457
opt->detect_renames = git_config_rename("diff.renames", value);
54505458
free(value);
54515459
}
5452-
if (!repo_config_get_string(the_repository, "merge.renames", &value)) {
5460+
if (!repo_config_get_string(opt->repo, "merge.renames", &value)) {
54535461
opt->detect_renames = git_config_rename("merge.renames", value);
54545462
free(value);
54555463
}
5456-
if (!repo_config_get_string(the_repository, "merge.directoryrenames", &value)) {
5464+
if (!repo_config_get_string(opt->repo, "merge.directoryrenames", &value)) {
54575465
int boolval = git_parse_maybe_bool(value);
54585466
if (0 <= boolval) {
54595467
opt->detect_directory_renames = boolval ?
@@ -5466,15 +5474,15 @@ static void merge_recursive_config(struct merge_options *opt, int ui)
54665474
free(value);
54675475
}
54685476
if (ui) {
5469-
if (!repo_config_get_string(the_repository, "diff.algorithm", &value)) {
5477+
if (!repo_config_get_string(opt->repo, "diff.algorithm", &value)) {
54705478
long diff_algorithm = parse_algorithm_value(value);
54715479
if (diff_algorithm < 0)
54725480
die(_("unknown value for config '%s': %s"), "diff.algorithm", value);
54735481
opt->xdl_opts = (opt->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | diff_algorithm;
54745482
free(value);
54755483
}
54765484
}
5477-
repo_config(the_repository, git_xmerge_config, NULL);
5485+
repo_config(opt->repo, git_xmerge_config, NULL);
54785486
}
54795487

54805488
static void init_merge_options(struct merge_options *opt,

replay.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include "strmap.h"
1212
#include "tree.h"
1313

14+
/*
15+
* We technically need USE_THE_REPOSITORY_VARIABLE for DEFAULT_ABBREV, but
16+
* do not want to use the_repository.
17+
*/
18+
#define the_repository DO_NOT_USE_THE_REPOSITORY
19+
1420
static const char *short_commit_name(struct repository *repo,
1521
struct commit *commit)
1622
{

0 commit comments

Comments
 (0)