Subject: Re: [PATCH v2 00/10] reftable: stop using `struct strbuf`

From: shejialuo <[email-masked]>
Date: Tue, 15 Oct 2024 18:33:21 +0800

On Tue, Oct 15, 2024 at 06:37:37AM +0200, Patrick Steinhardt wrote:
> On Mon, Oct 14, 2024 at 06:44:35PM -0400, Taylor Blau wrote:
> > On Mon, Oct 14, 2024 at 03:02:16PM +0200, Patrick Steinhardt wrote:
> > > Hi,
> > >
> > > this is the second part of my patch series that stop using `struct
> > > strbuf` in the reftable library. This is done such that the reftable
> > > library becomes standalone again and so that we can use the pluggable
> > > allocators part of the library.
> > 
> > I reviewed this round, and it looks generally good to me. I feel
> > somewhat unhappy to have to force the reftable backend to implement its
> > own strbuf-like functionality.
> > 
> > So I think it may be worth considering whether or not we can reuse Git's
> > strbuf implementation through a vtable or similar. But it may not be
> > immediately possible since that implementation just die()s on error,
> > can't easily swap out the allocator, etc. So perhaps this is the best
> > path forward, it just feels somewhat unsatisfying to me.
> 
> It's not perfect, I agree. I initially tried to do something like a
> vtable or to even compile this into code with something like a wrapper
> structure. But that approach in the end fell flat. So I decided to be
> pragmatic about this whole issue and just duplicate some code --
> overall, we are talking about ~200 lines of code to completely detangle
> the reftable library from libgit.a.
> 

I have read some patches yesterday, I feel quite strange that we need to
make repetition. Could we provide a header file which requires the users
who need to use the reftable library to implement the interfaces?

    reftable_strbuf_addf(void *buf, char *fmt, va_list ap);

Thus, we could reuse "strbuf_addf" to implement this interface in Git.
As for libgit2, could we let it implement these interfaces? Although I
have never read the source code of libgit2, I think there should be some
code which could be reuse to implement these interfaces?

However, I do not know the context. Maybe the above is totally wrong. If
so, please ignore.

Thanks,
Jialuo