Merge branch 'ep/shell-command-substitution'
[gitweb.git] / builtin / pack-objects.c
index 0ee5f1ff94e1689b099f04fff8a05728c70f2f4f..7950c4342f81544f719b20add2e1233be36fc718 100644 (file)
@@ -708,7 +708,7 @@ static struct object_entry **compute_write_order(void)
 static off_t write_reused_pack(struct sha1file *f)
 {
        unsigned char buffer[8192];
-       off_t to_write;
+       off_t to_write, total;
        int fd;
 
        if (!is_pack_valid(reuse_packfile))
@@ -725,7 +725,7 @@ static off_t write_reused_pack(struct sha1file *f)
        if (reuse_packfile_offset < 0)
                reuse_packfile_offset = reuse_packfile->pack_size - 20;
 
-       to_write = reuse_packfile_offset - sizeof(struct pack_header);
+       total = to_write = reuse_packfile_offset - sizeof(struct pack_header);
 
        while (to_write) {
                int read_pack = xread(fd, buffer, sizeof(buffer));
@@ -738,10 +738,23 @@ static off_t write_reused_pack(struct sha1file *f)
 
                sha1write(f, buffer, read_pack);
                to_write -= read_pack;
+
+               /*
+                * We don't know the actual number of objects written,
+                * only how many bytes written, how many bytes total, and
+                * how many objects total. So we can fake it by pretending all
+                * objects we are writing are the same size. This gives us a
+                * smooth progress meter, and at the end it matches the true
+                * answer.
+                */
+               written = reuse_packfile_objects *
+                               (((double)(total - to_write)) / total);
+               display_progress(progress_state, written);
        }
 
        close(fd);
-       written += reuse_packfile_objects;
+       written = reuse_packfile_objects;
+       display_progress(progress_state, written);
        return reuse_packfile_offset - sizeof(struct pack_header);
 }
 
@@ -995,6 +1008,10 @@ static void create_object_entry(const unsigned char *sha1,
        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)
 {
@@ -1005,14 +1022,20 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
        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),
                            index_pos, found_pack, found_offset);
 
-       display_progress(progress_state, to_pack.nr_objects);
+       display_progress(progress_state, nr_result);
        return 1;
 }
 
@@ -1028,7 +1051,7 @@ static int add_object_entry_from_bitmap(const unsigned char *sha1,
 
        create_object_entry(sha1, type, name_hash, 0, 0, index_pos, pack, offset);
 
-       display_progress(progress_state, to_pack.nr_objects);
+       display_progress(progress_state, nr_result);
        return 1;
 }
 
@@ -2427,12 +2450,7 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
                        &reuse_packfile_offset)) {
                assert(reuse_packfile_objects);
                nr_result += reuse_packfile_objects;
-
-               if (progress) {
-                       fprintf(stderr, "Reusing existing pack: %d, done.\n",
-                               reuse_packfile_objects);
-                       fflush(stderr);
-               }
+               display_progress(progress_state, nr_result);
        }
 
        traverse_bitmap_commit_list(&add_object_entry_from_bitmap);