Re: [PATCH 03/17] odb: embed base source in the "files" backend
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Mar 5, 2026, 13:23 UTC
- Message-ID
- <aamDzR_8oTaqRlhT@pks.im>
- In-Reply-To
- <CAOLa=ZSY8WE_BiWF0TZpV1-bf6p3z8zV4F_o4xo-V1ZC5ZiQLA@mail.gmail.com>
On Thu, Mar 05, 2026 at 10:45:07AM +0000, Karthik Nayak wrote:
Show 19 quoted lines
> Patrick Steinhardt <ps@pks.im> writes: > > Refactor our "files" object database source to do the same and embed the > > `struct odb_source` in the `struct odb_source_files`. > > > > There are still a bunch of sites in our code base where we do have to > > access internals of the "files" backend. The intent is that those will > > go away over time, but this will certainly take a while. Meanwhile, > > provide a `odb_source_files_downcast()` function that can convert a > > generic source into a "files" source. > > > > As we only have a single source the downcast succeeds unconditionally > > for now. Eventually though the intent is to make the cast `BUG()` in > > case the caller requests to downcast a non-"files" backend to a "files" > > backend. > > > > Do we also plan to add read/write permissions check within the downcast > logic? Similar to the refs DB? Doesn't have to be in this patch, just > curious if that is something we plan to include.
I didn't plan to. I guess we could have such a check eventually though to for example keep somebody from writing to secondary ODB sources. I don't have anything cooking here though.
Show 23 quoted lines
> > diff --git a/odb/source.c b/odb/source.c
> > index 9d7fd19f45..d8b2176a94 100644
> > --- a/odb/source.c
> > +++ b/odb/source.c
> > @@ -1,5 +1,6 @@
> > #include "git-compat-util.h"
> > #include "object-file.h"
> > +#include "odb/source-files.h"
> > #include "odb/source.h"
> > #include "packfile.h"
> >
> > @@ -7,20 +8,31 @@ struct odb_source *odb_source_new(struct object_database *odb,
> > const char *path,
> > bool local)
> > {
> > - struct odb_source *source;
> > + return &odb_source_files_new(odb, path, local)->base;
> > +}
> >
>
> Since we only have one source right now (files), we directly call the
> internals of that source, I guess once we add more this would be more
> modular.Yeah. This will eventually be handled via a new object storage extension, similar to how we do this for the reference backends.
Patrick