Commit 9762ad99 by Ben Straub

Renaming: fix example

parent 7d222e13
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <unistd.h> #include <unistd.h>
typedef struct progress_data { typedef struct progress_data {
git_indexer_stats fetch_progress; git_transfer_progress fetch_progress;
size_t completed_steps; size_t completed_steps;
size_t total_steps; size_t total_steps;
const char *path; const char *path;
...@@ -16,20 +16,21 @@ typedef struct progress_data { ...@@ -16,20 +16,21 @@ typedef struct progress_data {
static void print_progress(const progress_data *pd) static void print_progress(const progress_data *pd)
{ {
int network_percent = (100*pd->fetch_progress.received) / pd->fetch_progress.total; int network_percent = (100*pd->fetch_progress.received_objects) / pd->fetch_progress.total_objects;
int index_percent = (100*pd->fetch_progress.processed) / pd->fetch_progress.total; int index_percent = (100*pd->fetch_progress.indexed_objects) / pd->fetch_progress.total_objects;
int checkout_percent = pd->total_steps > 0 int checkout_percent = pd->total_steps > 0
? (100 * pd->completed_steps) / pd->total_steps ? (100 * pd->completed_steps) / pd->total_steps
: 0.f; : 0.f;
int kbytes = pd->fetch_progress.bytes / 1024; int kbytes = pd->fetch_progress.received_bytes / 1024;
printf("net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4lu/%4lu) %s\n", printf("net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4lu/%4lu) %s\n",
network_percent, kbytes, pd->fetch_progress.received, pd->fetch_progress.total, network_percent, kbytes,
index_percent, pd->fetch_progress.processed, pd->fetch_progress.total, pd->fetch_progress.received_objects, pd->fetch_progress.total_objects,
index_percent, pd->fetch_progress.indexed_objects, pd->fetch_progress.total_objects,
checkout_percent, pd->completed_steps, pd->total_steps, checkout_percent, pd->completed_steps, pd->total_steps,
pd->path); pd->path);
} }
static void fetch_progress(const git_indexer_stats *stats, void *payload) static void fetch_progress(const git_transfer_progress *stats, void *payload)
{ {
progress_data *pd = (progress_data*)payload; progress_data *pd = (progress_data*)payload;
pd->fetch_progress = *stats; pd->fetch_progress = *stats;
......
...@@ -105,16 +105,18 @@ int fetch(git_repository *repo, int argc, char **argv) ...@@ -105,16 +105,18 @@ int fetch(git_repository *repo, int argc, char **argv)
do { do {
usleep(10000); usleep(10000);
if (stats->total > 0) if (stats->total_objects > 0)
printf("Received %d/%d objects (%d) in %d bytes\r", printf("Received %d/%d objects (%d) in %d bytes\r",
stats->received, stats->total, stats->processed, bytes); stats->received_objects, stats->total_objects,
stats->indexed_objects, bytes);
} while (!data.finished); } while (!data.finished);
if (data.ret < 0) if (data.ret < 0)
goto on_error; goto on_error;
pthread_join(worker, NULL); pthread_join(worker, NULL);
printf("\rReceived %d/%d objects in %zu bytes\n", stats->processed, stats->total, bytes); printf("\rReceived %d/%d objects in %zu bytes\n",
stats->indexed_objects, stats->total_objects, bytes);
// Disconnect the underlying connection to prevent from idling. // Disconnect the underlying connection to prevent from idling.
git_remote_disconnect(remote); git_remote_disconnect(remote);
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
// This could be run in the main loop whilst the application waits for // This could be run in the main loop whilst the application waits for
// the indexing to finish in a worker thread // the indexing to finish in a worker thread
static int index_cb(const git_indexer_stats *stats, void *data) static int index_cb(const git_transfer_progress *stats, void *data)
{ {
data = data; data = data;
printf("\rProcessing %d of %d", stats->processed, stats->total); printf("\rProcessing %d of %d", stats->indexed_objects, stats->total_objects);
return 0; return 0;
} }
...@@ -21,7 +21,7 @@ static int index_cb(const git_indexer_stats *stats, void *data) ...@@ -21,7 +21,7 @@ static int index_cb(const git_indexer_stats *stats, void *data)
int index_pack(git_repository *repo, int argc, char **argv) int index_pack(git_repository *repo, int argc, char **argv)
{ {
git_indexer_stream *idx; git_indexer_stream *idx;
git_indexer_stats stats = {0, 0}; git_transfer_progress stats = {0, 0};
int error, fd; int error, fd;
char hash[GIT_OID_HEXSZ + 1] = {0}; char hash[GIT_OID_HEXSZ + 1] = {0};
ssize_t read_bytes; ssize_t read_bytes;
...@@ -63,7 +63,7 @@ int index_pack(git_repository *repo, int argc, char **argv) ...@@ -63,7 +63,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
if ((error = git_indexer_stream_finalize(idx, &stats)) < 0) if ((error = git_indexer_stream_finalize(idx, &stats)) < 0)
goto cleanup; goto cleanup;
printf("\rIndexing %d of %d\n", stats.processed, stats.total); printf("\rIndexing %d of %d\n", stats.indexed_objects, stats.total_objects);
git_oid_fmt(hash, git_indexer_stream_hash(idx)); git_oid_fmt(hash, git_indexer_stream_hash(idx));
puts(hash); puts(hash);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment