pack-objects: show some progress when counting kept objects

We only show progress when there are new objects to be packed. But when --keep-pack is specified on the base pack, we will exclude most of objects. This makes 'pack-objects' stay silent for a long time while the counting phase is going. Let's show some progress whenever we visit an object instead. The old "Counting objects" is renamed to "Enumerating objects" and a new progress "Counting objects" line is added. This new "Counting objects" line should progress pretty quick when the system is beefy. But when the system is under pressure, the reading object header done in this phase could be slow and showing progress is an improvement over staying silent in the current code. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 15, 2018 at 17:36 UTC 5af050437af1c061804b4317154085c65490bbac
1 file changed +12 -6
builtin/pack-objects.c
+12 -6
@@ -46,7 +46,7 @@ static const char *pack_usage[] = {
46 static struct packing_data to_pack;
47
48 static struct pack_idx_entry **written_list;
49 -static uint32_t nr_result, nr_written;
49 +static uint32_t nr_result, nr_written, nr_seen;
50
51 static int non_empty;
52 static int reuse_delta = 1, reuse_object = 1;
@@ -1096,6 +1096,8 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
1096 off_t found_offset = 0;
1097 uint32_t index_pos;
1098
1099 + display_progress(progress_state, ++nr_seen);
1100 +
1101 if (have_duplicate_entry(oid, exclude, &index_pos))
1102 return 0;
1103
@@ -1111,8 +1113,6 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
1113 create_object_entry(oid, type, pack_name_hash(name),
1114 exclude, name && no_try_delta(name),
1115 index_pos, found_pack, found_offset);
1114 -
1115 - display_progress(progress_state, nr_result);
1116 return 1;
1117 }
1118
@@ -1123,6 +1123,8 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
1123 {
1124 uint32_t index_pos;
1125
1126 + display_progress(progress_state, ++nr_seen);
1127 +
1128 if (have_duplicate_entry(oid, 0, &index_pos))
1129 return 0;
1130
@@ -1130,8 +1132,6 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
1132 return 0;
1133
1134 create_object_entry(oid, type, name_hash, 0, 0, index_pos, pack, offset);
1133 -
1134 - display_progress(progress_state, nr_result);
1135 return 1;
1136 }
1137
@@ -1716,6 +1716,10 @@ static void get_object_details(void)
1716 uint32_t i;
1717 struct object_entry **sorted_by_offset;
1718
1719 + if (progress)
1720 + progress_state = start_progress(_("Counting objects"),
1721 + to_pack.nr_objects);
1722 +
1723 sorted_by_offset = xcalloc(to_pack.nr_objects, sizeof(struct object_entry *));
1724 for (i = 0; i < to_pack.nr_objects; i++)
1725 sorted_by_offset[i] = to_pack.objects + i;
@@ -1726,7 +1730,9 @@ static void get_object_details(void)
1730 check_object(entry);
1731 if (big_file_threshold < entry->size)
1732 entry->no_try_delta = 1;
1733 + display_progress(progress_state, i + 1);
1734 }
1735 + stop_progress(&progress_state);
1736
1737 /*
1738 * This must happen in a second pass, since we rely on the delta
@@ -3209,7 +3215,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3215 }
3216
3217 if (progress)
3212 - progress_state = start_progress(_("Counting objects"), 0);
3218 + progress_state = start_progress(_("Enumerating objects"), 0);
3219 if (!use_internal_rev_list)
3220 read_object_list_from_stdin();
3221 else {