git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Log messages beginning # and git rebase -i
@ 2015-07-27 11:38 Ed Avis
  2015-07-27 23:25 ` Eric Sunshine
  0 siblings, 1 reply; 18+ messages in thread
From: Ed Avis @ 2015-07-27 11:38 UTC (permalink / raw
  To: git

git commit will happily let you specify log messages beginning with #.
But then on git rebase -i, when squashing some commits, the editing for the
combined log message treats lines beginning with # as comments.  This means
that if you are not careful the commit message can get lost on rebasing.

I suggest that git rebase should add an extra space at the start of existing
log message lines which begin with #.  That is a bit of a kludge but it is
better than losing them because they got mixed up with comments.

-- 
Ed Avis <eda@waniasset.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-27 11:38 Log messages beginning # and git rebase -i Ed Avis
@ 2015-07-27 23:25 ` Eric Sunshine
  2015-07-28  0:53   ` Duy Nguyen
  2015-07-28  9:51   ` Ed Avis
  0 siblings, 2 replies; 18+ messages in thread
From: Eric Sunshine @ 2015-07-27 23:25 UTC (permalink / raw
  To: Ed Avis; +Cc: Git List

On Mon, Jul 27, 2015 at 7:38 AM, Ed Avis <eda@waniasset.com> wrote:
> git commit will happily let you specify log messages beginning with #.
> But then on git rebase -i, when squashing some commits, the editing for the
> combined log message treats lines beginning with # as comments.  This means
> that if you are not careful the commit message can get lost on rebasing.
>
> I suggest that git rebase should add an extra space at the start of existing
> log message lines which begin with #.  That is a bit of a kludge but it is
> better than losing them because they got mixed up with comments.

'git rebase --interactive' respects the core.commentChar configuration
variable, which you can set to some value other than '#'.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-27 23:25 ` Eric Sunshine
@ 2015-07-28  0:53   ` Duy Nguyen
  2015-07-28  9:51   ` Ed Avis
  1 sibling, 0 replies; 18+ messages in thread
From: Duy Nguyen @ 2015-07-28  0:53 UTC (permalink / raw
  To: Eric Sunshine; +Cc: Ed Avis, Git List

On Tue, Jul 28, 2015 at 6:25 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Mon, Jul 27, 2015 at 7:38 AM, Ed Avis <eda@waniasset.com> wrote:
>> git commit will happily let you specify log messages beginning with #.
>> But then on git rebase -i, when squashing some commits, the editing for the
>> combined log message treats lines beginning with # as comments.  This means
>> that if you are not careful the commit message can get lost on rebasing.
>>
>> I suggest that git rebase should add an extra space at the start of existing
>> log message lines which begin with #.  That is a bit of a kludge but it is
>> better than losing them because they got mixed up with comments.
>
> 'git rebase --interactive' respects the core.commentChar configuration
> variable, which you can set to some value other than '#'.

Yeah. I recommend setting it to 'auto' so it will pick an unused
character as separator (most of the time, don't push it too hard)
-- 
Duy

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-27 23:25 ` Eric Sunshine
  2015-07-28  0:53   ` Duy Nguyen
@ 2015-07-28  9:51   ` Ed Avis
  2015-07-28 15:25     ` Matthieu Moy
  1 sibling, 1 reply; 18+ messages in thread
From: Ed Avis @ 2015-07-28  9:51 UTC (permalink / raw
  To: git

Eric Sunshine <sunshine <at> sunshineco.com> writes:

>>the editing for the
>>combined log message treats lines beginning with # as comments.  This means
>>that if you are not careful the commit message can get lost on rebasing.
>>
>>I suggest that git rebase should add an extra space at the start

>'git rebase --interactive' respects the core.commentChar configuration
>variable, which you can set to some value other than '#'.

I was thinking of the default configuration.  But you are right, this applies
to whatever the comment character is - so if commentChar is set to * for
example, then log lines beginning with * should get an extra space prepended
in git rebase --interactive so that they don't get lost.

-- 
Ed Avis <eda@waniasset.com> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-28  9:51   ` Ed Avis
@ 2015-07-28 15:25     ` Matthieu Moy
  2015-07-28 16:30       ` Junio C Hamano
  0 siblings, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2015-07-28 15:25 UTC (permalink / raw
  To: Ed Avis; +Cc: git

Ed Avis <eda@waniasset.com> writes:

> Eric Sunshine <sunshine <at> sunshineco.com> writes:
>
>>>the editing for the
>>>combined log message treats lines beginning with # as comments.  This means
>>>that if you are not careful the commit message can get lost on rebasing.
>>>
>>>I suggest that git rebase should add an extra space at the start
>
>>'git rebase --interactive' respects the core.commentChar configuration
>>variable, which you can set to some value other than '#'.
>
> I was thinking of the default configuration.  But you are right, this applies
> to whatever the comment character is - so if commentChar is set to * for
> example, then log lines beginning with * should get an extra space prepended
> in git rebase --interactive so that they don't get lost.

Actually, is there any reason why we do not allow a simple escaping like

\# this is a line starting with #
\\ this is a line starting with \
# this is a comment

?

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-28 15:25     ` Matthieu Moy
@ 2015-07-28 16:30       ` Junio C Hamano
  2015-07-28 16:40         ` Ed Avis
  2015-07-28 17:48         ` Matthieu Moy
  0 siblings, 2 replies; 18+ messages in thread
From: Junio C Hamano @ 2015-07-28 16:30 UTC (permalink / raw
  To: Matthieu Moy; +Cc: Ed Avis, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Ed Avis <eda@waniasset.com> writes:
>
>> Eric Sunshine <sunshine <at> sunshineco.com> writes:
>>
>>>>the editing for the
>>>>combined log message treats lines beginning with # as comments.  This means
>>>>that if you are not careful the commit message can get lost on rebasing.
>>>>
>>>>I suggest that git rebase should add an extra space at the start
>>
>>>'git rebase --interactive' respects the core.commentChar configuration
>>>variable, which you can set to some value other than '#'.
>>
>> I was thinking of the default configuration.  But you are right, this applies
>> to whatever the comment character is - so if commentChar is set to * for
>> example, then log lines beginning with * should get an extra space prepended
>> in git rebase --interactive so that they don't get lost.
>
> Actually, is there any reason why we do not allow a simple escaping like
>
> \# this is a line starting with #
> \\ this is a line starting with \
> # this is a comment

What are we trying to achieve?

Munging the original "# I want this line intact" to any other form
like " # I want this..." is as bad as losing it.  If the user wants
whatever she types in the resulting commit literally, there is the
"--cleanup=<choice>" option, no?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-28 16:30       ` Junio C Hamano
@ 2015-07-28 16:40         ` Ed Avis
  2015-07-28 17:48         ` Matthieu Moy
  1 sibling, 0 replies; 18+ messages in thread
From: Ed Avis @ 2015-07-28 16:40 UTC (permalink / raw
  To: git

I was considering this case:

- git commit -a '-m# characters are now handled OK'
- hack, hack
- git commit -a '-mWhoops, fixed last commit'
- run git-rebase -i
- squash the second commit into the first
- when prompted for the log message for the combined change,
  delete the "Whoops, fixed last commit" line but leave the first line

That will accidentally lose the first log message, assuming commentChar=#.
git-rebase -i should be a bit friendlier and not bring up an editing window
where the log message ends up being one of the comments.

I suggested it could munge the message with an extra space character, but I
agree that is a bit unpleasant.  Perhaps better would be

   % git-rebase -i
   error: commit abcde has log message beginning with '#', which is the
          current setting of commentChar.  This means that the interactive
          editing of the log message will not work.  Please set commentChar
          to some other value (such as 'auto') in your git configuration
          to be able to rebase interactively.

The current behaviour is a bit of a trap for the unwary, and anyway it leaves
no way to specify keeping the existing log message (which begins #).

-- 
Ed Avis <eda@waniasset.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-28 16:30       ` Junio C Hamano
  2015-07-28 16:40         ` Ed Avis
@ 2015-07-28 17:48         ` Matthieu Moy
  2015-07-28 18:44           ` Junio C Hamano
  2015-07-29 10:47           ` Log messages beginning # and git rebase -i Duy Nguyen
  1 sibling, 2 replies; 18+ messages in thread
From: Matthieu Moy @ 2015-07-28 17:48 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Ed Avis, git

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

> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>
>> Actually, is there any reason why we do not allow a simple escaping like
>>
>> \# this is a line starting with #
>> \\ this is a line starting with \
>> # this is a comment
>
> What are we trying to achieve?

What I would like would be a simple way to:

1) Allow any commit message to be typed. If I want to talk about #include
   in my commit message, I should have an easy way to do so.

2) Allow commands that pop an editor on an existing message to preserve
   the original message, whatever it is. Well, actually Git even strips
   # lines even if it doesn't pop the editor.

Currently, I can for example:

$ git commit -m "#include" -a
[detached HEAD 0f36ec9] #include
 1 file changed, 1 insertion(+), 1 deletion(-)
$ GIT_EDITOR=touch git commit --amend
Aborting commit due to empty commit message.

A simple escaping scheme like the above can solve both points:

1) If I want to talk about #include in my commit message, I can spell it
   \#include and Git would remove the \. The same way, if I want to tell
   my shell about a " inside a string, I can write "double-quote:\"."
   and get a litteral double-quote.

2) A command that pops an editor could add the escaping where needed,
   pop the editor, and then unescape. A command like "pick" in "rebase
   -i" could escape the message, and feed it to "git commit" which would
   unescape it.

> Munging the original "# I want this line intact" to any other form
> like " # I want this..." is as bad as losing it.

It would modify it only when shown in the text editor. The object
database would contain unescaped message, hence "git log" would show it
unescaped for example.

backslash-escaping special characters seems very natural to me, and I
guess it would be for most computer-scientists. If I have problem with a
special character, the first thing I would try would be to add a
backslash in front of it.

> If the user wants whatever she types in the resulting commit
> literally, there is the "--cleanup=<choice>" option, no?

$ GIT_EDITOR=touch git commit --cleanup=verbatim
[detached HEAD 1b136a7] # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want 
to. # An empty message aborts the commit. # HEAD detached from 5e70007 # Changes to be committed: #     modified:   foo.txt # # Changes not staged for commit
: #     modified:   foo.txt # # Untracked files: #      last-synchro.txt #                                                                                  
 1 file changed, 1 insertion(+), 1 deletion(-)

You really don't want that in day-to-day use.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-28 17:48         ` Matthieu Moy
@ 2015-07-28 18:44           ` Junio C Hamano
  2015-07-29 10:17             ` Matthieu Moy
  2019-04-22 10:05             ` [PATCH] allow commentChars in commit messages Corentin BOMPARD
  2015-07-29 10:47           ` Log messages beginning # and git rebase -i Duy Nguyen
  1 sibling, 2 replies; 18+ messages in thread
From: Junio C Hamano @ 2015-07-28 18:44 UTC (permalink / raw
  To: Matthieu Moy; +Cc: Ed Avis, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> A simple escaping scheme like the above can solve both points:
>
> 1) If I want to talk about #include in my commit message, I can spell it
>    \#include and Git would remove the \. The same way, if I want to tell
>    my shell about a " inside a string, I can write "double-quote:\"."
>    and get a litteral double-quote.
>
> 2) A command that pops an editor could add the escaping where needed,
>    pop the editor, and then unescape. A command like "pick" in "rebase
>    -i" could escape the message, and feed it to "git commit" which would
>    unescape it.
> ...
> backslash-escaping special characters seems very natural to me,...

OK.  So the proposal on the table is that a backslash at the
beginning of a line is stripped.

Stripping part should look like this.  To make it work for things
like "git commit --amend", you would need to prefix any line that
comes from the payload that begins with the core.commentchar or a
backslash with a backslash.

diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1259ed7..39ecb92 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -52,6 +52,11 @@ void stripspace(struct strbuf *sb, int skip_comments)
 		}
 		newlen = cleanup(sb->buf + i, len);
 
+		if (newlen && sb->buf[i] == '\\') {
+			i++;
+			newlen--;
+		}
+
 		/* Not just an empty line? */
 		if (newlen) {
 			if (empties > 0 && j > 0)

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-28 18:44           ` Junio C Hamano
@ 2015-07-29 10:17             ` Matthieu Moy
  2015-07-29 10:19               ` Ed Avis
  2019-04-22 10:05             ` [PATCH] allow commentChars in commit messages Corentin BOMPARD
  1 sibling, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2015-07-29 10:17 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Ed Avis, git

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

> OK.  So the proposal on the table is that a backslash at the
> beginning of a line is stripped.

Yes.

> Stripping part should look like this.

Thanks.

> To make it work for things like "git commit --amend", you would need
> to prefix any line that comes from the payload that begins with the
> core.commentchar or a backslash with a backslash.

That's it, probably the hardest part. No Git time budget for now, but
I'm adding this here in case I get time or a student to work on it:
http://git.wiki.kernel.org/index.php/SmallProjectsIdeas

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-29 10:17             ` Matthieu Moy
@ 2015-07-29 10:19               ` Ed Avis
  0 siblings, 0 replies; 18+ messages in thread
From: Ed Avis @ 2015-07-29 10:19 UTC (permalink / raw
  To: git

Thank you for looking into this.

-- 
Ed Avis <eda@waniasset.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-28 17:48         ` Matthieu Moy
  2015-07-28 18:44           ` Junio C Hamano
@ 2015-07-29 10:47           ` Duy Nguyen
  2015-07-29 12:17             ` Matthieu Moy
  1 sibling, 1 reply; 18+ messages in thread
From: Duy Nguyen @ 2015-07-29 10:47 UTC (permalink / raw
  To: Matthieu Moy; +Cc: Junio C Hamano, Ed Avis, Git Mailing List

On Wed, Jul 29, 2015 at 12:48 AM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
>> If the user wants whatever she types in the resulting commit
>> literally, there is the "--cleanup=<choice>" option, no?
>
> $ GIT_EDITOR=touch git commit --cleanup=verbatim
> [detached HEAD 1b136a7] # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want
> to. # An empty message aborts the commit. # HEAD detached from 5e70007 # Changes to be committed: #     modified:   foo.txt # # Changes not staged for commit
> : #     modified:   foo.txt # # Untracked files: #      last-synchro.txt #
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> You really don't want that in day-to-day use.

How about --cleanup=scissors? The chance that you have the same cut
line in your commit message is really low, compared to having comment
characters.
-- 
Duy

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-29 10:47           ` Log messages beginning # and git rebase -i Duy Nguyen
@ 2015-07-29 12:17             ` Matthieu Moy
  2015-07-29 12:47               ` Duy Nguyen
  2015-07-29 15:54               ` Junio C Hamano
  0 siblings, 2 replies; 18+ messages in thread
From: Matthieu Moy @ 2015-07-29 12:17 UTC (permalink / raw
  To: Duy Nguyen; +Cc: Junio C Hamano, Ed Avis, Git Mailing List

Duy Nguyen <pclouds@gmail.com> writes:

> On Wed, Jul 29, 2015 at 12:48 AM, Matthieu Moy
> <Matthieu.Moy@grenoble-inp.fr> wrote:
>>> If the user wants whatever she types in the resulting commit
>>> literally, there is the "--cleanup=<choice>" option, no?
>>
>> $ GIT_EDITOR=touch git commit --cleanup=verbatim
>> [detached HEAD 1b136a7] # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want
>> to. # An empty message aborts the commit. # HEAD detached from 5e70007 # Changes to be committed: #     modified:   foo.txt # # Changes not staged for commit
>> : #     modified:   foo.txt # # Untracked files: #      last-synchro.txt #
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> You really don't want that in day-to-day use.
>
> How about --cleanup=scissors?

I can read this in two different ways:

1) Keeping git as-is and suggest users to use --cleanup=scissors

   This has the same problem as --cleanup=verbatim: it doesn't work as-is
   since Git doesn't insert the scissors. You can hack around it by
   adding them by yourself when you need it, but it's really not
   convenient. You have to anticipate that you're going to require a #
   and call commit with --cleanup=scissors, add the scissors. And repeat
   it if you need to "commit --amend".

2) Modify Git to add scissors by default, and use --cleanup=scissors by
   default.
 
   This is actually more or less what SVN does: it inserts a line
   "--This line, and those below, will be ignored--", and the equivalent
   of what Git adds as comments in the template is inserted below this
   line.

I don't think option 1) is good. The fact that we have the --cleanup=
option shouldn't serve as an excuse to do nothing. I'd be fine with
option 2), but I find it much more intrusive than to allow a simple
backslash-escaping as I suggest.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-29 12:17             ` Matthieu Moy
@ 2015-07-29 12:47               ` Duy Nguyen
  2015-07-29 15:54               ` Junio C Hamano
  1 sibling, 0 replies; 18+ messages in thread
From: Duy Nguyen @ 2015-07-29 12:47 UTC (permalink / raw
  To: Matthieu Moy; +Cc: Junio C Hamano, Ed Avis, Git Mailing List

On Wed, Jul 29, 2015 at 7:17 PM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
> Duy Nguyen <pclouds@gmail.com> writes:
>
>> On Wed, Jul 29, 2015 at 12:48 AM, Matthieu Moy
>> <Matthieu.Moy@grenoble-inp.fr> wrote:
>>>> If the user wants whatever she types in the resulting commit
>>>> literally, there is the "--cleanup=<choice>" option, no?
>>>
>>> $ GIT_EDITOR=touch git commit --cleanup=verbatim
>>> [detached HEAD 1b136a7] # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want
>>> to. # An empty message aborts the commit. # HEAD detached from 5e70007 # Changes to be committed: #     modified:   foo.txt # # Changes not staged for commit
>>> : #     modified:   foo.txt # # Untracked files: #      last-synchro.txt #
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> You really don't want that in day-to-day use.
>>
>> How about --cleanup=scissors?
>
> I can read this in two different ways:
>
> 1) Keeping git as-is and suggest users to use --cleanup=scissors
>
>    This has the same problem as --cleanup=verbatim: it doesn't work as-is
>    since Git doesn't insert the scissors. You can hack around it by
>    adding them by yourself when you need it, but it's really not
>    convenient. You have to anticipate that you're going to require a #
>    and call commit with --cleanup=scissors, add the scissors. And repeat
>    it if you need to "commit --amend".
>
> 2) Modify Git to add scissors by default, and use --cleanup=scissors by
>    default.
>
>    This is actually more or less what SVN does: it inserts a line
>    "--This line, and those below, will be ignored--", and the equivalent
>    of what Git adds as comments in the template is inserted below this
>    line.
>
> I don't think option 1) is good. The fact that we have the --cleanup=
> option shouldn't serve as an excuse to do nothing. I'd be fine with
> option 2), but I find it much more intrusive than to allow a simple
> backslash-escaping as I suggest.

auto backslashing could cause some annoyance. Emacs supports
rearranging a paragraph to fit in a fixed text column. This generated
backslash may be moved around, no longer at the beginning of the line,
and it will remain in the commit message. I don't know how popular
this feature is outside emacs.

Having said that, even scissors has its own (and probably bigger)
problem: when you commit after conflict resolution, git inserts a
"Conflicts:" paragraph, prepended by core.commentChar. With default
settings, it serves as a reminder, but will be automatically stripped.
With scissors, it stays by default because it's placed before the
scissor line.
-- 
Duy

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-29 12:17             ` Matthieu Moy
  2015-07-29 12:47               ` Duy Nguyen
@ 2015-07-29 15:54               ` Junio C Hamano
  2015-07-29 16:03                 ` Matthieu Moy
  1 sibling, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2015-07-29 15:54 UTC (permalink / raw
  To: Matthieu Moy; +Cc: Duy Nguyen, Ed Avis, Git Mailing List

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Duy Nguyen <pclouds@gmail.com> writes:
>
>> On Wed, Jul 29, 2015 at 12:48 AM, Matthieu Moy
>> <Matthieu.Moy@grenoble-inp.fr> wrote:
>>>> If the user wants whatever she types in the resulting commit
>>>> literally, there is the "--cleanup=<choice>" option, no?
>>>
>>> $ GIT_EDITOR=touch git commit --cleanup=verbatim
>>> [detached HEAD 1b136a7] # Please enter the commit message for your
>>> changes. Lines starting # with '#' will be kept; you may remove
>>> them yourself if you want
>>> to. # An empty message aborts the commit. # HEAD detached from
>>> 5e70007 # Changes to be committed: # modified: foo.txt # # Changes
>>> not staged for commit
>>> : #     modified:   foo.txt # # Untracked files: #      last-synchro.txt #
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> You really don't want that in day-to-day use.

I do not quite follow this example.

The user said "I'll be responsible for cleaning up" by giving the
option.  It is up to the user to use an editor that is something a
bit more intelligent than "touch" to remove the instructional
comments meant for humans after reading them.

> 2) Modify Git to add scissors by default, and use --cleanup=scissors by
>    default.

I just did "$ git commit --amend --cleanup=scissors" (with and
without --amend) and it seems to do exactly that ;-).

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-29 15:54               ` Junio C Hamano
@ 2015-07-29 16:03                 ` Matthieu Moy
  2015-07-29 17:02                   ` Junio C Hamano
  0 siblings, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2015-07-29 16:03 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Duy Nguyen, Ed Avis, Git Mailing List

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

> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>
>> Duy Nguyen <pclouds@gmail.com> writes:
>>
>>> On Wed, Jul 29, 2015 at 12:48 AM, Matthieu Moy
>>> <Matthieu.Moy@grenoble-inp.fr> wrote:
>>>>> If the user wants whatever she types in the resulting commit
>>>>> literally, there is the "--cleanup=<choice>" option, no?
>>>>
>>>> $ GIT_EDITOR=touch git commit --cleanup=verbatim
>>>> [detached HEAD 1b136a7] # Please enter the commit message for your
>>>> changes. Lines starting # with '#' will be kept; you may remove
>>>> them yourself if you want
>>>> to. # An empty message aborts the commit. # HEAD detached from
>>>> 5e70007 # Changes to be committed: # modified: foo.txt # # Changes
>>>> not staged for commit
>>>> : #     modified:   foo.txt # # Untracked files: #      last-synchro.txt #
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> You really don't want that in day-to-day use.
>
> I do not quite follow this example.
>
> The user said "I'll be responsible for cleaning up" by giving the
> option.  It is up to the user to use an editor that is something a
> bit more intelligent than "touch" to remove the instructional
> comments meant for humans after reading them.

Yes, --cleanup=verbatim does what it says it does. Now, my claim is that
it does not answer the use-case "I want an easy way to talk about # in a
commit message". First, you have to specify --cleanup=verbatim _before_
typing the message, hence before knowing that you may need a #.

Then, as you say, it is up to the user to remove things that Git has
added. Why would we ask the user to do this when we have a way to have
the tool do it?

>> 2) Modify Git to add scissors by default, and use --cleanup=scissors by
>>    default.
>
> I just did "$ git commit --amend --cleanup=scissors" (with and
> without --amend) and it seems to do exactly that ;-).

Ah, I did my test in the same repo I messed-up with --cleanup=verbatim.
It's better than I thought then. So a viable alternative to the
backslas-escaping would be to change commit.cleanup to scissors by
default.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Log messages beginning # and git rebase -i
  2015-07-29 16:03                 ` Matthieu Moy
@ 2015-07-29 17:02                   ` Junio C Hamano
  0 siblings, 0 replies; 18+ messages in thread
From: Junio C Hamano @ 2015-07-29 17:02 UTC (permalink / raw
  To: Matthieu Moy; +Cc: Duy Nguyen, Ed Avis, Git Mailing List

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Then, as you say, it is up to the user to remove things that Git has
> added. Why would we ask the user to do this when we have a way to have
> the tool do it?

The timeline of development, perhaps?  I thought cleanup=scissors was
a fairly recent invention that hasn't been used widely yet.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH] allow commentChars in commit messages
  2015-07-28 18:44           ` Junio C Hamano
  2015-07-29 10:17             ` Matthieu Moy
@ 2019-04-22 10:05             ` Corentin BOMPARD
  1 sibling, 0 replies; 18+ messages in thread
From: Corentin BOMPARD @ 2019-04-22 10:05 UTC (permalink / raw
  To: gitster
  Cc: Matthieu.Moy, eda, git, Corentin Bompard, Nathan BERBEZIER,
	Pablo CHABANNE, Matthieu MOY

From: Corentin Bompard <corentin.bompard@etu.univ-lyon1.fr>

Add new argument which permits stripspace to escape backslashes
in order to have commit messages which begins with commentChars
and backslashes.

Add new function strbuf_addbackslash which adds a backslash before
commentChars and other backslashes used by git commit --amend
which prevents escaping the commit message lines which starts with
a commentChar.

Signed-off-by: Corentin BOMPARD <corentin.bompard@etu.univ-lyon1.fr>
Signed-off-by: Nathan BERBEZIER <nathan.berbezier@etu.univ-lyon1.fr>
Signed-off-by: Pablo CHABANNE <pablo.chabanne@etu.univ-lyon1.fr>
Signed-off-by: Matthieu MOY <matthieu.moy@univ-lyon1.fr>
---
 
 builtin/am.c                       |  2 +-
 builtin/branch.c                   |  2 +-
 builtin/commit.c                   |  8 ++-
 builtin/merge.c                    |  2 +-
 builtin/notes.c                    |  6 +-
 builtin/stripspace.c               |  2 +-
 builtin/tag.c                      |  2 +-
 rebase-interactive.c               |  2 +-
 sequencer.c                        |  6 +-
 strbuf.c                           | 64 +++++++++++++++++++-
 strbuf.h                           |  8 ++-
 t/t7526-commit-message-comments.sh | 93 ++++++++++++++++++++++++++++++
 12 files changed, 180 insertions(+), 17 deletions(-)
 create mode 100755 t/t7526-commit-message-comments.sh

diff --git a/builtin/am.c b/builtin/am.c
index 58a2aef28..58817ab90 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1212,7 +1212,7 @@ static int parse_mail(struct am_state *state, const char *mail)
 
 	strbuf_addstr(&msg, "\n\n");
 	strbuf_addbuf(&msg, &mi.log_message);
-	strbuf_stripspace(&msg, 0);
+	strbuf_stripspace(&msg, 0, 0);
 
 	assert(!state->author_name);
 	state->author_name = strbuf_detach(&author_name, NULL);
diff --git a/builtin/branch.c b/builtin/branch.c
index 1be727209..0bfb17fc3 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -568,7 +568,7 @@ static int edit_branch_description(const char *branch_name)
 		strbuf_release(&buf);
 		return -1;
 	}
-	strbuf_stripspace(&buf, 1);
+	strbuf_stripspace(&buf, 1, 0);
 
 	strbuf_addf(&name, "branch.%s.description", branch_name);
 	git_config_set(name.buf, buf.len ? buf.buf : NULL);
diff --git a/builtin/commit.c b/builtin/commit.c
index 2986553d5..49075a7ac 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -710,8 +710,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	} else if (use_message) {
 		char *buffer;
 		buffer = strstr(use_message_buffer, "\n\n");
-		if (buffer)
+		if (buffer) {
 			strbuf_addstr(&sb, skip_blank_lines(buffer + 2));
+			strbuf_addbackslash(&sb);
+		}
 		hook_arg1 = "commit";
 		hook_arg2 = use_message;
 	} else if (fixup_message) {
@@ -786,7 +788,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	s->hints = 0;
 
 	if (clean_message_contents)
-		strbuf_stripspace(&sb, 0);
+		strbuf_stripspace(&sb, 0, 0);
 
 	if (signoff)
 		append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0);
@@ -1621,7 +1623,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	    cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
 		strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));
 	if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE)
-		strbuf_stripspace(&sb, cleanup_mode == COMMIT_MSG_CLEANUP_ALL);
+		strbuf_stripspace(&sb, cleanup_mode == COMMIT_MSG_CLEANUP_ALL, 1);
 
 	if (message_is_empty(&sb, cleanup_mode) && !allow_empty_message) {
 		rollback_index_files();
diff --git a/builtin/merge.c b/builtin/merge.c
index e47d77bae..d0c3cb033 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -829,7 +829,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 		abort_commit(remoteheads, NULL);
 
 	read_merge_msg(&msg);
-	strbuf_stripspace(&msg, 0 < option_edit);
+	strbuf_stripspace(&msg, 0 < option_edit, 0);
 	if (!msg.len)
 		abort_commit(remoteheads, _("Empty commit message."));
 	strbuf_release(&merge_msg);
diff --git a/builtin/notes.c b/builtin/notes.c
index 02e97f55c..fd304ed9c 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -196,7 +196,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
 		if (launch_editor(d->edit_path, &d->buf, NULL)) {
 			die(_("please supply the note contents using either -m or -F option"));
 		}
-		strbuf_stripspace(&d->buf, 1);
+		strbuf_stripspace(&d->buf, 1, 0);
 	}
 }
 
@@ -221,7 +221,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
 	if (d->buf.len)
 		strbuf_addch(&d->buf, '\n');
 	strbuf_addstr(&d->buf, arg);
-	strbuf_stripspace(&d->buf, 0);
+	strbuf_stripspace(&d->buf, 0, 0);
 
 	d->given = 1;
 	return 0;
@@ -240,7 +240,7 @@ static int parse_file_arg(const struct option *opt, const char *arg, int unset)
 			die_errno(_("cannot read '%s'"), arg);
 	} else if (strbuf_read_file(&d->buf, arg, 1024) < 0)
 		die_errno(_("could not open or read '%s'"), arg);
-	strbuf_stripspace(&d->buf, 0);
+	strbuf_stripspace(&d->buf, 0, 0);
 
 	d->given = 1;
 	return 0;
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index be33eb83c..c5d449b5e 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -55,7 +55,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
 		die_errno("could not read the input");
 
 	if (mode == STRIP_DEFAULT || mode == STRIP_COMMENTS)
-		strbuf_stripspace(&buf, mode == STRIP_COMMENTS);
+		strbuf_stripspace(&buf, mode == STRIP_COMMENTS, 0);
 	else
 		comment_lines(&buf);
 
diff --git a/builtin/tag.c b/builtin/tag.c
index 02f6bd127..cb9422c17 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -261,7 +261,7 @@ static void create_tag(const struct object_id *object, const char *tag,
 	}
 
 	if (opt->cleanup_mode != CLEANUP_NONE)
-		strbuf_stripspace(buf, opt->cleanup_mode == CLEANUP_ALL);
+		strbuf_stripspace(buf, opt->cleanup_mode == CLEANUP_ALL, 0);
 
 	if (!opt->message_given && !buf->len)
 		die(_("no tag message?"));
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 68aff1dac..6e6e45c45 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -61,7 +61,7 @@ int edit_todo_list(struct repository *r, unsigned flags)
 	if (strbuf_read_file(&buf, todo_file, 0) < 0)
 		return error_errno(_("could not read '%s'."), todo_file);
 
-	strbuf_stripspace(&buf, 1);
+	strbuf_stripspace(&buf, 1, 0);
 	if (write_message(buf.buf, buf.len, todo_file, 0)) {
 		strbuf_release(&buf);
 		return -1;
diff --git a/sequencer.c b/sequencer.c
index 0db410d59..231682632 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1041,7 +1041,7 @@ int template_untouched(const struct strbuf *sb, const char *template_file,
 	if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0)
 		return 0;
 
-	strbuf_stripspace(&tmpl, cleanup_mode == COMMIT_MSG_CLEANUP_ALL);
+	strbuf_stripspace(&tmpl, cleanup_mode == COMMIT_MSG_CLEANUP_ALL, 0);
 	if (!skip_prefix(sb->buf, tmpl.buf, &start))
 		start = sb->buf;
 	strbuf_release(&tmpl);
@@ -1386,7 +1386,7 @@ static int try_to_commit(struct repository *r,
 					  opts->default_msg_cleanup;
 
 	if (cleanup != COMMIT_MSG_CLEANUP_NONE)
-		strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL);
+		strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL, 0);
 	if ((flags & EDIT_MSG) && message_is_empty(msg, cleanup)) {
 		res = 1; /* run 'git commit' to display error message */
 		goto out;
@@ -4941,7 +4941,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
 		return -1;
 	}
 
-	strbuf_stripspace(buf, 1);
+	strbuf_stripspace(buf, 1, 0);
 	if (buf->len == 0) {
 		apply_autostash(opts);
 		sequencer_remove_state(opts);
diff --git a/strbuf.c b/strbuf.c
index f6a6cf78b..148ba2815 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -966,8 +966,12 @@ static size_t cleanup(char *line, size_t len)
  *
  * Enable skip_comments to skip every line starting with comment
  * character.
+ *
+ * Enable escape_backslash to remove backslash in beginning of
+ * lines.
  */
-void strbuf_stripspace(struct strbuf *sb, int skip_comments)
+void strbuf_stripspace(struct strbuf *sb, int skip_comments,
+		int escape_backslash)
 {
 	size_t empties = 0;
 	size_t i, j, len, newlen;
@@ -999,8 +1003,66 @@ void strbuf_stripspace(struct strbuf *sb, int skip_comments)
 	}
 
 	strbuf_setlen(sb, j);
+
+	if (escape_backslash) {
+		strbuf_escape_backslash(sb);
+	}
+}
+
+/*
+ * Add a backslash in front of commentChar and other backslash.
+ */
+void strbuf_addbackslash(struct strbuf *sb)
+{
+	size_t i, len = 0, total = 0;
+	char *eol;
+
+	for (i = 0; i < sb->len; i += len) {
+		eol = memchr(sb->buf + i, '\n', sb->len -i);
+		len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
+
+		if (len > 0 && sb->buf[i] == comment_line_char) {
+			memmove(sb->buf + i + 1, sb->buf + i, sb->len - i);
+			sb->buf[i] = '\\';
+			total += (len + 1);
+		} else if (len > 0 && sb->buf[i] == '\\') {
+			memmove(sb->buf + i + 1, sb->buf + i, sb->len - i);
+			sb->buf[i] = '\\';
+			total += len;
+		} else {
+			total += len;
+		}
+	}
+	strbuf_grow(sb, total-len);
+	strbuf_setlen(sb, total);
 }
 
+/*
+ * Escape backslash in beginning of lines.
+ */
+void strbuf_escape_backslash(struct strbuf *sb)
+{
+	size_t i, len, total = sb->len;
+	char *eol;
+
+	for (i = 0; i < sb->len; i += len) {
+		eol = memchr(sb->buf + i, '\n', sb->len - i);
+		len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
+
+		if (sb->buf[i] == '\\') {
+			memmove(sb->buf + i, sb->buf + i + 1, total - 1 - i);
+			total --;
+			len --;
+			i++;
+		}
+		/* Avoid initite loop if len=0 */
+		if (len <= 0) len = 1;
+	}
+	strbuf_setlen(sb, sb->len - (sb->len - total));
+}
+
+
+
 int strbuf_normalize_path(struct strbuf *src)
 {
 	struct strbuf dst = STRBUF_INIT;
diff --git a/strbuf.h b/strbuf.h
index fc40873b6..6ee958498 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -499,8 +499,14 @@ int strbuf_normalize_path(struct strbuf *sb);
 /**
  * Strip whitespace from a buffer. The second parameter controls if
  * comments are considered contents to be removed or not.
+ * The third parameter controls if backslashes are escaped.
  */
-void strbuf_stripspace(struct strbuf *buf, int skip_comments);
+void strbuf_stripspace(struct strbuf *buf, int skip_comments,
+		int escape_backslash);
+
+void strbuf_escape_backslash(struct strbuf *sb);
+
+void strbuf_addbackslash(struct strbuf *sb);
 
 static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
 {
diff --git a/t/t7526-commit-message-comments.sh b/t/t7526-commit-message-comments.sh
new file mode 100755
index 000000000..e4b04eb7a
--- /dev/null
+++ b/t/t7526-commit-message-comments.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+test_description='"git commit" allows # in the start of a line in commit message.
+
+'
+. ./test-lib.sh
+
+
+# set up fake editor for interactive editing
+cat >fake-editor <<'EOF'
+#!/bin/sh
+cp FAKE_MSG "$1"
+exit 0
+EOF
+chmod +x fake-editor
+
+FAKE_EDITOR="$(pwd)/fake-editor"
+export FAKE_EDITOR
+
+commit_msg_is () {
+	test "$(git log --pretty=format:%s%b -1)" = "$1"
+}
+
+ensure_fresh_upstream () {
+	rm -rf parent && git init --bare parent
+}
+
+test_expect_success 'setup bare parent' '
+	ensure_fresh_upstream &&
+	git remote add upstream parent
+'
+
+test_expect_success 'git commit "\#text" keeps "#text" as a commit message' '
+	echo test1 >file &&
+	git add file &&
+	printf "%s\n" "\\#text" >FAKE_MSG &&
+	GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit &&
+	commit_msg_is "#text"
+'
+
+test_expect_success 'git commit "\text" keeps "text" as a commit message' '
+	echo test2 >file &&
+	git add file &&
+	printf "%s\n" "\\text" >FAKE_MSG &&
+	GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit &&
+	commit_msg_is "text"
+'
+
+test_expect_success 'git commit "\\text" keeps "\text" as a commit message' '
+	echo test5 >file &&
+	git add file &&
+	printf "%s\n" "\\\\text" >FAKE_MSG &&
+	GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit &&
+	commit_msg_is "\\text"
+'
+
+test_expect_success 'git commit -m "\#text" keeps "#text" as a commit message' '
+	echo test1 >file &&
+	git add file &&
+	git commit -m "\\#text" &&
+	commit_msg_is "#text"
+'
+
+test_expect_success 'git commit -m "\text" keeps "text" as a commit message' '
+	echo test2 >file &&
+	git add file &&
+	git commit -m "\\text" &&
+	commit_msg_is "text"
+'
+
+test_expect_success 'git commit -m "\\text" keeps "\text" as a commit message' '
+	echo test3 >file &&
+	git add file &&
+	git commit -m "\\\\text" &&
+	commit_msg_is "\\text"
+'
+
+test_expect_success 'git commit --amend add backslash in front of comment
+and other backslash' '
+	echo "\\#Include something" > msg &&
+	echo "" >> msg &&
+	echo "Some content" >> msg &&
+	echo "\\\\\\Backslash example" >> msg &&
+	echo "test amend" > file &&
+	git add file &&
+	git commit -F msg &&
+	cat .git/COMMIT_EDITMSG > expect &&
+	git commit --amend &&
+	sed "/^#/d" .git/COMMIT_EDITMSG > actual &&
+	sed -i -e "$ d" actual &&
+	test_cmp expect actual
+'
+test_done
-- 
2.21.0-rc0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2019-04-22 10:06 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-27 11:38 Log messages beginning # and git rebase -i Ed Avis
2015-07-27 23:25 ` Eric Sunshine
2015-07-28  0:53   ` Duy Nguyen
2015-07-28  9:51   ` Ed Avis
2015-07-28 15:25     ` Matthieu Moy
2015-07-28 16:30       ` Junio C Hamano
2015-07-28 16:40         ` Ed Avis
2015-07-28 17:48         ` Matthieu Moy
2015-07-28 18:44           ` Junio C Hamano
2015-07-29 10:17             ` Matthieu Moy
2015-07-29 10:19               ` Ed Avis
2019-04-22 10:05             ` [PATCH] allow commentChars in commit messages Corentin BOMPARD
2015-07-29 10:47           ` Log messages beginning # and git rebase -i Duy Nguyen
2015-07-29 12:17             ` Matthieu Moy
2015-07-29 12:47               ` Duy Nguyen
2015-07-29 15:54               ` Junio C Hamano
2015-07-29 16:03                 ` Matthieu Moy
2015-07-29 17:02                   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).