Re: [PATCH v4 11/21] revision: read --stdin with strbuf_getline()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 15, 2016, 18:38 UTC
- Message-ID
- <xmqqk2nait84.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <CAPig+cRJEUB-Fsage2G85g1s_TxSLbAmtDVqu8VDaNpBRWLkcQ@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 10 quoted lines
> On Thu, Jan 14, 2016 at 6:58 PM, Junio C Hamano <gitster@pobox.com> wrote: >> Reading with getwholeline() and manually stripping the terminating >> '\n' would leave CR at the end of the line if the input comes from >> a DOS editor. >> >> Constrasting this with the previous few changes, one may realize > > To what does "Contrasting this with the previous few changes" refer? > Did this patch previously come later in the series, or am I missing > something obvious?
Perhaps that is what happened. It was meant to ask the readers to compare the handling of "--stdin" by the log family of functions (done by code in revision.c here) with other codepaths.
Will reword. Thanks.
Show 41 quoted lines
>
>> that the way "log" family of commands read the paths with --stdin
>> looks inconsistent and sloppy. It does not allow us to C-quote a
>> textual input, and it does not accept NUL-terminated records. These
>> are unfortunately way too late to fix X-<.
>>
>> Signed-off-by: Junio C Hamano <gitster@pobox.com>
>> ---
>> revision.c | 9 ++-------
>> 1 file changed, 2 insertions(+), 7 deletions(-)
>>
>> diff --git a/revision.c b/revision.c
>> index 0a282f5..8df4e11 100644
>> --- a/revision.c
>> +++ b/revision.c
>> @@ -1635,10 +1635,7 @@ static void append_prune_data(struct cmdline_pathspec *prune, const char **av)
>> static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
>> struct cmdline_pathspec *prune)
>> {
>> - while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
>> - int len = sb->len;
>> - if (len && sb->buf[len - 1] == '\n')
>> - sb->buf[--len] = '\0';
>> + while (strbuf_getline(sb, stdin) != EOF) {
>> ALLOC_GROW(prune->path, prune->nr + 1, prune->alloc);
>> prune->path[prune->nr++] = xstrdup(sb->buf);
>> }
>> @@ -1655,10 +1652,8 @@ static void read_revisions_from_stdin(struct rev_info *revs,
>> warn_on_object_refname_ambiguity = 0;
>>
>> strbuf_init(&sb, 1000);
>> - while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
>> + while (strbuf_getline(&sb, stdin) != EOF) {
>> int len = sb.len;
>> - if (len && sb.buf[len - 1] == '\n')
>> - sb.buf[--len] = '\0';
>> if (!len)
>> break;
>> if (sb.buf[0] == '-') {
>> --
>> 2.7.0-250-ge1b5ba3