Commit e7be57a9 by schu

reflog: assimilate reflog API to return git_oid's

Rather than returning the OIDs out of the reflog as string return them
as git_oid.

Signed-off-by: schu <schu-github@schulog.org>
parent bae88c0d
......@@ -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
......
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment