mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 17:46:09 +00:00

The following new external methods have been added: GIT_EXTERN(const char *) git_commit_message_short(git_commit *commit); GIT_EXTERN(const char *) git_commit_message(git_commit *commit); GIT_EXTERN(time_t) git_commit_time(git_commit *commit); GIT_EXTERN(const git_commit_person *) git_commit_committer(git_commit *commit); GIT_EXTERN(const git_commit_person *) git_commit_author(git_commit *commit); GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit); A new structure, git_commit_person has been added to represent a commit's author or committer. The parsing of a commit has been split in two phases. When adding a commit to the revision pool: - the commit's ODB object is opened - its raw contents are parsed for commit TIME, PARENTS and TREE (the minimal amount of data required to traverse the pool) - the commit's ODB object is closed When querying for extended information on a commit: - the commit's ODB object is reopened - its raw contents are parsed for the requested information - the commit's ODB object remains open to handle additional queries New unit tests have been added for the new functionality: In t0401-parse: parse_person_test In t0402-details: query_details_test Signed-off-by: Vicent Marti <tanoku@gmail.com>
62 lines
1.7 KiB
C
62 lines
1.7 KiB
C
#include "test_lib.h"
|
|
#include "test_helpers.h"
|
|
#include "commit.h"
|
|
|
|
#include <git/odb.h>
|
|
#include <git/commit.h>
|
|
#include <git/revwalk.h>
|
|
|
|
static const char *odb_dir = "../t0501-objects";
|
|
static const char *commit_ids[] = {
|
|
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
|
|
"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
|
|
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
|
|
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
|
|
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
|
|
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
|
|
};
|
|
|
|
BEGIN_TEST(query_details_test)
|
|
const size_t commit_count = sizeof(commit_ids) / sizeof(const char *);
|
|
|
|
unsigned int i;
|
|
git_odb *db;
|
|
git_revpool *pool;
|
|
|
|
must_pass(git_odb_open(&db, odb_dir));
|
|
|
|
pool = gitrp_alloc(db);
|
|
must_be_true(pool != NULL);
|
|
|
|
for (i = 0; i < commit_count; ++i) {
|
|
git_oid id;
|
|
git_commit *commit;
|
|
|
|
const git_commit_person *author, *committer;
|
|
const char *message, *message_short;
|
|
time_t commit_time;
|
|
|
|
git_oid_mkstr(&id, commit_ids[i]);
|
|
|
|
commit = git_commit_parse(pool, &id);
|
|
must_be_true(commit != NULL);
|
|
|
|
message = git_commit_message(commit);
|
|
message_short = git_commit_message_short(commit);
|
|
author = git_commit_author(commit);
|
|
committer = git_commit_committer(commit);
|
|
commit_time = git_commit_time(commit);
|
|
|
|
must_be_true(strcmp(author->name, "Scott Chacon") == 0);
|
|
must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
|
|
must_be_true(strcmp(committer->name, "Scott Chacon") == 0);
|
|
must_be_true(strcmp(committer->email, "schacon@gmail.com") == 0);
|
|
must_be_true(strchr(message, '\n') != NULL);
|
|
must_be_true(strchr(message_short, '\n') == NULL);
|
|
must_be_true(commit_time > 0);
|
|
}
|
|
|
|
gitrp_free(pool);
|
|
git_odb_close(db);
|
|
END_TEST
|