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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/include/git2/reflog.h b/include/git2/reflog.h
index 7f2781f..53b3447 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 7609d9a..85e7681 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 da352ca..b6daf2a 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 f80c3f5..65fbdd6 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);