Skip to content

Commit 28632ef

Browse files
committed
Add max parameter to git_stat_files()
1 parent ea8e4ad commit 28632ef

6 files changed

Lines changed: 13 additions & 8 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: gert
33
Title: Simple Git Client for R
4-
Version: 2.3.0
4+
Version: 2.3.1
55
Authors@R: c(
66
person("Jeroen", "Ooms", role = c("aut", "cre"), email = "jeroenooms@gmail.com",
77
comment = c(ORCID = "0000-0002-4035-0289")),

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2.3.1
2+
- git_stat_files() gains a 'max' parameter
3+
- Fix function declaration error
14
2.3.0
25
- Add git_worktree() family of functions (#252)
36
- Reformat code with air

R/commit.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ git_log <- function(ref = "HEAD", max = 100, after = NULL, repo = ".") {
216216
#' @export
217217
#' @rdname git_commit
218218
#' @useDynLib gert R_git_stat_files
219-
git_stat_files <- function(files, ref = "HEAD", repo = '.') {
219+
git_stat_files <- function(files, ref = "HEAD", max = NULL, repo = '.') {
220220
repo <- git_open(repo)
221221
files <- as.character(files)
222-
.Call(R_git_stat_files, repo, files, ref)
222+
max <- as.integer(max)
223+
.Call(R_git_stat_files, repo, files, ref, max)
223224
}
224225

225226
assert_string <- function(x) {

man/git_commit.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ SEXP R_git_commit_stats(SEXP ptr, SEXP ref){
310310
return R_NilValue;
311311
}
312312

313-
SEXP R_git_stat_files(SEXP ptr, SEXP files, SEXP ref){
313+
SEXP R_git_stat_files(SEXP ptr, SEXP files, SEXP ref, SEXP max){
314314
git_commit *parent = NULL;
315315
git_repository *repo = get_git_repository(ptr);
316316
git_commit *commit = ref_to_commit(ref, repo);
@@ -327,7 +327,8 @@ SEXP R_git_stat_files(SEXP ptr, SEXP files, SEXP ref){
327327
INTEGER(changes)[fi] = 0L;
328328
SET_STRING_ELT(hashes, fi, NA_STRING);
329329
}
330-
while(1) {
330+
int max_iter = Rf_length(max) ? Rf_asInteger(max) : 2147483647;
331+
for(int iter = 0; iter < max_iter; iter++) {
331332
git_diff *diff = commit_to_diff(repo, commit);
332333
if(diff == NULL)
333334
Rf_error("Failed to get parent commit. Is this a shallow clone?");

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern SEXP R_git_stash_drop(SEXP, SEXP);
7070
extern SEXP R_git_stash_list(SEXP);
7171
extern SEXP R_git_stash_pop(SEXP, SEXP);
7272
extern SEXP R_git_stash_save(SEXP, SEXP, SEXP, SEXP, SEXP);
73-
extern SEXP R_git_stat_files(SEXP, SEXP, SEXP);
73+
extern SEXP R_git_stat_files(SEXP, SEXP, SEXP, SEXP);
7474
extern SEXP R_git_status_list(SEXP, SEXP, SEXP);
7575
extern SEXP R_git_submodule_info(SEXP, SEXP);
7676
extern SEXP R_git_submodule_init(SEXP, SEXP, SEXP);
@@ -154,7 +154,7 @@ static const R_CallMethodDef CallEntries[] = {
154154
{"R_git_stash_list", (DL_FUNC) &R_git_stash_list, 1},
155155
{"R_git_stash_pop", (DL_FUNC) &R_git_stash_pop, 2},
156156
{"R_git_stash_save", (DL_FUNC) &R_git_stash_save, 5},
157-
{"R_git_stat_files", (DL_FUNC) &R_git_stat_files, 3},
157+
{"R_git_stat_files", (DL_FUNC) &R_git_stat_files, 4},
158158
{"R_git_status_list", (DL_FUNC) &R_git_status_list, 3},
159159
{"R_git_submodule_info", (DL_FUNC) &R_git_submodule_info, 2},
160160
{"R_git_submodule_init", (DL_FUNC) &R_git_submodule_init, 3},

0 commit comments

Comments
 (0)