rebase: prepare reset_head() for more flags
[gitweb.git] / builtin / repack.c
index c6a7943d5cb108dbccdfd502d799ab71a9e7e146..82c19b755509f83bf189dd70323a678c299c6b66 100644 (file)
@@ -235,8 +235,8 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
        while (strbuf_getline_lf(&line, out) != EOF) {
                char *promisor_name;
                int fd;
-               if (line.len != 40)
-                       die("repack: Expecting 40 character sha1 lines only from pack-objects.");
+               if (line.len != the_hash_algo->hexsz)
+                       die("repack: Expecting full hex object ID lines only from pack-objects.");
                string_list_append(names, line.buf);
 
                /*
@@ -407,8 +407,8 @@ 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 != 40)
-                       die("repack: Expecting 40 character sha1 lines only from pack-objects.");
+               if (line.len != the_hash_algo->hexsz)
+                       die("repack: Expecting full hex object ID lines only from pack-objects.");
                string_list_append(&names, line.buf);
        }
        fclose(out);
@@ -535,20 +535,27 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        reprepare_packed_git(the_repository);
 
        if (delete_redundant) {
+               const int hexsz = the_hash_algo->hexsz;
                int opts = 0;
                string_list_sort(&names);
                for_each_string_list_item(item, &existing_packs) {
                        char *sha1;
                        size_t len = strlen(item->string);
-                       if (len < 40)
+                       if (len < hexsz)
                                continue;
-                       sha1 = item->string + len - 40;
+                       sha1 = item->string + len - hexsz;
                        if (!string_list_has_string(&names, sha1))
                                remove_redundant_pack(packdir, item->string);
                }
                if (!po_args.quiet && isatty(2))
                        opts |= PRUNE_PACKED_VERBOSE;
                prune_packed_objects(opts);
+
+               if (!keep_unreachable &&
+                   (!(pack_everything & LOOSEN_UNREACHABLE) ||
+                    unpack_unreachable) &&
+                   is_repository_shallow(the_repository))
+                       prune_shallow(PRUNE_QUICK);
        }
 
        if (!no_update_server_info)