enum object_type type;
unsigned long size;
void *buffer = read_object_file(oid, &type, &size);
- const unsigned char *repl = lookup_replace_object(oid->hash);
+ const struct object_id *repl = lookup_replace_object(oid);
if (buffer) {
- struct object_id reploid;
- hashcpy(reploid.hash, repl);
-
if (type == type_from_string(expected_type))
- ret = check_object_signature(&reploid, buffer, size, expected_type);
+ ret = check_object_signature(repl, buffer, size, expected_type);
free(buffer);
}
return ret;
* This internal function is only declared here for the benefit of
* lookup_replace_object(). Please do not call it directly.
*/
-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
+extern const struct object_id *do_lookup_replace_object(const struct object_id *oid);
/*
* If object sha1 should be replaced, return the replacement object's
* either sha1 or a pointer to a permanently-allocated value. When
* object replacement is suppressed, always return sha1.
*/
-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
+static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
{
if (!check_replace_refs)
- return sha1;
- return do_lookup_replace_object(sha1);
+ return oid;
+ return do_lookup_replace_object(oid);
}
/* Read and unpack an object file into memory, write memory to an object file */
unsigned long size;
enum object_type type;
int eaten;
- const unsigned char *repl = lookup_replace_object(oid->hash);
+ const struct object_id *repl = lookup_replace_object(oid);
void *buffer;
struct object *obj;
if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
(!obj && has_object_file(oid) &&
oid_object_info(oid, NULL) == OBJ_BLOB)) {
- struct object_id reploid;
- hashcpy(reploid.hash, repl);
-
- if (check_object_signature(&reploid, NULL, 0, NULL) < 0) {
+ if (check_object_signature(repl, NULL, 0, NULL) < 0) {
error("sha1 mismatch %s", oid_to_hex(oid));
return NULL;
}
buffer = read_object_file(oid, &type, &size);
if (buffer) {
- struct object_id reploid;
- hashcpy(reploid.hash, repl);
-
- if (check_object_signature(&reploid, buffer, size, type_name(type)) < 0) {
+ if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
free(buffer);
- error("sha1 mismatch %s", sha1_to_hex(repl));
+ error("sha1 mismatch %s", oid_to_hex(repl));
return NULL;
}
#define MAXREPLACEDEPTH 5
/*
- * If a replacement for object sha1 has been set up, return the
+ * If a replacement for object oid has been set up, return the
* replacement object's name (replaced recursively, if necessary).
- * The return value is either sha1 or a pointer to a
+ * The return value is either oid or a pointer to a
* permanently-allocated value. This function always respects replace
* references, regardless of the value of check_replace_refs.
*/
-const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
+const struct object_id *do_lookup_replace_object(const struct object_id *oid)
{
int pos, depth = MAXREPLACEDEPTH;
- const unsigned char *cur = sha1;
+ const struct object_id *cur = oid;
prepare_replace_object();
do {
if (--depth < 0)
die("replace depth too high for object %s",
- sha1_to_hex(sha1));
+ oid_to_hex(oid));
- pos = replace_object_pos(cur);
+ pos = replace_object_pos(cur->hash);
if (0 <= pos)
- cur = replace_object[pos]->replacement.hash;
+ cur = &replace_object[pos]->replacement;
} while (0 <= pos);
return cur;
static struct object_info blank_oi = OBJECT_INFO_INIT;
struct pack_entry e;
int rtype;
- const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
- lookup_replace_object(oid->hash) :
- oid->hash;
+ const struct object_id *real = oid;
int already_retried = 0;
- struct object_id realoid;
- hashcpy(realoid.hash, real);
+ if (flags & OBJECT_INFO_LOOKUP_REPLACE)
+ real = lookup_replace_object(oid);
- if (is_null_sha1(real))
+ if (is_null_oid(real))
return -1;
if (!oi)
oi = &blank_oi;
if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
- struct cached_object *co = find_cached_object(real);
+ struct cached_object *co = find_cached_object(real->hash);
if (co) {
if (oi->typep)
*(oi->typep) = co->type;
}
while (1) {
- if (find_pack_entry(real, &e))
+ if (find_pack_entry(real->hash, &e))
break;
/* Most likely it's a loose object. */
- if (!sha1_loose_object_info(real, oi, flags))
+ if (!sha1_loose_object_info(real->hash, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
reprepare_packed_git();
- if (find_pack_entry(real, &e))
+ if (find_pack_entry(real->hash, &e))
break;
/* Check if it is a missing object */
* TODO Investigate haveing fetch_object() return
* TODO error/success and stopping the music here.
*/
- fetch_object(repository_format_partial_clone, real);
+ fetch_object(repository_format_partial_clone, real->hash);
already_retried = 1;
continue;
}
return 0;
rtype = packed_object_info(e.p, e.offset, oi);
if (rtype < 0) {
- mark_bad_packed_object(e.p, real);
- return oid_object_info_extended(&realoid, oi, 0);
+ mark_bad_packed_object(e.p, real->hash);
+ return oid_object_info_extended(real, oi, 0);
} else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p;
const struct packed_git *p;
const char *path;
struct stat st;
- const unsigned char *repl = lookup_replace ? lookup_replace_object(oid->hash)
- : oid->hash;
+ const struct object_id *repl = lookup_replace ? lookup_replace_object(oid)
+ : oid;
errno = 0;
- data = read_object(repl, type, size);
+ data = read_object(repl->hash, type, size);
if (data)
return data;
die_errno("failed to read object %s", oid_to_hex(oid));
/* die if we replaced an object with one that does not exist */
- if (repl != oid->hash)
+ if (repl != oid)
die("replacement %s not found for %s",
- sha1_to_hex(repl), oid_to_hex(oid));
+ oid_to_hex(repl), oid_to_hex(oid));
- if (!stat_sha1_file(repl, &st, &path))
+ if (!stat_sha1_file(repl->hash, &st, &path))
die("loose object %s (stored in %s) is corrupt",
- sha1_to_hex(repl), path);
+ oid_to_hex(repl), path);
- if ((p = has_packed_and_bad(repl)) != NULL)
+ if ((p = has_packed_and_bad(repl->hash)) != NULL)
die("packed object %s (stored in %s) is corrupt",
- sha1_to_hex(repl), p->pack_name);
+ oid_to_hex(repl), p->pack_name);
return NULL;
}
return st->vtbl->read(st, buf, sz);
}
-static enum input_source istream_source(const unsigned char *sha1,
+static enum input_source istream_source(const struct object_id *oid,
enum object_type *type,
struct object_info *oi)
{
unsigned long size;
int status;
- struct object_id oid;
-
- hashcpy(oid.hash, sha1);
oi->typep = type;
oi->sizep = &size;
- status = oid_object_info_extended(&oid, oi, 0);
+ status = oid_object_info_extended(oid, oi, 0);
if (status < 0)
return stream_error;
{
struct git_istream *st;
struct object_info oi = OBJECT_INFO_INIT;
- const unsigned char *real = lookup_replace_object(oid->hash);
+ const struct object_id *real = lookup_replace_object(oid);
enum input_source src = istream_source(real, type, &oi);
- struct object_id realoid;
-
- hashcpy(realoid.hash, real);
if (src < 0)
return NULL;
st = xmalloc(sizeof(*st));
- if (open_istream_tbl[src](st, &oi, &realoid, type)) {
- if (open_istream_incore(st, &oi, &realoid, type)) {
+ if (open_istream_tbl[src](st, &oi, real, type)) {
+ if (open_istream_incore(st, &oi, real, type)) {
free(st);
return NULL;
}