From: Patrick Steinhardt <ps@pks.im>
To: shejialuo <shejialuo@gmail.com>
Cc: Taylor Blau <me@ttaylorr.com>,
git@vger.kernel.org, Edward Thomson <ethomson@edwardthomson.com>,
karthik nayak <karthik.188@gmail.com>
Subject: Re: [PATCH v2 00/10] reftable: stop using `struct strbuf`
Date: Tue, 15 Oct 2024 12:44:53 +0200 [thread overview]
Message-ID: <Zw5HntIyk_DLWESC@pks.im> (raw)
In-Reply-To: <Zw5E8d3AotDBYKSA@ArchLinux>
On Tue, Oct 15, 2024 at 06:33:21PM +0800, shejialuo wrote:
> 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.
The thing is that we'll have repetition regardless of what we end up
doing:
- We could either have repetition once in the reftable library,
reimplementing `struct strbuf`. This can then be reused by every
single user of the reftable library.
- Or we can have repetition for every single user of the reftable
library. For now that'd only be Git and libgit2, but we'd still have
repetition.
The second kind of repetition is way worse though, because now every
user of the reftable library has a different implementation of a type
that is as basic as a buffer. These _must_ behave the exact same across
implementations or we will hit issues. So I'd rather have the repetition
a single time in the reftable library such that all users of the library
will behave the same rather than having downstream users copy the
implementation of `struct strbuf` and making it work for their library.
Also, due to the nature of `struct strbuf` not allowing for allocation
failures we'd already have diverging behaviour. In Git you would never
hit error code paths for allocation failures, whereas every library user
potentially can.
So we really have to treat the reftable code base special. If we want to
be a good citizen and be a proper upstream for projects like libgit2 we
don't really have much of a choice than to detangle it from libgit.a. If
we don't we may be saving 20 lines of code, but we make everybody elses
life harder.
Patrick
next prev parent reply other threads:[~2024-10-15 10:45 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-11 6:54 [PATCH 00/10] reftable: stop using `struct strbuf` Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 01/10] reftable: stop using `strbuf_addbuf()` Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 02/10] reftable: stop using `strbuf_addf()` Patrick Steinhardt
2024-10-11 9:51 ` karthik nayak
2024-10-14 13:09 ` Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 03/10] reftable/basics: provide new `reftable_buf` interface Patrick Steinhardt
2024-10-11 10:03 ` karthik nayak
2024-10-14 13:09 ` Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 04/10] reftable: convert from `strbuf` to `reftable_buf` Patrick Steinhardt
2024-10-11 12:12 ` karthik nayak
2024-10-14 13:09 ` Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 05/10] reftable/blocksource: adapt interface name Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 06/10] t/unit-tests: check for `reftable_buf` allocation errors Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 07/10] reftable/stack: adapt `format_name()` to handle allocation failures Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 08/10] reftable/record: adapt `reftable_record_key()` " Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 09/10] reftable/stack: adapt `stack_filename()` " Patrick Steinhardt
2024-10-11 6:54 ` [PATCH 10/10] reftable: handle trivial `reftable_buf` errors Patrick Steinhardt
2024-10-11 12:18 ` [PATCH 00/10] reftable: stop using `struct strbuf` karthik nayak
2024-10-14 13:09 ` Patrick Steinhardt
2024-10-14 13:02 ` [PATCH v2 " Patrick Steinhardt
2024-10-14 13:02 ` [PATCH v2 01/10] reftable: stop using `strbuf_addbuf()` Patrick Steinhardt
2024-10-14 22:19 ` Taylor Blau
2024-10-14 13:02 ` [PATCH v2 02/10] reftable: stop using `strbuf_addf()` Patrick Steinhardt
2024-10-14 22:32 ` Taylor Blau
2024-10-15 4:37 ` Patrick Steinhardt
2024-10-15 19:26 ` Taylor Blau
2024-10-14 13:02 ` [PATCH v2 03/10] reftable/basics: provide new `reftable_buf` interface Patrick Steinhardt
2024-10-14 22:34 ` Taylor Blau
2024-10-15 4:38 ` Patrick Steinhardt
2024-10-15 5:10 ` Eric Sunshine
2024-10-15 19:27 ` Taylor Blau
2024-10-16 8:42 ` Patrick Steinhardt
2024-10-16 20:56 ` Taylor Blau
2024-10-17 4:54 ` Patrick Steinhardt
2024-10-17 20:59 ` Taylor Blau
2024-10-14 13:02 ` [PATCH v2 04/10] reftable: convert from `strbuf` to `reftable_buf` Patrick Steinhardt
2024-10-14 22:35 ` Taylor Blau
2024-10-14 13:02 ` [PATCH v2 05/10] reftable/blocksource: adapt interface name Patrick Steinhardt
2024-10-14 13:02 ` [PATCH v2 06/10] t/unit-tests: check for `reftable_buf` allocation errors Patrick Steinhardt
2024-10-14 13:02 ` [PATCH v2 07/10] reftable/stack: adapt `format_name()` to handle allocation failures Patrick Steinhardt
2024-10-14 22:41 ` Taylor Blau
2024-10-14 13:02 ` [PATCH v2 08/10] reftable/record: adapt `reftable_record_key()` " Patrick Steinhardt
2024-10-14 13:02 ` [PATCH v2 09/10] reftable/stack: adapt `stack_filename()` " Patrick Steinhardt
2024-10-14 13:02 ` [PATCH v2 10/10] reftable: handle trivial `reftable_buf` errors Patrick Steinhardt
2024-10-14 22:44 ` [PATCH v2 00/10] reftable: stop using `struct strbuf` Taylor Blau
2024-10-15 4:37 ` Patrick Steinhardt
2024-10-15 10:33 ` shejialuo
2024-10-15 10:44 ` Patrick Steinhardt [this message]
2024-10-15 11:23 ` shejialuo
2024-10-17 4:53 ` [PATCH v3 " Patrick Steinhardt
2024-10-17 4:53 ` [PATCH v3 01/10] reftable: stop using `strbuf_addbuf()` Patrick Steinhardt
2024-10-17 4:53 ` [PATCH v3 02/10] reftable: stop using `strbuf_addf()` Patrick Steinhardt
2024-10-17 4:53 ` [PATCH v3 03/10] reftable/basics: provide new `reftable_buf` interface Patrick Steinhardt
2024-10-17 4:53 ` [PATCH v3 04/10] reftable: convert from `strbuf` to `reftable_buf` Patrick Steinhardt
2024-10-17 4:53 ` [PATCH v3 05/10] reftable/blocksource: adapt interface name Patrick Steinhardt
2024-10-17 4:54 ` [PATCH v3 06/10] t/unit-tests: check for `reftable_buf` allocation errors Patrick Steinhardt
2024-10-17 4:54 ` [PATCH v3 07/10] reftable/stack: adapt `format_name()` to handle allocation failures Patrick Steinhardt
2024-10-17 4:54 ` [PATCH v3 08/10] reftable/record: adapt `reftable_record_key()` " Patrick Steinhardt
2024-10-17 4:54 ` [PATCH v3 09/10] reftable/stack: adapt `stack_filename()` " Patrick Steinhardt
2024-10-17 4:54 ` [PATCH v3 10/10] reftable: handle trivial `reftable_buf` errors Patrick Steinhardt
2024-10-17 21:00 ` [PATCH v3 00/10] reftable: stop using `struct strbuf` Taylor Blau
2024-10-18 7:46 ` karthik nayak
2024-10-18 21:41 ` Taylor Blau
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=Zw5HntIyk_DLWESC@pks.im \
--to=ps@pks.im \
--cc=ethomson@edwardthomson.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=me@ttaylorr.com \
--cc=shejialuo@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).