@matheusbsbs / matheus-bagliano / commits / 4d4fcc5451
Fork 0

relax usage of the progress API

Since it is now OK to pass a null pointer to display_progress() and stop_progress() resulting in a no-op, then we can simplify the code and remove a bunch of lines by not making those calls conditional all the time. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Oct 30, 2007 at 14:57 UTC 4d4fcc5451d9d653bebcc8afa18543cb426abeed
5 files changed +20 -38
builtin-pack-objects.c
+6 -12
@@ -629,8 +629,7 @@ static void write_pack_file(void)
629 if (!offset_one)
630 break;
631 offset = offset_one;
632 - if (do_progress)
633 - display_progress(progress_state, written);
632 + display_progress(progress_state, written);
633 }
634
635 /*
@@ -684,8 +683,7 @@ static void write_pack_file(void)
683 } while (nr_remaining && i < nr_objects);
684
685 free(written_list);
687 - if (do_progress)
688 - stop_progress(&progress_state);
686 + stop_progress(&progress_state);
687 if (written != nr_result)
688 die("wrote %u objects while expecting %u", written, nr_result);
689 /*
@@ -853,8 +851,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
851 else
852 object_ix[-1 - ix] = nr_objects;
853
856 - if (progress)
857 - display_progress(progress_state, nr_objects);
854 + display_progress(progress_state, nr_objects);
855
856 if (name && no_try_delta(name))
857 entry->no_try_delta = 1;
@@ -1517,8 +1514,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
1514
1515 progress_lock();
1516 (*processed)++;
1520 - if (progress)
1521 - display_progress(progress_state, *processed);
1517 + display_progress(progress_state, *processed);
1518 progress_unlock();
1519
1520 /*
@@ -1722,8 +1718,7 @@ static void prepare_pack(int window, int depth)
1718 nr_deltas);
1719 qsort(delta_list, n, sizeof(*delta_list), type_size_sort);
1720 ll_find_deltas(delta_list, n, window+1, depth, &nr_done);
1725 - if (progress)
1726 - stop_progress(&progress_state);
1721 + stop_progress(&progress_state);
1722 if (nr_done != nr_deltas)
1723 die("inconsistency with delta count");
1724 }
@@ -2142,8 +2137,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2137 rp_av[rp_ac] = NULL;
2138 get_object_list(rp_ac, rp_av);
2139 }
2145 - if (progress)
2146 - stop_progress(&progress_state);
2140 + stop_progress(&progress_state);
2141
2142 if (non_empty && !nr_result)
2143 return 0;
builtin-prune-packed.c
+2 -4
@@ -15,8 +15,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
15 struct dirent *de;
16 char hex[40];
17
18 - if (opts == VERBOSE)
19 - display_progress(progress, i + 1);
18 + display_progress(progress, i + 1);
19
20 sprintf(hex, "%02x", i);
21 while ((de = readdir(dir)) != NULL) {
@@ -64,8 +63,7 @@ void prune_packed_objects(int opts)
63 prune_dir(i, d, pathname, len + 3, opts);
64 closedir(d);
65 }
67 - if (opts == VERBOSE)
68 - stop_progress(&progress);
66 + stop_progress(&progress);
67 }
68
69 int cmd_prune_packed(int argc, const char **argv, const char *prefix)
builtin-unpack-objects.c
+2 -4
@@ -326,11 +326,9 @@ static void unpack_all(void)
326 obj_list = xmalloc(nr_objects * sizeof(*obj_list));
327 for (i = 0; i < nr_objects; i++) {
328 unpack_one(i);
329 - if (!quiet)
330 - display_progress(progress, i + 1);
329 + display_progress(progress, i + 1);
330 }
332 - if (!quiet)
333 - stop_progress(&progress);
331 + stop_progress(&progress);
332
333 if (delta_list)
334 die("unresolved deltas left after unpacking");
index-pack.c
+7 -13
@@ -418,12 +418,10 @@ static void parse_pack_objects(unsigned char *sha1)
418 } else
419 sha1_object(data, obj->size, obj->type, obj->idx.sha1);
420 free(data);
421 - if (verbose)
422 - display_progress(progress, i+1);
421 + display_progress(progress, i+1);
422 }
423 objects[i].idx.offset = consumed_bytes;
425 - if (verbose)
426 - stop_progress(&progress);
424 + stop_progress(&progress);
425
426 /* Check pack integrity */
427 flush();
@@ -486,8 +484,7 @@ static void parse_pack_objects(unsigned char *sha1)
484 obj->size, obj->type);
485 }
486 free(data);
489 - if (verbose)
490 - display_progress(progress, nr_resolved_deltas);
487 + display_progress(progress, nr_resolved_deltas);
488 }
489 }
490
@@ -594,8 +591,7 @@ static void fix_unresolved_deltas(int nr_unresolved)
591 die("local object %s is corrupt", sha1_to_hex(d->base.sha1));
592 append_obj_to_pack(d->base.sha1, data, size, type);
593 free(data);
597 - if (verbose)
598 - display_progress(progress, nr_resolved_deltas);
594 + display_progress(progress, nr_resolved_deltas);
595 }
596 free(sorted_by_pos);
597 }
@@ -774,8 +770,7 @@ int main(int argc, char **argv)
770 deltas = xmalloc(nr_objects * sizeof(struct delta_entry));
771 parse_pack_objects(sha1);
772 if (nr_deltas == nr_resolved_deltas) {
777 - if (verbose)
778 - stop_progress(&progress);
773 + stop_progress(&progress);
774 /* Flush remaining pack final 20-byte SHA1. */
775 flush();
776 } else {
@@ -788,11 +783,10 @@ int main(int argc, char **argv)
783 (nr_objects + nr_unresolved + 1)
784 * sizeof(*objects));
785 fix_unresolved_deltas(nr_unresolved);
791 - if (verbose) {
792 - stop_progress(&progress);
786 + stop_progress(&progress);
787 + if (verbose)
788 fprintf(stderr, "%d objects were added to complete this thin pack.\n",
789 nr_objects - nr_objects_initial);
795 - }
790 fixup_pack_header_footer(output_fd, sha1,
791 curr_pack, nr_objects);
792 }
unpack-trees.c
+3 -5
@@ -316,9 +316,8 @@ static void check_updates(struct cache_entry **src, int nr,
316 while (nr--) {
317 struct cache_entry *ce = *src++;
318
319 - if (total)
320 - if (!ce->ce_mode || ce->ce_flags & mask)
321 - display_progress(progress, ++cnt);
319 + if (!ce->ce_mode || ce->ce_flags & mask)
320 + display_progress(progress, ++cnt);
321 if (!ce->ce_mode) {
322 if (o->update)
323 unlink_entry(ce->name, last_symlink);
@@ -332,8 +331,7 @@ static void check_updates(struct cache_entry **src, int nr,
331 }
332 }
333 }
335 - if (total)
336 - stop_progress(&progress);
334 + stop_progress(&progress);
335 }
336
337 int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)