Merge branch 'jk/tap-verbose-fix'
[gitweb.git] / sha1_file.c
index 51d40241a742839d0740a28144ef111c00cb1091..2eda9291ee307127bdd715f0540994464534429d 100644 (file)
@@ -172,36 +172,28 @@ enum scld_error safe_create_leading_directories_const(const char *path)
        return result;
 }
 
-static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
+static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
 {
        int i;
        for (i = 0; i < 20; i++) {
                static char hex[] = "0123456789abcdef";
                unsigned int val = sha1[i];
-               *pathbuf++ = hex[val >> 4];
-               *pathbuf++ = hex[val & 0xf];
+               strbuf_addch(buf, hex[val >> 4]);
+               strbuf_addch(buf, hex[val & 0xf]);
                if (!i)
-                       *pathbuf++ = '/';
+                       strbuf_addch(buf, '/');
        }
-       *pathbuf = '\0';
 }
 
 const char *sha1_file_name(const unsigned char *sha1)
 {
-       static char buf[PATH_MAX];
-       const char *objdir;
-       int len;
+       static struct strbuf buf = STRBUF_INIT;
 
-       objdir = get_object_directory();
-       len = strlen(objdir);
+       strbuf_reset(&buf);
+       strbuf_addf(&buf, "%s/", get_object_directory());
 
-       /* '/' + sha1(2) + '/' + sha1(38) + '\0' */
-       if (len + 43 > PATH_MAX)
-               die("insanely long object directory %s", objdir);
-       memcpy(buf, objdir, len);
-       buf[len] = '/';
-       fill_sha1_path(buf + len + 1, sha1);
-       return buf;
+       fill_sha1_path(&buf, sha1);
+       return buf.buf;
 }
 
 struct strbuf *alt_scratch_buf(struct alternate_object_database *alt)
@@ -213,14 +205,8 @@ struct strbuf *alt_scratch_buf(struct alternate_object_database *alt)
 static const char *alt_sha1_path(struct alternate_object_database *alt,
                                 const unsigned char *sha1)
 {
-       /* hex sha1 plus internal "/" */
-       size_t len = GIT_SHA1_HEXSZ + 1;
        struct strbuf *buf = alt_scratch_buf(alt);
-
-       strbuf_grow(buf, len);
-       fill_sha1_path(buf->buf + buf->len, sha1);
-       strbuf_setlen(buf, buf->len + len);
-
+       fill_sha1_path(buf, sha1);
        return buf->buf;
 }
 
@@ -274,7 +260,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
         * thing twice, or object directory itself.
         */
        for (alt = alt_odb_list; alt; alt = alt->next) {
-               if (!strcmp(path->buf, alt->path))
+               if (!fspathcmp(path->buf, alt->path))
                        return 0;
        }
        if (!fspathcmp(path->buf, normalized_objdir))
@@ -368,12 +354,7 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
                const char *entry = entries.items[i].string;
                if (entry[0] == '\0' || entry[0] == '#')
                        continue;
-               if (!is_absolute_path(entry) && depth) {
-                       error("%s: ignoring relative alternate object store %s",
-                                       relative_base, entry);
-               } else {
-                       link_alt_odb_entry(entry, relative_base, depth, objdirbuf.buf);
-               }
+               link_alt_odb_entry(entry, relative_base, depth, objdirbuf.buf);
        }
        string_list_clear(&entries, 0);
        free(alt_copy);
@@ -1871,11 +1852,9 @@ static int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
 
 int parse_sha1_header(const char *hdr, unsigned long *sizep)
 {
-       struct object_info oi;
+       struct object_info oi = OBJECT_INFO_INIT;
 
        oi.sizep = sizep;
-       oi.typename = NULL;
-       oi.typep = NULL;
        return parse_sha1_header_extended(hdr, &oi, LOOKUP_REPLACE_OBJECT);
 }
 
@@ -2113,8 +2092,8 @@ static enum object_type packed_to_object_type(struct packed_git *p,
        goto out;
 }
 
-static int packed_object_info(struct packed_git *p, off_t obj_offset,
-                             struct object_info *oi)
+int packed_object_info(struct packed_git *p, off_t obj_offset,
+                      struct object_info *oi)
 {
        struct pack_window *w_curs = NULL;
        unsigned long size;
@@ -2885,7 +2864,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
 int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
 {
        enum object_type type;
-       struct object_info oi = {NULL};
+       struct object_info oi = OBJECT_INFO_INIT;
 
        oi.typep = &type;
        oi.sizep = sizep;
@@ -3356,6 +3335,11 @@ int has_object_file(const struct object_id *oid)
        return has_sha1_file(oid->hash);
 }
 
+int has_object_file_with_flags(const struct object_id *oid, int flags)
+{
+       return has_sha1_file_with_flags(oid->hash, flags);
+}
+
 static void check_tree(const void *buf, size_t size)
 {
        struct tree_desc desc;