mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-21 22:21:37 +00:00
Improve error propogation in checkout
This commit is contained in:
parent
21e0d297af
commit
fade21db0a
@ -30,6 +30,7 @@ struct checkout_diff_data
|
|||||||
git_indexer_stats *stats;
|
git_indexer_stats *stats;
|
||||||
git_repository *owner;
|
git_repository *owner;
|
||||||
bool can_symlink;
|
bool can_symlink;
|
||||||
|
int error;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int buffer_to_file(
|
static int buffer_to_file(
|
||||||
@ -84,7 +85,7 @@ static int blob_content_to_file(
|
|||||||
return nb_filters;
|
return nb_filters;
|
||||||
|
|
||||||
if (nb_filters > 0) {
|
if (nb_filters > 0) {
|
||||||
if (git_blob__getbuf(&unfiltered, blob) < 0)
|
if ((error = git_blob__getbuf(&unfiltered, blob)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((error = git_filters_apply(&filtered, &unfiltered, &filters)) < 0)
|
if ((error = git_filters_apply(&filtered, &unfiltered, &filters)) < 0)
|
||||||
@ -111,8 +112,8 @@ static int blob_content_to_link(git_blob *blob, const char *path, bool can_symli
|
|||||||
git_buf linktarget = GIT_BUF_INIT;
|
git_buf linktarget = GIT_BUF_INIT;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (git_blob__getbuf(&linktarget, blob) < 0)
|
if ((error = git_blob__getbuf(&linktarget, blob)) < 0)
|
||||||
return -1;
|
return error;
|
||||||
|
|
||||||
if (can_symlink)
|
if (can_symlink)
|
||||||
error = p_symlink(git_buf_cstr(&linktarget), path);
|
error = p_symlink(git_buf_cstr(&linktarget), path);
|
||||||
@ -135,8 +136,8 @@ static int checkout_blob(
|
|||||||
git_blob *blob;
|
git_blob *blob;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (git_blob_lookup(&blob, repo, blob_oid) < 0)
|
if ((error = git_blob_lookup(&blob, repo, blob_oid)) < 0)
|
||||||
return -1; /* Add an error message */
|
return error; /* Add an error message */
|
||||||
|
|
||||||
if (S_ISLNK(filemode))
|
if (S_ISLNK(filemode))
|
||||||
error = blob_content_to_link(blob, path, can_symlink);
|
error = blob_content_to_link(blob, path, can_symlink);
|
||||||
@ -153,12 +154,10 @@ static int checkout_diff_fn(
|
|||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
float progress)
|
float progress)
|
||||||
{
|
{
|
||||||
struct checkout_diff_data *data;
|
struct checkout_diff_data *data = cb_data;
|
||||||
int error = -1;
|
int error = 0;
|
||||||
git_checkout_opts *opts;
|
git_checkout_opts *opts;
|
||||||
|
|
||||||
data = (struct checkout_diff_data *)cb_data;
|
|
||||||
|
|
||||||
data->stats->processed = (unsigned int)(data->stats->total * progress);
|
data->stats->processed = (unsigned int)(data->stats->total * progress);
|
||||||
|
|
||||||
git_buf_truncate(data->path, data->workdir_len);
|
git_buf_truncate(data->path, data->workdir_len);
|
||||||
@ -188,20 +187,17 @@ static int checkout_diff_fn(
|
|||||||
delta->old_file.mode,
|
delta->old_file.mode,
|
||||||
opts->notify_payload))) {
|
opts->notify_payload))) {
|
||||||
giterr_clear();
|
giterr_clear();
|
||||||
return GIT_EUSER;
|
error = GIT_EUSER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (checkout_blob(
|
error = checkout_blob(
|
||||||
data->owner,
|
data->owner,
|
||||||
&delta->old_file.oid,
|
&delta->old_file.oid,
|
||||||
git_buf_cstr(data->path),
|
git_buf_cstr(data->path),
|
||||||
delta->old_file.mode,
|
delta->old_file.mode,
|
||||||
data->can_symlink,
|
data->can_symlink,
|
||||||
opts) < 0)
|
opts);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -209,25 +205,24 @@ static int checkout_diff_fn(
|
|||||||
if (!(opts->checkout_strategy & GIT_CHECKOUT_CREATE_MISSING))
|
if (!(opts->checkout_strategy & GIT_CHECKOUT_CREATE_MISSING))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (checkout_blob(
|
error = checkout_blob(
|
||||||
data->owner,
|
data->owner,
|
||||||
&delta->old_file.oid,
|
&delta->old_file.oid,
|
||||||
git_buf_cstr(data->path),
|
git_buf_cstr(data->path),
|
||||||
delta->old_file.mode,
|
delta->old_file.mode,
|
||||||
data->can_symlink,
|
data->can_symlink,
|
||||||
opts) < 0)
|
opts);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
giterr_set(GITERR_INVALID, "Unexpected status (%d) for path '%s'.", delta->status, delta->new_file.path);
|
giterr_set(GITERR_INVALID, "Unexpected status (%d) for path '%s'.",
|
||||||
goto cleanup;
|
delta->status, delta->new_file.path);
|
||||||
|
error = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = 0;
|
if (error)
|
||||||
|
data->error = error; /* preserve real error */
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +327,9 @@ int git_checkout_index(
|
|||||||
|
|
||||||
error = git_diff_foreach(diff, &data, checkout_diff_fn, NULL, NULL);
|
error = git_diff_foreach(diff, &data, checkout_diff_fn, NULL, NULL);
|
||||||
|
|
||||||
|
if (error == GIT_EUSER)
|
||||||
|
error = (data.error != 0) ? data.error : -1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
git_diff_list_free(diff);
|
git_diff_list_free(diff);
|
||||||
|
Loading…
Reference in New Issue
Block a user