Improve error propogation in checkout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
diff --git a/src/checkout.c b/src/checkout.c
index e429d28..55130aa 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -30,6 +30,7 @@ struct checkout_diff_data
git_indexer_stats *stats;
git_repository *owner;
bool can_symlink;
+ int error;
};
static int buffer_to_file(
@@ -84,7 +85,7 @@ static int blob_content_to_file(
return nb_filters;
if (nb_filters > 0) {
- if (git_blob__getbuf(&unfiltered, blob) < 0)
+ if ((error = git_blob__getbuf(&unfiltered, blob)) < 0)
goto cleanup;
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;
int error;
- if (git_blob__getbuf(&linktarget, blob) < 0)
- return -1;
+ if ((error = git_blob__getbuf(&linktarget, blob)) < 0)
+ return error;
if (can_symlink)
error = p_symlink(git_buf_cstr(&linktarget), path);
@@ -135,8 +136,8 @@ static int checkout_blob(
git_blob *blob;
int error;
- if (git_blob_lookup(&blob, repo, blob_oid) < 0)
- return -1; /* Add an error message */
+ if ((error = git_blob_lookup(&blob, repo, blob_oid)) < 0)
+ return error; /* Add an error message */
if (S_ISLNK(filemode))
error = blob_content_to_link(blob, path, can_symlink);
@@ -153,12 +154,10 @@ static int checkout_diff_fn(
const git_diff_delta *delta,
float progress)
{
- struct checkout_diff_data *data;
- int error = -1;
+ struct checkout_diff_data *data = cb_data;
+ int error = 0;
git_checkout_opts *opts;
- data = (struct checkout_diff_data *)cb_data;
-
data->stats->processed = (unsigned int)(data->stats->total * progress);
git_buf_truncate(data->path, data->workdir_len);
@@ -188,20 +187,17 @@ static int checkout_diff_fn(
delta->old_file.mode,
opts->notify_payload))) {
giterr_clear();
- return GIT_EUSER;
+ error = GIT_EUSER;
}
-
- return 0;
}
-
- if (checkout_blob(
+ else
+ error = checkout_blob(
data->owner,
&delta->old_file.oid,
git_buf_cstr(data->path),
delta->old_file.mode,
data->can_symlink,
- opts) < 0)
- goto cleanup;
+ opts);
break;
@@ -209,25 +205,24 @@ static int checkout_diff_fn(
if (!(opts->checkout_strategy & GIT_CHECKOUT_CREATE_MISSING))
return 0;
- if (checkout_blob(
+ error = checkout_blob(
data->owner,
&delta->old_file.oid,
git_buf_cstr(data->path),
delta->old_file.mode,
data->can_symlink,
- opts) < 0)
- goto cleanup;
-
+ opts);
break;
default:
- giterr_set(GITERR_INVALID, "Unexpected status (%d) for path '%s'.", delta->status, delta->new_file.path);
- goto cleanup;
+ giterr_set(GITERR_INVALID, "Unexpected status (%d) for path '%s'.",
+ delta->status, delta->new_file.path);
+ error = -1;
}
- error = 0;
+ if (error)
+ data->error = error; /* preserve real error */
-cleanup:
return error;
}
@@ -332,6 +327,9 @@ int git_checkout_index(
error = git_diff_foreach(diff, &data, checkout_diff_fn, NULL, NULL);
+ if (error == GIT_EUSER)
+ error = (data.error != 0) ? data.error : -1;
+
cleanup:
git_index_free(index);
git_diff_list_free(diff);