On Fri, Mar 27, 2020 at 02:04:18PM -0700, Junio C Hamano wrote: > Patrick Steinhardt <ps@xxxxxx> writes: > > > While the strbuf interface already provides functions to read a line > > into it that completely replaces its current contents, we do not have an > > interface that allows for appending lines without discarding current > > contents. > > > > Add a new function `strbuf_appendwholeline` that reads a line including > > its terminating character into a strbuf non-destructively. This is a > > preparatory step for git-update-ref(1) reading standard input line-wise > > instead of as a block. > > Hmph. If we were to gain more uses of this function over time, the > necessity for an extra strbuf_addbuf() becomes annoying. I wonder > if we should be doing this patch the other way around, i.e. move the > whole implementation, except for the early > > if (feof(fp)) > return EOF; > strbuf_reset(sb); > > part, and call it strbuf_addwholeline(), and strbuf_getwholeline() > becomes a thin wrapper around it that resets the incoming buffer > before calling strbuf_addwholeline(). The logic to determine EOF > would need to be updated if we go that route (i.e. instead of > checking sb->len is zero in the !HAVE_GETDELIM side of the > implementation, we need to see if the number is the same as before) > but it should be minor. Unfortunately it's not that easy for the HAVE_GETDELIM case, though, as we cannot call getdelim(3P) to append to an already populated buffer. So we'd have to call getdelim(3P) either on a NULL line and append manually or on an empty line in case the strbuf doesn't have any contents. While doable, I wanted to keep out this additional complexity for now. Patrick
Attachment:
signature.asc
Description: PGP signature