git_hash_final_oid(oid, c);
}
-static void write_object_file_prepare(const struct git_hash_algo *algo,
- const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid,
- char *hdr, int *hdrlen)
+void write_object_file_prepare(const struct git_hash_algo *algo,
+ const void *buf, unsigned long len,
+ enum object_type type, struct object_id *oid,
+ char *hdr, int *hdrlen)
{
struct git_hash_ctx c;
return Z_OK;
}
-static int write_loose_object(struct odb_source *source,
- const struct object_id *oid, char *hdr,
- int hdrlen, const void *buf, unsigned long len,
- time_t mtime, unsigned flags)
+int write_loose_object(struct odb_source *source,
+ const struct object_id *oid, char *hdr,
+ int hdrlen, const void *buf, unsigned long len,
+ time_t mtime, unsigned flags)
{
int fd, ret;
unsigned char compressed[4096];
return err;
}
-int odb_source_loose_write_object(struct odb_source *source,
- const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid,
- struct object_id *compat_oid_in,
- enum odb_write_object_flags flags)
-{
- struct odb_source_files *files = odb_source_files_downcast(source);
- const struct git_hash_algo *algo = source->odb->repo->hash_algo;
- const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
- struct object_id compat_oid;
- char hdr[MAX_HEADER_LEN];
- int hdrlen = sizeof(hdr);
-
- /* Generate compat_oid */
- if (compat) {
- if (compat_oid_in)
- oidcpy(&compat_oid, compat_oid_in);
- else if (type == OBJ_BLOB)
- hash_object_file(compat, buf, len, type, &compat_oid);
- else {
- struct strbuf converted = STRBUF_INIT;
- convert_object_file(source->odb->repo, &converted, algo, compat,
- buf, len, type, 0);
- hash_object_file(compat, converted.buf, converted.len,
- type, &compat_oid);
- strbuf_release(&converted);
- }
- }
-
- /* 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(source, oid, hdr, hdrlen, buf, len, 0, flags))
- return -1;
- if (compat)
- return repo_add_loose_object_map(files->loose, oid, &compat_oid);
- return 0;
-}
-
int force_object_loose(struct odb_source *source,
const struct object_id *oid, time_t mtime)
{
struct object_info;
struct odb_source;
-int odb_source_loose_write_object(struct odb_source *source,
- const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid,
- struct object_id *compat_oid_in,
- enum odb_write_object_flags flags);
-
int odb_source_loose_write_stream(struct odb_source *source,
struct odb_write_stream *stream, size_t len,
struct object_id *oid);
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
unsigned long len, enum object_type type,
struct object_id *oid);
+void write_object_file_prepare(const struct git_hash_algo *algo,
+ const void *buf, unsigned long len,
+ enum object_type type, struct object_id *oid,
+ char *hdr, int *hdrlen);
+int write_loose_object(struct odb_source *source,
+ const struct object_id *oid, char *hdr,
+ int hdrlen, const void *buf, unsigned long len,
+ time_t mtime, unsigned flags);
/* Helper to check and "touch" a file */
int check_and_freshen_file(const char *fn, int freshen);
struct object_id *compat_oid,
enum odb_write_object_flags flags)
{
- return odb_source_loose_write_object(source, buf, len, type,
- oid, compat_oid, flags);
+ struct odb_source_files *files = odb_source_files_downcast(source);
+ return odb_source_write_object(&files->loose->base, buf, len, type,
+ oid, compat_oid, flags);
}
static int odb_source_files_write_object_stream(struct odb_source *source,
#include "hex.h"
#include "loose.h"
#include "object-file.h"
+#include "object-file-convert.h"
#include "odb.h"
#include "odb/source-files.h"
#include "odb/source-loose.h"
return !!check_and_freshen_file(path.buf, 1);
}
+static int odb_source_loose_write_object(struct odb_source *source,
+ const void *buf, unsigned long len,
+ enum object_type type, struct object_id *oid,
+ struct object_id *compat_oid_in,
+ 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;
+ const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
+ struct object_id compat_oid;
+ char hdr[MAX_HEADER_LEN];
+ int hdrlen = sizeof(hdr);
+
+ /* Generate compat_oid */
+ if (compat) {
+ if (compat_oid_in)
+ oidcpy(&compat_oid, compat_oid_in);
+ else if (type == OBJ_BLOB)
+ hash_object_file(compat, buf, len, type, &compat_oid);
+ else {
+ struct strbuf converted = STRBUF_INIT;
+ convert_object_file(source->odb->repo, &converted, algo, compat,
+ buf, len, type, 0);
+ hash_object_file(compat, converted.buf, converted.len,
+ type, &compat_oid);
+ strbuf_release(&converted);
+ }
+ }
+
+ /* 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(source, oid, hdr, hdrlen, buf, len, 0, flags))
+ return -1;
+ if (compat)
+ return repo_add_loose_object_map(loose, oid, &compat_oid);
+ return 0;
+}
+
static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
{
oidtree_clear(loose->cache);
loose->base.find_abbrev_len = odb_source_loose_find_abbrev_len;
loose->base.count_objects = odb_source_loose_count_objects;
loose->base.freshen_object = odb_source_loose_freshen_object;
+ loose->base.write_object = odb_source_loose_write_object;
if (!is_absolute_path(loose->base.path))
chdir_notify_register(NULL, odb_source_loose_reparent, loose);