git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Phillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Eric Sunshine <sunshine@sunshineco.com>,
	Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH] worktree: add -z option for list subcommand
Date: Mon, 28 Feb 2022 16:00:21 +0000	[thread overview]
Message-ID: <e90340b0-09da-bf3a-f8eb-47fa408c51f1@gmail.com> (raw)
In-Reply-To: <xmqqh78mesj6.fsf@gitster.g>

On 25/02/2022 17:59, Junio C Hamano wrote:
> "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:

> [...]
>>   	reason = worktree_lock_reason(wt);
>>   	if (reason && *reason) {
>>   		struct strbuf sb = STRBUF_INIT;
>> -		quote_c_style(reason, &sb, NULL, 0);
>> -		printf("locked %s\n", sb.buf);
>> +		if (line_terminator) {
>> +			quote_c_style(reason, &sb, NULL, 0);
>> +			reason = sb.buf;
>> +		}
>> +		printf("locked %s%c", reason, line_terminator);
> 
> OK.  I suspect write_name_quoted() may be a better fit that does not
> require us to have our own strbuf, but this should be OK.
> 
>>   		strbuf_release(&sb);
>>   	} else if (reason)
>> -		printf("locked\n");
>> +		printf("locked%c", line_terminator);
> 
> It is a shame that we need a special code path for an empty string
> given as the reason, only for the single SP after "locked", but we
> have to live with it, I guess.

We could have

	if (reason) {
		fputs("locked", stdout);
		if (*reason) {
			fputc(" ", stdout)
			write_name_quoted(reason, stdout, line_terminator);
		} else {
			fputc(line_terminator, stdout)
		
	}

which shares the code to print "locked" but I'm not sure it is any 
bettor overall though especially as write_name_quoted() means we only 
want to output a terminator when there is no reason text.


Best Wishes

Phillip

  parent reply	other threads:[~2022-02-28 16:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25 15:08 [PATCH] worktree: add -z option for list subcommand Phillip Wood via GitGitGadget
2022-02-25 17:59 ` Junio C Hamano
2022-02-28  8:35   ` Eric Sunshine
2022-02-28 16:10     ` Phillip Wood
2022-02-28 17:16     ` Junio C Hamano
2022-02-28 16:00   ` Phillip Wood [this message]
2022-02-28  8:16 ` Eric Sunshine
2022-02-28 11:08   ` Phillip Wood
2022-02-28  9:47 ` Jean-Noël Avila
2022-02-28 10:57   ` Phillip Wood
2022-03-31 16:21 ` [PATCH v2] " Phillip Wood via GitGitGadget
2022-03-31 20:37   ` Junio C Hamano
2022-04-04 15:47     ` Phillip Wood
2023-05-11  4:11     ` Eric Sunshine
  -- strict thread matches above, loose matches on Subject: below --
2021-01-05 10:29 [PATCH 5/7] worktree: `list` escape lock reason in --porcelain Phillip Wood
2021-01-05 11:02 ` [PATCH] worktree: add -z option for list subcommand Phillip Wood
2021-01-07  3:34   ` Eric Sunshine
2021-01-08 10:33     ` Phillip Wood
2021-01-10  7:27       ` Eric Sunshine

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=e90340b0-09da-bf3a-f8eb-47fa408c51f1@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=sunshine@sunshineco.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).