git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Garima Singh <garimasigit@gmail.com>
Cc: Garima Singh via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, Garima Singh <garima.singh@microsoft.com>
Subject: Re: [PATCH v2 1/1] quote: handle null and empty strings in sq_quote_buf_pretty()
Date: Mon, 26 Aug 2019 09:20:40 -0700
Message-ID: <xmqq1rx7kief.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <CAN+QWEZU2FqkH1jWnv==owKLsMk8XNXJh6PpF6njvB6MmKt+Dw@mail.gmail.com> (Garima Singh's message of "Mon, 26 Aug 2019 11:24:45 -0400")

Garima Singh <garimasigit@gmail.com> writes:

>> diff --git a/quote.c b/quote.c
>> index 7f2aa6faa4..6d0f8a22a9 100644
>> --- a/quote.c
>> +++ b/quote.c
>> @@ -48,6 +48,18 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
>>         static const char ok_punct[] = "+,-./:=@_^";
>>         const char *p;
>>
>> +       /* In case of null tokens, warn the user of the BUG in their call. */
>> +       if (!src)
>> +               BUG("BUG can't append a NULL token to the buffer");

I thought that the BUG() macro already says "BUG" upfront, no?

Dereferencing to see if we have an empty string below will
immediately give us segfault, so I would omit this check if I were
writing this code, though.

>> +       /* In case of empty tokens, add a '' to ensure they
>> +        * don't get inadvertently dropped.
>> +        */

Our multi-line comments have the opening slash-asterisk and the
closing asterisk-slash on their own lines.

But more importantly, "In case of empty tokens, add a ''" in this
comment has zero information contents---you can read that from the
code.  Why we do that is what we cannot express in the code, and
deserves a comment.

	/* avoid losing a zero-length string by giving nothing */

or something like that, perhaps?

>> +       if (!*src) {
>> +               strbuf_addstr(dst, "''");
>> +               return;
>> +       }
>> +
>>         for (p = src; *p; p++) {
>>                 if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
>>                         sq_quote_buf(dst, src);
>> diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
>> index a070e645d7..9c176c7cbb 100755
>> --- a/t/t0014-alias.sh
>> +++ b/t/t0014-alias.sh
>> @@ -37,4 +37,12 @@ test_expect_success 'looping aliases - internal execution' '
>>  #      test_i18ngrep "^fatal: alias loop detected: expansion of" output
>>  #'
>>
>> +test_expect_success 'run-command parses empty args properly, using sq_quote_buf_pretty' '
>> +       cat >expect <<-EOF &&
>> +       fatal: cannot change to '\''alias.foo=frotz foo '\'''\'' bar'\'': No such file or directory
>> +       EOF
>> +       test_expect_code 128 git -C "alias.foo=frotz foo '\'''\'' bar" foo 2>actual &&
>> +       test_cmp expect actual
>> +'

I think it was my mistake, but we do not ahe to use "alias" for
something like this, perhaps like:

    # 'git frotz' will fail with "no such command", but we are
    # not interested in its exit status.  We just want to see
    # how sq_quote_argv_pretty() shows arguments in the trace.
    GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
    sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
    echo "git-frotz a '' b ' ' c" >expect &&
    test_cmp expect actual

>> +
>>  test_done
>> --
>> gitgitgadget

  reply index

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-20 19:35 [PATCH 0/1] " Garima Singh via GitGitGadget
2019-08-20 19:35 ` [PATCH 1/1] " Garima Singh via GitGitGadget
2019-08-20 20:29   ` Junio C Hamano
2019-08-21 15:22     ` Junio C Hamano
2019-08-20 20:32   ` Junio C Hamano
2019-08-26 14:44 ` [PATCH v2 0/1] " Garima Singh via GitGitGadget
2019-08-26 14:44   ` [PATCH v2 1/1] " Garima Singh via GitGitGadget
2019-08-26 15:24     ` Garima Singh
2019-08-26 16:20       ` Junio C Hamano [this message]
2019-10-07 16:17   ` [PATCH v3 0/1] " Garima Singh via GitGitGadget
2019-10-07 16:17     ` [PATCH v3 1/1] quote: handle numm and empty strings in sq_quote_buf_pretty Garima Singh via GitGitGadget
2019-10-07 17:08       ` Garima Singh
2019-10-07 17:27       ` Eric Sunshine
2019-10-07 17:47         ` Garima Singh
2019-10-07 19:38     ` [PATCH v4 0/1] quote: handle null and empty strings in sq_quote_buf_pretty() Garima Singh via GitGitGadget
2019-10-07 19:38       ` [PATCH v4 1/1] sq_quote_buf_pretty: don't drop empty arguments Garima Singh via GitGitGadget
2019-10-08  3:16         ` Junio C Hamano
2019-10-08 16:40       ` [PATCH v5 0/1] quote: handle null and empty strings in sq_quote_buf_pretty() Garima Singh via GitGitGadget
2019-10-08 16:40         ` [PATCH v5 1/1] sq_quote_buf_pretty: don't drop empty arguments Garima Singh via GitGitGadget

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq1rx7kief.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=garima.singh@microsoft.com \
    --cc=garimasigit@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@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

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git