gc: save log from daemonized gc --auto and print it next time
[gitweb.git] / sha1_file.c
index b231b627846e4f213dca4e1db704fd7852fa3172..ec3adcaead32f5fde9fccf869cbcce7543f54e11 100644 (file)
@@ -1195,7 +1195,7 @@ static void report_pack_garbage(struct string_list *list)
        if (!report_garbage)
                return;
 
-       sort_string_list(list);
+       string_list_sort(list);
 
        for (i = 0; i < list->nr; i++) {
                const char *path = list->items[i].string;
@@ -2940,7 +2940,6 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
        }
 
        /* Set it up */
-       memset(&stream, 0, sizeof(stream));
        git_deflate_init(&stream, zlib_compression_level);
        stream.next_out = compressed;
        stream.avail_out = sizeof(compressed);
@@ -3356,31 +3355,42 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
        return r;
 }
 
-int for_each_loose_file_in_objdir(const char *path,
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
                            each_loose_object_fn obj_cb,
                            each_loose_cruft_fn cruft_cb,
                            each_loose_subdir_fn subdir_cb,
                            void *data)
 {
-       struct strbuf buf = STRBUF_INIT;
-       size_t baselen;
+       size_t baselen = path->len;
        int r = 0;
        int i;
 
-       strbuf_addstr(&buf, path);
-       strbuf_addch(&buf, '/');
-       baselen = buf.len;
-
        for (i = 0; i < 256; i++) {
-               strbuf_addf(&buf, "%02x", i);
-               r = for_each_file_in_obj_subdir(i, &buf, obj_cb, cruft_cb,
+               strbuf_addf(path, "/%02x", i);
+               r = for_each_file_in_obj_subdir(i, path, obj_cb, cruft_cb,
                                                subdir_cb, data);
-               strbuf_setlen(&buf, baselen);
+               strbuf_setlen(path, baselen);
                if (r)
                        break;
        }
 
+       return r;
+}
+
+int for_each_loose_file_in_objdir(const char *path,
+                                 each_loose_object_fn obj_cb,
+                                 each_loose_cruft_fn cruft_cb,
+                                 each_loose_subdir_fn subdir_cb,
+                                 void *data)
+{
+       struct strbuf buf = STRBUF_INIT;
+       int r;
+
+       strbuf_addstr(&buf, path);
+       r = for_each_loose_file_in_objdir_buf(&buf, obj_cb, cruft_cb,
+                                             subdir_cb, data);
        strbuf_release(&buf);
+
        return r;
 }
 
@@ -3393,9 +3403,16 @@ static int loose_from_alt_odb(struct alternate_object_database *alt,
                              void *vdata)
 {
        struct loose_alt_odb_data *data = vdata;
-       return for_each_loose_file_in_objdir(alt->base,
-                                            data->cb, NULL, NULL,
-                                            data->data);
+       struct strbuf buf = STRBUF_INIT;
+       int r;
+
+       /* copy base not including trailing '/' */
+       strbuf_add(&buf, alt->base, alt->name - alt->base - 1);
+       r = for_each_loose_file_in_objdir_buf(&buf,
+                                             data->cb, NULL, NULL,
+                                             data->data);
+       strbuf_release(&buf);
+       return r;
 }
 
 int for_each_loose_object(each_loose_object_fn cb, void *data)