Skip to content

Commit 4d4fcc5

Browse files
Nicolas Pitregitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc6a075 commit 4d4fcc5

File tree

5 files changed

+20
-38
lines changed

5 files changed

+20
-38
lines changed

builtin-pack-objects.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ static void write_pack_file(void)
629629
if (!offset_one)
630630
break;
631631
offset = offset_one;
632-
if (do_progress)
633-
display_progress(progress_state, written);
632+
display_progress(progress_state, written);
634633
}
635634

636635
/*
@@ -684,8 +683,7 @@ static void write_pack_file(void)
684683
} while (nr_remaining && i < nr_objects);
685684

686685
free(written_list);
687-
if (do_progress)
688-
stop_progress(&progress_state);
686+
stop_progress(&progress_state);
689687
if (written != nr_result)
690688
die("wrote %u objects while expecting %u", written, nr_result);
691689
/*
@@ -853,8 +851,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
853851
else
854852
object_ix[-1 - ix] = nr_objects;
855853

856-
if (progress)
857-
display_progress(progress_state, nr_objects);
854+
display_progress(progress_state, nr_objects);
858855

859856
if (name && no_try_delta(name))
860857
entry->no_try_delta = 1;
@@ -1517,8 +1514,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
15171514

15181515
progress_lock();
15191516
(*processed)++;
1520-
if (progress)
1521-
display_progress(progress_state, *processed);
1517+
display_progress(progress_state, *processed);
15221518
progress_unlock();
15231519

15241520
/*
@@ -1722,8 +1718,7 @@ static void prepare_pack(int window, int depth)
17221718
nr_deltas);
17231719
qsort(delta_list, n, sizeof(*delta_list), type_size_sort);
17241720
ll_find_deltas(delta_list, n, window+1, depth, &nr_done);
1725-
if (progress)
1726-
stop_progress(&progress_state);
1721+
stop_progress(&progress_state);
17271722
if (nr_done != nr_deltas)
17281723
die("inconsistency with delta count");
17291724
}
@@ -2142,8 +2137,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
21422137
rp_av[rp_ac] = NULL;
21432138
get_object_list(rp_ac, rp_av);
21442139
}
2145-
if (progress)
2146-
stop_progress(&progress_state);
2140+
stop_progress(&progress_state);
21472141

21482142
if (non_empty && !nr_result)
21492143
return 0;

builtin-prune-packed.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
1515
struct dirent *de;
1616
char hex[40];
1717

18-
if (opts == VERBOSE)
19-
display_progress(progress, i + 1);
18+
display_progress(progress, i + 1);
2019

2120
sprintf(hex, "%02x", i);
2221
while ((de = readdir(dir)) != NULL) {
@@ -64,8 +63,7 @@ void prune_packed_objects(int opts)
6463
prune_dir(i, d, pathname, len + 3, opts);
6564
closedir(d);
6665
}
67-
if (opts == VERBOSE)
68-
stop_progress(&progress);
66+
stop_progress(&progress);
6967
}
7068

7169
int cmd_prune_packed(int argc, const char **argv, const char *prefix)

builtin-unpack-objects.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,9 @@ static void unpack_all(void)
326326
obj_list = xmalloc(nr_objects * sizeof(*obj_list));
327327
for (i = 0; i < nr_objects; i++) {
328328
unpack_one(i);
329-
if (!quiet)
330-
display_progress(progress, i + 1);
329+
display_progress(progress, i + 1);
331330
}
332-
if (!quiet)
333-
stop_progress(&progress);
331+
stop_progress(&progress);
334332

335333
if (delta_list)
336334
die("unresolved deltas left after unpacking");

index-pack.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,10 @@ static void parse_pack_objects(unsigned char *sha1)
418418
} else
419419
sha1_object(data, obj->size, obj->type, obj->idx.sha1);
420420
free(data);
421-
if (verbose)
422-
display_progress(progress, i+1);
421+
display_progress(progress, i+1);
423422
}
424423
objects[i].idx.offset = consumed_bytes;
425-
if (verbose)
426-
stop_progress(&progress);
424+
stop_progress(&progress);
427425

428426
/* Check pack integrity */
429427
flush();
@@ -486,8 +484,7 @@ static void parse_pack_objects(unsigned char *sha1)
486484
obj->size, obj->type);
487485
}
488486
free(data);
489-
if (verbose)
490-
display_progress(progress, nr_resolved_deltas);
487+
display_progress(progress, nr_resolved_deltas);
491488
}
492489
}
493490

@@ -594,8 +591,7 @@ static void fix_unresolved_deltas(int nr_unresolved)
594591
die("local object %s is corrupt", sha1_to_hex(d->base.sha1));
595592
append_obj_to_pack(d->base.sha1, data, size, type);
596593
free(data);
597-
if (verbose)
598-
display_progress(progress, nr_resolved_deltas);
594+
display_progress(progress, nr_resolved_deltas);
599595
}
600596
free(sorted_by_pos);
601597
}
@@ -774,8 +770,7 @@ int main(int argc, char **argv)
774770
deltas = xmalloc(nr_objects * sizeof(struct delta_entry));
775771
parse_pack_objects(sha1);
776772
if (nr_deltas == nr_resolved_deltas) {
777-
if (verbose)
778-
stop_progress(&progress);
773+
stop_progress(&progress);
779774
/* Flush remaining pack final 20-byte SHA1. */
780775
flush();
781776
} else {
@@ -788,11 +783,10 @@ int main(int argc, char **argv)
788783
(nr_objects + nr_unresolved + 1)
789784
* sizeof(*objects));
790785
fix_unresolved_deltas(nr_unresolved);
791-
if (verbose) {
792-
stop_progress(&progress);
786+
stop_progress(&progress);
787+
if (verbose)
793788
fprintf(stderr, "%d objects were added to complete this thin pack.\n",
794789
nr_objects - nr_objects_initial);
795-
}
796790
fixup_pack_header_footer(output_fd, sha1,
797791
curr_pack, nr_objects);
798792
}

unpack-trees.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,8 @@ static void check_updates(struct cache_entry **src, int nr,
316316
while (nr--) {
317317
struct cache_entry *ce = *src++;
318318

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);
322321
if (!ce->ce_mode) {
323322
if (o->update)
324323
unlink_entry(ce->name, last_symlink);
@@ -332,8 +331,7 @@ static void check_updates(struct cache_entry **src, int nr,
332331
}
333332
}
334333
}
335-
if (total)
336-
stop_progress(&progress);
334+
stop_progress(&progress);
337335
}
338336

339337
int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)

0 commit comments

Comments
 (0)