summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2010-08-07 00:59:58 +0200
committerVicent Marti <tanoku@gmail.com>2010-08-07 00:59:58 +0200
commit364788e1d114a174dd3c6fdfd3aa16d9627551b2 (patch)
treececae822706ee4ddd4c661e11de9634547c8e766
parent7e4f56a5bb4a87cd9537821ba4ccd1f642481a0a (diff)
downloadlibgit2-364788e1d114a174dd3c6fdfd3aa16d9627551b2.tar.gz
Refactor parsing methods
The 'parse_oid' and 'parse_person' methods which were used by the commit parser are now global so they can be used when parsing other objects. The 'git_commit_person' struct has been changed to a generic 'git_person'. Signed-off-by: Vicent Marti <tanoku@gmail.com>
-rw-r--r--src/commit.c26
-rw-r--r--src/commit.h8
-rw-r--r--src/git/commit.h11
-rw-r--r--src/git/common.h7
-rw-r--r--tests/t0401-parse.c12
-rw-r--r--tests/t0402-details.c2
6 files changed, 33 insertions, 33 deletions
diff --git a/src/commit.c b/src/commit.c
index e4e56117d..4199e8e9c 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -161,7 +161,7 @@ git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
return commit;
}
-int git_commit__parse_person(git_commit_person *person, char **buffer_out,
+int git__parse_person(git_person *person, char **buffer_out,
const char *buffer_end, const char *header)
{
const size_t header_len = strlen(header);
@@ -220,7 +220,7 @@ int git_commit__parse_person(git_commit_person *person, char **buffer_out,
return 0;
}
-int git_commit__parse_oid(git_oid *oid, char **buffer_out,
+int git__parse_oid(git_oid *oid, char **buffer_out,
const char *buffer_end, const char *header)
{
const size_t sha_len = GIT_OID_HEXSZ;
@@ -251,9 +251,9 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len, unsigne
const char *buffer_end = (char *)data + len;
git_oid oid;
- git_commit_person person;
+ git_person person;
- if (git_commit__parse_oid(&oid, &buffer, buffer_end, "tree ") < 0)
+ if (git__parse_oid(&oid, &buffer, buffer_end, "tree ") < 0)
return GIT_EOBJCORRUPTED;
if (parse_flags & GIT_COMMIT_TREE)
@@ -266,7 +266,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len, unsigne
if (parse_flags & GIT_COMMIT_PARENTS)
git_commit_list_clear(&commit->parents, 0);
- while (git_commit__parse_oid(&oid, &buffer, buffer_end, "parent ") == 0) {
+ while (git__parse_oid(&oid, &buffer, buffer_end, "parent ") == 0) {
git_commit *parent;
if ((parse_flags & GIT_COMMIT_PARENTS) == 0)
@@ -283,18 +283,18 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len, unsigne
return GIT_ENOMEM;
}
- if (git_commit__parse_person(&person, &buffer, buffer_end, "author ") < 0)
+ if (git__parse_person(&person, &buffer, buffer_end, "author ") < 0)
return GIT_EOBJCORRUPTED;
if (parse_flags & GIT_COMMIT_AUTHOR) {
if (commit->author)
free(commit->author);
- commit->author = git__malloc(sizeof(git_commit_person));
- memcpy(commit->author, &person, sizeof(git_commit_person));
+ commit->author = git__malloc(sizeof(git_person));
+ memcpy(commit->author, &person, sizeof(git_person));
}
- if (git_commit__parse_person(&person, &buffer, buffer_end, "committer ") < 0)
+ if (git__parse_person(&person, &buffer, buffer_end, "committer ") < 0)
return GIT_EOBJCORRUPTED;
if (parse_flags & GIT_COMMIT_TIME)
@@ -304,8 +304,8 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len, unsigne
if (commit->committer)
free(commit->committer);
- commit->committer = git__malloc(sizeof(git_commit_person));
- memcpy(commit->committer, &person, sizeof(git_commit_person));
+ commit->committer = git__malloc(sizeof(git_person));
+ memcpy(commit->committer, &person, sizeof(git_person));
}
/* parse commit message */
@@ -347,7 +347,7 @@ const git_tree *git_commit_tree(git_commit *commit)
return commit->tree;
}
-const git_commit_person *git_commit_author(git_commit *commit)
+const git_person *git_commit_author(git_commit *commit)
{
if (commit->author)
return commit->author;
@@ -356,7 +356,7 @@ const git_commit_person *git_commit_author(git_commit *commit)
return commit->author;
}
-const git_commit_person *git_commit_committer(git_commit *commit)
+const git_person *git_commit_committer(git_commit *commit)
{
if (commit->committer)
return commit->committer;
diff --git a/src/commit.h b/src/commit.h
index 36fd65cf2..028c83712 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -40,8 +40,8 @@ struct git_commit {
git_commit_list parents;
git_tree *tree;
- git_commit_person *author;
- git_commit_person *committer;
+ git_person *author;
+ git_person *committer;
char *message;
char *message_short;
@@ -58,11 +58,11 @@ struct git_commit {
void git_commit__free(git_commit *c);
int git_commit__parse(git_commit *commit, unsigned int flags, int close_odb);
int git_commit__parse_basic(git_commit *commit);
-int git_commit__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_end, const char *header);
int git_commit__parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags);
-int git_commit__parse_person(git_commit_person *person, char **buffer_out, const char *buffer_end, const char *header);
void git_commit__mark_uninteresting(git_commit *commit);
+int git__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_end, const char *header);
+int git__parse_person(git_person *person, char **buffer_out, const char *buffer_end, const char *header);
int git_commit_list_push_back(git_commit_list *list, git_commit *commit);
int git_commit_list_push_front(git_commit_list *list, git_commit *commit);
diff --git a/src/git/commit.h b/src/git/commit.h
index 6d34f01ce..89f0929c9 100644
--- a/src/git/commit.h
+++ b/src/git/commit.h
@@ -17,13 +17,6 @@ GIT_BEGIN_DECL
/** Parsed representation of a commit object. */
typedef struct git_commit git_commit;
-/** Parsed representation of an author/committer of a commit */
-typedef struct git_commit_person {
- char name[64]; /**< Full name */
- char email[64]; /**< Email address */
- time_t time; /**< Time when this person commited the change */
-} git_commit_person;
-
/**
* Locate a reference to a commit without loading it.
* The generated commit object is owned by the revision
@@ -84,14 +77,14 @@ GIT_EXTERN(time_t) git_commit_time(git_commit *commit);
* @param commit a previously loaded commit.
* @return the committer of a commit
*/
-GIT_EXTERN(const git_commit_person *) git_commit_committer(git_commit *commit);
+GIT_EXTERN(const git_person *) git_commit_committer(git_commit *commit);
/**
* Get the author of a commit.
* @param commit a previously loaded commit.
* @return the author of a commit
*/
-GIT_EXTERN(const git_commit_person *) git_commit_author(git_commit *commit);
+GIT_EXTERN(const git_person *) git_commit_author(git_commit *commit);
/**
* Get the tree pointed to by a commit.
diff --git a/src/git/common.h b/src/git/common.h
index 2506dae36..09972aade 100644
--- a/src/git/common.h
+++ b/src/git/common.h
@@ -88,6 +88,13 @@ GIT_BEGIN_DECL
/** A revision traversal pool. */
typedef struct git_revpool git_revpool;
+/** Parsed representation of a person */
+typedef struct git_person {
+ char name[64]; /**< Full name */
+ char email[64]; /**< Email address */
+ time_t time; /**< Time when this person commited the change */
+} git_person;
+
/** @} */
GIT_END_DECL
#endif
diff --git a/tests/t0401-parse.c b/tests/t0401-parse.c
index 3c6a4c09f..f3011827e 100644
--- a/tests/t0401-parse.c
+++ b/tests/t0401-parse.c
@@ -87,14 +87,14 @@ BEGIN_TEST(parse_oid_test)
char *ptr = string;\
char *ptr_original = ptr;\
size_t len = strlen(ptr);\
- must_pass(git_commit__parse_oid(&oid, &ptr, ptr + len, header));\
+ must_pass(git__parse_oid(&oid, &ptr, ptr + len, header));\
must_be_true(ptr == ptr_original + len);\
}
#define TEST_OID_FAIL(string, header) { \
char *ptr = string;\
size_t len = strlen(ptr);\
- must_fail(git_commit__parse_oid(&oid, &ptr, ptr + len, header));\
+ must_fail(git__parse_oid(&oid, &ptr, ptr + len, header));\
}
TEST_OID_PASS("parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent ");
@@ -126,8 +126,8 @@ BEGIN_TEST(parse_person_test)
#define TEST_PERSON_PASS(_string, _header, _name, _email, _time) { \
char *ptr = _string; \
size_t len = strlen(_string);\
- git_commit_person person; \
- must_pass(git_commit__parse_person(&person, &ptr, ptr + len, _header));\
+ git_person person; \
+ must_pass(git__parse_person(&person, &ptr, ptr + len, _header));\
must_be_true(strncmp(_name, person.name, 63) == 0);\
must_be_true(strncmp(_email, person.email, 63) == 0);\
must_be_true(_time == person.time);\
@@ -136,8 +136,8 @@ BEGIN_TEST(parse_person_test)
#define TEST_PERSON_FAIL(_string, _header) { \
char *ptr = _string; \
size_t len = strlen(_string);\
- git_commit_person person; \
- must_fail(git_commit__parse_person(&person, &ptr, ptr + len, _header));\
+ git_person person; \
+ must_fail(git__parse_person(&person, &ptr, ptr + len, _header));\
}
TEST_PERSON_PASS(
diff --git a/tests/t0402-details.c b/tests/t0402-details.c
index e412d5a41..df4a07461 100644
--- a/tests/t0402-details.c
+++ b/tests/t0402-details.c
@@ -32,7 +32,7 @@ BEGIN_TEST(query_details_test)
git_oid id;
git_commit *commit;
- const git_commit_person *author, *committer;
+ const git_person *author, *committer;
const char *message, *message_short;
time_t commit_time;