Imported Upstream version 2.10.0
[platform/upstream/git.git] / builtin / repack.c
index 70b9b1e..80dd06b 100644 (file)
@@ -146,6 +146,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        int pack_everything = 0;
        int delete_redundant = 0;
        const char *unpack_unreachable = NULL;
+       int keep_unreachable = 0;
        const char *window = NULL, *window_memory = NULL;
        const char *depth = NULL;
        const char *max_pack_size = NULL;
@@ -175,6 +176,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                                N_("write bitmap index")),
                OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
                                N_("with -A, do not loosen objects older than this")),
+               OPT_BOOL('k', "keep-unreachable", &keep_unreachable,
+                               N_("with -a, repack unreachable objects")),
                OPT_STRING(0, "window", &window, N_("n"),
                                N_("size of the window used for delta compression")),
                OPT_STRING(0, "window-memory", &window_memory, N_("bytes"),
@@ -193,6 +196,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, builtin_repack_options,
                                git_repack_usage, 0);
 
+       if (delete_redundant && repository_format_precious_objects)
+               die(_("cannot delete packs in a precious-objects repo"));
+
+       if (keep_unreachable &&
+           (unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE)))
+               die(_("--keep-unreachable and -A are incompatible"));
+
        if (pack_kept_objects < 0)
                pack_kept_objects = write_bitmaps;
 
@@ -236,6 +246,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                        } else if (pack_everything & LOOSEN_UNREACHABLE) {
                                argv_array_push(&cmd.args,
                                                "--unpack-unreachable");
+                       } else if (keep_unreachable) {
+                               argv_array_push(&cmd.args, "--keep-unreachable");
+                               argv_array_push(&cmd.args, "--pack-loose-unreachable");
                        } else {
                                argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
                        }
@@ -263,7 +276,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                return ret;
 
        out = xfdopen(cmd.out, "r");
-       while (strbuf_getline(&line, out, '\n') != EOF) {
+       while (strbuf_getline_lf(&line, out) != EOF) {
                if (line.len != 40)
                        die("repack: Expecting 40 character sha1 lines only from pack-objects.");
                string_list_append(&names, line.buf);
@@ -375,7 +388,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                                          item->string,
                                          exts[ext].name);
                        if (remove_path(fname))
-                               warning(_("removing '%s' failed"), fname);
+                               warning(_("failed to remove '%s'"), fname);
                        free(fname);
                }
        }