Commit 3b2cb2c91ee77e5e45957e8355025e3e742c07bd

Ciro Santilli 2014-09-16T11:49:25

Factor 40 and 41 constants from source.

diff --git a/examples/general.c b/examples/general.c
index ae87563..051d693 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -94,8 +94,8 @@ int main (int argc, char** argv)
   // Next we will convert the 20 byte raw SHA1 value to a human readable 40
   // char hex value.
   printf("\n*Raw to Hex*\n");
-  char out[41];
-  out[40] = '\0';
+  char out[GIT_OID_HEXSZ+1];
+  out[GIT_OID_HEXSZ] = '\0';
 
   // If you have a oid, you can easily get the hex value of the SHA as well.
   git_oid_fmt(out, &oid);
diff --git a/examples/rev-list.c b/examples/rev-list.c
index 5c0d751..940a011 100644
--- a/examples/rev-list.c
+++ b/examples/rev-list.c
@@ -22,7 +22,7 @@ int main (int argc, char **argv)
 	git_repository *repo;
 	git_revwalk *walk;
 	git_oid oid;
-	char buf[41];
+	char buf[GIT_OID_HEXSZ+1];
 
 	git_threads_init();
 
@@ -32,7 +32,7 @@ int main (int argc, char **argv)
 
 	while (!git_revwalk_next(&oid, walk)) {
 		git_oid_fmt(buf, &oid);
-		buf[40] = '\0';
+		buf[GIT_OID_HEXSZ] = '\0';
 		printf("%s\n", buf);
 	}
 
diff --git a/examples/showindex.c b/examples/showindex.c
index ad4a16e..604124f 100644
--- a/examples/showindex.c
+++ b/examples/showindex.c
@@ -20,8 +20,8 @@ int main (int argc, char** argv)
 	unsigned int i, ecount;
 	char *dir = ".";
 	size_t dirlen;
-	char out[41];
-	out[40] = '\0';
+	char out[GIT_OID_HEXSZ+1];
+	out[GIT_OID_HEXSZ] = '\0';
 
 	git_threads_init();
 
diff --git a/src/global.h b/src/global.h
index 1065046..a89a8d6 100644
--- a/src/global.h
+++ b/src/global.h
@@ -7,13 +7,14 @@
 #ifndef INCLUDE_global_h__
 #define INCLUDE_global_h__
 
+#include "common.h"
 #include "mwindow.h"
 #include "hash.h"
 
 typedef struct {
 	git_error *last_error;
 	git_error error_t;
-	char oid_fmt[41];
+	char oid_fmt[GIT_OID_HEXSZ+1];
 } git_global_st;
 
 #ifdef GIT_SSL
diff --git a/src/odb_loose.c b/src/odb_loose.c
index b2e8bed..ef6de41 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -714,7 +714,7 @@ struct foreach_state {
 GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
 {
 	int v, i = 0;
-	if (strlen(ptr) != 41)
+	if (strlen(ptr) != GIT_OID_HEXSZ+1)
 		return -1;
 
 	if (ptr[2] != '/') {
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 5ca5065..7c20382 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -640,9 +640,9 @@ static int gen_pktline(git_buf *buf, git_push *push)
 {
 	push_spec *spec;
 	size_t i, len;
-	char old_id[41], new_id[41];
+	char old_id[GIT_OID_HEXSZ+1], new_id[GIT_OID_HEXSZ+1];
 
-	old_id[40] = '\0'; new_id[40] = '\0';
+	old_id[GIT_OID_HEXSZ] = '\0'; new_id[GIT_OID_HEXSZ] = '\0';
 
 	git_vector_foreach(&push->specs, i, spec) {
 		len = 2*GIT_OID_HEXSZ + 7 + strlen(spec->rref);
@@ -963,7 +963,7 @@ int git_smart__push(git_transport *transport, git_push *push)
 #ifdef PUSH_DEBUG
 {
 	git_remote_head *head;
-	char hex[41]; hex[40] = '\0';
+	char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0';
 
 	git_vector_foreach(&push->remote->refs, i, head) {
 		git_oid_fmt(hex, &head->oid);
diff --git a/tests/blame/blame_helpers.c b/tests/blame/blame_helpers.c
index 9bb77a5..21cd1a6 100644
--- a/tests/blame/blame_helpers.c
+++ b/tests/blame/blame_helpers.c
@@ -17,7 +17,7 @@ void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...)
 void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx,
 		int start_line, int len, char boundary, const char *commit_id, const char *orig_path)
 {
-	char expected[41] = {0}, actual[41] = {0};
+	char expected[GIT_OID_HEXSZ+1] = {0}, actual[GIT_OID_HEXSZ+1] = {0};
 	const git_blame_hunk *hunk = git_blame_get_hunk_byindex(blame, idx);
 	cl_assert(hunk);
 
diff --git a/tests/checkout/conflict.c b/tests/checkout/conflict.c
index b8ae805..943371d 100644
--- a/tests/checkout/conflict.c
+++ b/tests/checkout/conflict.c
@@ -48,7 +48,7 @@ static git_index *g_index;
 
 struct checkout_index_entry {
 	uint16_t mode;
-	char oid_str[41];
+	char oid_str[GIT_OID_HEXSZ+1];
 	int stage;
 	char path[128];
 };
diff --git a/tests/merge/merge_helpers.h b/tests/merge/merge_helpers.h
index fddf8fa..554c24b 100644
--- a/tests/merge/merge_helpers.h
+++ b/tests/merge/merge_helpers.h
@@ -49,7 +49,7 @@
 
 struct merge_index_entry {
 	uint16_t mode;
-	char oid_str[41];
+	char oid_str[GIT_OID_HEXSZ+1];
 	int stage;
 	char path[128];
 };
@@ -70,9 +70,9 @@ struct merge_reuc_entry {
 	unsigned int ancestor_mode;
 	unsigned int our_mode;
 	unsigned int their_mode;
-	char ancestor_oid_str[41];
-	char our_oid_str[41];
-	char their_oid_str[41];
+	char ancestor_oid_str[GIT_OID_HEXSZ+1];
+	char our_oid_str[GIT_OID_HEXSZ+1];
+	char their_oid_str[GIT_OID_HEXSZ+1];
 };
 
 struct merge_index_conflict_data {
diff --git a/tests/object/raw/chars.c b/tests/object/raw/chars.c
index 206bf71..cde0bdb 100644
--- a/tests/object/raw/chars.c
+++ b/tests/object/raw/chars.c
@@ -12,7 +12,7 @@ void test_object_raw_chars__find_invalid_chars_in_oid(void)
 		0xb7, 0x75, 0x21, 0x3c, 0x23,
 		0xa8, 0xbd, 0x74, 0xf5, 0xe0,
 	};
-	char in[41] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0";
+	char in[] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0";
 	unsigned int i;
 
 	for (i = 0; i < 256; i++) {
diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c
index 1059424..12273ec 100644
--- a/tests/pack/packbuilder.c
+++ b/tests/pack/packbuilder.c
@@ -93,7 +93,7 @@ void test_pack_packbuilder__create_pack(void)
 	git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
 	git_hash_ctx ctx;
 	git_oid hash;
-	char hex[41]; hex[40] = '\0';
+	char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0';
 
 	seed_packbuilder();
 
@@ -135,7 +135,7 @@ void test_pack_packbuilder__create_pack(void)
 
 void test_pack_packbuilder__get_hash(void)
 {
-	char hex[41]; hex[40] = '\0';
+	char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0';
 
 	seed_packbuilder();
 
diff --git a/tests/revwalk/basic.c b/tests/revwalk/basic.c
index b015db1..ff05fa2 100644
--- a/tests/revwalk/basic.c
+++ b/tests/revwalk/basic.c
@@ -49,12 +49,12 @@ static const int result_bytes = 24;
 static int get_commit_index(git_oid *raw_oid)
 {
 	int i;
-	char oid[40];
+	char oid[GIT_OID_HEXSZ];
 
 	git_oid_fmt(oid, raw_oid);
 
 	for (i = 0; i < commit_count; ++i)
-		if (memcmp(oid, commit_ids[i], 40) == 0)
+		if (memcmp(oid, commit_ids[i], GIT_OID_HEXSZ) == 0)
 			return i;
 
 	return -1;
@@ -74,9 +74,9 @@ static int test_walk_only(git_revwalk *walk,
 	while (git_revwalk_next(&oid, walk) == 0) {
 		result_array[i++] = get_commit_index(&oid);
 		/*{
-			char str[41];
+			char str[GIT_OID_HEXSZ+1];
 			git_oid_fmt(str, &oid);
-			str[40] = 0;
+			str[GIT_OID_HEXSZ] = 0;
 			printf("  %d) %s\n", i, str);
 		}*/
 	}