threads / patch / 33419

patch, 2 partsfmt-merge-msg: respect core.commentchar in people credits

Subject: [PATCH 1/2] fmt-merge-msg: respect core.commentchar in people credits

## tl;dr

12 messages between Apr 7, 2013 and Apr 21, 2013. Diffs are folded; open one to read it.

replies: 11people: 4as markdown or json

Ralf Thielow· Apr 7, 2013, 15:25 UTC · lore

Commit eff80a9 (Allow custom "comment char") introduced a custom comment character for commit messages but forgot to use it in people credits which can be a part of a commit message.

With this commit, the custom comment character is also used in people credits.

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
 builtin/fmt-merge-msg.c  |  6 +++---
 t/t6200-fmt-merge-msg.sh | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
Show changes to 2 files +21 −3

builtin/fmt-merge-msg.c, t/t6200-fmt-merge-msg.sh

diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 265a925..88df93a 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -287,10 +287,10 @@ static void credit_people(struct strbuf *out,
 	const char *me;
 
 	if (kind == 'a') {
-		label = "\n# By ";
+		label = "By";
 		me = git_author_info(IDENT_NO_DATE);
 	} else {
-		label = "\n# Via ";
+		label = "Via";
 		me = git_committer_info(IDENT_NO_DATE);
 	}
 
@@ -300,7 +300,7 @@ static void credit_people(struct strbuf *out,
 	     (me = skip_prefix(me, them->items->string)) != NULL &&
 	     skip_prefix(me, " <")))
 		return;
-	strbuf_addstr(out, label);
+	strbuf_addf(out, "\n%c %s ", comment_line_char, label);
 	add_people_count(out, them);
 }
 
diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh
index 992c2a0..84e10fd 100755
--- a/t/t6200-fmt-merge-msg.sh
+++ b/t/t6200-fmt-merge-msg.sh
@@ -180,6 +180,24 @@ test_expect_success 'merge.log=5 shows all 5 commits' '
 	test_cmp expected actual
 '
 
+test_expect_success '--log=5 with custom comment character' '
+	cat >expected <<-EOF &&
+	Merge branch ${apos}left${apos}
+
+	/ By Another Author (3) and A U Thor (2)
+	/ Via Another Committer
+	* left:
+	  Left #5
+	  Left #4
+	  Left #3
+	  Common #2
+	  Common #1
+	EOF
+
+	git -c core.commentchar="/" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'merge.log=0 disables shortlog' '
 	echo "Merge branch ${apos}left${apos}" >expected
 	git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
-- 
1.8.2.470.g21ccebe
Ralf Thielow· Apr 7, 2013, 15:25 UTC · re: Ralf Thielow · lore

[PATCH 2/2] fmt-merge-msg: use core.commentchar in tag signatures completely

Commit eff80a9 (Allow custom "comment char") introduced a custom comment character for commit messages but didn't use it completely in the tag signature part.

This commit fixes that.
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
 builtin/fmt-merge-msg.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Show changes to builtin/fmt-merge-msg.c +8 −4
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 88df93a..1c04070 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -503,14 +503,18 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
 		} else {
 			if (tag_number == 2) {
 				struct strbuf tagline = STRBUF_INIT;
-				strbuf_addf(&tagline, "\n# %s\n",
-					    origins.items[first_tag].string);
+				strbuf_addch(&tagline, '\n');
+				strbuf_add_commented_lines(&tagline,
+						origins.items[first_tag].string,
+						strlen(origins.items[first_tag].string));
 				strbuf_insert(&tagbuf, 0, tagline.buf,
 					      tagline.len);
 				strbuf_release(&tagline);
 			}
-			strbuf_addf(&tagbuf, "\n# %s\n",
-				    origins.items[i].string);
+			strbuf_addch(&tagbuf, '\n');
+			strbuf_add_commented_lines(&tagbuf,
+					origins.items[i].string,
+					strlen(origins.items[i].string));
 			fmt_tag_signature(&tagbuf, &sig, buf, len);
 		}
 		strbuf_release(&sig);
-- 
1.8.2.470.g21ccebe
Johannes Sixt· Apr 18, 2013, 06:42 UTC · re: Ralf Thielow · lore

t6200: avoid path mangling issue on Windows

From: Johannes Sixt <j6t@kdbg.org>

MSYS bash interprets the slash in the argument core.commentchar="/" as root directory and mangles it into a Windows style path. Use a different core.commentchar to dodge the issue.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 t/t6200-fmt-merge-msg.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to t/t6200-fmt-merge-msg.sh +3 −3
diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh
index e7e945d..54b5744 100755
--- a/t/t6200-fmt-merge-msg.sh
+++ b/t/t6200-fmt-merge-msg.sh
@@ -179,8 +179,8 @@ test_expect_success '--log=5 with custom comment character' '
 	cat >expected <<-EOF &&
 	Merge branch ${apos}left${apos}
 
-	/ By Another Author (3) and A U Thor (2)
-	/ Via Another Committer
+	x By Another Author (3) and A U Thor (2)
+	x Via Another Committer
 	* left:
 	  Left #5
 	  Left #4
@@ -189,7 +189,7 @@ test_expect_success '--log=5 with custom comment character' '
 	  Common #1
 	EOF
 
-	git -c core.commentchar="/" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
+	git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
 	test_cmp expected actual
 '
 
-- 
1.8.2.1.1678.gf713add
Junio C Hamano· Apr 18, 2013, 17:05 UTC · re: Johannes Sixt · lore

Re: t6200: avoid path mangling issue on Windows

Johannes Sixt <j.sixt@viscovery.net> writes:
Show 10 quoted lines
> From: Johannes Sixt <j6t@kdbg.org>
>
> MSYS bash interprets the slash in the argument core.commentchar="/"
> as root directory and mangles it into a Windows style path. Use a
> different core.commentchar to dodge the issue.
>
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ...
> -	git -c core.commentchar="/" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
> +	git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
Sigh... Again?

Are folks working on Msys bash aware that sometimes the users may want to say key=value on their command line without the value getting molested in any way and giving them some escape hatch would help them? Perhaps they have already decided that it is not feasible after thinking about the issue, in which case I do not have new ideas to offer.

I'll apply the patch as-is, but this feels really painful to the users.

Thanks.
Johannes Sixt· Apr 19, 2013, 05:48 UTC · re: Junio C Hamano · lore

Re: t6200: avoid path mangling issue on Windows

Am 4/18/2013 19:05, schrieb Junio C Hamano:
Show 21 quoted lines
> Johannes Sixt <j.sixt@viscovery.net> writes:
> 
>> From: Johannes Sixt <j6t@kdbg.org>
>>
>> MSYS bash interprets the slash in the argument core.commentchar="/"
>> as root directory and mangles it into a Windows style path. Use a
>> different core.commentchar to dodge the issue.
>>
>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
>> ...
>> -	git -c core.commentchar="/" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
>> +	git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
> 
> Sigh... Again?
> 
> Are folks working on Msys bash aware that sometimes the users may
> want to say key=value on their command line without the value
> getting molested in any way and giving them some escape hatch would
> help them?  Perhaps they have already decided that it is not
> feasible after thinking about the issue, in which case I do not have
> new ideas to offer.

What is "the issue"? And in which way would an escape hatch help us here? We would have to apply a patch anyway after a glitch like this shows up, because disabling path mangling whole-sale (if there were a method -- there is none currently) is a no-go in the context of our test suite, let a lone in our scripted tool set.

When "foo=/" appears on the command line, the most obvious interpretation of the slash for a program without mind-reading mode is that it is an absolute path, and then path mangling must happen (if and only if the invoked program is a non-MSYS program such as git).

> I'll apply the patch as-is, but this feels really painful to the
> users.
No, generally, path mangling is a service for the user.
-- Hannes
Junio C Hamano· Apr 19, 2013, 16:33 UTC · re: Johannes Sixt · lore

Re: t6200: avoid path mangling issue on Windows

Johannes Sixt <j.sixt@viscovery.net> writes:
Show 24 quoted lines
> Am 4/18/2013 19:05, schrieb Junio C Hamano:
>> Johannes Sixt <j.sixt@viscovery.net> writes:
>> 
>>> From: Johannes Sixt <j6t@kdbg.org>
>>>
>>> MSYS bash interprets the slash in the argument core.commentchar="/"
>>> as root directory and mangles it into a Windows style path. Use a
>>> different core.commentchar to dodge the issue.
>>>
>>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
>>> ...
>>> -	git -c core.commentchar="/" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
>>> +	git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
>> 
>> Sigh... Again?
>> 
>> Are folks working on Msys bash aware that sometimes the users may
>> want to say key=value on their command line without the value
>> getting molested in any way and giving them some escape hatch would
>> help them?  Perhaps they have already decided that it is not
>> feasible after thinking about the issue, in which case I do not have
>> new ideas to offer.
>
> What is "the issue"? And in which way would an escape hatch help us here?

When the user passes key=value and value begins with a slash, value may be a path in the filesystem very often, and adjusting it to the local filesystem convention helps Windows users a lot.

But there are cases outside that very often when the user wants the value passed literally. There seems to be no way to do so.

That is the issue I was wondering. If there is a clean solution to disable path mangling per token, we could cleanly solve it.

For example, while making sure that a value that begins with slash in normal cases is still adjusted, i.e. mangling all of the following,

	xyzzy key=/a/b/c
        xyzzy key="/a/b/c"
        value=/a/b/c; xyzzy key="$value"
        value=/a/b/c; xyzzy "key=$value"

if bash could be told with a very unnatural and not so hard to type way that the particular value is not to be mangled, e.g.

	xyzzy key="""/a/b/c"""
        value=/a/b/c; xyzzy """key=$value"""

which a normal bash would interpret as the concatenation of an empty string inside dq, /a/b/c/ (or key=$value) inside dq, and an empty string inside dq, which is the same as /a/b/c (or key=$value) inside dq, it would help the less common case. Nobody would type a string surrounded by two empty strings to be concatenated on purpose (i.e. very unnatural) and typing the same dq four more times than you would normally do is not too much of a hassle (not so hard to type). The problematic case can then be fixed to

	git -c core.commentchar="""/""" fmt-merge-msg ...
and it will work the same way on and off Windows.
Johannes Sixt· Apr 19, 2013, 19:46 UTC · re: Junio C Hamano · lore

Re: t6200: avoid path mangling issue on Windows

Am 19.04.2013 18:33, schrieb Junio C Hamano:
Show 38 quoted lines
> Johannes Sixt <j.sixt@viscovery.net> writes:
> 
>> Am 4/18/2013 19:05, schrieb Junio C Hamano:
>>> Johannes Sixt <j.sixt@viscovery.net> writes:
>>>
>>>> From: Johannes Sixt <j6t@kdbg.org>
>>>>
>>>> MSYS bash interprets the slash in the argument core.commentchar="/"
>>>> as root directory and mangles it into a Windows style path. Use a
>>>> different core.commentchar to dodge the issue.
>>>>
>>>> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
>>>> ...
>>>> -	git -c core.commentchar="/" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
>>>> +	git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
>>>
>>> Sigh... Again?
>>>
>>> Are folks working on Msys bash aware that sometimes the users may
>>> want to say key=value on their command line without the value
>>> getting molested in any way and giving them some escape hatch would
>>> help them?  Perhaps they have already decided that it is not
>>> feasible after thinking about the issue, in which case I do not have
>>> new ideas to offer.
>>
>> What is "the issue"? And in which way would an escape hatch help us here?
> 
> When the user passes key=value and value begins with a slash, value
> may be a path in the filesystem very often, and adjusting it to the
> local filesystem convention helps Windows users a lot.
> 
> But there are cases outside that very often when the user wants the
> value passed literally.  There seems to be no way to do so.
> ...
> if bash could be told with a very unnatural and not so hard to type
> way that the particular value is not to be mangled, e.g.
> 
> 	xyzzy key="""/a/b/c"""

I'll not argue whether such a feature would make sense or not, or whether it can be implemented, because it is aimed at the user, but misses one important point: It does in no way help our development process.

A patch auther whose first instinct is to write 'foo=/' will never write 'foo=x', let alone 'foo="""/"""'. Someone will have to discover the issue eventually and write a patch to fix it, and someone will have to apply it.

I don't think that we can do anything about it.
-- Hannes
Junio C Hamano· Apr 19, 2013, 21:22 UTC · re: Johannes Sixt · lore

Re: t6200: avoid path mangling issue on Windows

Johannes Sixt <j6t@kdbg.org> writes:
> A patch auther whose first instinct is to write 'foo=/' will never write
> 'foo=x', let alone 'foo="""/"""'. Someone will have to discover the
> issue eventually and write a patch to fix it, and someone will have to
> apply it.

That is a separate issue. Didn't I say I'll apply it as-is at the very beginning?

Our _tests_ can afford to use an unrealistic setting like
    git -c core.commentchar="x" fmt-merge-msg

to work it around, because the tests do not _care_ how the final outcome looks like. It only cares what we specified gets used.

But a _real user_ who wants to use a slash there has no way of doing so. It is still not realistic, as it is more likely that she would want to use a double-slash, but that would not fit in a commentchar, and she is a lot more likely to have it in the configuration file, but I wouldn't imagine that there are things other than "-c var=val" that are more commonly given on the command line that share the same pain point as this one.

That is what I meant by "feels painful to the users" and wondered if bash on Windows can be more helpful to them.

Jonathan Nieder· Apr 21, 2013, 00:05 UTC · re: Junio C Hamano · lore

Re: t6200: avoid path mangling issue on Windows

Junio C Hamano wrote:
> But a _real user_ who wants to use a slash there has no way of doing
> so.

Doesn't foo=// do that in the msys world? If I am reading mingw/msys/rt/src/winsup/cygwin/path.cc correctly then the way to pass a true double-slash is foo=///.

Jonathan
Johannes Sixt· Apr 21, 2013, 06:22 UTC · re: Jonathan Nieder · lore

Re: t6200: avoid path mangling issue on Windows

Am 21.04.2013 02:05, schrieb Jonathan Nieder:
Show 8 quoted lines
> Junio C Hamano wrote:
> 
>> But a _real user_ who wants to use a slash there has no way of doing
>> so.
> 
> Doesn't foo=// do that in the msys world?  If I am reading
> mingw/msys/rt/src/winsup/cygwin/path.cc correctly then the way to pass
> a true double-slash is foo=///.
That would be totally unexpected.
-- Hannes
Jonathan Nieder· Apr 21, 2013, 06:35 UTC · re: Johannes Sixt · lore

Re: t6200: avoid path mangling issue on Windows

Johannes Sixt wrote:
> Am 21.04.2013 02:05, schrieb Jonathan Nieder:
>> Junio C Hamano wrote:
Show 8 quoted lines
>>> But a _real user_ who wants to use a slash there has no way of doing
>>> so.
>>
>> Doesn't foo=// do that in the msys world?  If I am reading
>> mingw/msys/rt/src/winsup/cygwin/path.cc correctly then the way to pass
>> a true double-slash is foo=///.
>
> That would be totally unexpected.

There is an exception to the path mangling for //unc/paths, if that's what you mean.

>From [1]:
  if (path[0] == '/' && path[1] == '/')
    {
      int tidx = 2;
      while (spath[tidx] && spath[tidx] == '/')
	  tidx++;
      if (strchr (&spath[tidx], '/'))
	{
	  retpathcpy (spath);
	}
      else
	{
	  retpathcpy (&spath[1]);
	}
      return ScrubRetpath (retpath);
    }

I haven't tested, since I don't have easy access to a Windows test setup.

Regards, Jonathan

[1] http://mingw.cvs.sourceforge.net/viewvc/mingw/msys/rt/src/winsup/cygwin/path.cc?content-type=text%2Fplain
Junio C Hamano· Apr 21, 2013, 07:12 UTC · re: Jonathan Nieder · lore

Re: t6200: avoid path mangling issue on Windows

Jonathan Nieder <jrnieder@gmail.com> writes:
Show 6 quoted lines
> Junio C Hamano wrote:
>
>> But a _real user_ who wants to use a slash there has no way of doing
>> so.
>
> Doesn't foo=// do that in the msys world?
"that" refers to...?  Do you mean:
    $ value=/; mycmd key="$value"
    breaks msys, but you can say
    $ value=//; mycmd key="$value"
    instead to pass a value that is a single slash.

then that is not a valid workaround; it would work differently between Windows (passes one slash?) and everybody else (passes two slashes).

I do not mean to say the "'' (empty string) and what you want to say and '' (empty string) concatenated together" I suggested in the previous message is a workable (let alone the best) proposition, but if

    $ value=/; mycmd key=''"$value"''

worked as a way to temporarily turn off the path mangling, it at least would be a usable workaround that would work the same way between Windows and everybody else.

← back to recent threads