976
return map_loose_object_1(r, NULL, oid, size);
977
}
978
979
-static int unpack_sha1_short_header(git_zstream *stream,
980
- unsigned char *map, unsigned long mapsize,
981
- void *buffer, unsigned long bufsiz)
979
+static int unpack_loose_short_header(git_zstream *stream,
980
+ unsigned char *map, unsigned long mapsize,
981
+ void *buffer, unsigned long bufsiz)
982
{
983
/* Get the data stream */
984
memset(stream, 0, sizeof(*stream));
991
return git_inflate(stream, 0);
992
}
993
994
-int unpack_sha1_header(git_zstream *stream,
995
- unsigned char *map, unsigned long mapsize,
996
- void *buffer, unsigned long bufsiz)
994
+int unpack_loose_header(git_zstream *stream,
995
+ unsigned char *map, unsigned long mapsize,
996
+ void *buffer, unsigned long bufsiz)
997
{
998
- int status = unpack_sha1_short_header(stream, map, mapsize,
999
- buffer, bufsiz);
998
+ int status = unpack_loose_short_header(stream, map, mapsize,
999
+ buffer, bufsiz);
1000
1001
if (status < Z_OK)
1002
return status;
1007
return 0;
1008
}
1009
1010
-static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
1011
- unsigned long mapsize, void *buffer,
1012
- unsigned long bufsiz, struct strbuf *header)
1010
+static int unpack_loose_header_to_strbuf(git_zstream *stream, unsigned char *map,
1011
+ unsigned long mapsize, void *buffer,
1012
+ unsigned long bufsiz, struct strbuf *header)
1013
{
1014
int status;
1015
1016
- status = unpack_sha1_short_header(stream, map, mapsize, buffer, bufsiz);
1016
+ status = unpack_loose_short_header(stream, map, mapsize, buffer, bufsiz);
1017
if (status < Z_OK)
1018
return -1;
1019
1043
return -1;
1044
}
1045
1046
-static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long size, const unsigned char *sha1)
1046
+static void *unpack_loose_rest(git_zstream *stream,
1047
+ void *buffer, unsigned long size,
1048
+ const struct object_id *oid)
1049
{
1050
int bytes = strlen(buffer) + 1;
1051
unsigned char *buf = xmallocz(size);
1082
}
1083
1084
if (status < 0)
1083
- error(_("corrupt loose object '%s'"), sha1_to_hex(sha1));
1085
+ error(_("corrupt loose object '%s'"), oid_to_hex(oid));
1086
else if (stream->avail_in)
1087
error(_("garbage at end of loose object '%s'"),
1086
- sha1_to_hex(sha1));
1088
+ oid_to_hex(oid));
1089
free(buf);
1090
return NULL;
1091
}
1095
* too permissive for what we want to check. So do an anal
1096
* object header parse by hand.
1097
*/
1096
-static int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
1097
- unsigned int flags)
1098
+static int parse_loose_header_extended(const char *hdr, struct object_info *oi,
1099
+ unsigned int flags)
1100
{
1101
const char *type_buf = hdr;
1102
unsigned long size;
1156
return *hdr ? -1 : type;
1157
}
1158
1157
-int parse_sha1_header(const char *hdr, unsigned long *sizep)
1159
+int parse_loose_header(const char *hdr, unsigned long *sizep)
1160
{
1161
struct object_info oi = OBJECT_INFO_INIT;
1162
1163
oi.sizep = sizep;
1162
- return parse_sha1_header_extended(hdr, &oi, 0);
1164
+ return parse_loose_header_extended(hdr, &oi, 0);
1165
}
1166
1167
static int loose_object_info(struct repository *r,
1209
if (oi->disk_sizep)
1210
*oi->disk_sizep = mapsize;
1211
if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE)) {
1210
- if (unpack_sha1_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
1212
+ if (unpack_loose_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
1213
status = error(_("unable to unpack %s header with --allow-unknown-type"),
1214
oid_to_hex(oid));
1213
- } else if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
1215
+ } else if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
1216
status = error(_("unable to unpack %s header"),
1217
oid_to_hex(oid));
1218
if (status < 0)
1219
; /* Do nothing */
1220
else if (hdrbuf.len) {
1219
- if ((status = parse_sha1_header_extended(hdrbuf.buf, oi, flags)) < 0)
1221
+ if ((status = parse_loose_header_extended(hdrbuf.buf, oi, flags)) < 0)
1222
status = error(_("unable to parse %s header with --allow-unknown-type"),
1223
oid_to_hex(oid));
1222
- } else if ((status = parse_sha1_header_extended(hdr, oi, flags)) < 0)
1224
+ } else if ((status = parse_loose_header_extended(hdr, oi, flags)) < 0)
1225
status = error(_("unable to parse %s header"), oid_to_hex(oid));
1226
1227
if (status >= 0 && oi->contentp) {
1226
- *oi->contentp = unpack_sha1_rest(&stream, hdr,
1227
- *oi->sizep, oid->hash);
1228
+ *oi->contentp = unpack_loose_rest(&stream, hdr,
1229
+ *oi->sizep, oid);
1230
if (!*oi->contentp) {
1231
git_inflate_end(&stream);
1232
status = -1;
2186
sizeof(odb->loose_objects_subdir_seen));
2187
}
2188
2187
-static int check_stream_sha1(git_zstream *stream,
2188
- const char *hdr,
2189
- unsigned long size,
2190
- const char *path,
2191
- const unsigned char *expected_sha1)
2189
+static int check_stream_oid(git_zstream *stream,
2190
+ const char *hdr,
2191
+ unsigned long size,
2192
+ const char *path,
2193
+ const struct object_id *expected_oid)
2194
{
2195
git_hash_ctx c;
2194
- unsigned char real_sha1[GIT_MAX_RAWSZ];
2196
+ struct object_id real_oid;
2197
unsigned char buf[4096];
2198
unsigned long total_read;
2199
int status = Z_OK;
2209
2210
/*
2211
* This size comparison must be "<=" to read the final zlib packets;
2210
- * see the comment in unpack_sha1_rest for details.
2212
+ * see the comment in unpack_loose_rest for details.
2213
*/
2214
while (total_read <= size &&
2215
(status == Z_OK ||
2225
git_inflate_end(stream);
2226
2227
if (status != Z_STREAM_END) {
2226
- error(_("corrupt loose object '%s'"), sha1_to_hex(expected_sha1));
2228
+ error(_("corrupt loose object '%s'"), oid_to_hex(expected_oid));
2229
return -1;
2230
}
2231
if (stream->avail_in) {
2232
error(_("garbage at end of loose object '%s'"),
2231
- sha1_to_hex(expected_sha1));
2233
+ oid_to_hex(expected_oid));
2234
return -1;
2235
}
2236
2235
- the_hash_algo->final_fn(real_sha1, &c);
2236
- if (!hasheq(expected_sha1, real_sha1)) {
2237
+ the_hash_algo->final_fn(real_oid.hash, &c);
2238
+ if (!oideq(expected_oid, &real_oid)) {
2239
error(_("sha1 mismatch for %s (expected %s)"), path,
2238
- sha1_to_hex(expected_sha1));
2240
+ oid_to_hex(expected_oid));
2241
return -1;
2242
}
2243
2264
goto out;
2265
}
2266
2265
- if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) {
2267
+ if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) {
2268
error(_("unable to unpack header of %s"), path);
2269
goto out;
2270
}
2271
2270
- *type = parse_sha1_header(hdr, size);
2272
+ *type = parse_loose_header(hdr, size);
2273
if (*type < 0) {
2274
error(_("unable to parse header of %s"), path);
2275
git_inflate_end(&stream);
2277
}
2278
2279
if (*type == OBJ_BLOB && *size > big_file_threshold) {
2278
- if (check_stream_sha1(&stream, hdr, *size, path, expected_oid->hash) < 0)
2280
+ if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0)
2281
goto out;
2282
} else {
2281
- *contents = unpack_sha1_rest(&stream, hdr, *size, expected_oid->hash);
2283
+ *contents = unpack_loose_rest(&stream, hdr, *size, expected_oid);
2284
if (!*contents) {
2285
error(_("unable to unpack contents of %s"), path);
2286
git_inflate_end(&stream);