Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Commit -> parents() and Tree -> entries() don't behave like the documentation states #122

Merged
merged 2 commits into from

2 participants

@jacquesg
Owner

Commit -> parents() and Tree -> entries() return array references instead of lists. Bring them in sync with the documentation, that is, return lists not references.

@coveralls

Coverage Status

Coverage increased (+0.02%) when pulling 06f7c11 on jacquesg/entry-list-not-ref into 8ea35bb on master.

@jacquesg jacquesg merged commit 06f7c11 into from
@jacquesg jacquesg deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 t/02-commit.t
@@ -233,9 +233,12 @@ is $head -> committer -> offset, $off;
is $head -> time, $time;
is $head -> offset, $off;
-my $parents = $head -> parents;
+my $parent_count = $head -> parents;
+is $parent_count, 1;
+my @parents = $head -> parents;
+is scalar(@parents), 1;
-is $parents -> [0] -> message, "initial commit\n";
+is $parents [0] -> message, "initial commit\n";
make_path($repo -> workdir . 'test3/under/the/tree');
$file = $repo -> workdir . 'test3/under/the/tree/test3';
View
2  t/04-walker.t
@@ -21,7 +21,7 @@ is $walk -> next, undef;
is $walk -> next, undef;
$walk -> push($repo -> head -> target);
-$walk -> hide($repo -> head -> target -> parents -> [0]);
+$walk -> hide(($repo -> head -> target -> parents())[0]);
is $walk -> next -> message, "third commit\n";
is $walk -> next, undef;
View
37 t/05-tree.t
@@ -11,9 +11,13 @@ my $repo = Git::Raw::Repository -> open($path);
my $head_id = $repo -> head -> target -> id;
my $head = $repo -> lookup($head_id);
-ok $head -> tree -> entries -> [0] -> object;
+my @entries = $head -> tree -> entries;
+
+ok $entries [0] -> object;
$head = $repo -> lookup(substr($head_id, 0, 7));
-ok $head -> tree -> entries -> [0] -> object;
+
+@entries = $head -> tree -> entries;
+ok $entries [0] -> object;
$head = $repo -> head -> target;
@@ -34,20 +38,23 @@ 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';
-my $entries = $tree -> entries;
+my $entry_count = $tree -> entries;
+is $entry_count, 3;
+@entries = $tree -> entries;
+is scalar(@entries), 3;
-is $entries -> [0] -> name, 'test';
-is $entries -> [1] -> name, 'test2';
-is $entries -> [2] -> name, 'test3';
+is $entries [0] -> name, 'test';
+is $entries [1] -> name, 'test2';
+is $entries [2] -> name, 'test3';
-is length($entries -> [0] -> id), 40;
-is length($entries -> [1] -> id), 40;
-is length($entries -> [2] -> id), 40;
+is length($entries [0] -> id), 40;
+is length($entries [1] -> id), 40;
+is length($entries [2] -> id), 40;
-is $entries -> [0] -> file_mode, 0100644;
-is $entries -> [2] -> file_mode, 0040000;
+is $entries [0] -> file_mode, 0100644;
+is $entries [2] -> file_mode, 0040000;
-my $obj0 = $entries -> [0] -> object;
+my $obj0 = $entries [0] -> object;
isa_ok $obj0, 'Git::Raw::Blob';
is $obj0 -> is_blob, 1;
@@ -65,17 +72,17 @@ is $blob_obj0 -> is_blob, 1;
is $obj0 -> content, $blob_obj0 -> content;
is $obj0 -> size, $blob_obj0 -> size;
-my $obj1 = $entries -> [1] -> object;
+my $obj1 = $entries [1] -> object;
isa_ok $obj1, 'Git::Raw::Blob';
is $obj1 -> content, 'this is a second test';
is $obj1 -> size, '21';
-my $obj2 = $entries -> [2] -> object;
+my $obj2 = $entries [2] -> object;
isa_ok $obj2, 'Git::Raw::Tree';
-is $entries -> [3], undef;
+is $entries [3], undef;
my $non_existent_entry = $tree -> entry_byname('unknownfile');
is $non_existent_entry, undef;
View
2  t/09-diff.t
@@ -231,7 +231,7 @@ is_deeply $patches[1] -> line_stats, {
};
my $tree2 = $repo -> head -> target -> tree;
-my $tree1 = $repo -> head -> target -> parents -> [0] -> tree;
+my $tree1 = ($repo -> head -> target -> parents())[0] -> tree;
$diff = $tree1 -> diff({
'tree' => $tree2,
View
2  t/13-checkout.t
@@ -9,7 +9,7 @@ use Cwd qw(abs_path);
my $path = abs_path('t/test_repo');
my $repo = Git::Raw::Repository -> open($path);
-my $fst = $repo -> head -> target -> parents -> [0];
+my $fst = ($repo -> head -> target -> parents())[0];
is $fst -> message, "second commit\n";
$repo -> checkout($fst, {
View
20 t/14-tree-builder.t
@@ -44,12 +44,12 @@ my $tree = $builder -> write();
isa_ok $tree, 'Git::Raw::Tree';
is $tree -> id(), '228c738569c82d9906ea1801f698a7c2a70e56b1';
-my $entries = $tree -> entries();
+my @entries = $tree -> entries();
-is_deeply [ sort map { $_ -> name() } @$entries ],
+is_deeply [ sort map { $_ -> name() } @entries ],
[ qw/one.txt three.txt two.txt/ ];
-is_deeply [ map { $_ -> object -> id() } @$entries ],
+is_deeply [ map { $_ -> object -> id() } @entries ],
[ map { $empty_blob -> id() } (1..3) ];
$builder -> clear();
@@ -65,12 +65,12 @@ $builder -> remove('two.txt');
is $builder -> entry_count, 2;
$tree = $builder -> write();
-$entries = $tree -> entries();
+@entries = $tree -> entries();
-is_deeply [ sort map { $_ -> name() } @$entries ],
+is_deeply [ sort map { $_ -> name() } @entries ],
[ qw/one.txt three.txt/ ];
-is_deeply [ map { $_ -> object -> id() } @$entries ],
+is_deeply [ map { $_ -> object -> id() } @entries ],
[ map { $empty_blob -> id() } (1..2) ];
eval {
@@ -100,14 +100,14 @@ $builder -> insert('subdir', $subtree, 0040000);
is $builder -> entry_count, 3;
$tree = $builder -> write();
-$entries = $tree -> entries();
+@entries = $tree -> entries();
-@$entries = sort { $a -> name() cmp $b -> name() } @$entries;
+@entries = sort { $a -> name() cmp $b -> name() } @entries;
-is_deeply [ map { $_ -> name() } @$entries ],
+is_deeply [ map { $_ -> name() } @entries ],
[ qw/one.txt subdir three.txt/ ];
-is_deeply [ map { $_ -> object -> id() } @$entries ],
+is_deeply [ map { $_ -> object -> id() } @entries ],
[ $empty_blob -> id(), $subtree -> id(), $empty_blob -> id() ];
done_testing;
View
55 xs/Commit.xs
@@ -240,43 +240,48 @@ tree(self)
OUTPUT: RETVAL
-AV *
+void
parents(self)
SV *self
PREINIT:
- int rc;
+ int ctx;
- SV *repo;
- int count, i;
+ PPCODE:
+ ctx = GIMME_V;
- AV *parents;
- Commit child;
+ if (ctx != G_VOID) {
+ int rc, count;
+ Commit child;
+ SV *repo = GIT_SV_TO_MAGIC(self);
- CODE:
- repo = GIT_SV_TO_MAGIC(self);
+ child = GIT_SV_TO_PTR(Commit, self);
+ count = git_commit_parentcount(child);
- child = GIT_SV_TO_PTR(Commit, self);
- count = git_commit_parentcount(child);
+ if (ctx == G_ARRAY) {
+ int i;
- parents = newAV();
+ for (i = 0; i < count; i++) {
+ SV *tmp;
+ Commit parent;
- for (i = 0; i < count; i++) {
- SV *tmp;
- Commit parent;
+ rc = git_commit_parent(&parent, child, i);
+ git_check_error(rc);
- rc = git_commit_parent(&parent, child, i);
- git_check_error(rc);
+ GIT_NEW_OBJ_WITH_MAGIC(
+ tmp, "Git::Raw::Commit", parent, repo
+ );
+ mXPUSHs(tmp);
+ }
- GIT_NEW_OBJ_WITH_MAGIC(
- tmp, "Git::Raw::Commit", parent, repo
- );
- av_push(parents, tmp);
- }
-
- RETVAL = parents;
-
- OUTPUT: RETVAL
+ mXPUSHs(newSViv((int) count));
+ XSRETURN((int) count);
+ } else {
+ mXPUSHs(newSViv((int) count));
+ XSRETURN(1);
+ }
+ } else
+ XSRETURN_EMPTY;
SV *
merge(self, commit, ...)
View
53 xs/Tree.xs
@@ -67,43 +67,52 @@ id(self)
OUTPUT: RETVAL
-AV *
+void
entries(self)
SV *self
PREINIT:
- int rc;
- int i, count;
+ int ctx;
Tree self_ptr;
- Tree_Entry entry;
- AV *entries = newAV();
- CODE:
- self_ptr = GIT_SV_TO_PTR(Tree, self);
+ PPCODE:
+ ctx = GIMME_V;
- count = git_tree_entrycount(self_ptr);
+ if (ctx != G_VOID) {
+ int rc, count;
- for (i = 0; i < count; i++) {
- SV *tmp;
+ self_ptr = GIT_SV_TO_PTR(Tree, self);
+ count = git_tree_entrycount(self_ptr);
- Tree_Entry tmp_entry = (Tree_Entry)
- git_tree_entry_byindex(self_ptr, i);
+ if (ctx == G_ARRAY) {
+ int i;
- rc = git_tree_entry_dup(&entry, tmp_entry);
- git_check_error(rc);
+ for (i = 0; i < count; i++) {
+ SV *tmp;
+ Tree_Entry entry;
- GIT_NEW_OBJ_WITH_MAGIC(
- tmp, "Git::Raw::Tree::Entry",
- entry, GIT_SV_TO_MAGIC(self)
- );
+ Tree_Entry tmp_entry = (Tree_Entry)
+ git_tree_entry_byindex(self_ptr, i);
- av_push(entries, tmp);
- }
+ rc = git_tree_entry_dup(&entry, tmp_entry);
+ git_check_error(rc);
- RETVAL = entries;
+ GIT_NEW_OBJ_WITH_MAGIC(
+ tmp, "Git::Raw::Tree::Entry",
+ entry, GIT_SV_TO_MAGIC(self)
+ );
+ mXPUSHs(tmp);
+ }
- OUTPUT: RETVAL
+ mXPUSHs(newSViv((int) count));
+ XSRETURN((int) count);
+ } else {
+ mXPUSHs(newSViv((int) count));
+ XSRETURN(1);
+ }
+ } else
+ XSRETURN_EMPTY;
SV *
entry_byname(self, name)
Something went wrong with that request. Please try again.