Re: [PATCH v2] Allow custom "comment char"

2013-01-16 Thread Jens Lehmann
Am 16.01.2013 20:18, schrieb Ralf Thielow:
> From: Junio C Hamano 
> 
> Some users do want to write a line that begin with a pound sign, #,
> in their commit log message.  Many tracking system recognise
> a token of # form, for example.
> 
> The support we offer these use cases is not very friendly to the end
> users.  They have a choice between
> 
>  - Don't do it.  Avoid such a line by rewrapping or indenting; and
> 
>  - Use --cleanup=whitespace but remove all the hint lines we add.
> 
> Give them a way to set a custom comment char, e.g.
> 
> $ git -c core.commentchar="%" commit
> 
> so that they do not have to do either of the two workarounds.
> 
> Signed-off-by: Junio C Hamano 
> Signed-off-by: Ralf Thielow 
> ---
> Junio, thanks for the code in your reply to the
> first version. It works very well and looks nice.
> I was also unhappy about this "\n%c\n" thing and
> pretty unsure with the code in "git-submodule.sh".

I can't see anything wrong with it (but didn't have the time to
test it). On my todo list (but *way* down) is the task to replace
the call to "git submodule summary --for-status ..." in
wt_status_print_submodule_summary() with a call to "git diff
--submodule" (and - at least in the long term - rip out the
--for-status option from the submodule script). Maybe now is a
good time for someone else to tackle that? (especially as the new
strbuf_commented_add*() functions should make that rather easy)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] Allow custom "comment char"

2013-01-16 Thread Junio C Hamano
Ralf Thielow  writes:

> From: Junio C Hamano 
>
> Some users do want to write a line that begin with a pound sign, #,
> in their commit log message.  Many tracking system recognise
> a token of # form, for example.
>
> The support we offer these use cases is not very friendly to the end
> users.  They have a choice between
>
>  - Don't do it.  Avoid such a line by rewrapping or indenting; and
>
>  - Use --cleanup=whitespace but remove all the hint lines we add.
>
> Give them a way to set a custom comment char, e.g.
>
> $ git -c core.commentchar="%" commit
>
> so that they do not have to do either of the two workarounds.
>
> Signed-off-by: Junio C Hamano 
> Signed-off-by: Ralf Thielow 
> ---
> Junio, thanks for the code in your reply to the
> first version. It works very well and looks nice.
> I was also unhappy about this "\n%c\n" thing and
> pretty unsure with the code in "git-submodule.sh".
> But with this, it looks good to me. Thanks.
>
> Changes in v2:
> - extend "git stripspace" with an option to make
>   it's input being converted to commented lines
> - teach git-submodule.sh using this
> - rename strbuf_commented_addstr to strbuf_add_commented_lines
>   and improve it's design

Oh, I love it when something like this happens.  Throw a "perhaps
along these lines" patch and then a finished product that fills the
gaps I didn't bother to fill magically appears, even with tests and
updates to comments and documentation.

What good things did I do recently to deserve such a luck? ;-)

> @@ -66,21 +67,52 @@ void stripspace(struct strbuf *sb, int skip_comments)
>   strbuf_setlen(sb, j);
>  }
>  
> +static void comment_lines(struct strbuf *buf)
> +{
> + char *msg;
> + size_t len;
> +
> + msg = strbuf_detach(buf, &len);
> + strbuf_add_commented_lines(buf, msg, len);
> +}

This leaks msg (inherited from my "perhaps along these lines"
patch).  I think I can just add free(msg) at the end.

> + if (strip_comments || mode == COMMENT_LINES)
> + git_config(git_default_config, NULL);

Nice spotting.  The "along these lines" patch broke "stripspace -s"
under custom comment line char; this fixes it.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] Allow custom "comment char"

2013-01-16 Thread Ralf Thielow
From: Junio C Hamano 

Some users do want to write a line that begin with a pound sign, #,
in their commit log message.  Many tracking system recognise
a token of # form, for example.

The support we offer these use cases is not very friendly to the end
users.  They have a choice between

 - Don't do it.  Avoid such a line by rewrapping or indenting; and

 - Use --cleanup=whitespace but remove all the hint lines we add.

Give them a way to set a custom comment char, e.g.

$ git -c core.commentchar="%" commit

so that they do not have to do either of the two workarounds.

Signed-off-by: Junio C Hamano 
Signed-off-by: Ralf Thielow 
---
Junio, thanks for the code in your reply to the
first version. It works very well and looks nice.
I was also unhappy about this "\n%c\n" thing and
pretty unsure with the code in "git-submodule.sh".
But with this, it looks good to me. Thanks.

Changes in v2:
- extend "git stripspace" with an option to make
  it's input being converted to commented lines
- teach git-submodule.sh using this
- rename strbuf_commented_addstr to strbuf_add_commented_lines
  and improve it's design

 Documentation/config.txt   |  6 
 Documentation/git-stripspace.txt   |  8 -
 Documentation/technical/api-strbuf.txt | 10 ++
 builtin/branch.c   | 10 +++---
 builtin/commit.c   | 12 +++
 builtin/fmt-merge-msg.c|  2 +-
 builtin/merge.c|  5 ++-
 builtin/notes.c| 34 +---
 builtin/stripspace.c   | 48 +++-
 builtin/tag.c  | 34 ++--
 cache.h|  6 
 config.c   |  8 +
 environment.c  |  6 
 git-submodule.sh   |  8 ++---
 strbuf.c   | 58 --
 strbuf.h   |  4 +++
 t/t0030-stripspace.sh  | 35 
 t/t7502-commit.sh  |  7 
 t/t7508-status.sh  | 50 +
 wt-status.c| 10 +++---
 20 files changed, 283 insertions(+), 78 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index d5809e0..e99b9f2 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -528,6 +528,12 @@ core.editor::
variable when it is set, and the environment variable
`GIT_EDITOR` is not set.  See linkgit:git-var[1].
 
+core.commentchar::
+   Commands such as `commit` and `tag` that lets you edit
+   messages consider a line that begins with this character
+   commented, and removes them after the editor returns
+   (default '#').
+
 sequence.editor::
Text editor used by `git rebase -i` for editing the rebase insn file.
The value is meant to be interpreted by the shell when it is used.
diff --git a/Documentation/git-stripspace.txt b/Documentation/git-stripspace.txt
index a80d946..e6fdfcb 100644
--- a/Documentation/git-stripspace.txt
+++ b/Documentation/git-stripspace.txt
@@ -35,7 +35,13 @@ OPTIONS
 ---
 -s::
 --strip-comments::
-   Skip and remove all lines starting with '#'.
+   Skip and remove all lines starting with comment character (default '#').
+
+-c::
+--comment-lines::
+   Prepend comment character and blank to each line. Lines will 
automatically
+   be terminated with a newline. On empty lines, only the comment character
+   will be prepended.
 
 EXAMPLES
 
diff --git a/Documentation/technical/api-strbuf.txt 
b/Documentation/technical/api-strbuf.txt
index 84686b5..2c59cb2 100644
--- a/Documentation/technical/api-strbuf.txt
+++ b/Documentation/technical/api-strbuf.txt
@@ -156,6 +156,11 @@ then they will free() it.
Remove the bytes between `pos..pos+len` and replace it with the given
data.
 
+`strbuf_add_commented_lines`::
+
+   Add a NUL-terminated string to the buffer. Each line will be prepended
+   by a comment character and a blank.
+
 `strbuf_add`::
 
Add data of given length to the buffer.
@@ -229,6 +234,11 @@ which can be used by the programmer of the callback as she 
sees fit.
 
Add a formatted string to the buffer.
 
+`strbuf_commented_addf`::
+
+   Add a formatted string prepended by a comment character and a
+   blank to the buffer.
+
 `strbuf_fread`::
 
Read a given size of data from a FILE* pointer to the buffer.
diff --git a/builtin/branch.c b/builtin/branch.c
index 873f624..3548271 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -706,11 +706,11 @@ static int edit_branch_description(const char 
*branch_name)
read_branch_desc(&buf, branch_name);
if (!buf.len || buf.buf[buf.len-1] != '\n')
strbuf_addch(&buf, '\n');
-   strbuf_addf(&buf,
-   "#