Commit 3b2cb2c9 by Ciro Santilli

Factor 40 and 41 constants from source.

parent 3a495c19
......@@ -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);
......
......@@ -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);
}
......
......@@ -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();
......
......@@ -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
......
......@@ -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] != '/') {
......
......@@ -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);
......
......@@ -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);
......
......@@ -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];
};
......
......@@ -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 {
......
......@@ -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++) {
......
......@@ -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();
......
......@@ -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);
}*/
}
......
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