Merge branch 'jt/remove-pack-bitmap-global'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Jul 2018 19:20:30 +0000 (12:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Jul 2018 19:20:30 +0000 (12:20 -0700)
The effort to move globals to per-repository in-core structure
continues.

* jt/remove-pack-bitmap-global:
pack-bitmap: add free function
pack-bitmap: remove bitmap_git global variable

1  2 
builtin/pack-objects.c
builtin/rev-list.c
pack-bitmap-write.c
diff --combined builtin/pack-objects.c
index 69d3d7b82af8b69b589327f9420bb02bab339a25,896e41300733e387aa65b0aa401e30f82cf45780..ebc8cefb53f4a1fde99eff8d6f19c8df0cec0ede
@@@ -2929,11 -2929,13 +2929,13 @@@ static int pack_options_allow_reuse(voi
  
  static int get_object_list_from_bitmap(struct rev_info *revs)
  {
-       if (prepare_bitmap_walk(revs) < 0)
+       struct bitmap_index *bitmap_git;
+       if (!(bitmap_git = prepare_bitmap_walk(revs)))
                return -1;
  
        if (pack_options_allow_reuse() &&
            !reuse_partial_packfile_from_bitmap(
+                       bitmap_git,
                        &reuse_packfile,
                        &reuse_packfile_objects,
                        &reuse_packfile_offset)) {
                display_progress(progress_state, nr_result);
        }
  
-       traverse_bitmap_commit_list(&add_object_entry_from_bitmap);
+       traverse_bitmap_commit_list(bitmap_git, &add_object_entry_from_bitmap);
+       free_bitmap_index(bitmap_git);
        return 0;
  }
  
@@@ -2969,7 -2972,7 +2972,7 @@@ static void get_object_list(int ac, con
        setup_revisions(ac, av, &revs, NULL);
  
        /* make sure shallows are read */
 -      is_repository_shallow();
 +      is_repository_shallow(the_repository);
  
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
                                struct object_id oid;
                                if (get_oid_hex(line + 10, &oid))
                                        die("not an SHA-1 '%s'", line + 10);
 -                              register_shallow(&oid);
 +                              register_shallow(the_repository, &oid);
                                use_bitmap_index = 0;
                                continue;
                        }
@@@ -3299,7 -3302,7 +3302,7 @@@ int cmd_pack_objects(int argc, const ch
                use_bitmap_index = use_bitmap_index_default;
  
        /* "hard" reasons not to use bitmaps; these just won't work at all */
 -      if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow())
 +      if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository))
                use_bitmap_index = 0;
  
        if (pack_to_stdout || !rev_list_all)
diff --combined builtin/rev-list.c
index e9bd4e378adc11fa79a8f5056b0d8c2a7dc6d4bf,62776721f30f884b1bd2677ae5e8ccfdc89197b1..6fcb0ff6d56154b9849108028f529c09d0c3450e
@@@ -6,7 -6,6 +6,7 @@@
  #include "list-objects.h"
  #include "list-objects-filter.h"
  #include "list-objects-filter-options.h"
 +#include "object-store.h"
  #include "pack.h"
  #include "pack-bitmap.h"
  #include "builtin.h"
@@@ -17,6 -16,7 +17,7 @@@
  #include "reflog-walk.h"
  #include "oidset.h"
  #include "packfile.h"
+ #include "object-store.h"
  
  static const char rev_list_usage[] =
  "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@@ -515,17 -515,21 +516,21 @@@ int cmd_rev_list(int argc, const char *
                if (revs.count && !revs.left_right && !revs.cherry_mark) {
                        uint32_t commit_count;
                        int max_count = revs.max_count;
-                       if (!prepare_bitmap_walk(&revs)) {
-                               count_bitmap_commit_list(&commit_count, NULL, NULL, NULL);
+                       struct bitmap_index *bitmap_git;
+                       if ((bitmap_git = prepare_bitmap_walk(&revs))) {
+                               count_bitmap_commit_list(bitmap_git, &commit_count, NULL, NULL, NULL);
                                if (max_count >= 0 && max_count < commit_count)
                                        commit_count = max_count;
                                printf("%d\n", commit_count);
+                               free_bitmap_index(bitmap_git);
                                return 0;
                        }
                } else if (revs.max_count < 0 &&
                           revs.tag_objects && revs.tree_objects && revs.blob_objects) {
-                       if (!prepare_bitmap_walk(&revs)) {
-                               traverse_bitmap_commit_list(&show_object_fast);
+                       struct bitmap_index *bitmap_git;
+                       if ((bitmap_git = prepare_bitmap_walk(&revs))) {
+                               traverse_bitmap_commit_list(bitmap_git, &show_object_fast);
+                               free_bitmap_index(bitmap_git);
                                return 0;
                        }
                }
diff --combined pack-bitmap-write.c
index 953c5dd84dff2d87b639d29b71d844b29f925618,7896fedd363e0bdc23bc8493cf144d7c147e83ab..d977e9bacb19ed766dd0a501b6fbcae800bb4ae0
@@@ -1,5 -1,4 +1,5 @@@
  #include "cache.h"
 +#include "object-store.h"
  #include "commit.h"
  #include "tag.h"
  #include "diff.h"
@@@ -361,11 -360,17 +361,17 @@@ static int date_compare(const void *_a
  
  void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
  {
-       if (prepare_bitmap_git() < 0)
+       struct bitmap_index *bitmap_git;
+       if (!(bitmap_git = prepare_bitmap_git()))
                return;
  
        writer.reused = kh_init_sha1();
-       rebuild_existing_bitmaps(to_pack, writer.reused, writer.show_progress);
+       rebuild_existing_bitmaps(bitmap_git, to_pack, writer.reused,
+                                writer.show_progress);
+       /*
+        * NEEDSWORK: rebuild_existing_bitmaps() makes writer.reused reference
+        * some bitmaps in bitmap_git, so we can't free the latter.
+        */
  }
  
  static struct ewah_bitmap *find_reused_bitmap(const unsigned char *sha1)