diff options
-rw-r--r-- | include/git2/reflog.h | 4 | ||||
-rw-r--r-- | src/reflog.c | 17 | ||||
-rw-r--r-- | src/reflog.h | 4 | ||||
-rw-r--r-- | tests/t10-refs.c | 14 |
4 files changed, 22 insertions, 17 deletions
diff --git a/include/git2/reflog.h b/include/git2/reflog.h index 7f2781fc..53b34473 100644 --- a/include/git2/reflog.h +++ b/include/git2/reflog.h @@ -91,7 +91,7 @@ GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog * @param entry a reflog entry * @return the old oid */ -GIT_EXTERN(char *) git_reflog_entry_oidold(const git_reflog_entry *entry); +GIT_EXTERN(const git_oid *) git_reflog_entry_oidold(const git_reflog_entry *entry); /** * Get the new oid @@ -99,7 +99,7 @@ GIT_EXTERN(char *) git_reflog_entry_oidold(const git_reflog_entry *entry); * @param entry a reflog entry * @return the new oid at this time */ -GIT_EXTERN(char *) git_reflog_entry_oidnew(const git_reflog_entry *entry); +GIT_EXTERN(const git_oid *) git_reflog_entry_oidnew(const git_reflog_entry *entry); /** * Get the committer of this entry diff --git a/src/reflog.c b/src/reflog.c index 7609d9a4..85e76812 100644 --- a/src/reflog.c +++ b/src/reflog.c @@ -113,10 +113,12 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) if (entry == NULL) return GIT_ENOMEM; - entry->oid_old = git__strndup(buf, GIT_OID_HEXSZ); + if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < GIT_SUCCESS) + return GIT_ERROR; seek_forward(GIT_OID_HEXSZ + 1); - entry->oid_cur = git__strndup(buf, GIT_OID_HEXSZ); + if (git_oid_fromstrn(&entry->oid_cur, buf, GIT_OID_HEXSZ) < GIT_SUCCESS) + return GIT_ERROR; seek_forward(GIT_OID_HEXSZ + 1); ptr = buf; @@ -165,9 +167,6 @@ void git_reflog_free(git_reflog *reflog) for (i=0; i < reflog->entries.length; i++) { entry = git_vector_get(&reflog->entries, i); - free(entry->oid_old); - free(entry->oid_cur); - git_signature_free(entry->committer); free(entry->msg); @@ -255,16 +254,16 @@ const git_reflog_entry * git_reflog_entry_byindex(git_reflog *reflog, unsigned i return git_vector_get(&reflog->entries, idx); } -char * git_reflog_entry_oidold(const git_reflog_entry *entry) +const git_oid * git_reflog_entry_oidold(const git_reflog_entry *entry) { assert(entry); - return entry->oid_old; + return &entry->oid_old; } -char * git_reflog_entry_oidnew(const git_reflog_entry *entry) +const git_oid * git_reflog_entry_oidnew(const git_reflog_entry *entry) { assert(entry); - return entry->oid_cur; + return &entry->oid_cur; } git_signature * git_reflog_entry_committer(const git_reflog_entry *entry) diff --git a/src/reflog.h b/src/reflog.h index da352ca8..b6daf2a7 100644 --- a/src/reflog.h +++ b/src/reflog.h @@ -10,8 +10,8 @@ #define GIT_REFLOG_SIZE_MIN (2*GIT_OID_HEXSZ+2+17) struct git_reflog_entry { - char *oid_old; - char *oid_cur; + git_oid oid_old; + git_oid oid_cur; git_signature *committer; diff --git a/tests/t10-refs.c b/tests/t10-refs.c index f80c3f51..65fbdd69 100644 --- a/tests/t10-refs.c +++ b/tests/t10-refs.c @@ -1026,6 +1026,7 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r git_signature *committer; git_reflog *reflog; git_reflog_entry *entry; + char oid_str[GIT_OID_HEXSZ+1]; must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); @@ -1037,6 +1038,7 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r must_pass(git_signature_now(&committer, "foo", "foo@bar")); must_pass(git_reflog_write(ref, NULL, committer, NULL)); + must_fail(git_reflog_write(ref, NULL, committer, "no ancestor NULL for an existing reflog")); must_fail(git_reflog_write(ref, NULL, committer, "no\nnewline")); must_pass(git_reflog_write(ref, &oid, committer, commit_msg)); @@ -1054,14 +1056,18 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 0); must_pass(assert_signature(committer, entry->committer)); - must_be_true(strcmp("0000000000000000000000000000000000000000", entry->oid_old) == 0); - must_be_true(strcmp(current_master_tip, entry->oid_cur) == 0); + git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old); + must_be_true(strcmp("0000000000000000000000000000000000000000", oid_str) == 0); + git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur); + must_be_true(strcmp(current_master_tip, oid_str) == 0); must_be_true(entry->msg == NULL); entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 1); must_pass(assert_signature(committer, entry->committer)); - must_be_true(strcmp(current_master_tip, entry->oid_old) == 0); - must_be_true(strcmp(current_master_tip, entry->oid_cur) == 0); + git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old); + must_be_true(strcmp(current_master_tip, oid_str) == 0); + git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur); + must_be_true(strcmp(current_master_tip, oid_str) == 0); must_be_true(strcmp(commit_msg, entry->msg) == 0); git_signature_free(committer); |