diff --git a/t/02-commit.t b/t/02-commit.t index 9f637914..de2b86dd 100644 --- a/t/02-commit.t +++ b/t/02-commit.t @@ -233,6 +233,7 @@ is $head -> committer -> offset, $off; is $head -> time, $time; is $head -> offset, $off; +$head -> parents; # void context my $parent_count = $head -> parents; is $parent_count, 1; my @parents = $head -> parents; diff --git a/t/05-tree.t b/t/05-tree.t index b512d8d3..df69d84e 100644 --- a/t/05-tree.t +++ b/t/05-tree.t @@ -38,6 +38,7 @@ isa_ok $lookup_tree, 'Git::Raw::Tree'; $lookup_tree = Git::Raw::Tree -> lookup($repo, substr($tree -> id, 0, 7)); isa_ok $lookup_tree, 'Git::Raw::Tree'; +$tree -> entries; # void context my $entry_count = $tree -> entries; is $entry_count, 3; @entries = $tree -> entries; diff --git a/t/09-diff.t b/t/09-diff.t index 7689aa22..40b35f89 100644 --- a/t/09-diff.t +++ b/t/09-diff.t @@ -160,6 +160,9 @@ $output = capture_stdout { $diff -> print("patch_header", $printer) }; is $output, $expected; is $diff -> delta_count, 2; +$diff -> patches; # void context +my $patch_count = $diff -> patches; +is $patch_count, 2; my @patches = $diff -> patches; is scalar(@patches), 2; diff --git a/xs/Commit.xs b/xs/Commit.xs index edb2f66e..56748214 100644 --- a/xs/Commit.xs +++ b/xs/Commit.xs @@ -274,7 +274,6 @@ parents(self) mXPUSHs(tmp); } - mXPUSHs(newSViv((int) count)); XSRETURN((int) count); } else { mXPUSHs(newSViv((int) count)); diff --git a/xs/Diff.xs b/xs/Diff.xs index 8fe449bc..f56b05ca 100644 --- a/xs/Diff.xs +++ b/xs/Diff.xs @@ -116,35 +116,42 @@ patches(self) SV *self PREINIT: - int rc; + int ctx; - Diff diff_ptr; + PPCODE: + ctx = GIMME_V; - size_t i, count, num_patches = 0; + if (ctx != G_VOID) { + int rc; + size_t count; + Diff diff_ptr; + diff_ptr = GIT_SV_TO_PTR(Diff, self); - PPCODE: - diff_ptr = GIT_SV_TO_PTR(Diff, self); + count = git_diff_num_deltas(diff_ptr); + if (ctx == G_ARRAY) { + size_t i; - count = git_diff_num_deltas(diff_ptr); - for (i = 0; i < count; ++i) { - Patch patch; + for (i = 0; i < count; ++i) { + SV *tmp; + Patch patch; - rc = git_patch_from_diff(&patch, diff_ptr, i); - git_check_error(rc); + rc = git_patch_from_diff(&patch, diff_ptr, i); + git_check_error(rc); - if (patch) { - SV *p; + GIT_NEW_OBJ_WITH_MAGIC( + tmp, "Git::Raw::Patch", patch, SvRV(self) + ); - GIT_NEW_OBJ_WITH_MAGIC( - p, "Git::Raw::Patch", patch, SvRV(self) - ); + mXPUSHs(tmp); + } - mXPUSHs(p); - ++num_patches; + XSRETURN((int) count); + } else { + mXPUSHs(newSViv((int) count)); + XSRETURN(1); } - } - - XSRETURN(num_patches); + } else + XSRETURN_EMPTY; void DESTROY(self) diff --git a/xs/Tree.xs b/xs/Tree.xs index 1bfce1db..3d251355 100644 --- a/xs/Tree.xs +++ b/xs/Tree.xs @@ -105,7 +105,6 @@ entries(self) mXPUSHs(tmp); } - mXPUSHs(newSViv((int) count)); XSRETURN((int) count); } else { mXPUSHs(newSViv((int) count));