Commit 7c458e3aee7b39bfec368456d494972fe9ae244b

nulltoken 2012-07-17T10:53:19

reflog: add GIT_OID_HEX_ZERO constant

diff --git a/src/reflog.c b/src/reflog.c
index 004ba93..0e07583 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -258,7 +258,7 @@ int git_reflog_write(git_reference *ref, const git_oid *oid_old,
 	if (oid_old)
 		git_oid_tostr(old, sizeof(old), oid_old);
 	else
-		p_snprintf(old, sizeof(old), "%0*d", GIT_OID_HEXSZ, 0);
+		memmove(old, GIT_OID_HEX_ZERO, sizeof(old));
 
 	error = reflog_write(log_path.ptr, old, new, committer, msg);
 
diff --git a/src/reflog.h b/src/reflog.h
index 33cf077..fe28919 100644
--- a/src/reflog.h
+++ b/src/reflog.h
@@ -17,6 +17,8 @@
 
 #define GIT_REFLOG_SIZE_MIN (2*GIT_OID_HEXSZ+2+17)
 
+#define GIT_OID_HEX_ZERO "0000000000000000000000000000000000000000"
+
 struct git_reflog_entry {
 	git_oid oid_old;
 	git_oid oid_cur;
diff --git a/tests-clar/refs/reflog/reflog.c b/tests-clar/refs/reflog/reflog.c
index 45da8c3..fb69dd2 100644
--- a/tests-clar/refs/reflog/reflog.c
+++ b/tests-clar/refs/reflog/reflog.c
@@ -73,7 +73,7 @@ void test_refs_reflog_reflog__write_then_read(void)
 	entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 0);
 	assert_signature(committer, entry->committer);
 	git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old);
-	cl_assert_equal_s("0000000000000000000000000000000000000000", oid_str);
+	cl_assert_equal_s(GIT_OID_HEX_ZERO, oid_str);
 	git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur);
 	cl_assert_equal_s(current_master_tip, oid_str);
 	cl_assert(entry->msg == NULL);