summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'sha1-file.c')
-rw-r--r--sha1-file.c84
1 files changed, 43 insertions, 41 deletions
diff --git a/sha1-file.c b/sha1-file.c
index 1af5fef..91cc345 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -976,9 +976,9 @@ void *map_loose_object(struct repository *r,
return map_loose_object_1(r, NULL, oid, size);
}
-static int unpack_sha1_short_header(git_zstream *stream,
- unsigned char *map, unsigned long mapsize,
- void *buffer, unsigned long bufsiz)
+static int unpack_loose_short_header(git_zstream *stream,
+ unsigned char *map, unsigned long mapsize,
+ void *buffer, unsigned long bufsiz)
{
/* Get the data stream */
memset(stream, 0, sizeof(*stream));
@@ -991,12 +991,12 @@ static int unpack_sha1_short_header(git_zstream *stream,
return git_inflate(stream, 0);
}
-int unpack_sha1_header(git_zstream *stream,
- unsigned char *map, unsigned long mapsize,
- void *buffer, unsigned long bufsiz)
+int unpack_loose_header(git_zstream *stream,
+ unsigned char *map, unsigned long mapsize,
+ void *buffer, unsigned long bufsiz)
{
- int status = unpack_sha1_short_header(stream, map, mapsize,
- buffer, bufsiz);
+ int status = unpack_loose_short_header(stream, map, mapsize,
+ buffer, bufsiz);
if (status < Z_OK)
return status;
@@ -1007,13 +1007,13 @@ int unpack_sha1_header(git_zstream *stream,
return 0;
}
-static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
- unsigned long mapsize, void *buffer,
- unsigned long bufsiz, struct strbuf *header)
+static int unpack_loose_header_to_strbuf(git_zstream *stream, unsigned char *map,
+ unsigned long mapsize, void *buffer,
+ unsigned long bufsiz, struct strbuf *header)
{
int status;
- status = unpack_sha1_short_header(stream, map, mapsize, buffer, bufsiz);
+ status = unpack_loose_short_header(stream, map, mapsize, buffer, bufsiz);
if (status < Z_OK)
return -1;
@@ -1043,7 +1043,9 @@ static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
return -1;
}
-static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long size, const unsigned char *sha1)
+static void *unpack_loose_rest(git_zstream *stream,
+ void *buffer, unsigned long size,
+ const struct object_id *oid)
{
int bytes = strlen(buffer) + 1;
unsigned char *buf = xmallocz(size);
@@ -1080,10 +1082,10 @@ static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long s
}
if (status < 0)
- error(_("corrupt loose object '%s'"), sha1_to_hex(sha1));
+ error(_("corrupt loose object '%s'"), oid_to_hex(oid));
else if (stream->avail_in)
error(_("garbage at end of loose object '%s'"),
- sha1_to_hex(sha1));
+ oid_to_hex(oid));
free(buf);
return NULL;
}
@@ -1093,8 +1095,8 @@ static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long s
* too permissive for what we want to check. So do an anal
* object header parse by hand.
*/
-static int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
- unsigned int flags)
+static int parse_loose_header_extended(const char *hdr, struct object_info *oi,
+ unsigned int flags)
{
const char *type_buf = hdr;
unsigned long size;
@@ -1154,12 +1156,12 @@ static int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
return *hdr ? -1 : type;
}
-int parse_sha1_header(const char *hdr, unsigned long *sizep)
+int parse_loose_header(const char *hdr, unsigned long *sizep)
{
struct object_info oi = OBJECT_INFO_INIT;
oi.sizep = sizep;
- return parse_sha1_header_extended(hdr, &oi, 0);
+ return parse_loose_header_extended(hdr, &oi, 0);
}
static int loose_object_info(struct repository *r,
@@ -1207,24 +1209,24 @@ static int loose_object_info(struct repository *r,
if (oi->disk_sizep)
*oi->disk_sizep = mapsize;
if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE)) {
- if (unpack_sha1_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
+ if (unpack_loose_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
status = error(_("unable to unpack %s header with --allow-unknown-type"),
oid_to_hex(oid));
- } else if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
+ } else if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
status = error(_("unable to unpack %s header"),
oid_to_hex(oid));
if (status < 0)
; /* Do nothing */
else if (hdrbuf.len) {
- if ((status = parse_sha1_header_extended(hdrbuf.buf, oi, flags)) < 0)
+ if ((status = parse_loose_header_extended(hdrbuf.buf, oi, flags)) < 0)
status = error(_("unable to parse %s header with --allow-unknown-type"),
oid_to_hex(oid));
- } else if ((status = parse_sha1_header_extended(hdr, oi, flags)) < 0)
+ } else if ((status = parse_loose_header_extended(hdr, oi, flags)) < 0)
status = error(_("unable to parse %s header"), oid_to_hex(oid));
if (status >= 0 && oi->contentp) {
- *oi->contentp = unpack_sha1_rest(&stream, hdr,
- *oi->sizep, oid->hash);
+ *oi->contentp = unpack_loose_rest(&stream, hdr,
+ *oi->sizep, oid);
if (!*oi->contentp) {
git_inflate_end(&stream);
status = -1;
@@ -2184,14 +2186,14 @@ void odb_clear_loose_cache(struct object_directory *odb)
sizeof(odb->loose_objects_subdir_seen));
}
-static int check_stream_sha1(git_zstream *stream,
- const char *hdr,
- unsigned long size,
- const char *path,
- const unsigned char *expected_sha1)
+static int check_stream_oid(git_zstream *stream,
+ const char *hdr,
+ unsigned long size,
+ const char *path,
+ const struct object_id *expected_oid)
{
git_hash_ctx c;
- unsigned char real_sha1[GIT_MAX_RAWSZ];
+ struct object_id real_oid;
unsigned char buf[4096];
unsigned long total_read;
int status = Z_OK;
@@ -2207,7 +2209,7 @@ static int check_stream_sha1(git_zstream *stream,
/*
* This size comparison must be "<=" to read the final zlib packets;
- * see the comment in unpack_sha1_rest for details.
+ * see the comment in unpack_loose_rest for details.
*/
while (total_read <= size &&
(status == Z_OK ||
@@ -2223,19 +2225,19 @@ static int check_stream_sha1(git_zstream *stream,
git_inflate_end(stream);
if (status != Z_STREAM_END) {
- error(_("corrupt loose object '%s'"), sha1_to_hex(expected_sha1));
+ error(_("corrupt loose object '%s'"), oid_to_hex(expected_oid));
return -1;
}
if (stream->avail_in) {
error(_("garbage at end of loose object '%s'"),
- sha1_to_hex(expected_sha1));
+ oid_to_hex(expected_oid));
return -1;
}
- the_hash_algo->final_fn(real_sha1, &c);
- if (!hasheq(expected_sha1, real_sha1)) {
+ the_hash_algo->final_fn(real_oid.hash, &c);
+ if (!oideq(expected_oid, &real_oid)) {
error(_("sha1 mismatch for %s (expected %s)"), path,
- sha1_to_hex(expected_sha1));
+ oid_to_hex(expected_oid));
return -1;
}
@@ -2262,12 +2264,12 @@ int read_loose_object(const char *path,
goto out;
}
- if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) {
+ if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) {
error(_("unable to unpack header of %s"), path);
goto out;
}
- *type = parse_sha1_header(hdr, size);
+ *type = parse_loose_header(hdr, size);
if (*type < 0) {
error(_("unable to parse header of %s"), path);
git_inflate_end(&stream);
@@ -2275,10 +2277,10 @@ int read_loose_object(const char *path,
}
if (*type == OBJ_BLOB && *size > big_file_threshold) {
- if (check_stream_sha1(&stream, hdr, *size, path, expected_oid->hash) < 0)
+ if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0)
goto out;
} else {
- *contents = unpack_sha1_rest(&stream, hdr, *size, expected_oid->hash);
+ *contents = unpack_loose_rest(&stream, hdr, *size, expected_oid);
if (!*contents) {
error(_("unable to unpack contents of %s"), path);
git_inflate_end(&stream);