pack-objects: create pack.useSparse setting
[gitweb.git] / builtin / pack-objects.c
index 794714e4f8703c0efed76fc37006fba05496f660..124b1bafc4b892466d20ec38ac3a2f8a5b81eac0 100644 (file)
@@ -84,6 +84,7 @@ static unsigned long pack_size_limit;
 static int depth = 50;
 static int delta_search_threads;
 static int pack_to_stdout;
+static int sparse;
 static int thin;
 static int num_preferred_base;
 static struct progress *progress_state;
@@ -2083,9 +2084,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
                        die(_("object %s cannot be read"),
                            oid_to_hex(&trg_entry->idx.oid));
                if (sz != trg_size)
-                       die(_("object %s inconsistent object length (%lu vs %lu)"),
-                           oid_to_hex(&trg_entry->idx.oid), sz,
-                           trg_size);
+                       die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
+                           oid_to_hex(&trg_entry->idx.oid), (uintmax_t)sz,
+                           (uintmax_t)trg_size);
                *mem_usage += sz;
        }
        if (!src->data) {
@@ -2110,9 +2111,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
                            oid_to_hex(&src_entry->idx.oid));
                }
                if (sz != src_size)
-                       die(_("object %s inconsistent object length (%lu vs %lu)"),
-                           oid_to_hex(&src_entry->idx.oid), sz,
-                           src_size);
+                       die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
+                           oid_to_hex(&src_entry->idx.oid), (uintmax_t)sz,
+                           (uintmax_t)src_size);
                *mem_usage += sz;
        }
        if (!src->index) {
@@ -2710,6 +2711,10 @@ static int git_pack_config(const char *k, const char *v, void *cb)
                use_bitmap_index_default = git_config_bool(k, v);
                return 0;
        }
+       if (!strcmp(k, "pack.usesparse")) {
+               sparse = git_config_bool(k, v);
+               return 0;
+       }
        if (!strcmp(k, "pack.threads")) {
                delta_search_threads = git_config_int(k, v);
                if (delta_search_threads < 0)
@@ -2786,9 +2791,11 @@ static void show_object(struct object *obj, const char *name, void *data)
 
        if (use_delta_islands) {
                const char *p;
-               unsigned depth = 0;
+               unsigned depth;
                struct object_entry *ent;
 
+               /* the empty string is a root tree, which is depth 0 */
+               depth = *name ? 1 : 0;
                for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
                        depth++;
 
@@ -3084,6 +3091,7 @@ static void get_object_list(int ac, const char **av)
        struct rev_info revs;
        char line[1000];
        int flags = 0;
+       int save_warning;
 
        repo_init_revisions(the_repository, &revs, NULL);
        save_commit_buffer = 0;
@@ -3093,6 +3101,9 @@ static void get_object_list(int ac, const char **av)
        /* make sure shallows are read */
        is_repository_shallow(the_repository);
 
+       save_warning = warn_on_object_refname_ambiguity;
+       warn_on_object_refname_ambiguity = 0;
+
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
                if (len && line[len - 1] == '\n')
@@ -3119,6 +3130,8 @@ static void get_object_list(int ac, const char **av)
                        die(_("bad revision '%s'"), line);
        }
 
+       warn_on_object_refname_ambiguity = save_warning;
+
        if (use_bitmap_index && !get_object_list_from_bitmap(&revs))
                return;
 
@@ -3127,7 +3140,7 @@ static void get_object_list(int ac, const char **av)
 
        if (prepare_revision_walk(&revs))
                die(_("revision walk setup failed"));
-       mark_edges_uninteresting(&revs, show_edge);
+       mark_edges_uninteresting(&revs, show_edge, sparse);
 
        if (!fn_show_object)
                fn_show_object = show_object;
@@ -3284,6 +3297,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                { OPTION_CALLBACK, 0, "unpack-unreachable", NULL, N_("time"),
                  N_("unpack unreachable objects newer than <time>"),
                  PARSE_OPT_OPTARG, option_parse_unpack_unreachable },
+               OPT_BOOL(0, "sparse", &sparse,
+                        N_("use the sparse reachability algorithm")),
                OPT_BOOL(0, "thin", &thin,
                         N_("create thin packs")),
                OPT_BOOL(0, "shallow", &shallow,