odb: Do not pass around a header when hashing
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
diff --git a/src/indexer.c b/src/indexer.c
index 23556a3..bef62a2 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -322,8 +322,7 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
git_oid oid;
struct git_pack_entry *pentry;
git_mwindow *w = NULL;
- char hdr[512] = {0}; /* FIXME: How long should this be? */
- int i, hdr_len;
+ int i;
off_t entry_start = off;
void *packed;
size_t entry_size;
@@ -345,7 +344,7 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
}
/* FIXME: Parse the object instead of hashing it */
- error = git_odb__hash_obj(&oid, hdr, sizeof(hdr), &hdr_len, &obj);
+ error = git_odb__hash_obj(&oid, &obj);
if (error < GIT_SUCCESS) {
error = git__rethrow(error, "Failed to hash object");
goto cleanup;
diff --git a/src/odb.c b/src/odb.c
index a3045f7..fcba4fc 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -59,12 +59,13 @@ static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype o
return len+1;
}
-int git_odb__hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_rawobj *obj)
+int git_odb__hash_obj(git_oid *id, git_rawobj *obj)
{
git_buf_vec vec[2];
- int hdrlen;
+ char header[64];
+ int hdrlen;
- assert(id && hdr && len && obj);
+ assert(id && obj);
if (!git_object_typeisloose(obj->type))
return git__throw(GIT_ERROR, "Failed to hash object. Wrong object type");
@@ -72,12 +73,10 @@ int git_odb__hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_rawobj *ob
if (!obj->data && obj->len != 0)
return git__throw(GIT_ERROR, "Failed to hash object. No data given");
- if ((hdrlen = format_object_header(hdr, n, obj->len, obj->type)) < 0)
+ if ((hdrlen = format_object_header(header, sizeof(header), obj->len, obj->type)) < 0)
return git__rethrow(hdrlen, "Failed to hash object");
- *len = hdrlen;
-
- vec[0].data = hdr;
+ vec[0].data = header;
vec[0].len = hdrlen;
vec[1].data = obj->data;
vec[1].len = obj->len;
@@ -182,8 +181,6 @@ int git_odb_hashfile(git_oid *out, const char *path, git_otype type)
int git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type)
{
- char hdr[64];
- int hdrlen;
git_rawobj raw;
assert(id);
@@ -192,7 +189,7 @@ int git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type)
raw.len = len;
raw.type = type;
- return git_odb__hash_obj(id, hdr, sizeof(hdr), &hdrlen, &raw);
+ return git_odb__hash_obj(id, &raw);
}
/**
diff --git a/src/odb.h b/src/odb.h
index f368583..1d4f07d 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -28,6 +28,6 @@ struct git_odb {
git_cache cache;
};
-int git_odb__hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_rawobj *obj);
+int git_odb__hash_obj(git_oid *id, git_rawobj *obj);
#endif