Rename advice.object_name_warning to objectNameWarning
[gitweb.git] / sha1_file.c
index 452e4647b387799ebed343b100236b1cba9b0104..8e27db1bd2b49f28b235fcd7e18a0dda43a1f045 100644 (file)
@@ -36,6 +36,9 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }
 
 const unsigned char null_sha1[20];
 
+static const char *no_log_pack_access = "no_log_pack_access";
+static const char *log_pack_access;
+
 /*
  * This is meant to hold a *small* number of objects that you would
  * want read_sha1_file() to be able to return, but yet you do not want
@@ -2001,12 +2004,19 @@ static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
 {
        static FILE *log_file;
 
+       if (!log_pack_access)
+               log_pack_access = getenv("GIT_TRACE_PACK_ACCESS");
+       if (!log_pack_access)
+               log_pack_access = no_log_pack_access;
+       if (log_pack_access == no_log_pack_access)
+               return;
+
        if (!log_file) {
                log_file = fopen(log_pack_access, "w");
                if (!log_file) {
                        error("cannot open pack access log '%s' for writing: %s",
                              log_pack_access, strerror(errno));
-                       log_pack_access = NULL;
+                       log_pack_access = no_log_pack_access;
                        return;
                }
        }
@@ -2037,7 +2047,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
        int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;
        int base_from_cache = 0;
 
-       if (log_pack_access)
+       if (log_pack_access != no_log_pack_access)
                write_pack_access_log(p, obj_offset);
 
        /* PHASE 1: drill down to the innermost base object */
@@ -2180,10 +2190,19 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
                data = patch_delta(base, base_size,
                                   delta_data, delta_size,
                                   &size);
+
+               /*
+                * We could not apply the delta; warn the user, but keep going.
+                * Our failure will be noticed either in the next iteration of
+                * the loop, or if this is the final delta, in the caller when
+                * we return NULL. Those code paths will take care of making
+                * a more explicit warning and retrying with another copy of
+                * the object.
+                */
                if (!data)
-                       die("failed to apply delta");
+                       error("failed to apply delta");
 
-               free (delta_data);
+               free(delta_data);
        }
 
        *final_type = type;
@@ -2408,7 +2427,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
 
        map = map_sha1_file(sha1, &mapsize);
        if (!map)
-               return error("unable to find %s", sha1_to_hex(sha1));
+               return -1;
        if (oi->disk_sizep)
                *oi->disk_sizep = mapsize;
        if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)