Skip to content

Commit 7ae4d9a

Browse files
committed
Simplify code
1 parent fd73bfa commit 7ae4d9a

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

src/files.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,11 @@ SEXP R_git_restore(SEXP ptr, SEXP files, SEXP ref){
216216
git_repository *repo = get_git_repository(ptr);
217217
git_object *obj = resolve_refish(ref, repo);
218218
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
219-
int len = Rf_length(files);
220-
const char **strings = NULL;
221-
int err;
222219
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
223-
if(len > 0){
224-
strings = malloc(len * sizeof(char *));
225-
for(int i = 0; i < len; i++){
226-
strings[i] = CHAR(STRING_ELT(files, i));
227-
}
228-
opts.paths.strings = (char **) strings;
229-
opts.paths.count = len;
230-
}
231-
err = git_checkout_tree(repo, obj, &opts);
232-
free(strings);
220+
git_strarray *paths = files_to_array(files);
221+
opts.paths = *paths;
222+
int err = git_checkout_tree(repo, obj, &opts);
223+
git_strarray_free(paths);
233224
git_object_free(obj);
234225
bail_if(err, "git_checkout_tree");
235226
return R_NilValue;

0 commit comments

Comments
 (0)