public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: git@vger•kernel.org, Christian Couder <chriscool@tuxfamily•org>
Subject: Re: [PATCH] merge & sequencer: turn "Conflicts:" hint into a comment
Date: Mon, 27 Oct 2014 13:59:18 -0700	[thread overview]
Message-ID: <xmqqsii9qleh.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqqegttfmg0.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Mon, 27 Oct 2014 10:32:15 -0700")

Junio C Hamano <gitster@pobox•com> writes:

>>> diff --git a/sequencer.c b/sequencer.c
>>> index 0f84bbe..1d97da3 100644
>>> --- a/sequencer.c
>>> +++ b/sequencer.c
>>> @@ -291,13 +291,12 @@ void append_conflicts_hint(struct strbuf *msgbuf)
>>>  {
>>>  	int i;
>>>  
>>> -	strbuf_addstr(msgbuf, "\nConflicts:\n");
>>> +	strbuf_addch(msgbuf, '\n');
>>> +	strbuf_commented_addf(msgbuf, "Conflicts:\n");
>>>  	for (i = 0; i < active_nr;) {
>>>  		const struct cache_entry *ce = active_cache[i++];
>>>  		if (ce_stage(ce)) {
>>> -			strbuf_addch(msgbuf, '\t');
>>> -			strbuf_addstr(msgbuf, ce->name);
>>> -			strbuf_addch(msgbuf, '\n');
>>> +			strbuf_commented_addf(msgbuf, "\t%s\n", ce->name);
>>
>> This ends up adding a space followed by a tab. Besides being redundant,
>> it makes my editor highlight it as a whitespace error. I realize this is
>> a pretty minor nit, though.
>
> Interesting ;-)
>
> I do not think it is too hard to teach strbuf_commented_addf() about
> the leading HT, but that would be a separate topic; if squashing the
> SP-HT to HT is worth doing for this codepath, doing it at that helper
> would benefit all callers.

-- >8 --
Subject: [PATCH] strbuf_add_lines(): avoid SP-HT sequence

The strbuf_add_commented_lines() function passes a pair of prefixes,
one for a line that has some meat on it, and the other for an empty
line.  The former is set to a comment char followed by a SP, while
the latter is set to just the comment char.  This is to give a SP
after the comment character, e.g. "# <user text>\n" and to avoid
emitting an unsightly "# \n" in its output.

Teach the machinery to also use the latter space-less prefix when
the payload line begins with a tab; otherwise we will end up showing
"# \t<user text>\n" which is similarly unsightly.

Signed-off-by: Junio C Hamano <gitster@pobox•com>
---
 strbuf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/strbuf.c b/strbuf.c
index 0346e74..88cafd4 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -229,7 +229,8 @@ static void add_lines(struct strbuf *out,
 		const char *next = memchr(buf, '\n', size);
 		next = next ? (next + 1) : (buf + size);
 
-		prefix = (prefix2 && buf[0] == '\n') ? prefix2 : prefix1;
+		prefix = ((prefix2 && (buf[0] == '\n' || buf[0] == '\t'))
+			  ? prefix2 : prefix1);
 		strbuf_addstr(out, prefix);
 		strbuf_add(out, buf, next - buf);
 		size -= next - buf;

  reply	other threads:[~2014-10-27 21:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 18:27 [PATCH] builtin/merge.c: drop a parameter that is never used Junio C Hamano
2014-10-24 19:37 ` Jonathan Nieder
2014-10-24 21:22 ` [PATCH] merge & sequencer: unify codepaths that write "Conflicts:" hint Junio C Hamano
2014-10-24 21:24   ` [PATCH] merge & sequencer: turn "Conflicts:" hint into a comment Junio C Hamano
2014-10-26 18:59     ` Jeff King
2014-10-27 17:32       ` Junio C Hamano
2014-10-27 20:59         ` Junio C Hamano [this message]
2014-10-28 22:21           ` Jeff King
2014-10-28  6:51         ` Christian Couder
2014-10-27 21:14       ` Jonathan Nieder
2014-10-28 22:22         ` Jeff King
2014-10-28 21:36 ` [PATCH v2 0/4] Turning Conflicts: hint into comment Junio C Hamano
2014-10-28 21:36   ` [PATCH v2 1/4] builtin/merge.c: drop a parameter that is never used Junio C Hamano
2014-10-28 21:36   ` [PATCH v2 2/4] merge & sequencer: unify codepaths that write "Conflicts:" hint Junio C Hamano
2014-10-28 21:36   ` [PATCH v2 3/4] builtin/commit.c: extract ignore_non_trailer() helper function Junio C Hamano
2014-10-28 21:36   ` [PATCH v2 4/4] merge & sequencer: turn "Conflicts:" hint into a comment Junio C Hamano

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=xmqqsii9qleh.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=chriscool@tuxfamily$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    --cc=peff@peff$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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