Merge branch 'tz/complete-tag-delete-tagname' into next
[gitweb.git] / sha1_file.c
index cdd49e5274158a3caf7e426b66fa5302378e9f96..aea9124a78fce21eb4cb756af29823493274e581 100644 (file)
@@ -30,6 +30,9 @@
 #include "packfile.h"
 #include "fetch-object.h"
 
+/* The maximum size for an object header. */
+#define MAX_HEADER_LEN 32
+
 const unsigned char null_sha1[GIT_MAX_RAWSZ];
 const struct object_id null_oid;
 const struct object_id empty_tree_oid = {
@@ -665,15 +668,11 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
 
 void prepare_alt_odb(void)
 {
-       const char *alt;
-
        if (alt_odb_tail)
                return;
 
-       alt = getenv(ALTERNATE_DB_ENVIRONMENT);
-
        alt_odb_tail = &alt_odb_list;
-       link_alt_odb_entries(alt, PATH_SEP, NULL, 0);
+       link_alt_odb_entries(the_repository->alternate_db, PATH_SEP, NULL, 0);
 
        read_info_alternates(get_object_directory(), 0);
 }
@@ -791,7 +790,7 @@ int check_object_signature(const struct object_id *oid, void *map,
        enum object_type obj_type;
        struct git_istream *st;
        git_hash_ctx c;
-       char hdr[32];
+       char hdr[MAX_HEADER_LEN];
        int hdrlen;
 
        if (map) {
@@ -1150,7 +1149,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
        unsigned long mapsize;
        void *map;
        git_zstream stream;
-       char hdr[32];
+       char hdr[MAX_HEADER_LEN];
        struct strbuf hdrbuf = STRBUF_INIT;
        unsigned long size_scratch;
 
@@ -1227,22 +1226,20 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
        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;
@@ -1262,17 +1259,22 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
        }
 
        while (1) {
-               if (find_pack_entry(real, &e))
+               if (find_pack_entry(real->hash, &e))
                        break;
 
+               if (flags & OBJECT_INFO_IGNORE_LOOSE)
+                       return -1;
+
                /* 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))
-                       break;
+               if (!(flags & OBJECT_INFO_QUICK)) {
+                       reprepare_packed_git();
+                       if (find_pack_entry(real->hash, &e))
+                               break;
+               }
 
                /* Check if it is a missing object */
                if (fetch_if_missing && repository_format_partial_clone &&
@@ -1281,7 +1283,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
                         * 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;
                }
@@ -1297,8 +1299,8 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
                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;
@@ -1372,11 +1374,11 @@ void *read_object_file_extended(const struct object_id *oid,
        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;
 
@@ -1384,17 +1386,17 @@ void *read_object_file_extended(const struct object_id *oid,
                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;
 }
@@ -1516,7 +1518,7 @@ static int write_buffer(int fd, const void *buf, size_t len)
 int hash_object_file(const void *buf, unsigned long len, const char *type,
                     struct object_id *oid)
 {
-       char hdr[32];
+       char hdr[MAX_HEADER_LEN];
        int hdrlen = sizeof(hdr);
        write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
        return 0;
@@ -1671,7 +1673,7 @@ static int freshen_packed_object(const unsigned char *sha1)
 int write_object_file(const void *buf, unsigned long len, const char *type,
                      struct object_id *oid)
 {
-       char hdr[32];
+       char hdr[MAX_HEADER_LEN];
        int hdrlen = sizeof(hdr);
 
        /* Normally if we have it in the pack then we do not bother writing
@@ -1691,7 +1693,7 @@ int hash_object_file_literally(const void *buf, unsigned long len,
        int hdrlen, status = 0;
 
        /* type string, SP, %lu of the length plus NUL must fit this */
-       hdrlen = strlen(type) + 32;
+       hdrlen = strlen(type) + MAX_HEADER_LEN;
        header = xmalloc(hdrlen);
        write_object_file_prepare(buf, len, type, oid, header, &hdrlen);
 
@@ -1711,7 +1713,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
        void *buf;
        unsigned long len;
        enum object_type type;
-       char hdr[32];
+       char hdr[MAX_HEADER_LEN];
        int hdrlen;
        int ret;
 
@@ -2193,7 +2195,7 @@ int read_loose_object(const char *path,
        void *map = NULL;
        unsigned long mapsize;
        git_zstream stream;
-       char hdr[32];
+       char hdr[MAX_HEADER_LEN];
 
        *contents = NULL;