Merge branch 'jk/repack-pack-keep-objects' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 10 Jul 2014 18:10:05 +0000 (11:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Jul 2014 18:10:05 +0000 (11:10 -0700)
* jk/repack-pack-keep-objects:
repack: s/write_bitmap/&s/ in code
repack: respect pack.writebitmaps
repack: do not accidentally pack kept objects by default

1  2 
builtin/repack.c
t/t7700-repack.sh
diff --combined builtin/repack.c
index 6b0b62dcb2687e78ec433e7de1103f0c0f74a1fc,0ec643f38848ad8636372a097560cea3683b07c4..36c1cf9c2544d579e2b12116e731c0f6cb7dfb71
@@@ -10,6 -10,7 +10,7 @@@
  
  static int delta_base_offset = 1;
  static int pack_kept_objects = -1;
+ static int write_bitmaps = -1;
  static char *packdir, *packtmp;
  
  static const char *const git_repack_usage[] = {
@@@ -27,6 -28,10 +28,10 @@@ static int repack_config(const char *va
                pack_kept_objects = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "pack.writebitmaps")) {
+               write_bitmaps = git_config_bool(var, value);
+               return 0;
+       }
        return git_default_config(var, value, cb);
  }
  
@@@ -83,7 -88,7 +88,7 @@@ static void get_non_kept_pack_filenames
                return;
  
        while ((e = readdir(dir)) != NULL) {
 -              if (suffixcmp(e->d_name, ".pack"))
 +              if (!ends_with(e->d_name, ".pack"))
                        continue;
  
                len = strlen(e->d_name) - strlen(".pack");
@@@ -135,21 -140,20 +140,20 @@@ int cmd_repack(int argc, const char **a
        struct string_list rollback = STRING_LIST_INIT_NODUP;
        struct string_list existing_packs = STRING_LIST_INIT_DUP;
        struct strbuf line = STRBUF_INIT;
 -      int nr_packs, ext, ret, failed;
 +      int ext, ret, failed;
        FILE *out;
  
        /* variables to be filled by option parsing */
        int pack_everything = 0;
        int delete_redundant = 0;
 -      char *unpack_unreachable = NULL;
 -      int window = 0, window_memory = 0;
 -      int depth = 0;
 -      int max_pack_size = 0;
 +      const char *unpack_unreachable = NULL;
 +      const char *window = NULL, *window_memory = NULL;
 +      const char *depth = NULL;
 +      const char *max_pack_size = NULL;
        int no_reuse_delta = 0, no_reuse_object = 0;
        int no_update_server_info = 0;
        int quiet = 0;
        int local = 0;
-       int write_bitmap = -1;
  
        struct option builtin_repack_options[] = {
                OPT_BIT('a', NULL, &pack_everything,
                OPT__QUIET(&quiet, N_("be quiet")),
                OPT_BOOL('l', "local", &local,
                                N_("pass --local to git-pack-objects")),
-               OPT_BOOL('b', "write-bitmap-index", &write_bitmap,
+               OPT_BOOL('b', "write-bitmap-index", &write_bitmaps,
                                N_("write bitmap index")),
                OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
                                N_("with -A, do not loosen objects older than this")),
 -              OPT_INTEGER(0, "window", &window,
 +              OPT_STRING(0, "window", &window, N_("n"),
                                N_("size of the window used for delta compression")),
 -              OPT_INTEGER(0, "window-memory", &window_memory,
 +              OPT_STRING(0, "window-memory", &window_memory, N_("bytes"),
                                N_("same as the above, but limit memory size instead of entries count")),
 -              OPT_INTEGER(0, "depth", &depth,
 +              OPT_STRING(0, "depth", &depth, N_("n"),
                                N_("limits the maximum delta depth")),
 -              OPT_INTEGER(0, "max-pack-size", &max_pack_size,
 +              OPT_STRING(0, "max-pack-size", &max_pack_size, N_("bytes"),
                                N_("maximum size of each packfile")),
                OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
                                N_("repack objects in packs marked with .keep")),
                                git_repack_usage, 0);
  
        if (pack_kept_objects < 0)
-               pack_kept_objects = write_bitmap;
+               pack_kept_objects = write_bitmaps > 0;
  
        packdir = mkpathdup("%s/pack", get_object_directory());
        packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
        argv_array_push(&cmd_args, "--all");
        argv_array_push(&cmd_args, "--reflog");
        if (window)
 -              argv_array_pushf(&cmd_args, "--window=%u", window);
 +              argv_array_pushf(&cmd_args, "--window=%s", window);
        if (window_memory)
 -              argv_array_pushf(&cmd_args, "--window-memory=%u", window_memory);
 +              argv_array_pushf(&cmd_args, "--window-memory=%s", window_memory);
        if (depth)
 -              argv_array_pushf(&cmd_args, "--depth=%u", depth);
 +              argv_array_pushf(&cmd_args, "--depth=%s", depth);
        if (max_pack_size)
 -              argv_array_pushf(&cmd_args, "--max_pack_size=%u", max_pack_size);
 +              argv_array_pushf(&cmd_args, "--max-pack-size=%s", max_pack_size);
        if (no_reuse_delta)
                argv_array_pushf(&cmd_args, "--no-reuse-delta");
        if (no_reuse_object)
                argv_array_pushf(&cmd_args, "--no-reuse-object");
-       if (write_bitmap >= 0)
+       if (write_bitmaps >= 0)
                argv_array_pushf(&cmd_args, "--%swrite-bitmap-index",
-                                write_bitmap ? "" : "no-");
+                                write_bitmaps ? "" : "no-");
  
        if (pack_everything & ALL_INTO_ONE) {
                get_non_kept_pack_filenames(&existing_packs);
        if (ret)
                return ret;
  
 -      nr_packs = 0;
        out = xfdopen(cmd.out, "r");
        while (strbuf_getline(&line, out, '\n') != EOF) {
                if (line.len != 40)
                        die("repack: Expecting 40 character sha1 lines only from pack-objects.");
                string_list_append(&names, line.buf);
 -              nr_packs++;
        }
        fclose(out);
        ret = finish_command(&cmd);
                return ret;
        argv_array_clear(&cmd_args);
  
 -      if (!nr_packs && !quiet)
 +      if (!names.nr && !quiet)
                printf("Nothing new to pack.\n");
  
        /*
        for_each_string_list_item(item, &names) {
                for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
                        char *fname, *fname_old;
 -                      fname = mkpathdup("%s/%s%s", packdir,
 +                      fname = mkpathdup("%s/pack-%s%s", packdir,
                                                item->string, exts[ext].name);
                        if (!file_exists(fname)) {
                                free(fname);
        for_each_string_list_item(item, &names) {
                for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
                        char *fname;
 -                      fname = mkpath("%s/old-pack-%s%s",
 +                      fname = mkpath("%s/old-%s%s",
                                        packdir,
                                        item->string,
                                        exts[ext].name);
diff --combined t/t7700-repack.sh
index 284018e3cdb31e7db179a93f7196fda47578c43c,e70b98358b02e0d547bb2c7ed5d50b5c5753fee4..61e6ed37aa6fd6bff8bfe4d5c267c0ed3cad3db4
@@@ -17,7 -17,7 +17,7 @@@ test_expect_success 'objects in packs m
        # The second pack will contain the excluded object
        packsha1=$(git rev-list --objects --all | grep file2 |
                git pack-objects pack) &&
 -      touch -r pack-$packsha1.pack pack-$packsha1.keep &&
 +      >pack-$packsha1.keep &&
        objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
                sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
        mv pack-* .git/objects/pack/ &&
        test -z "$found_duplicate_object"
  '
  
- test_expect_success 'writing bitmaps can duplicate .keep objects' '
+ test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
        # build on $objsha1, $packsha1, and .keep state from previous
-       git repack -Adl &&
+       git repack -Adbl &&
+       test_when_finished "found_duplicate_object=" &&
+       for p in .git/objects/pack/*.idx; do
+               idx=$(basename $p)
+               test "pack-$packsha1.idx" = "$idx" && continue
+               if git verify-pack -v $p | egrep "^$objsha1"; then
+                       found_duplicate_object=1
+                       echo "DUPLICATE OBJECT FOUND"
+                       break
+               fi
+       done &&
+       test "$found_duplicate_object" = 1
+ '
+ test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
+       # build on $objsha1, $packsha1, and .keep state from previous
+       git -c pack.writebitmaps=true repack -Adl &&
        test_when_finished "found_duplicate_object=" &&
        for p in .git/objects/pack/*.idx; do
                idx=$(basename $p)