Merge branch 'jk/pack-bitmap'
authorJunio C Hamano <gitster@pobox.com>
Fri, 28 Mar 2014 20:50:50 +0000 (13:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 28 Mar 2014 20:50:50 +0000 (13:50 -0700)
Instead of dying when asked to (re)pack with the reachability
bitmap when a bitmap cannot be built, just (re)pack without
producing a bitmap in such a case, with a warning.

* jk/pack-bitmap:
pack-objects: turn off bitmaps when skipping objects

1  2 
builtin/pack-objects.c
diff --combined builtin/pack-objects.c
index 0ee5f1ff94e1689b099f04fff8a05728c70f2f4f,50d794f5d9a2c53ca596e8f04a0b61809cc91fd0..e3150d7d4edef2c725bb0f6e8e480c0207b33a38
@@@ -755,7 -755,7 +755,7 @@@ static void write_pack_file(void
        struct object_entry **write_order;
  
        if (progress > pack_to_stdout)
 -              progress_state = start_progress("Writing objects", nr_result);
 +              progress_state = start_progress(_("Writing objects"), nr_result);
        written_list = xmalloc(to_pack.nr_objects * sizeof(*written_list));
        write_order = compute_write_order();
  
                        f = create_tmp_packfile(&pack_tmp_name);
  
                offset = write_pack_header(f, nr_remaining);
 -              if (!offset)
 -                      die_errno("unable to write pack header");
  
                if (reuse_packfile) {
                        off_t packfile_size;
  
                if (!pack_to_stdout) {
                        struct stat st;
 -                      char tmpname[PATH_MAX];
 +                      struct strbuf tmpname = STRBUF_INIT;
  
                        /*
                         * Packs are runtime accessed in their mtime
                                utb.modtime = --last_mtime;
                                if (utime(pack_tmp_name, &utb) < 0)
                                        warning("failed utime() on %s: %s",
 -                                              tmpname, strerror(errno));
 +                                              pack_tmp_name, strerror(errno));
                        }
  
 -                      /* Enough space for "-<sha-1>.pack"? */
 -                      if (sizeof(tmpname) <= strlen(base_name) + 50)
 -                              die("pack base name '%s' too long", base_name);
 -                      snprintf(tmpname, sizeof(tmpname), "%s-", base_name);
 +                      strbuf_addf(&tmpname, "%s-", base_name);
  
                        if (write_bitmap_index) {
                                bitmap_writer_set_checksum(sha1);
                                bitmap_writer_build_type_index(written_list, nr_written);
                        }
  
 -                      finish_tmp_packfile(tmpname, pack_tmp_name,
 +                      finish_tmp_packfile(&tmpname, pack_tmp_name,
                                            written_list, nr_written,
                                            &pack_idx_opts, sha1);
  
                        if (write_bitmap_index) {
 -                              char *end_of_name_prefix = strrchr(tmpname, 0);
 -                              sprintf(end_of_name_prefix, "%s.bitmap", sha1_to_hex(sha1));
 +                              strbuf_addf(&tmpname, "%s.bitmap", sha1_to_hex(sha1));
  
                                stop_progress(&progress_state);
  
                                bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
                                bitmap_writer_build(&to_pack);
                                bitmap_writer_finish(written_list, nr_written,
 -                                                   tmpname, write_bitmap_options);
 +                                                   tmpname.buf, write_bitmap_options);
                                write_bitmap_index = 0;
                        }
  
 +                      strbuf_release(&tmpname);
                        free(pack_tmp_name);
                        puts(sha1_to_hex(sha1));
                }
@@@ -995,6 -1000,10 +995,10 @@@ static void create_object_entry(const u
        entry->no_try_delta = no_try_delta;
  }
  
+ static const char no_closure_warning[] = N_(
+ "disabling bitmap writing, as some objects are not being packed"
+ );
  static int add_object_entry(const unsigned char *sha1, enum object_type type,
                            const char *name, int exclude)
  {
        if (have_duplicate_entry(sha1, exclude, &index_pos))
                return 0;
  
-       if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset))
+       if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset)) {
+               /* The pack is missing an object, so it will not have closure */
+               if (write_bitmap_index) {
+                       warning(_(no_closure_warning));
+                       write_bitmap_index = 0;
+               }
                return 0;
+       }
  
        create_object_entry(sha1, type, pack_name_hash(name),
                            exclude, name && no_try_delta(name),
@@@ -1210,9 -1225,12 +1220,9 @@@ static int check_pbase_path(unsigned ha
        if (0 <= pos)
                return 1;
        pos = -pos - 1;
 -      if (done_pbase_paths_alloc <= done_pbase_paths_num) {
 -              done_pbase_paths_alloc = alloc_nr(done_pbase_paths_alloc);
 -              done_pbase_paths = xrealloc(done_pbase_paths,
 -                                          done_pbase_paths_alloc *
 -                                          sizeof(unsigned));
 -      }
 +      ALLOC_GROW(done_pbase_paths,
 +                 done_pbase_paths_num + 1,
 +                 done_pbase_paths_alloc);
        done_pbase_paths_num++;
        if (pos < done_pbase_paths_num)
                memmove(done_pbase_paths + pos + 1,
@@@ -2081,7 -2099,7 +2091,7 @@@ static int add_ref_tag(const char *path
  {
        unsigned char peeled[20];
  
 -      if (!prefixcmp(path, "refs/tags/") && /* is a tag? */
 +      if (starts_with(path, "refs/tags/") && /* is a tag? */
            !peel_ref(path, peeled)        && /* peelable? */
            packlist_find(&to_pack, peeled, NULL))      /* object packed? */
                add_object_entry(sha1, OBJ_TAG, NULL, 0);
@@@ -2148,7 -2166,7 +2158,7 @@@ static void prepare_pack(int window, in
        if (nr_deltas && n > 1) {
                unsigned nr_done = 0;
                if (progress)
 -                      progress_state = start_progress("Compressing objects",
 +                      progress_state = start_progress(_("Compressing objects"),
                                                        nr_deltas);
                qsort(delta_list, n, sizeof(*delta_list), type_size_sort);
                ll_find_deltas(delta_list, n, window+1, depth, &nr_done);
@@@ -2449,9 -2467,6 +2459,9 @@@ static void get_object_list(int ac, con
        save_commit_buffer = 0;
        setup_revisions(ac, av, &revs, NULL);
  
 +      /* make sure shallows are read */
 +      is_repository_shallow();
 +
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
                if (len && line[len - 1] == '\n')
                                write_bitmap_index = 0;
                                continue;
                        }
 +                      if (starts_with(line, "--shallow ")) {
 +                              unsigned char sha1[20];
 +                              if (get_sha1_hex(line + 10, sha1))
 +                                      die("not an SHA-1 '%s'", line + 10);
 +                              register_shallow(sha1);
 +                              continue;
 +                      }
                        die("not a rev '%s'", line);
                }
                if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME))
@@@ -2616,7 -2624,7 +2626,7 @@@ int cmd_pack_objects(int argc, const ch
                OPT_END(),
        };
  
 -      read_replace_refs = 0;
 +      check_replace_refs = 0;
  
        reset_pack_idx_option(&pack_idx_opts);
        git_config(git_pack_config, NULL);
        prepare_packed_git();
  
        if (progress)
 -              progress_state = start_progress("Counting objects", 0);
 +              progress_state = start_progress(_("Counting objects"), 0);
        if (!use_internal_rev_list)
                read_object_list_from_stdin();
        else {