tree-walk: convert tree entry functions to object_id
[gitweb.git] / streaming.c
index 5892b50bd89c3c66bdb541ca0100f0671834a542..3f4be1ea2c3e9ed68190b8e2bb54c9b3de6d853b 100644 (file)
@@ -14,7 +14,7 @@ enum input_source {
 
 typedef int (*open_istream_fn)(struct git_istream *,
                               struct object_info *,
-                              const unsigned char *,
+                              const struct object_id *,
                               enum object_type *);
 typedef int (*close_istream_fn)(struct git_istream *);
 typedef ssize_t (*read_istream_fn)(struct git_istream *, char *, size_t);
@@ -27,7 +27,7 @@ struct stream_vtbl {
 #define open_method_decl(name) \
        int open_istream_ ##name \
        (struct git_istream *st, struct object_info *oi, \
-        const unsigned char *sha1, \
+        const struct object_id *oid, \
         enum object_type *type)
 
 #define close_method_decl(name) \
@@ -111,10 +111,13 @@ static enum input_source istream_source(const unsigned char *sha1,
 {
        unsigned long size;
        int status;
+       struct object_id oid;
+
+       hashcpy(oid.hash, sha1);
 
        oi->typep = type;
        oi->sizep = &size;
-       status = sha1_object_info_extended(sha1, oi, 0);
+       status = oid_object_info_extended(&oid, oi, 0);
        if (status < 0)
                return stream_error;
 
@@ -130,22 +133,25 @@ static enum input_source istream_source(const unsigned char *sha1,
        }
 }
 
-struct git_istream *open_istream(const unsigned char *sha1,
+struct git_istream *open_istream(const struct object_id *oid,
                                 enum object_type *type,
                                 unsigned long *size,
                                 struct stream_filter *filter)
 {
        struct git_istream *st;
        struct object_info oi = OBJECT_INFO_INIT;
-       const unsigned char *real = lookup_replace_object(sha1);
+       const unsigned char *real = lookup_replace_object(oid->hash);
        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, real, type)) {
-               if (open_istream_incore(st, &oi, real, type)) {
+       if (open_istream_tbl[src](st, &oi, &realoid, type)) {
+               if (open_istream_incore(st, &oi, &realoid, type)) {
                        free(st);
                        return NULL;
                }
@@ -335,7 +341,7 @@ static struct stream_vtbl loose_vtbl = {
 
 static open_method_decl(loose)
 {
-       st->u.loose.mapped = map_sha1_file(sha1, &st->u.loose.mapsize);
+       st->u.loose.mapped = map_sha1_file(oid->hash, &st->u.loose.mapsize);
        if (!st->u.loose.mapped)
                return -1;
        if ((unpack_sha1_header(&st->z,
@@ -486,7 +492,7 @@ static struct stream_vtbl incore_vtbl = {
 
 static open_method_decl(incore)
 {
-       st->u.incore.buf = read_sha1_file_extended(sha1, type, &st->size, 0);
+       st->u.incore.buf = read_sha1_file_extended(oid->hash, type, &st->size, 0);
        st->u.incore.read_ptr = 0;
        st->vtbl = &incore_vtbl;
 
@@ -507,7 +513,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
        ssize_t kept = 0;
        int result = -1;
 
-       st = open_istream(oid->hash, &type, &sz, filter);
+       st = open_istream(oid, &type, &sz, filter);
        if (!st) {
                if (filter)
                        free_stream_filter(filter);