sha1-file: support OBJECT_INFO_FOR_PREFETCH
Teach oid_object_info_extended() to support a new flag that inhibits fetching of missing objects. This is equivalent to setting fetch_is_missing to 0, calling oid_object_info_extended(), then setting fetch_if_missing to whatever it was before. Update unpack-trees.c to use this new flag instead of repeatedly setting fetch_if_missing. This new flag complicates things slightly in that there are now 2 ways to do the same thing. But this eliminates the need to repeatedly set a global variable, and more importantly, allows prefetching to be done in parallel (in the future); hence, this patch. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Mar 29, 2019 at 14:39 UTC
0f4a4fb1c4239a2aa46343add84ad6f99f6f3aae
3 files changed
+17
-9
object-store.h
+6
@@ -280,6 +280,12 @@ struct object_info {
280
#define OBJECT_INFO_QUICK 8
281
/* Do not check loose object */
282
#define OBJECT_INFO_IGNORE_LOOSE 16
283
+/*
284
+ * Do not attempt to fetch the object if missing (even if fetch_is_missing is
285
+ * nonzero). This is meant for bulk prefetching of missing blobs in a partial
286
+ * clone. Implies OBJECT_INFO_QUICK.
287
+ */
288
+#define OBJECT_INFO_FOR_PREFETCH (32 + OBJECT_INFO_QUICK)
289
290
int oid_object_info_extended(struct repository *r,
291
const struct object_id *,
sha1-file.c
+2
-1
@@ -1370,7 +1370,8 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
1370
1371
/* Check if it is a missing object */
1372
if (fetch_if_missing && repository_format_partial_clone &&
1373
- !already_retried && r == the_repository) {
1373
+ !already_retried && r == the_repository &&
1374
+ !(flags & OBJECT_INFO_FOR_PREFETCH)) {
1375
/*
1376
* TODO Investigate having fetch_object() return
1377
* TODO error/success and stopping the music here.
unpack-trees.c
+9
-8
@@ -404,20 +404,21 @@ static int check_updates(struct unpack_trees_options *o)
404
* below.
405
*/
406
struct oid_array to_fetch = OID_ARRAY_INIT;
407
- int fetch_if_missing_store = fetch_if_missing;
408
- fetch_if_missing = 0;
407
for (i = 0; i < index->cache_nr; i++) {
408
struct cache_entry *ce = index->cache[i];
411
- if ((ce->ce_flags & CE_UPDATE) &&
412
- !S_ISGITLINK(ce->ce_mode)) {
413
- if (!has_object_file(&ce->oid))
414
- oid_array_append(&to_fetch, &ce->oid);
415
- }
409
+
410
+ if (!(ce->ce_flags & CE_UPDATE) ||
411
+ S_ISGITLINK(ce->ce_mode))
412
+ continue;
413
+ if (!oid_object_info_extended(the_repository, &ce->oid,
414
+ NULL,
415
+ OBJECT_INFO_FOR_PREFETCH))
416
+ continue;
417
+ oid_array_append(&to_fetch, &ce->oid);
418
}
419
if (to_fetch.nr)
420
fetch_objects(repository_format_partial_clone,
421
to_fetch.oid, to_fetch.nr);
420
- fetch_if_missing = fetch_if_missing_store;
422
oid_array_clear(&to_fetch);
423
}
424
for (i = 0; i < index->cache_nr; i++) {