return 0;
}
-static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
- const void *buf, size_t len,
- struct object_id *oid,
- char *hdr, size_t *hdrlen)
-{
- git_hash_init(c, algo);
- git_hash_update(c, hdr, *hdrlen);
- git_hash_update(c, buf, len);
- git_hash_final_oid(oid, c);
-}
-
-void write_object_file_prepare(const struct git_hash_algo *algo,
- const void *buf, size_t len,
- enum object_type type, struct object_id *oid,
- char *hdr, size_t *hdrlen)
-{
- struct git_hash_ctx c;
-
- /* Generate the header */
- *hdrlen = format_object_header(hdr, *hdrlen, type, len);
-
- /* Hash (function pointers) computation */
- hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
-}
-
#define CHECK_COLLISION_DEST_VANISHED -2
static int check_collision(const char *source, const char *dest)
size_t len, enum object_type type,
struct object_id *oid)
{
+ struct git_hash_ctx c;
char hdr[MAX_HEADER_LEN];
- size_t hdrlen = sizeof(hdr);
+ int hdrlen;
+
+ hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
- write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
+ git_hash_init(&c, algo);
+ git_hash_update(&c, hdr, hdrlen);
+ git_hash_update(&c, buf, len);
+ git_hash_final_oid(oid, &c);
}
struct transaction_packfile {
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
size_t len, enum object_type type,
struct object_id *oid);
-void write_object_file_prepare(const struct git_hash_algo *algo,
- const void *buf, size_t len,
- enum object_type type, struct object_id *oid,
- char *hdr, size_t *hdrlen);
int write_loose_object(struct odb_source_loose *loose,
const struct object_id *oid, char *hdr,
int hdrlen, const void *buf, unsigned long len,
const struct git_hash_algo *compat = odb->repo->compat_hash_algo;
struct object_id compat_oid, *compat_oid_p = NULL;
+ hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
+
if (compat) {
const struct git_hash_algo *algo = odb->repo->hash_algo;
static int odb_source_files_write_object(struct odb_source *source,
const void *buf, size_t len,
enum object_type type,
- struct object_id *oid,
+ const struct object_id *oid,
const struct object_id *compat_oid,
enum odb_write_object_flags flags)
{
static int odb_source_inmemory_write_object(struct odb_source *source,
const void *buf, size_t len,
enum object_type type,
- struct object_id *oid,
+ const struct object_id *oid,
const struct object_id *compat_oid UNUSED,
enum odb_write_object_flags flags UNUSED)
{
struct odb_source_inmemory *inmemory = odb_source_inmemory_downcast(source);
struct inmemory_object *object;
- hash_object_file(source->odb->repo->hash_algo, buf, len, type, oid);
-
if (!inmemory->objects) {
CALLOC_ARRAY(inmemory->objects, 1);
oidtree_init(inmemory->objects);
goto out;
}
+ hash_object_file(source->odb->repo->hash_algo, data, total_read, OBJ_BLOB, oid);
+
ret = odb_source_inmemory_write_object(source, data, len, OBJ_BLOB, oid,
NULL, 0);
if (ret < 0)
static int odb_source_loose_write_object(struct odb_source *source,
const void *buf, size_t len,
- enum object_type type, struct object_id *oid,
+ enum object_type type,
+ const struct object_id *oid,
const struct object_id *compat_oid,
enum odb_write_object_flags flags)
{
struct odb_source_loose *loose = odb_source_loose_downcast(source);
- const struct git_hash_algo *algo = source->odb->repo->hash_algo;
char hdr[MAX_HEADER_LEN];
- size_t hdrlen = sizeof(hdr);
+ int hdrlen;
+
+ hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
- /* Normally if we have it in the pack then we do not bother writing
+ /*
+ * Normally if we have it in the pack then we do not bother writing
* it out into .git/objects/??/?{38} file.
*/
- write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
if (odb_freshen_object(source->odb, oid))
return 0;
if (write_loose_object(loose, oid, hdr, hdrlen, buf, len, 0, flags))
const void *buf UNUSED,
size_t len UNUSED,
enum object_type type UNUSED,
- struct object_id *oid UNUSED,
+ const struct object_id *oid UNUSED,
const struct object_id *compat_oid UNUSED,
unsigned flags UNUSED)
{
int (*write_object)(struct odb_source *source,
const void *buf, size_t len,
enum object_type type,
- struct object_id *oid,
+ const struct object_id *oid,
const struct object_id *compat_oid,
enum odb_write_object_flags flags);
static inline int odb_source_write_object(struct odb_source *source,
const void *buf, unsigned long len,
enum object_type type,
- struct object_id *oid,
+ const struct object_id *oid,
const struct object_id *compat_oid,
enum odb_write_object_flags flags)
{
struct object_id *oid)
{
size_t content_len = strlen(content);
+ hash_object_file(repo.hash_algo, content, content_len, type, oid);
cl_must_pass(odb_source_write_object(&source->base, content, content_len,
type, oid, NULL, 0));
}