X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=sha1_file.c;h=4ea0b18d0aaeca48ed75ed21863195c5ce830cbc;hb=3d913526b19545eb4e463f96d2f3b8db8daae6ef;hp=8f5fe62d545ace21c338cd554c76bac5d5acb431;hpb=a49eb197d809d2d7efbd81d935c61e1a0caa983e;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 8f5fe62d5..4ea0b18d0 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1170,7 +1170,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf, size = c & 15; shift = 4; while (c & 0x80) { - if (len <= used || sizeof(long) * 8 <= shift) { + if (len <= used || bitsizeof(long) <= shift) { error("bad object header"); return 0; } @@ -2144,13 +2144,26 @@ static void *read_object(const unsigned char *sha1, enum object_type *type, return read_packed_sha1(sha1, type, size); } -void *read_sha1_file(const unsigned char *sha1, enum object_type *type, - unsigned long *size) +void *read_sha1_file_repl(const unsigned char *sha1, + enum object_type *type, + unsigned long *size, + const unsigned char **replacement) { - void *data = read_object(sha1, type, size); + const unsigned char *repl = lookup_replace_object(sha1); + void *data = read_object(repl, type, size); + + /* die if we replaced an object with one that does not exist */ + if (!data && repl != sha1) + die("replacement %s not found for %s", + sha1_to_hex(repl), sha1_to_hex(sha1)); + /* legacy behavior is to die on corrupted objects */ - if (!data && (has_loose_object(sha1) || has_packed_and_bad(sha1))) - die("object %s is corrupted", sha1_to_hex(sha1)); + if (!data && (has_loose_object(repl) || has_packed_and_bad(repl))) + die("object %s is corrupted", sha1_to_hex(repl)); + + if (replacement) + *replacement = repl; + return data; } @@ -2286,7 +2299,7 @@ static void close_sha1_file(int fd) if (fsync_object_files) fsync_or_die(fd, "sha1 file"); if (close(fd) != 0) - die("error when closing sha1 file (%s)", strerror(errno)); + die_errno("error when closing sha1 file"); } /* Size of directory component, including the ending '/' */