handle concurrent pruning of packed objects
This patch causes read_sha1_file and sha1_object_info to re-examine the list of packs if an object cannot be found. It works by re-running prepare_packed_git() after an object fails to be found. It does not attempt to clean up the old pack list. Old packs which are in use can continue to be used (until unused by lru selection). New packs are placed at the front of the list and will thus be examined before old packs. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jeff King committed
Jun 2, 2006 at 11:32 UTC
637cdd9d1d997fca34a1fc668fed1311e30fe95f
1 file changed
+18
-6
sha1_file.c
+18
-6
@@ -626,12 +626,12 @@ static void prepare_packed_git_one(char *objdir, int local)
626
closedir(dir);
627
}
628
629
+static int prepare_packed_git_run_once = 0;
630
void prepare_packed_git(void)
631
{
631
- static int run_once = 0;
632
struct alternate_object_database *alt;
633
634
- if (run_once)
634
+ if (prepare_packed_git_run_once)
635
return;
636
prepare_packed_git_one(get_object_directory(), 1);
637
prepare_alt_odb();
@@ -640,7 +640,13 @@ void prepare_packed_git(void)
640
prepare_packed_git_one(alt->base, 0);
641
alt->name[-1] = '/';
642
}
643
- run_once = 1;
643
+ prepare_packed_git_run_once = 1;
644
+}
645
+
646
+static void reprepare_packed_git(void)
647
+{
648
+ prepare_packed_git_run_once = 0;
649
+ prepare_packed_git();
650
}
651
652
int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long size, const char *type)
@@ -1212,9 +1218,12 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
1218
if (!map) {
1219
struct pack_entry e;
1220
1215
- if (!find_pack_entry(sha1, &e))
1216
- return error("unable to find %s", sha1_to_hex(sha1));
1217
- return packed_object_info(&e, type, sizep);
1221
+ if (find_pack_entry(sha1, &e))
1222
+ return packed_object_info(&e, type, sizep);
1223
+ reprepare_packed_git();
1224
+ if (find_pack_entry(sha1, &e))
1225
+ return packed_object_info(&e, type, sizep);
1226
+ return error("unable to find %s", sha1_to_hex(sha1));
1227
}
1228
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
1229
status = error("unable to unpack %s header",
@@ -1256,6 +1265,9 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
1265
munmap(map, mapsize);
1266
return buf;
1267
}
1268
+ reprepare_packed_git();
1269
+ if (find_pack_entry(sha1, &e))
1270
+ return read_packed_sha1(sha1, type, size);
1271
return NULL;
1272
}
1273