]> git.ipfire.org Git - thirdparty/git.git/blobdiff - object-file.c
test-ref-store: remove force-create argument for create-reflog
[thirdparty/git.git] / object-file.c
index 8b35fd85bf3390679d9892c49e3ba9ede5b06f8f..eb972cdccd2c2359b05a333e8b70725c5710cea2 100644 (file)
@@ -1306,7 +1306,7 @@ static void *unpack_loose_rest(git_zstream *stream,
 int parse_loose_header(const char *hdr, struct object_info *oi)
 {
        const char *type_buf = hdr;
-       unsigned long size;
+       size_t size;
        int type, type_len = 0;
 
        /*
@@ -1341,12 +1341,12 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
                        if (c > 9)
                                break;
                        hdr++;
-                       size = size * 10 + c;
+                       size = st_add(st_mult(size, 10), c);
                }
        }
 
        if (oi->sizep)
-               *oi->sizep = size;
+               *oi->sizep = cast_size_t_to_ulong(size);
 
        /*
         * The length must be followed by a zero byte
@@ -1528,7 +1528,14 @@ static int do_oid_object_info_extended(struct repository *r,
                                break;
                }
 
-               if (register_all_submodule_odb_as_alternates())
+               /*
+                * If r is the_repository, this might be an attempt at
+                * accessing a submodule object as if it were in the_repository
+                * (having called add_submodule_odb() on that submodule's ODB).
+                * If any such ODBs exist, register them and try again.
+                */
+               if (r == the_repository &&
+                   register_all_submodule_odb_as_alternates())
                        /* We added some alternates; retry */
                        continue;
 
@@ -1855,7 +1862,7 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
 
 static int write_loose_object(const struct object_id *oid, char *hdr,
                              int hdrlen, const void *buf, unsigned long len,
-                             time_t mtime)
+                             time_t mtime, unsigned flags)
 {
        int fd, ret;
        unsigned char compressed[4096];
@@ -1869,7 +1876,9 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
 
        fd = create_tmpfile(&tmp_file, filename.buf);
        if (fd < 0) {
-               if (errno == EACCES)
+               if (flags & HASH_SILENT)
+                       return -1;
+               else if (errno == EACCES)
                        return error(_("insufficient permission for adding an object to repository database %s"), get_object_directory());
                else
                        return error_errno(_("unable to create temporary file"));
@@ -1919,7 +1928,8 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
                struct utimbuf utb;
                utb.actime = mtime;
                utb.modtime = mtime;
-               if (utime(tmp_file.buf, &utb) < 0)
+               if (utime(tmp_file.buf, &utb) < 0 &&
+                   !(flags & HASH_SILENT))
                        warning_errno(_("failed utime() on %s"), tmp_file.buf);
        }
 
@@ -1944,8 +1954,9 @@ static int freshen_packed_object(const struct object_id *oid)
        return 1;
 }
 
-int write_object_file(const void *buf, unsigned long len, const char *type,
-                     struct object_id *oid)
+int write_object_file_flags(const void *buf, unsigned long len,
+                           const char *type, struct object_id *oid,
+                           unsigned flags)
 {
        char hdr[MAX_HEADER_LEN];
        int hdrlen = sizeof(hdr);
@@ -1957,7 +1968,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,
                                  &hdrlen);
        if (freshen_packed_object(oid) || freshen_loose_object(oid))
                return 0;
-       return write_loose_object(oid, hdr, hdrlen, buf, len, 0);
+       return write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags);
 }
 
 int hash_object_file_literally(const void *buf, unsigned long len,
@@ -1977,7 +1988,7 @@ int hash_object_file_literally(const void *buf, unsigned long len,
                goto cleanup;
        if (freshen_packed_object(oid) || freshen_loose_object(oid))
                goto cleanup;
-       status = write_loose_object(oid, header, hdrlen, buf, len, 0);
+       status = write_loose_object(oid, header, hdrlen, buf, len, 0, 0);
 
 cleanup:
        free(header);
@@ -1999,7 +2010,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
        if (!buf)
                return error(_("cannot read object for %s"), oid_to_hex(oid));
        hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
-       ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
+       ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0);
        free(buf);
 
        return ret;
@@ -2546,10 +2557,9 @@ int read_loose_object(const char *path,
                        goto out;
                }
                if (check_object_signature(the_repository, expected_oid,
-                                          *contents, *size, oi->type_name->buf, real_oid)) {
-                       free(*contents);
+                                          *contents, *size,
+                                          oi->type_name->buf, real_oid))
                        goto out;
-               }
        }
 
        ret = 0; /* everything checks out */