summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0e54913)
raw | patch | inline | side by side (parent: 0e54913)
author | Nicolas Pitre <nico@cam.org> | |
Tue, 30 Oct 2007 18:57:32 +0000 (14:57 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 30 Oct 2007 23:08:40 +0000 (16:08 -0700) |
This allows for better management of progress "object" existence,
as well as making the progress display implementation more independent
from its callers.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
as well as making the progress display implementation more independent
from its callers.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 21ba977df39fa38c5e33537aca29df2d76a232ba..3ca5cc780088a7076f46cff7f968cf45764de1ec 100644 (file)
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
static int delta_search_threads = 1;
static int pack_to_stdout;
static int num_preferred_base;
-static struct progress progress_state;
+static struct progress *progress_state;
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
static int pack_compression_seen;
uint32_t nr_remaining = nr_result;
if (do_progress)
- start_progress(&progress_state, "Writing objects", nr_result);
+ progress_state = start_progress("Writing objects", nr_result);
written_list = xmalloc(nr_objects * sizeof(struct object_entry *));
do {
break;
offset = offset_one;
if (do_progress)
- display_progress(&progress_state, written);
+ display_progress(progress_state, written);
}
/*
object_ix[-1 - ix] = nr_objects;
if (progress)
- display_progress(&progress_state, nr_objects);
+ display_progress(progress_state, nr_objects);
if (name && no_try_delta(name))
entry->no_try_delta = 1;
progress_lock();
(*processed)++;
if (progress)
- display_progress(&progress_state, *processed);
+ display_progress(progress_state, *processed);
progress_unlock();
/*
if (nr_deltas && n > 1) {
unsigned nr_done = 0;
if (progress)
- start_progress(&progress_state, "Compressing objects",
- nr_deltas);
+ 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);
if (progress)
prepare_packed_git();
if (progress)
- start_progress(&progress_state, "Counting objects", 0);
+ progress_state = start_progress("Counting objects", 0);
if (!use_internal_rev_list)
read_object_list_from_stdin();
else {
diff --git a/builtin-prune-packed.c b/builtin-prune-packed.c
index 907e36828f61ee925adfe5eff111abb2fe3f0681..c66fb037f6ef10e370b1a405e8e27dbb0e753a17 100644 (file)
--- a/builtin-prune-packed.c
+++ b/builtin-prune-packed.c
#define DRY_RUN 01
#define VERBOSE 02
-static struct progress progress;
+static struct progress *progress;
static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
{
char hex[40];
if (opts == VERBOSE)
- display_progress(&progress, i + 1);
+ display_progress(progress, i + 1);
sprintf(hex, "%02x", i);
while ((de = readdir(dir)) != NULL) {
int len = strlen(dir);
if (opts == VERBOSE)
- start_progress_delay(&progress,
- "Removing duplicate objects",
+ progress = start_progress_delay("Removing duplicate objects",
256, 95, 2);
if (len > PATH_MAX - 42)
index 2317b8f411bcf9c331552bb59456802d7eb4d2bc..e0ecbc51a77b207fda0cdee50a4385fbcb550720 100644 (file)
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
static void unpack_all(void)
{
int i;
- struct progress progress;
+ struct progress *progress = NULL;
struct pack_header *hdr = fill(sizeof(struct pack_header));
unsigned nr_objects = ntohl(hdr->hdr_entries);
use(sizeof(struct pack_header));
if (!quiet)
- start_progress(&progress, "Unpacking objects", nr_objects);
+ progress = start_progress("Unpacking objects", nr_objects);
obj_list = xmalloc(nr_objects * sizeof(*obj_list));
for (i = 0; i < nr_objects; i++) {
unpack_one(i);
if (!quiet)
- display_progress(&progress, i + 1);
+ display_progress(progress, i + 1);
}
if (!quiet)
stop_progress(&progress);
diff --git a/index-pack.c b/index-pack.c
index 2f149a40fdc40a84d33420fc363fbf7edafe1712..b4543a4cc20ffabde3de8dc77f25af31255a94dd 100644 (file)
--- a/index-pack.c
+++ b/index-pack.c
static int from_stdin;
static int verbose;
-static struct progress progress;
+static struct progress *progress;
/* We always read in 4kB chunks. */
static unsigned char input_buffer[4096];
* - remember base (SHA1 or offset) for all deltas.
*/
if (verbose)
- start_progress(&progress, "Indexing objects", nr_objects);
+ progress = start_progress("Indexing objects", nr_objects);
for (i = 0; i < nr_objects; i++) {
struct object_entry *obj = &objects[i];
data = unpack_raw_entry(obj, &delta->base);
sha1_object(data, obj->size, obj->type, obj->idx.sha1);
free(data);
if (verbose)
- display_progress(&progress, i+1);
+ display_progress(progress, i+1);
}
objects[i].idx.offset = consumed_bytes;
if (verbose)
* for some more deltas.
*/
if (verbose)
- start_progress(&progress, "Resolving deltas", nr_deltas);
+ progress = start_progress("Resolving deltas", nr_deltas);
for (i = 0; i < nr_objects; i++) {
struct object_entry *obj = &objects[i];
union delta_base base;
}
free(data);
if (verbose)
- display_progress(&progress, nr_resolved_deltas);
+ display_progress(progress, nr_resolved_deltas);
}
}
append_obj_to_pack(d->base.sha1, data, size, type);
free(data);
if (verbose)
- display_progress(&progress, nr_resolved_deltas);
+ display_progress(progress, nr_resolved_deltas);
}
free(sorted_by_pos);
}
diff --git a/progress.c b/progress.c
index 7629e0572bceb80086a5b2f503234340bc74361b..c342e39c5d2e5673fc95e0cdc91856b0bc3cdd35 100644 (file)
--- a/progress.c
+++ b/progress.c
#include "git-compat-util.h"
#include "progress.h"
+struct progress {
+ const char *title;
+ int last_value;
+ unsigned total;
+ unsigned last_percent;
+ unsigned delay;
+ unsigned delayed_percent_treshold;
+};
+
static volatile sig_atomic_t progress_update;
static void progress_interval(int signum)
int display_progress(struct progress *progress, unsigned n)
{
- return display(progress, n, 0);
+ return progress ? display(progress, n, 0) : 0;
}
-void start_progress_delay(struct progress *progress, const char *title,
- unsigned total, unsigned percent_treshold, unsigned delay)
+struct progress *start_progress_delay(const char *title, unsigned total,
+ unsigned percent_treshold, unsigned delay)
{
+ struct progress *progress = malloc(sizeof(*progress));
+ if (!progress) {
+ /* unlikely, but here's a good fallback */
+ fprintf(stderr, "%s...\n", title);
+ return NULL;
+ }
progress->title = title;
progress->total = total;
progress->last_value = -1;
progress->delayed_percent_treshold = percent_treshold;
progress->delay = delay;
set_progress_signal();
+ return progress;
}
-void start_progress(struct progress *progress, const char *title, unsigned total)
+struct progress *start_progress(const char *title, unsigned total)
{
- start_progress_delay(progress, title, total, 0, 0);
+ return start_progress_delay(title, total, 0, 0);
}
-void stop_progress(struct progress *progress)
+void stop_progress(struct progress **p_progress)
{
+ struct progress *progress = *p_progress;
+ if (!progress)
+ return;
+ *p_progress = NULL;
if (progress->last_value != -1) {
/* Force the last update */
progress_update = 1;
display(progress, progress->last_value, 1);
}
clear_progress_signal();
+ free(progress);
}
diff --git a/progress.h b/progress.h
index 07b56bdbb5abc70fbd9d4080ccb219716a5297f1..4c6d53524b5ebc6bec4fd4c569776802816dfdbc 100644 (file)
--- a/progress.h
+++ b/progress.h
#ifndef PROGRESS_H
#define PROGRESS_H
-struct progress {
- const char *title;
- int last_value;
- unsigned total;
- unsigned last_percent;
- unsigned delay;
- unsigned delayed_percent_treshold;
-};
+struct progress;
int display_progress(struct progress *progress, unsigned n);
-void start_progress(struct progress *progress, const char *title,
- unsigned total);
-void start_progress_delay(struct progress *progress, const char *title,
- unsigned total, unsigned percent_treshold, unsigned delay);
-void stop_progress(struct progress *progress);
+struct progress *start_progress(const char *title, unsigned total);
+struct progress *start_progress_delay(const char *title, unsigned total,
+ unsigned percent_treshold, unsigned delay);
+void stop_progress(struct progress **progress);
#endif
diff --git a/unpack-trees.c b/unpack-trees.c
index 32251018b20da26b2587b656ff012b5e59e74b2b..6776c29cde3e4f5125d38827e9aa2148dd987dc8 100644 (file)
--- a/unpack-trees.c
+++ b/unpack-trees.c
{
unsigned short mask = htons(CE_UPDATE);
unsigned cnt = 0, total = 0;
- struct progress progress;
+ struct progress *progress = NULL;
char last_symlink[PATH_MAX];
if (o->update && o->verbose_update) {
total++;
}
- start_progress_delay(&progress, "Checking out files",
- total, 50, 2);
+ progress = start_progress_delay("Checking out files",
+ total, 50, 2);
cnt = 0;
}
if (total)
if (!ce->ce_mode || ce->ce_flags & mask)
- display_progress(&progress, ++cnt);
+ display_progress(progress, ++cnt);
if (!ce->ce_mode) {
if (o->update)
unlink_entry(ce->name, last_symlink);
}
}
if (total)
- stop_progress(&progress);;
+ stop_progress(&progress);
}
int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)