test-read-cache: drop namelen variable
[gitweb.git] / builtin / repack.c
index 82c19b755509f83bf189dd70323a678c299c6b66..632c0c0a79422a229d52c83665331501e8c54e29 100644 (file)
@@ -14,7 +14,7 @@
 
 static int delta_base_offset = 1;
 static int pack_kept_objects = -1;
-static int write_bitmaps;
+static int write_bitmaps = -1;
 static int use_delta_islands;
 static char *packdir, *packtmp;
 
@@ -129,19 +129,9 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list,
 
 static void remove_redundant_pack(const char *dir_name, const char *base_name)
 {
-       const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
-       int i;
        struct strbuf buf = STRBUF_INIT;
-       size_t plen;
-
-       strbuf_addf(&buf, "%s/%s", dir_name, base_name);
-       plen = buf.len;
-
-       for (i = 0; i < ARRAY_SIZE(exts); i++) {
-               strbuf_setlen(&buf, plen);
-               strbuf_addstr(&buf, exts[i]);
-               unlink(buf.buf);
-       }
+       strbuf_addf(&buf, "%s/%s.pack", dir_name, base_name);
+       unlink_pack_path(buf.buf, 1);
        strbuf_release(&buf);
 }
 
@@ -197,7 +187,7 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,
 
        if (cmd->in == -1) {
                if (start_command(cmd))
-                       die("Could not start pack-objects to repack promisor objects");
+                       die(_("could not start pack-objects to repack promisor objects"));
        }
 
        xwrite(cmd->in, oid_to_hex(oid), GIT_SHA1_HEXSZ);
@@ -236,7 +226,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
                char *promisor_name;
                int fd;
                if (line.len != the_hash_algo->hexsz)
-                       die("repack: Expecting full hex object ID lines only from pack-objects.");
+                       die(_("repack: Expecting full hex object ID lines only from pack-objects."));
                string_list_append(names, line.buf);
 
                /*
@@ -247,13 +237,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
                                          line.buf);
                fd = open(promisor_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
                if (fd < 0)
-                       die_errno("unable to create '%s'", promisor_name);
+                       die_errno(_("unable to create '%s'"), promisor_name);
                close(fd);
                free(promisor_name);
        }
        fclose(out);
        if (finish_command(&cmd))
-               die("Could not finish pack-objects to repack promisor objects");
+               die(_("could not finish pack-objects to repack promisor objects"));
 }
 
 #define ALL_INTO_ONE 1
@@ -343,8 +333,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
            (unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE)))
                die(_("--keep-unreachable and -A are incompatible"));
 
+       if (write_bitmaps < 0) {
+               if (!(pack_everything & ALL_INTO_ONE) ||
+                   !is_bare_repository())
+                       write_bitmaps = 0;
+       }
        if (pack_kept_objects < 0)
-               pack_kept_objects = write_bitmaps;
+               pack_kept_objects = write_bitmaps > 0;
 
        if (write_bitmaps && !(pack_everything & ALL_INTO_ONE))
                die(_(incremental_bitmap_conflict_error));
@@ -368,8 +363,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        argv_array_push(&cmd.args, "--indexed-objects");
        if (repository_format_partial_clone)
                argv_array_push(&cmd.args, "--exclude-promisor-objects");
-       if (write_bitmaps)
+       if (write_bitmaps > 0)
                argv_array_push(&cmd.args, "--write-bitmap-index");
+       else if (write_bitmaps < 0)
+               argv_array_push(&cmd.args, "--write-bitmap-index-quiet");
        if (use_delta_islands)
                argv_array_push(&cmd.args, "--delta-islands");
 
@@ -408,7 +405,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        out = xfdopen(cmd.out, "r");
        while (strbuf_getline_lf(&line, out) != EOF) {
                if (line.len != the_hash_algo->hexsz)
-                       die("repack: Expecting full hex object ID lines only from pack-objects.");
+                       die(_("repack: Expecting full hex object ID lines only from pack-objects."));
                string_list_append(&names, line.buf);
        }
        fclose(out);
@@ -417,7 +414,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                return ret;
 
        if (!names.nr && !po_args.quiet)
-               printf("Nothing new to pack.\n");
+               printf_ln(_("Nothing new to pack."));
+
+       close_object_store(the_repository->objects);
 
        /*
         * Ok we have prepared all new packfiles.
@@ -431,8 +430,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                        char *fname, *fname_old;
 
                        if (!midx_cleared) {
-                               /* if we move a packfile, it will invalidated the midx */
-                               clear_midx_file(get_object_directory());
+                               clear_midx_file(the_repository);
                                midx_cleared = 1;
                        }
 
@@ -477,13 +475,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                if (rollback_failure.nr) {
                        int i;
                        fprintf(stderr,
-                               "WARNING: Some packs in use have been renamed by\n"
-                               "WARNING: prefixing old- to their name, in order to\n"
-                               "WARNING: replace them with the new version of the\n"
-                               "WARNING: file.  But the operation failed, and the\n"
-                               "WARNING: attempt to rename them back to their\n"
-                               "WARNING: original names also failed.\n"
-                               "WARNING: Please rename them in %s manually:\n", packdir);
+                               _("WARNING: Some packs in use have been renamed by\n"
+                                 "WARNING: prefixing old- to their name, in order to\n"
+                                 "WARNING: replace them with the new version of the\n"
+                                 "WARNING: file.  But the operation failed, and the\n"
+                                 "WARNING: attempt to rename them back to their\n"
+                                 "WARNING: original names also failed.\n"
+                                 "WARNING: Please rename them in %s manually:\n"), packdir);
                        for (i = 0; i < rollback_failure.nr; i++)
                                fprintf(stderr, "WARNING:   old-%s -> %s\n",
                                        rollback_failure.items[i].string,
@@ -561,6 +559,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        if (!no_update_server_info)
                update_server_info(0);
        remove_temporary_files();
+
+       if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
+               write_midx_file(get_object_directory());
+
        string_list_clear(&names, 0);
        string_list_clear(&rollback, 0);
        string_list_clear(&existing_packs, 0);