progress: store throughput display in a strbuf
[gitweb.git] / builtin / fsck.c
index f4b87e9b33710e5ae67ec8886aad5259fdb0177f..a019f4a2408ab4c549a91b7307b4356d0f27abb7 100644 (file)
@@ -243,13 +243,14 @@ static void check_unreachable_object(struct object *obj)
                        printf("dangling %s %s\n", typename(obj->type),
                               sha1_to_hex(obj->sha1));
                if (write_lost_and_found) {
-                       const char *filename = git_path("lost-found/%s/%s",
+                       char *filename = git_pathdup("lost-found/%s/%s",
                                obj->type == OBJ_COMMIT ? "commit" : "other",
                                sha1_to_hex(obj->sha1));
                        FILE *f;
 
                        if (safe_create_leading_directories_const(filename)) {
                                error("Could not create lost-found");
+                               free(filename);
                                return;
                        }
                        if (!(f = fopen(filename, "w")))
@@ -262,6 +263,7 @@ static void check_unreachable_object(struct object *obj)
                        if (fclose(f))
                                die_errno("Could not finish '%s'",
                                          filename);
+                       free(filename);
                }
                return;
        }
@@ -676,16 +678,18 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
        git_config(fsck_config, NULL);
 
        fsck_head_link();
-       if (!connectivity_only)
+       if (!connectivity_only) {
                fsck_object_dir(get_object_directory());
 
-       prepare_alt_odb();
-       for (alt = alt_odb_list; alt; alt = alt->next) {
-               char namebuf[PATH_MAX];
-               int namelen = alt->name - alt->base;
-               memcpy(namebuf, alt->base, namelen);
-               namebuf[namelen - 1] = 0;
-               fsck_object_dir(namebuf);
+               prepare_alt_odb();
+               for (alt = alt_odb_list; alt; alt = alt->next) {
+                       /* directory name, minus trailing slash */
+                       size_t namelen = alt->name - alt->base - 1;
+                       struct strbuf name = STRBUF_INIT;
+                       strbuf_add(&name, alt->base, namelen);
+                       fsck_object_dir(name.buf);
+                       strbuf_release(&name);
+               }
        }
 
        if (check_full) {