From: Toon Claes <toon@iotcl.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Cc: Justin Tobler <jltobler@gmail.com>
Subject: Re: [PATCH 4/9] odb: lift object existence check out of the "loose" backend
Date: Wed, 22 Jul 2026 15:25:06 +0200 [thread overview]
Message-ID: <87jyqnp365.fsf@emacs.iotcl.com> (raw)
In-Reply-To: <20260717-pks-odb-move-loose-object-writing-v1-4-46446a3cb5b7@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
> Before writing a new loose object we first check whether the object
> already exists in any of the sources attached to the object database.
> This results in a couple of issues:
>
> - We have a layering violation, where the source needs to be aware of
> objects stored in any of the other sources.
>
> - Every backend would have to reimplement this check, which feels
> somewhat pointless.
>
> - It is not possible to easily write an object into a source in case
> the same object already exists in another source.
>
> Refactor the code and lift up the object existence check from the
> "loose" backend into the generic ODB layer. No callers need adjustment
> as none of them write via a specific source, but via the ODB layer.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> odb.c | 7 +++++++
> odb/source-loose.c | 8 ++------
> 2 files changed, 9 insertions(+), 6 deletions(-)
>
> 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;
> +
For the loose backend, this calls check_and_freshen_file(), which code
comment says:
/*
* All of the check_and_freshen functions return 1 if the file exists and was
* freshened (if freshening was requested), 0 otherwise. If they return
* 0, you should not assume that it is safe to skip a write of the object (it
* either does not exist on disk, or has a stale mtime and may be subject to
* pruning).
*/
And I see similar logic in the packed backend. So a non-zero value skips
the write and the file was freshened. Makes sense.
--
Cheers,
Toon
next prev parent reply other threads:[~2026-07-22 13:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 9:32 [PATCH 0/9] object-file: move writing of loose objects into "loose" source Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 1/9] odb: compute compat object ID in `odb_write_object_ext()` Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 2/9] t/u-odb-inmemory: implement wrapper for writing objects Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 3/9] odb: compute object hash in `odb_write_object_ext()` Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 4/9] odb: lift object existence check out of the "loose" backend Patrick Steinhardt
2026-07-22 13:25 ` Toon Claes [this message]
2026-07-17 9:32 ` [PATCH 5/9] odb: support setting mtime when writing objects Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 6/9] object-file: fix memory leak in `force_object_loose()` Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 7/9] object-file: force objects loose via generic interface Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 8/9] object-file: move `force_object_loose()` Patrick Steinhardt
2026-07-17 9:32 ` [PATCH 9/9] object-file: move logic to write loose objects Patrick Steinhardt
2026-07-22 14:26 ` Toon Claes
2026-07-18 19:39 ` [PATCH 0/9] object-file: move writing of loose objects into "loose" source SZEDER Gábor
2026-07-19 1:04 ` Junio C Hamano
2026-07-19 5:48 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87jyqnp365.fsf@emacs.iotcl.com \
--to=toon@iotcl.com \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.