xdiff-interface: stop using the_repository
Use the algorithm-agnostic is_null_oid() and push the dependency of read_mmblob() on the_repository->objects to its callers. This allows it to be used with arbitrary object databases. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Feb 9, 2026 at 20:24 UTC
af5706f033466b2a4f17d83168bf0bd021197c1d
7 files changed
+21
-18
apply.c
+3
-3
@@ -3568,9 +3568,9 @@ static int three_way_merge(struct apply_state *state,
3568
else if (oideq(base, theirs) || oideq(ours, theirs))
3569
return resolve_to(image, ours);
3570
3571
- read_mmblob(&base_file, base);
3572
- read_mmblob(&our_file, ours);
3573
- read_mmblob(&their_file, theirs);
3571
+ read_mmblob(&base_file, the_repository->objects, base);
3572
+ read_mmblob(&our_file, the_repository->objects, ours);
3573
+ read_mmblob(&their_file, the_repository->objects, theirs);
3574
merge_opts.variant = state->merge_variant;
3575
status = ll_merge(&result, path,
3576
&base_file, "base",
builtin/checkout.c
+3
-3
@@ -294,9 +294,9 @@ static int checkout_merged(int pos, const struct checkout *state,
294
if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
295
return error(_("path '%s' does not have necessary versions"), path);
296
297
- read_mmblob(&ancestor, &threeway[0]);
298
- read_mmblob(&ours, &threeway[1]);
299
- read_mmblob(&theirs, &threeway[2]);
297
+ read_mmblob(&ancestor, the_repository->objects, &threeway[0]);
298
+ read_mmblob(&ours, the_repository->objects, &threeway[1]);
299
+ read_mmblob(&theirs, the_repository->objects, &threeway[2]);
300
301
repo_config_get_bool(the_repository, "merge.renormalize", &renormalize);
302
ll_opts.renormalize = renormalize;
builtin/merge-file.c
+1
-1
@@ -128,7 +128,7 @@ int cmd_merge_file(int argc,
128
ret = error(_("object '%s' does not exist"),
129
argv[i]);
130
else if (!oideq(&oid, the_hash_algo->empty_blob))
131
- read_mmblob(mmf, &oid);
131
+ read_mmblob(mmf, the_repository->objects, &oid);
132
else
133
read_mmfile(mmf, "/dev/null");
134
} else if (read_mmfile(mmf, fname)) {
merge-ort.c
+3
-3
@@ -2136,9 +2136,9 @@ static int merge_3way(struct merge_options *opt,
2136
name2 = mkpathdup("%s:%s", opt->branch2, pathnames[2]);
2137
}
2138
2139
- read_mmblob(&orig, o);
2140
- read_mmblob(&src1, a);
2141
- read_mmblob(&src2, b);
2139
+ read_mmblob(&orig, the_repository->objects, o);
2140
+ read_mmblob(&src1, the_repository->objects, a);
2141
+ read_mmblob(&src2, the_repository->objects, b);
2142
2143
merge_status = ll_merge(result_buf, path, &orig, base,
2144
&src1, name1, &src2, name2,
notes-merge.c
+3
-3
@@ -359,9 +359,9 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
359
mmfile_t base, local, remote;
360
enum ll_merge_result status;
361
362
- read_mmblob(&base, &p->base);
363
- read_mmblob(&local, &p->local);
364
- read_mmblob(&remote, &p->remote);
362
+ read_mmblob(&base, the_repository->objects, &p->base);
363
+ read_mmblob(&local, the_repository->objects, &p->local);
364
+ read_mmblob(&remote, the_repository->objects, &p->remote);
365
366
status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
367
&local, o->local_ref, &remote, o->remote_ref,
xdiff-interface.c
+4
-4
@@ -1,4 +1,3 @@
1
-#define USE_THE_REPOSITORY_VARIABLE
1
#define DISABLE_SIGN_COMPARE_WARNINGS
2
3
#include "git-compat-util.h"
@@ -177,18 +176,19 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
176
return 0;
177
}
178
180
-void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
179
+void read_mmblob(mmfile_t *ptr, struct object_database *odb,
180
+ const struct object_id *oid)
181
{
182
unsigned long size;
183
enum object_type type;
184
185
- if (oideq(oid, null_oid(the_hash_algo))) {
185
+ if (is_null_oid(oid)) {
186
ptr->ptr = xstrdup("");
187
ptr->size = 0;
188
return;
189
}
190
191
- ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
191
+ ptr->ptr = odb_read_object(odb, oid, &type, &size);
192
if (!ptr->ptr || type != OBJ_BLOB)
193
die("unable to read blob object %s", oid_to_hex(oid));
194
ptr->size = size;
xdiff-interface.h
+4
-1
@@ -4,6 +4,8 @@
4
#include "hash.h"
5
#include "xdiff/xdiff.h"
6
7
+struct object_database;
8
+
9
/*
10
* xdiff isn't equipped to handle content over a gigabyte;
11
* we make the cutoff 1GB - 1MB to give some breathing
@@ -45,7 +47,8 @@ int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
47
void *consume_callback_data,
48
xpparam_t const *xpp, xdemitconf_t const *xecfg);
49
int read_mmfile(mmfile_t *ptr, const char *filename);
48
-void read_mmblob(mmfile_t *ptr, const struct object_id *oid);
50
+void read_mmblob(mmfile_t *ptr, struct object_database *odb,
51
+ const struct object_id *oid);
52
int buffer_is_binary(const char *ptr, unsigned long size);
53
54
void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);