Commit c85e08b1 by Vicent Marti

odb: Do not pass around a header when hashing

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