Re: [PATCH 01/16] odb: introduce "inmemory" source
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Apr 9, 2026, 05:22 UTC
- Message-ID
- <adc3pDxks6rCrZo6@pks.im>
- In-Reply-To
- <ada_W-IWfNKUKnVK@denethor>
On Wed, Apr 08, 2026 at 04:00:48PM -0500, Justin Tobler wrote:
Show 20 quoted lines
> On 26/04/03 08:01AM, Patrick Steinhardt wrote: > > Next to our typical object database sources, each object database also > > has an implicit source of "cached" objects. These cached objects only > > exist in memory and some use cases: > > > > - They contain evergreen objects that we expect to always exist, like > > for example the empty tree. > > > > - They can be used to store temporary objects that we don't want to > > persist to disk. > > > > Overall, their use is somewhat restricted though. For example, we don't > > provide the ability to use it as a temporary object database source that > > allows the user to write objects, but discard them after Git exists. So > > while these cached objects behave almost like a source, they aren't used > > as one. > > I find the wording of the second bullet point and paragraph above a > little confusing. Are there existing uses where new objects are written > to only the cache?
Yes, there's a single user with git-blame(1). I'll mention that user explcitly.
Show 14 quoted lines
> > @@ -1123,9 +1126,11 @@ void odb_free(struct object_database *o) > > odb_close(o); > > odb_free_sources(o); > > > > - for (size_t i = 0; i < o->cached_object_nr; i++) > > - free((char *) o->cached_objects[i].value.buf); > > - free(o->cached_objects); > > + for (size_t i = 0; i < o->inmemory_objects->objects_nr; i++) > > + free((char *) o->inmemory_objects->objects[i].value.buf); > > + free(o->inmemory_objects->objects); > > + free(o->inmemory_objects->base.path); > > + free(o->inmemory_objects); > > Should we have some sort of `odb_source_inmemory_release()`?
Yup, this is coming in subsequent commits.
Show 21 quoted lines
> > diff --git a/odb/source-inmemory.c b/odb/source-inmemory.c
> > new file mode 100644
> > index 0000000000..c7ac5c24f0
> > --- /dev/null
> > +++ b/odb/source-inmemory.c
> > @@ -0,0 +1,12 @@
> > +#include "git-compat-util.h"
> > +#include "odb/source-inmemory.h"
> > +
> > +struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
> > +{
> > + struct odb_source_inmemory *source;
> > +
> > + CALLOC_ARRAY(source, 1);
> > + odb_source_init(&source->base, odb, ODB_SOURCE_INMEMORY, "source", false);
>
> huh, so we set the path for the `struct odb_source` to "source". In the
> context of an inmemory source, a path doesn't make much sense. I suspect
> though that storing a path is likely only useful the context of the
> files ODB source. Is there reason for us to still keep this around in
> the generic ODB source?There are two reasons for the "path" field to exist:
- It is used to compare sources with one another to figure out whether
two sources are actually the same. This is used when reloading
sources. This usage makes sense in principle, but it's wrong that we
consider this to be a "path" -- it should rather be considered an
opaque "payload". - The path field is used in a bunch of sites to actually figure out
paths. This is plain wrong, as we cannot guarantee that the field
even is a path for backends that don't store data on the filesystem.It's one of the topics that we've got on our plate, to disentangle this. The goal is ultimately to move the path into the files backend, fix up callers to do the right thing (TM) and then convert the current path field that we have into a payload.
Patrick