diff --git a/odb.c b/odb.c index 4adbdf8a64..bfeca76f4e 100644 --- a/odb.c +++ b/odb.c @@ -997,6 +997,13 @@ int odb_write_object_ext(struct object_database *odb, hash_object_file(odb->repo->hash_algo, buf, len, type, oid); + /* + * We can skip the write in case we already have the object available. + * In that case, we only freshen its mtime. + */ + if (odb_freshen_object(odb, oid)) + return 0; + if (compat) { const struct git_hash_algo *algo = odb->repo->hash_algo; diff --git a/odb/source-loose.c b/odb/source-loose.c index d4715da6d1..04af1a54a3 100644 --- a/odb/source-loose.c +++ b/odb/source-loose.c @@ -595,16 +595,12 @@ static int odb_source_loose_write_object(struct odb_source *source, hdrlen = format_object_header(hdr, sizeof(hdr), type, len); - /* - * Normally if we have it in the pack then we do not bother writing - * it out into .git/objects/??/?{38} file. - */ - if (odb_freshen_object(source->odb, oid)) - return 0; if (write_loose_object(loose, oid, hdr, hdrlen, buf, len, 0, flags)) return -1; + if (compat_oid) return repo_add_loose_object_map(loose, oid, compat_oid); + return 0; }