Skip to content

Commit ee99ba7

Browse files
committed
Merge branch 'jt/lazy-object-fetch-fix'
The code to backfill objects in lazily cloned repository did not work correctly, which has been corrected. * jt/lazy-object-fetch-fix: fetch-object: set exact_oid when fetching fetch-object: unify fetch_object[s] functions
2 parents 4af130a + e683020 commit ee99ba7

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

fetch-object.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,16 @@ static void fetch_refs(const char *remote_name, struct ref *ref)
2323
fetch_if_missing = original_fetch_if_missing;
2424
}
2525

26-
void fetch_object(const char *remote_name, const unsigned char *sha1)
27-
{
28-
struct ref *ref = alloc_ref(sha1_to_hex(sha1));
29-
hashcpy(ref->old_oid.hash, sha1);
30-
fetch_refs(remote_name, ref);
31-
}
32-
33-
void fetch_objects(const char *remote_name, const struct oid_array *to_fetch)
26+
void fetch_objects(const char *remote_name, const struct object_id *oids,
27+
int oid_nr)
3428
{
3529
struct ref *ref = NULL;
3630
int i;
3731

38-
for (i = 0; i < to_fetch->nr; i++) {
39-
struct ref *new_ref = alloc_ref(oid_to_hex(&to_fetch->oid[i]));
40-
oidcpy(&new_ref->old_oid, &to_fetch->oid[i]);
32+
for (i = 0; i < oid_nr; i++) {
33+
struct ref *new_ref = alloc_ref(oid_to_hex(&oids[i]));
34+
oidcpy(&new_ref->old_oid, &oids[i]);
35+
new_ref->exact_oid = 1;
4136
new_ref->next = ref;
4237
ref = new_ref;
4338
}

fetch-object.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#ifndef FETCH_OBJECT_H
22
#define FETCH_OBJECT_H
33

4-
#include "sha1-array.h"
5-
6-
extern void fetch_object(const char *remote_name, const unsigned char *sha1);
7-
8-
extern void fetch_objects(const char *remote_name,
9-
const struct oid_array *to_fetch);
4+
void fetch_objects(const char *remote_name, const struct object_id *oids,
5+
int oid_nr);
106

117
#endif

sha1-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
13171317
* TODO Pass a repository struct through fetch_object,
13181318
* such that arbitrary repositories work.
13191319
*/
1320-
fetch_object(repository_format_partial_clone, real->hash);
1320+
fetch_objects(repository_format_partial_clone, real, 1);
13211321
already_retried = 1;
13221322
continue;
13231323
}

t/t0410-partial-clone.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ test_expect_success 'fetching of missing objects' '
170170
git verify-pack --verbose "$IDX" | grep "$HASH"
171171
'
172172

173+
test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
174+
# ref-in-want requires protocol version 2
175+
git -C server config protocol.version 2 &&
176+
git -C server config uploadpack.allowrefinwant 1 &&
177+
git -C repo config protocol.version 2 &&
178+
179+
rm -rf repo/.git/objects/* &&
180+
rm -f trace &&
181+
GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
182+
grep "git< fetch=.*ref-in-want" trace
183+
'
184+
173185
test_expect_success 'rev-list stops traversal at missing and promised commit' '
174186
rm -rf repo &&
175187
test_create_repo repo &&

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static int check_updates(struct unpack_trees_options *o)
436436
}
437437
if (to_fetch.nr)
438438
fetch_objects(repository_format_partial_clone,
439-
&to_fetch);
439+
to_fetch.oid, to_fetch.nr);
440440
fetch_if_missing = fetch_if_missing_store;
441441
oid_array_clear(&to_fetch);
442442
}

0 commit comments

Comments
 (0)