Commit 45b60d7b by Ben Straub

Correct progress reporting from checkout

parent 30a46ab1
...@@ -15,17 +15,17 @@ typedef struct progress_data { ...@@ -15,17 +15,17 @@ 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) / pd->fetch_progress.total;
int index_percent = (100*pd->fetch_progress.processed) / pd->fetch_progress.total; int index_percent = (100*pd->fetch_progress.processed) / pd->fetch_progress.total;
int checkout_percent = (int)(100.f * pd->checkout_progress); int checkout_percent = (int)(100.f * pd->checkout_progress);
printf("net %3d%% / idx %3d%% / chk %3d%% %20s\r", printf("net %3d%% / idx %3d%% / chk %3d%% %50s\r",
network_percent, index_percent, checkout_percent, pd->path); network_percent, index_percent, checkout_percent, pd->path);
*/ /*
printf("net %5d /%5d – idx %5d /%5d – chk %.04f %20s\r", printf("net %5d /%5d – idx %5d /%5d – chk %.04f %20s\r",
pd->fetch_progress.received, pd->fetch_progress.total, pd->fetch_progress.received, pd->fetch_progress.total,
pd->fetch_progress.processed, pd->fetch_progress.total, pd->fetch_progress.processed, pd->fetch_progress.total,
pd->checkout_progress, pd->path); pd->checkout_progress, pd->path);
*/
} }
static void fetch_progress(const git_indexer_stats *stats, void *payload) static void fetch_progress(const git_indexer_stats *stats, void *payload)
......
...@@ -31,6 +31,7 @@ struct checkout_diff_data ...@@ -31,6 +31,7 @@ struct checkout_diff_data
bool can_symlink; bool can_symlink;
bool found_submodules; bool found_submodules;
bool create_submodules; bool create_submodules;
int num_stages;
int error; int error;
}; };
...@@ -157,6 +158,23 @@ static int checkout_submodule( ...@@ -157,6 +158,23 @@ static int checkout_submodule(
return 0; return 0;
} }
static void report_progress(
int stage,
float stage_progress,
struct checkout_diff_data *data,
const char *path)
{
float per_stage_progress = 1.f/data->num_stages;
float overall_progress = (stage-1)*per_stage_progress +
stage_progress*per_stage_progress;
if (data->checkout_opts->progress_cb)
data->checkout_opts->progress_cb(
path,
overall_progress,
data->checkout_opts->progress_payload);
}
static int checkout_blob( static int checkout_blob(
struct checkout_diff_data *data, struct checkout_diff_data *data,
const git_diff_file *file) const git_diff_file *file)
...@@ -202,11 +220,7 @@ static int checkout_remove_the_old( ...@@ -202,11 +220,7 @@ static int checkout_remove_the_old(
GIT_DIRREMOVAL_FILES_AND_DIRS); GIT_DIRREMOVAL_FILES_AND_DIRS);
} }
if (data->checkout_opts->progress_cb) report_progress(1, progress, data, delta->new_file.path);
data->checkout_opts->progress_cb(
delta->new_file.path,
progress,
data->checkout_opts->progress_payload);
return data->error; return data->error;
} }
...@@ -246,14 +260,22 @@ static int checkout_create_the_new( ...@@ -246,14 +260,22 @@ static int checkout_create_the_new(
if (do_checkout) { if (do_checkout) {
bool is_submodule = S_ISGITLINK(delta->old_file.mode); bool is_submodule = S_ISGITLINK(delta->old_file.mode);
if (is_submodule) if (is_submodule) {
data->found_submodules = true; data->found_submodules = true;
data->num_stages = 3;
}
if (!is_submodule && !data->create_submodules) if (!is_submodule && !data->create_submodules) {
error = checkout_blob(data, &delta->old_file); error = checkout_blob(data, &delta->old_file);
report_progress(2, progress, data, delta->old_file.path);
}
else if (is_submodule && data->create_submodules) else if (is_submodule && data->create_submodules) {
error = checkout_submodule(data, &delta->old_file); error = checkout_submodule(data, &delta->old_file);
report_progress(3, progress, data, delta->old_file.path);
}
} }
if (error) if (error)
...@@ -346,6 +368,7 @@ int git_checkout_index( ...@@ -346,6 +368,7 @@ int git_checkout_index(
data.workdir_len = git_buf_len(&workdir); data.workdir_len = git_buf_len(&workdir);
data.checkout_opts = &checkout_opts; data.checkout_opts = &checkout_opts;
data.owner = repo; data.owner = repo;
data.num_stages = 2;
if ((error = retrieve_symlink_capabilities(repo, &data.can_symlink)) < 0) if ((error = retrieve_symlink_capabilities(repo, &data.can_symlink)) < 0)
goto cleanup; goto cleanup;
...@@ -360,6 +383,8 @@ int git_checkout_index( ...@@ -360,6 +383,8 @@ int git_checkout_index(
* checked out during pass #2. * checked out during pass #2.
*/ */
report_progress(1, 0.f, &data, NULL);
if (!(error = git_diff_foreach( if (!(error = git_diff_foreach(
diff, &data, checkout_remove_the_old, NULL, NULL)) && diff, &data, checkout_remove_the_old, NULL, NULL)) &&
!(error = git_diff_foreach( !(error = git_diff_foreach(
...@@ -371,6 +396,8 @@ int git_checkout_index( ...@@ -371,6 +396,8 @@ int git_checkout_index(
diff, &data, checkout_create_the_new, NULL, NULL); diff, &data, checkout_create_the_new, NULL, NULL);
} }
report_progress(data.num_stages, 1.f, &data, NULL);
cleanup: cleanup:
if (error == GIT_EUSER) if (error == GIT_EUSER)
error = (data.error != 0) ? data.error : -1; error = (data.error != 0) ? data.error : -1;
......
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