sha1_object_info(): be consistent with read_sha1_file()
We used to try loose objects first with sha1_object_info(), but packed objects first with read_sha1_file(). Now, prefer packed objects over loose ones with sha1_object_info(), too. Usually the old behaviour would pose no problem, but when you tried to fix a fscked up repository by inserting a known-good pack, git cat-file $(git cat-file -t <sha1>) <sha1> could fail, even when git cat-file blob <sha1> would _not_ fail. Worse, a repack would fail, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Nov 28, 2006 at 00:18 UTC
f0df4ed5629c25e9978708115ad654b9f83f55df
1 file changed
+20
-15
sha1_file.c
+20
-15
@@ -1261,7 +1261,7 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
1261
1262
}
1263
1264
-int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)
1264
+static int sha1_loose_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)
1265
{
1266
int status;
1267
unsigned long mapsize, size;
@@ -1270,20 +1270,8 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
1270
char hdr[128];
1271
1272
map = map_sha1_file(sha1, &mapsize);
1273
- if (!map) {
1274
- struct pack_entry e;
1275
-
1276
- if (!find_pack_entry(sha1, &e, NULL)) {
1277
- reprepare_packed_git();
1278
- if (!find_pack_entry(sha1, &e, NULL))
1279
- return error("unable to find %s", sha1_to_hex(sha1));
1280
- }
1281
- if (use_packed_git(e.p))
1282
- die("cannot map packed file");
1283
- status = packed_object_info(e.p, e.offset, type, sizep);
1284
- unuse_packed_git(e.p);
1285
- return status;
1286
- }
1273
+ if (!map)
1274
+ return error("unable to find %s", sha1_to_hex(sha1));
1275
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
1276
status = error("unable to unpack %s header",
1277
sha1_to_hex(sha1));
@@ -1299,6 +1287,23 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
1287
return status;
1288
}
1289
1290
+int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)
1291
+{
1292
+ int status;
1293
+ struct pack_entry e;
1294
+
1295
+ if (!find_pack_entry(sha1, &e, NULL)) {
1296
+ reprepare_packed_git();
1297
+ if (!find_pack_entry(sha1, &e, NULL))
1298
+ return sha1_loose_object_info(sha1, type, sizep);
1299
+ }
1300
+ if (use_packed_git(e.p))
1301
+ die("cannot map packed file");
1302
+ status = packed_object_info(e.p, e.offset, type, sizep);
1303
+ unuse_packed_git(e.p);
1304
+ return status;
1305
+}
1306
+
1307
static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned long *size)
1308
{
1309
struct pack_entry e;