Skip to content

Commit

Permalink
Bindings and unit tests for git_object_lookup_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
potyl committed Jul 26, 2011
1 parent 7c166d4 commit deffe72
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ object.h
git_object_directory
git_object_id - done
git_object_lookup - done
git_object_lookup_prefix - done
git_object_owner - done
git_object_string2type - done
git_object_type - done
Expand Down
33 changes: 33 additions & 0 deletions t/git-object.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sub main {
test_blob($repo);
test_commit_1($repo);
test_commit_2($repo);
test_commit_3($repo);
return 0;
}

Expand Down Expand Up @@ -100,6 +101,7 @@ sub test_commit_1 {
is($id, undef, "No parent");
}


sub test_commit_2 {
my ($repo) = @_;

Expand Down Expand Up @@ -131,4 +133,35 @@ sub test_commit_2 {
}


sub test_commit_3 {
my ($repo) = @_;

my $sha1hex = '0dac239f796b57e58faaeb80125ff1607eefd3bc';
my $oid = Git2::Oid->fromstr($sha1hex);
my $commit = $repo->lookup_prefix($oid, length($sha1hex), Git2::GIT_OBJ_COMMIT);
isa_ok($commit, 'Git2::Object', "A commit is an object");
isa_ok($commit, 'Git2::Commit', "A commit is a blob");

my $id = $commit->id;
isa_ok($id, "Git2::Oid");
is($id->fmt, $sha1hex, "Oid sha1hex matches");

is($commit->type, Git2::GIT_OBJ_COMMIT, "Type matches");

isa_ok($commit->owner, "Git2::Repository", "Owner is a repo");

is($commit->message_short, "Updates", "Commit's message short matches");
is($commit->parentcount, 1, "Parentcount matches");
is($commit->time, 1306011477, "Time matches");
is($commit->time_offset, 120, "Timezone matches");

$id = $commit->parent_oid(1);
is($id, undef, "No parent for (1)");

$id = $commit->parent_oid(0);
isa_ok($id, 'Git2::Oid', "Got a parent for (0)");
is($id->fmt, '9e50c4af90e4a175bffba6683fd1ec2f9085d541', "Parent's oid sha1hex matches");
}


exit main() unless caller;
27 changes: 27 additions & 0 deletions xs/GitRepository.xs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ lookup (git_repository *repo, git_oid *id, int type)
RETVAL


SV*
lookup_prefix (git_repository *repo, git_oid *id, unsigned len, int type)
PREINIT:
git_object *object;
int code;

CODE:
code = git_object_lookup_prefix(&object, repo, id, len, type);
GIT2PERL_CROAK(code);

switch (type) {
case GIT_OBJ_BLOB:
GIT2PERL_BLESS_FROM_CLASSNAME(object, "Git2::Blob");
break;

case GIT_OBJ_COMMIT:
GIT2PERL_BLESS_FROM_CLASSNAME(object, "Git2::Commit");
break;

default:
GIT2PERL_BLESS_FROM_CLASSNAME(object, "Git2::Object");
break;
}

OUTPUT:
RETVAL

SV*
create_blob_fromfile(git_repository *repo, const char *path)
PREINIT:
Expand Down

0 comments on commit deffe72

Please sign in to comment.