* [PATCH] commit: make default of "cleanup" option configurable
@ 2013-01-08 20:16 Ralf Thielow
2013-01-08 21:18 ` Junio C Hamano
` (2 more replies)
0 siblings, 3 replies; 18+ messages in thread
From: Ralf Thielow @ 2013-01-08 20:16 UTC (permalink / raw)
To: git; +Cc: gitster, Ralf Thielow
The default of the "cleanup" option in "git commit"
is not configurable. Users who don't want to use the
default have to pass this option on every commit since
there's no way to configure it. This commit introduces
a new config option "commit.cleanup" which can be used
to change the default of the "cleanup" option in
"git commit".
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
Documentation/config.txt | 4 ++++
builtin/commit.c | 29 ++++++++++++++++++-----------
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 53c4ca1..3f76cd1 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -917,6 +917,10 @@ column.tag::
Specify whether to output tag listing in `git tag` in columns.
See `column.ui` for details.
+commit.cleanup::
+ This setting overrides the default of the `--cleanup` option in
+ `git commit`. See linkgit:git-commit[1] for details.
+
commit.status::
A boolean to enable/disable inclusion of status information in the
commit message template when using an editor to prepare the commit
diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..42acde7 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -103,7 +103,7 @@ static enum {
CLEANUP_NONE,
CLEANUP_ALL
} cleanup_mode;
-static char *cleanup_arg;
+const static char *cleanup_arg;
static enum commit_whence whence;
static int use_editor = 1, include_status = 1;
@@ -966,6 +966,20 @@ static const char *read_commit_message(const char *name)
return out;
}
+static void parse_cleanup_arg()
+{
+ if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
+ cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
+ else if (!strcmp(cleanup_arg, "verbatim"))
+ cleanup_mode = CLEANUP_NONE;
+ else if (!strcmp(cleanup_arg, "whitespace"))
+ cleanup_mode = CLEANUP_SPACE;
+ else if (!strcmp(cleanup_arg, "strip"))
+ cleanup_mode = CLEANUP_ALL;
+ else
+ die(_("Invalid cleanup mode %s"), cleanup_arg);
+}
+
static int parse_and_validate_options(int argc, const char *argv[],
const struct option *options,
const char * const usage[],
@@ -1044,18 +1058,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
only_include_assumed = _("Clever... amending the last one with dirty index.");
if (argc > 0 && !also && !only)
only_include_assumed = _("Explicit paths specified without -i nor -o; assuming --only paths...");
- if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
- cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
- else if (!strcmp(cleanup_arg, "verbatim"))
- cleanup_mode = CLEANUP_NONE;
- else if (!strcmp(cleanup_arg, "whitespace"))
- cleanup_mode = CLEANUP_SPACE;
- else if (!strcmp(cleanup_arg, "strip"))
- cleanup_mode = CLEANUP_ALL;
- else
- die(_("Invalid cleanup mode %s"), cleanup_arg);
handle_untracked_files_arg(s);
+ parse_cleanup_arg();
if (all && argc > 0)
die(_("Paths with -a does not make sense."));
@@ -1320,6 +1325,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
include_status = git_config_bool(k, v);
return 0;
}
+ if (!strcmp(k, "commit.cleanup"))
+ return git_config_string(&cleanup_arg, k, v);
status = git_gpg_config(k, v, NULL);
if (status)
--
1.8.1.165.gd94bd4e.dirty
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH] commit: make default of "cleanup" option configurable
2013-01-08 20:16 [PATCH] commit: make default of "cleanup" option configurable Ralf Thielow
@ 2013-01-08 21:18 ` Junio C Hamano
2013-01-09 7:29 ` Jonathan Nieder
2013-01-09 19:36 ` [PATCHv2] commit: make default of "cleanup" option configurable Ralf Thielow
2 siblings, 0 replies; 18+ messages in thread
From: Junio C Hamano @ 2013-01-08 21:18 UTC (permalink / raw)
To: Ralf Thielow; +Cc: git
Ralf Thielow <ralf.thielow@gmail.com> writes:
> The default of the "cleanup" option in "git commit"
> is not configurable. Users who don't want to use the
> default have to pass this option on every commit since
> there's no way to configure it. This commit introduces
> a new config option "commit.cleanup" which can be used
> to change the default of the "cleanup" option in
> "git commit".
>
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
The idea makes sense, but I am not sure the implementation is
correct. Does the code already know the final value of use_editor
at the point where it calls git_commit_config? I think you do not
know at least until you call parse_and_validate_options().
Once you got the implementation right, we would want to make sure
that future changes will not break it by adding some tests that
verify:
- Without configuration and without option, the command keeps the
built-in default;
- Without configuration but with option, the command uses the
command line option (we may already have this test, I didn't
check);
- With configuration and without option, the command uses the
configured default (what this patch adds); and
- With configuration and with option, the command uses the command
line option.
The latter two probably needs a few variants, one with --edit (with
EDITOR set to something like "true"), another with --no-edit, one
without --edit nor --no-edit but with -m "$msg" to implicitly turn
use_editor off, and one without --edit, --no-edit, nor -m but with
EDITOR set to a scriptlet that writes a message to the file to
implicitly turn use_editor on.
Also, the readers of the documentation for "commit --cleanup" will
wonder the same thing you wondered before you wrote this patch;
mentioning the configuration variable in its documentation will help
them.
Thanks.
> Documentation/config.txt | 4 ++++
> builtin/commit.c | 29 ++++++++++++++++++-----------
> 2 files changed, 22 insertions(+), 11 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 53c4ca1..3f76cd1 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -917,6 +917,10 @@ column.tag::
> Specify whether to output tag listing in `git tag` in columns.
> See `column.ui` for details.
>
> +commit.cleanup::
> + This setting overrides the default of the `--cleanup` option in
> + `git commit`. See linkgit:git-commit[1] for details.
> +
> commit.status::
> A boolean to enable/disable inclusion of status information in the
> commit message template when using an editor to prepare the commit
> diff --git a/builtin/commit.c b/builtin/commit.c
> index d6dd3df..42acde7 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -103,7 +103,7 @@ static enum {
> CLEANUP_NONE,
> CLEANUP_ALL
> } cleanup_mode;
> -static char *cleanup_arg;
> +const static char *cleanup_arg;
>
> static enum commit_whence whence;
> static int use_editor = 1, include_status = 1;
> @@ -966,6 +966,20 @@ static const char *read_commit_message(const char *name)
> return out;
> }
>
> +static void parse_cleanup_arg()
> +{
> + if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
> + cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
> + else if (!strcmp(cleanup_arg, "verbatim"))
> + cleanup_mode = CLEANUP_NONE;
> + else if (!strcmp(cleanup_arg, "whitespace"))
> + cleanup_mode = CLEANUP_SPACE;
> + else if (!strcmp(cleanup_arg, "strip"))
> + cleanup_mode = CLEANUP_ALL;
> + else
> + die(_("Invalid cleanup mode %s"), cleanup_arg);
> +}
> +
> static int parse_and_validate_options(int argc, const char *argv[],
> const struct option *options,
> const char * const usage[],
> @@ -1044,18 +1058,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
> only_include_assumed = _("Clever... amending the last one with dirty index.");
> if (argc > 0 && !also && !only)
> only_include_assumed = _("Explicit paths specified without -i nor -o; assuming --only paths...");
> - if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
> - cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
> - else if (!strcmp(cleanup_arg, "verbatim"))
> - cleanup_mode = CLEANUP_NONE;
> - else if (!strcmp(cleanup_arg, "whitespace"))
> - cleanup_mode = CLEANUP_SPACE;
> - else if (!strcmp(cleanup_arg, "strip"))
> - cleanup_mode = CLEANUP_ALL;
> - else
> - die(_("Invalid cleanup mode %s"), cleanup_arg);
>
> handle_untracked_files_arg(s);
> + parse_cleanup_arg();
>
> if (all && argc > 0)
> die(_("Paths with -a does not make sense."));
> @@ -1320,6 +1325,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
> include_status = git_config_bool(k, v);
> return 0;
> }
> + if (!strcmp(k, "commit.cleanup"))
> + return git_config_string(&cleanup_arg, k, v);
>
> status = git_gpg_config(k, v, NULL);
> if (status)
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] commit: make default of "cleanup" option configurable
2013-01-08 20:16 [PATCH] commit: make default of "cleanup" option configurable Ralf Thielow
2013-01-08 21:18 ` Junio C Hamano
@ 2013-01-09 7:29 ` Jonathan Nieder
2013-01-09 8:16 ` Ralf Thielow
2013-01-09 19:36 ` [PATCHv2] commit: make default of "cleanup" option configurable Ralf Thielow
2 siblings, 1 reply; 18+ messages in thread
From: Jonathan Nieder @ 2013-01-09 7:29 UTC (permalink / raw)
To: Ralf Thielow; +Cc: git, gitster
Hi,
Ralf Thielow wrote:
> The default of the "cleanup" option in "git commit"
> is not configurable. Users who don't want to use the
> default have to pass this option on every commit since
> there's no way to configure it.
Could you give an example? I'm trying to get a sense of whether these
habitual --cleanup= passers would use --cleanup=verbatim or
--cleanup=strip.
I'm a bit worried that a setting like 'commit.cleanup = strip' would
be likely to break scripts. Yes, scripts using "git commit" instead
of commit-tree while caring about detailed semantics are asking for
trouble, but I'm worried about importers, for example, which are
sometimes written by new git users. Some scripts might assume that
"git commit" preserves the entire change description from their source
data, even when some lines happen to start by listing the ways the
author is #1.
I don't think that necessarily rules out this change, but:
1. We need more of an explanation of the purpose than "this lets
people type less". What workflow does setting this option fit
into?
2. I would prefer to see a little thought about whether it's possible
to avoid silently impacting scripts. E.g., depending on the
answer to (1), maybe supporting "verbatim" but not "strip" would be
ok? Or alternatively, maybe a search of public code repositories
would reveal that new git users tend to write their importers in a
way that this doesn't break.
As a side effect, the information gathered to answer (1) and (2) could
have the potential to make the user-level documentation more useful,
by adding context to the description of the configuration item.
[...]
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -103,7 +103,7 @@ static enum {
> CLEANUP_NONE,
> CLEANUP_ALL
> } cleanup_mode;
> -static char *cleanup_arg;
> +const static char *cleanup_arg;
Style nit: storage class comes first, then the type. Otherwise the
typename "const char *" is split up.
Hope that helps,
Jonathan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] commit: make default of "cleanup" option configurable
2013-01-09 7:29 ` Jonathan Nieder
@ 2013-01-09 8:16 ` Ralf Thielow
2013-01-09 8:28 ` Jonathan Nieder
` (2 more replies)
0 siblings, 3 replies; 18+ messages in thread
From: Ralf Thielow @ 2013-01-09 8:16 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: git, gitster
Hi,
2013/1/9 Jonathan Nieder <jrnieder@gmail.com>:
> Hi,
>
> Ralf Thielow wrote:
>
>> The default of the "cleanup" option in "git commit"
>> is not configurable. Users who don't want to use the
>> default have to pass this option on every commit since
>> there's no way to configure it.
>
> Could you give an example? I'm trying to get a sense of whether these
> habitual --cleanup= passers would use --cleanup=verbatim or
> --cleanup=strip.
>
It's actually my own usecase :). The bugtracker I'm using is able
to create relationships between issues and related commits. It
expects that a part of the commit message contains the issue number
in format "#<issueId>". So I need to use a cleanup mode different
from "default" to keep the commentary. The mode I'd use is "whitespace",
"verbatim" is also possible.
> I'm a bit worried that a setting like 'commit.cleanup = strip' would
> be likely to break scripts. Yes, scripts using "git commit" instead
> of commit-tree while caring about detailed semantics are asking for
> trouble, but I'm worried about importers, for example, which are
> sometimes written by new git users. Some scripts might assume that
> "git commit" preserves the entire change description from their source
> data, even when some lines happen to start by listing the ways the
> author is #1.
>
When a user uses a script/importer which expects that the "default" option
is used without setting it explicitly, and then the user changes the default,
isn't it the users fault if that would break things?
> I don't think that necessarily rules out this change, but:
>
> 1. We need more of an explanation of the purpose than "this lets
> people type less". What workflow does setting this option fit
> into?
>
> 2. I would prefer to see a little thought about whether it's possible
> to avoid silently impacting scripts. E.g., depending on the
> answer to (1), maybe supporting "verbatim" but not "strip" would be
> ok? Or alternatively, maybe a search of public code repositories
> would reveal that new git users tend to write their importers in a
> way that this doesn't break.
>
> As a side effect, the information gathered to answer (1) and (2) could
> have the potential to make the user-level documentation more useful,
> by adding context to the description of the configuration item.
>
I'll add a sentence of my bugtracker example to it. I think many developers
are using such a tool, so it'd makes sense.
> [...]
>> --- a/builtin/commit.c
>> +++ b/builtin/commit.c
>> @@ -103,7 +103,7 @@ static enum {
>> CLEANUP_NONE,
>> CLEANUP_ALL
>> } cleanup_mode;
>> -static char *cleanup_arg;
>> +const static char *cleanup_arg;
>
> Style nit: storage class comes first, then the type. Otherwise the
> typename "const char *" is split up.
>
Thanks.
I'll send a new version of the patch including changes of your and
Junios comments.
Ralf
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] commit: make default of "cleanup" option configurable
2013-01-09 8:16 ` Ralf Thielow
@ 2013-01-09 8:28 ` Jonathan Nieder
2013-01-09 15:40 ` Junio C Hamano
2013-01-09 15:56 ` Junio C Hamano
2 siblings, 0 replies; 18+ messages in thread
From: Jonathan Nieder @ 2013-01-09 8:28 UTC (permalink / raw)
To: Ralf Thielow; +Cc: git, gitster
Ralf Thielow wrote:
> It's actually my own usecase :). The bugtracker I'm using is able
> to create relationships between issues and related commits. It
> expects that a part of the commit message contains the issue number
> in format "#<issueId>". So I need to use a cleanup mode different
> from "default" to keep the commentary. The mode I'd use is "whitespace",
> "verbatim" is also possible.
Hm, so "whitespace-when-editing" would be the ideal setting.
Would it be confusing if the '[commit] cleanup' setting only took
effect when launching an editor (and not with -F, -C, or -m)? My
first impression is that I'd like that behavior better, even though
it's harder to explain.
[...]
> When a user uses a script/importer which expects that the "default" option
> is used without setting it explicitly, and then the user changes the default,
> isn't it the users fault if that would break things?
Consider the following series of events.
1. My friend writes an importer that uses the "git commit" command.
I like it and start using it.
2. Another friend writes a blog post about the '[commit] cleanup'
setting. I like it and start using it.
3. I try to use the importer again.
4. Years later, I notice the commit messages are corrupted in the
imported history.
It's hard to assign blame. I guess it's my fault. ;)
[...]
> I'll add a sentence of my bugtracker example to it. I think many developers
> are using such a tool, so it'd makes sense.
Thanks, sounds good.
Regards,
Jonathan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] commit: make default of "cleanup" option configurable
2013-01-09 8:16 ` Ralf Thielow
2013-01-09 8:28 ` Jonathan Nieder
@ 2013-01-09 15:40 ` Junio C Hamano
2013-01-09 15:56 ` Junio C Hamano
2 siblings, 0 replies; 18+ messages in thread
From: Junio C Hamano @ 2013-01-09 15:40 UTC (permalink / raw)
To: Ralf Thielow; +Cc: Jonathan Nieder, git
Ralf Thielow <ralf.thielow@gmail.com> writes:
> When a user uses a script/importer which expects that the "default" option
> is used without setting it explicitly, and then the user changes the default,
> isn't it the users fault if that would break things?
Not necessarily. There are many people who use scripts written by
others, without knowing how they work. You could blame that the
script is broken, but not the poor user of that script.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] commit: make default of "cleanup" option configurable
2013-01-09 8:16 ` Ralf Thielow
2013-01-09 8:28 ` Jonathan Nieder
2013-01-09 15:40 ` Junio C Hamano
@ 2013-01-09 15:56 ` Junio C Hamano
2013-01-10 19:37 ` Re* " Junio C Hamano
2 siblings, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2013-01-09 15:56 UTC (permalink / raw)
To: Ralf Thielow; +Cc: Jonathan Nieder, git
Ralf Thielow <ralf.thielow@gmail.com> writes:
> It's actually my own usecase :). The bugtracker I'm using is able
> to create relationships between issues and related commits. It
> expects that a part of the commit message contains the issue number
> in format "#<issueId>". So I need to use a cleanup mode different
> from "default" to keep the commentary.
This is orthogonal to the patch in question, but in your particular
case, I wonder if it is a workable solution to indent #<bugid> in
your message, which won't be stripped away.
I also wonder, as a longer term alternative (which would require a
lot of code auditing and some refactoring), if it is useful to have
an option and/or configuration that lets you configure the "comment
in log message editor" character from the default "#" to something
else. "git -c log.commentchar=% commit" may start the log message
editor with something like this in it:
% Please enter the commit message for your changes. Lines starting
% with '%' will be ignored, and an empty message aborts the commit.
Naturally, setting log.commentchar to "none" would disable stripping
of any commented lines if such a feature existed, and stop issuing
these helpful comments altogether, but still strip excess blank
lines and trailing whitespaces.
I wouldn't seriously suggest it as I am not sure if the usefulness
of such a feature would outweigh the cost of coding it, though; at
least not at this point yet.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCHv2] commit: make default of "cleanup" option configurable
2013-01-08 20:16 [PATCH] commit: make default of "cleanup" option configurable Ralf Thielow
2013-01-08 21:18 ` Junio C Hamano
2013-01-09 7:29 ` Jonathan Nieder
@ 2013-01-09 19:36 ` Ralf Thielow
2013-01-10 0:17 ` Junio C Hamano
2013-01-10 17:45 ` [PATCHv3] " Ralf Thielow
2 siblings, 2 replies; 18+ messages in thread
From: Ralf Thielow @ 2013-01-09 19:36 UTC (permalink / raw)
To: gitster, jrnieder; +Cc: git, Ralf Thielow
The default of the "cleanup" option in "git commit"
is not configurable. Users who don't want to use the
default have to pass this option on every commit since
there's no way to configure it. This commit introduces
a new config option "commit.cleanup" which can be used
to change the default of the "cleanup" option in
"git commit".
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
Changes in v2:
- simplify implementation
- mention configuration variable in documentation of "git commit --cleanup"
- add an example usecase to documention of commit.cleanup configuration variable
- add tests
Documentation/config.txt | 7 ++++
Documentation/git-commit.txt | 4 +-
builtin/commit.c | 5 ++-
t/t7500/add-content-and-comment | 4 ++
t/t7502-commit.sh | 84 +++++++++++++++++++++++++++++++++++++----
5 files changed, 95 insertions(+), 9 deletions(-)
create mode 100755 t/t7500/add-content-and-comment
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 53c4ca1..0452d56 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -917,6 +917,13 @@ column.tag::
Specify whether to output tag listing in `git tag` in columns.
See `column.ui` for details.
+commit.cleanup::
+ This setting overrides the default of the `--cleanup` option in
+ `git commit`. See linkgit:git-commit[1] for details. Changing the
+ default can be useful if you want to use the comment character (#)
+ consistently within your commit messages, in which case you would
+ like to change the default to 'whitespace'.
+
commit.status::
A boolean to enable/disable inclusion of status information in the
commit message template when using an editor to prepare the commit
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 7bdb039..41b27da 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -179,7 +179,9 @@ OPTIONS
only if the message is to be edited. Otherwise only whitespace
removed. The 'verbatim' mode does not change message at all,
'whitespace' removes just leading/trailing whitespace lines
- and 'strip' removes both whitespace and commentary.
+ and 'strip' removes both whitespace and commentary. The default
+ can be changed by the 'commit.cleanup' configuration variable
+ (see linkgit:git-config[1]).
-e::
--edit::
diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..4d55f8f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -103,7 +103,7 @@ static enum {
CLEANUP_NONE,
CLEANUP_ALL
} cleanup_mode;
-static char *cleanup_arg;
+static const char *cleanup_arg;
static enum commit_whence whence;
static int use_editor = 1, include_status = 1;
@@ -966,6 +966,7 @@ static const char *read_commit_message(const char *name)
return out;
}
+
static int parse_and_validate_options(int argc, const char *argv[],
const struct option *options,
const char * const usage[],
@@ -1320,6 +1321,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
include_status = git_config_bool(k, v);
return 0;
}
+ if (!strcmp(k, "commit.cleanup"))
+ return git_config_string(&cleanup_arg, k, v);
status = git_gpg_config(k, v, NULL);
if (status)
diff --git a/t/t7500/add-content-and-comment b/t/t7500/add-content-and-comment
new file mode 100755
index 0000000..988f5e9
--- /dev/null
+++ b/t/t7500/add-content-and-comment
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "commit message" >> "$1"
+echo "# comment" >> "$1"
+exit 0
\ No newline at end of file
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 1a5cb69..b1c7648 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -4,6 +4,15 @@ test_description='git commit porcelain-ish'
. ./test-lib.sh
+commit_msg_is () {
+ expect=commit_msg_is.expect
+ actual=commit_msg_is.actual
+
+ printf "%s" "$(git log --pretty=format:%s%b -1)" >$actual &&
+ printf "%s" "$1" >$expect &&
+ test_i18ncmp $expect $actual
+}
+
# Arguments: [<prefix] [<commit message>] [<commit options>]
check_summary_oneline() {
test_tick &&
@@ -168,7 +177,7 @@ test_expect_success 'verbose respects diff config' '
git config --unset color.diff
'
-test_expect_success 'cleanup commit messages (verbatim,-t)' '
+test_expect_success 'cleanup commit messages (verbatim option,-t)' '
echo >>negative &&
{ echo;echo "# text";echo; } >expect &&
@@ -178,7 +187,7 @@ test_expect_success 'cleanup commit messages (verbatim,-t)' '
'
-test_expect_success 'cleanup commit messages (verbatim,-F)' '
+test_expect_success 'cleanup commit messages (verbatim option,-F)' '
echo >>negative &&
git commit --cleanup=verbatim -F expect -a &&
@@ -187,7 +196,7 @@ test_expect_success 'cleanup commit messages (verbatim,-F)' '
'
-test_expect_success 'cleanup commit messages (verbatim,-m)' '
+test_expect_success 'cleanup commit messages (verbatim option,-m)' '
echo >>negative &&
git commit --cleanup=verbatim -m "$(cat expect)" -a &&
@@ -196,7 +205,7 @@ test_expect_success 'cleanup commit messages (verbatim,-m)' '
'
-test_expect_success 'cleanup commit messages (whitespace,-F)' '
+test_expect_success 'cleanup commit messages (whitespace option,-F)' '
echo >>negative &&
{ echo;echo "# text";echo; } >text &&
@@ -207,7 +216,7 @@ test_expect_success 'cleanup commit messages (whitespace,-F)' '
'
-test_expect_success 'cleanup commit messages (strip,-F)' '
+test_expect_success 'cleanup commit messages (strip option,-F)' '
echo >>negative &&
{ echo;echo "# text";echo sample;echo; } >text &&
@@ -218,7 +227,7 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
'
-test_expect_success 'cleanup commit messages (strip,-F,-e)' '
+test_expect_success 'cleanup commit messages (strip option,-F,-e)' '
echo >>negative &&
{ echo;echo sample;echo; } >text &&
@@ -231,10 +240,71 @@ echo "sample
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit." >expect
-test_expect_success 'cleanup commit messages (strip,-F,-e): output' '
+test_expect_success 'cleanup commit messages (strip option,-F,-e): output' '
test_i18ncmp expect actual
'
+test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' '
+ test_must_fail git commit --cleanup=non-existent
+'
+
+test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' '
+ test_must_fail git -c commit.cleanup=non-existent commit
+'
+
+test_expect_success 'cleanup commit message (no config and no option uses default)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git commit --no-status &&
+ commit_msg_is "commit message"
+'
+
+test_expect_success 'cleanup commit message (option overrides default)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git commit --cleanup=whitespace --no-status &&
+ commit_msg_is "commit message # comment"
+'
+
+test_expect_success 'cleanup commit message (config overrides default)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git -c commit.cleanup=whitespace commit --no-status &&
+ commit_msg_is "commit message # comment"
+'
+
+test_expect_success 'cleanup commit message (option overrides config)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git -c commit.cleanup=whitespace commit --cleanup=default &&
+ commit_msg_is "commit message"
+'
+
+test_expect_success 'cleanup commit message (default, -m)' '
+ echo content >>file &&
+ git add file &&
+ git commit -m "message #comment " &&
+ commit_msg_is "message #comment"
+'
+
+test_expect_success 'cleanup commit message (whitespace option, -m)' '
+ echo content >>file &&
+ git add file &&
+ git commit --cleanup=whitespace --no-status -m "message #comment " &&
+ commit_msg_is "message #comment"
+'
+
+test_expect_success 'cleanup commit message (whitespace config, -m)' '
+ echo content >>file &&
+ git add file &&
+ git -c commit.cleanup=whitespace commit --no-status -m "message #comment " &&
+ commit_msg_is "message #comment"
+'
+
test_expect_success 'message shows author when it is not equal to committer' '
echo >>negative &&
git commit -e -m "sample" -a &&
--
1.8.1.165.g0eb732d.dirty
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCHv2] commit: make default of "cleanup" option configurable
2013-01-09 19:36 ` [PATCHv2] commit: make default of "cleanup" option configurable Ralf Thielow
@ 2013-01-10 0:17 ` Junio C Hamano
2013-01-10 17:45 ` [PATCHv3] " Ralf Thielow
1 sibling, 0 replies; 18+ messages in thread
From: Junio C Hamano @ 2013-01-10 0:17 UTC (permalink / raw)
To: Ralf Thielow; +Cc: jrnieder, git
Ralf Thielow <ralf.thielow@gmail.com> writes:
> The default of the "cleanup" option in "git commit"
> is not configurable. Users who don't want to use the
> default have to pass this option on every commit since
> there's no way to configure it. This commit introduces
> a new config option "commit.cleanup" which can be used
> to change the default of the "cleanup" option in
> "git commit".
>
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
Thanks.
> Changes in v2:
> - simplify implementation
> - mention configuration variable in documentation of "git commit --cleanup"
> - add an example usecase to documention of commit.cleanup configuration variable
> - add tests
>
> Documentation/config.txt | 7 ++++
> Documentation/git-commit.txt | 4 +-
> builtin/commit.c | 5 ++-
> t/t7500/add-content-and-comment | 4 ++
> t/t7502-commit.sh | 84 +++++++++++++++++++++++++++++++++++++----
> 5 files changed, 95 insertions(+), 9 deletions(-)
> create mode 100755 t/t7500/add-content-and-comment
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 53c4ca1..0452d56 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -917,6 +917,13 @@ column.tag::
> Specify whether to output tag listing in `git tag` in columns.
> See `column.ui` for details.
>
> +commit.cleanup::
> + This setting overrides the default of the `--cleanup` option in
> + `git commit`. See linkgit:git-commit[1] for details. Changing the
> + default can be useful if you want to use the comment character (#)
> + consistently within your commit messages, in which case you would
> + like to change the default to 'whitespace'.
When the documentation suggests to use 'whitespace', it would be
helpful to warn the readers that hints Git produces in '#'-commented
section need to be removed, if they are not ment to be kept (which
is 99.99% of the case). Perhaps:
This setting overrides the default of the `--cleanup` option
in `git commit`. Changing the default can be useful when you
always want to keep lines that begin with comment character
`#` in your log message, in which case you would do `git
config commit.cleanup whitespace` (note that you will have
to remove the help lines that begin with '#' in the commit
log template yourself, if you do this).
or something?
> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
> index 7bdb039..41b27da 100644
> --- a/Documentation/git-commit.txt
> +++ b/Documentation/git-commit.txt
> @@ -179,7 +179,9 @@ OPTIONS
> only if the message is to be edited. Otherwise only whitespace
> removed. The 'verbatim' mode does not change message at all,
> 'whitespace' removes just leading/trailing whitespace lines
> - and 'strip' removes both whitespace and commentary.
> + and 'strip' removes both whitespace and commentary. The default
> + can be changed by the 'commit.cleanup' configuration variable
> + (see linkgit:git-config[1]).
Nicely written.
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -103,7 +103,7 @@ static enum {
> CLEANUP_NONE,
> CLEANUP_ALL
> } cleanup_mode;
> -static char *cleanup_arg;
> +static const char *cleanup_arg;
>
> static enum commit_whence whence;
> static int use_editor = 1, include_status = 1;
> @@ -966,6 +966,7 @@ static const char *read_commit_message(const char *name)
> return out;
> }
>
> +
> static int parse_and_validate_options(int argc, const char *argv[],
> const struct option *options,
> const char * const usage[],
Don't add an extra blank line, please.
> @@ -1320,6 +1321,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
> include_status = git_config_bool(k, v);
> return 0;
> }
> + if (!strcmp(k, "commit.cleanup"))
> + return git_config_string(&cleanup_arg, k, v);
Nice.
> diff --git a/t/t7500/add-content-and-comment b/t/t7500/add-content-and-comment
> new file mode 100755
> index 0000000..988f5e9
> --- /dev/null
> +++ b/t/t7500/add-content-and-comment
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +echo "commit message" >> "$1"
> +echo "# comment" >> "$1"
> +exit 0
> \ No newline at end of file
Have newline at end of file, please.
> diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
> index 1a5cb69..b1c7648 100755
> --- a/t/t7502-commit.sh
> +++ b/t/t7502-commit.sh
> @@ -4,6 +4,15 @@ test_description='git commit porcelain-ish'
> +...
> +'
> +
Nicely done.
Thanks.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCHv3] commit: make default of "cleanup" option configurable
2013-01-09 19:36 ` [PATCHv2] commit: make default of "cleanup" option configurable Ralf Thielow
2013-01-10 0:17 ` Junio C Hamano
@ 2013-01-10 17:45 ` Ralf Thielow
1 sibling, 0 replies; 18+ messages in thread
From: Ralf Thielow @ 2013-01-10 17:45 UTC (permalink / raw)
To: gitster, jrnieder; +Cc: git, Ralf Thielow
The default of the "cleanup" option in "git commit"
is not configurable. Users who don't want to use the
default have to pass this option on every commit since
there's no way to configure it. This commit introduces
a new config option "commit.cleanup" which can be used
to change the default of the "cleanup" option in
"git commit".
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
changes in v3:
- remove extra blank line in builtin/commit.c
- add newline at end of t/t7500/add-content-and-comment
- improve documentation of commit.cleanup configuration variable
as Junio suggested (makes a lot of sense)
Thanks
Documentation/config.txt | 9 +++++
Documentation/git-commit.txt | 4 +-
builtin/commit.c | 4 +-
t/t7500/add-content-and-comment | 5 +++
t/t7502-commit.sh | 84 +++++++++++++++++++++++++++++++++++++----
5 files changed, 97 insertions(+), 9 deletions(-)
create mode 100755 t/t7500/add-content-and-comment
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 53c4ca1..c92a308 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -917,6 +917,15 @@ column.tag::
Specify whether to output tag listing in `git tag` in columns.
See `column.ui` for details.
+commit.cleanup::
+ This setting overrides the default of the `--cleanup` option in
+ `git commit`. See linkgit:git-commit[1] for details. Changing the
+ default can be useful when you always want to keep lines that begin
+ with comment character `#` in your log message, in which case you
+ would do `git config commit.cleanup whitespace` (note that you will
+ have to remove the help lines that begin with `#` in the commit log
+ template yourself, if you do this).
+
commit.status::
A boolean to enable/disable inclusion of status information in the
commit message template when using an editor to prepare the commit
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 7bdb039..41b27da 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -179,7 +179,9 @@ OPTIONS
only if the message is to be edited. Otherwise only whitespace
removed. The 'verbatim' mode does not change message at all,
'whitespace' removes just leading/trailing whitespace lines
- and 'strip' removes both whitespace and commentary.
+ and 'strip' removes both whitespace and commentary. The default
+ can be changed by the 'commit.cleanup' configuration variable
+ (see linkgit:git-config[1]).
-e::
--edit::
diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..7c2a3d4 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -103,7 +103,7 @@ static enum {
CLEANUP_NONE,
CLEANUP_ALL
} cleanup_mode;
-static char *cleanup_arg;
+static const char *cleanup_arg;
static enum commit_whence whence;
static int use_editor = 1, include_status = 1;
@@ -1320,6 +1320,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
include_status = git_config_bool(k, v);
return 0;
}
+ if (!strcmp(k, "commit.cleanup"))
+ return git_config_string(&cleanup_arg, k, v);
status = git_gpg_config(k, v, NULL);
if (status)
diff --git a/t/t7500/add-content-and-comment b/t/t7500/add-content-and-comment
new file mode 100755
index 0000000..c4dccff
--- /dev/null
+++ b/t/t7500/add-content-and-comment
@@ -0,0 +1,5 @@
+#!/bin/sh
+echo "commit message" >> "$1"
+echo "# comment" >> "$1"
+exit 0
+
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 1a5cb69..b1c7648 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -4,6 +4,15 @@ test_description='git commit porcelain-ish'
. ./test-lib.sh
+commit_msg_is () {
+ expect=commit_msg_is.expect
+ actual=commit_msg_is.actual
+
+ printf "%s" "$(git log --pretty=format:%s%b -1)" >$actual &&
+ printf "%s" "$1" >$expect &&
+ test_i18ncmp $expect $actual
+}
+
# Arguments: [<prefix] [<commit message>] [<commit options>]
check_summary_oneline() {
test_tick &&
@@ -168,7 +177,7 @@ test_expect_success 'verbose respects diff config' '
git config --unset color.diff
'
-test_expect_success 'cleanup commit messages (verbatim,-t)' '
+test_expect_success 'cleanup commit messages (verbatim option,-t)' '
echo >>negative &&
{ echo;echo "# text";echo; } >expect &&
@@ -178,7 +187,7 @@ test_expect_success 'cleanup commit messages (verbatim,-t)' '
'
-test_expect_success 'cleanup commit messages (verbatim,-F)' '
+test_expect_success 'cleanup commit messages (verbatim option,-F)' '
echo >>negative &&
git commit --cleanup=verbatim -F expect -a &&
@@ -187,7 +196,7 @@ test_expect_success 'cleanup commit messages (verbatim,-F)' '
'
-test_expect_success 'cleanup commit messages (verbatim,-m)' '
+test_expect_success 'cleanup commit messages (verbatim option,-m)' '
echo >>negative &&
git commit --cleanup=verbatim -m "$(cat expect)" -a &&
@@ -196,7 +205,7 @@ test_expect_success 'cleanup commit messages (verbatim,-m)' '
'
-test_expect_success 'cleanup commit messages (whitespace,-F)' '
+test_expect_success 'cleanup commit messages (whitespace option,-F)' '
echo >>negative &&
{ echo;echo "# text";echo; } >text &&
@@ -207,7 +216,7 @@ test_expect_success 'cleanup commit messages (whitespace,-F)' '
'
-test_expect_success 'cleanup commit messages (strip,-F)' '
+test_expect_success 'cleanup commit messages (strip option,-F)' '
echo >>negative &&
{ echo;echo "# text";echo sample;echo; } >text &&
@@ -218,7 +227,7 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
'
-test_expect_success 'cleanup commit messages (strip,-F,-e)' '
+test_expect_success 'cleanup commit messages (strip option,-F,-e)' '
echo >>negative &&
{ echo;echo sample;echo; } >text &&
@@ -231,10 +240,71 @@ echo "sample
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit." >expect
-test_expect_success 'cleanup commit messages (strip,-F,-e): output' '
+test_expect_success 'cleanup commit messages (strip option,-F,-e): output' '
test_i18ncmp expect actual
'
+test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' '
+ test_must_fail git commit --cleanup=non-existent
+'
+
+test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' '
+ test_must_fail git -c commit.cleanup=non-existent commit
+'
+
+test_expect_success 'cleanup commit message (no config and no option uses default)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git commit --no-status &&
+ commit_msg_is "commit message"
+'
+
+test_expect_success 'cleanup commit message (option overrides default)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git commit --cleanup=whitespace --no-status &&
+ commit_msg_is "commit message # comment"
+'
+
+test_expect_success 'cleanup commit message (config overrides default)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git -c commit.cleanup=whitespace commit --no-status &&
+ commit_msg_is "commit message # comment"
+'
+
+test_expect_success 'cleanup commit message (option overrides config)' '
+ echo content >>file &&
+ git add file &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+ git -c commit.cleanup=whitespace commit --cleanup=default &&
+ commit_msg_is "commit message"
+'
+
+test_expect_success 'cleanup commit message (default, -m)' '
+ echo content >>file &&
+ git add file &&
+ git commit -m "message #comment " &&
+ commit_msg_is "message #comment"
+'
+
+test_expect_success 'cleanup commit message (whitespace option, -m)' '
+ echo content >>file &&
+ git add file &&
+ git commit --cleanup=whitespace --no-status -m "message #comment " &&
+ commit_msg_is "message #comment"
+'
+
+test_expect_success 'cleanup commit message (whitespace config, -m)' '
+ echo content >>file &&
+ git add file &&
+ git -c commit.cleanup=whitespace commit --no-status -m "message #comment " &&
+ commit_msg_is "message #comment"
+'
+
test_expect_success 'message shows author when it is not equal to committer' '
echo >>negative &&
git commit -e -m "sample" -a &&
--
1.8.1.227.g44fe835
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re* [PATCH] commit: make default of "cleanup" option configurable
2013-01-09 15:56 ` Junio C Hamano
@ 2013-01-10 19:37 ` Junio C Hamano
2013-01-15 18:50 ` [PATCH] Allow custom "comment char" Ralf Thielow
0 siblings, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2013-01-10 19:37 UTC (permalink / raw)
To: git; +Cc: Jonathan Nieder, Ralf Thielow
Junio C Hamano <gitster@pobox.com> writes:
> I also wonder, as a longer term alternative (which would require a
> lot of code auditing and some refactoring), if it is useful to have
> an option and/or configuration that lets you configure the "comment
> in log message editor" character from the default "#" to something
> else. "git -c log.commentchar=% commit" may start the log message
> editor with something like this in it:
>
> % Please enter the commit message for your changes. Lines starting
> % with '%' will be ignored, and an empty message aborts the commit.
>
> Naturally, setting log.commentchar to "none" would disable stripping
> of any commented lines if such a feature existed, and stop issuing
> these helpful comments altogether, but still strip excess blank
> lines and trailing whitespaces.
>
> I wouldn't seriously suggest it as I am not sure if the usefulness
> of such a feature would outweigh the cost of coding it, though; at
> least not at this point yet.
A beginning of a patch to do would be like this, which does not look
too bad. There are some low hanging fruits I didn't bother to do in
this illustration (see NEEDSWORK comment in builtin/branch.c if some
of you are interested in pursuing it).
-- >8 --
From: Junio C Hamano <gitster@pobox.com>
Date: Thu, 10 Jan 2013 11:17:21 -0800
Subject: [PATCH] Allow custom "comment char"
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 #<bugid> 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 <gitster@pobox.com>
---
Documentation/config.txt | 6 ++++++
builtin/branch.c | 16 ++++++++++++----
builtin/commit.c | 15 ++++++++-------
builtin/fmt-merge-msg.c | 4 +++-
builtin/merge.c | 15 +++++++++++----
builtin/stripspace.c | 2 +-
cache.h | 6 ++++++
config.c | 8 ++++++++
environment.c | 6 ++++++
wt-status.c | 10 ++++++----
10 files changed, 67 insertions(+), 21 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/builtin/branch.c b/builtin/branch.c
index 873f624..7f8865a 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -706,11 +706,19 @@ 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');
+ /*
+ * NEEDSWORK: introduce a strbuf_commented_addf(), possibly
+ * sharing code with status_vprintf(), that makes each line
+ * commented with comment_line_char, and use it here and from
+ * other places (e.g. write_commented_object() and create_note()
+ * in builtin/notes.c and create_tag() in builtin/tag.c).
+ */
strbuf_addf(&buf,
- "# Please edit the description for the branch\n"
- "# %s\n"
- "# Lines starting with '#' will be stripped.\n",
- branch_name);
+ "%c Please edit the description for the branch\n"
+ "%c %s\n"
+ "%c Lines starting with '%c' will be stripped.\n",
+ comment_line_char, comment_line_char,
+ branch_name, comment_line_char, comment_line_char);
fp = fopen(git_path(edit_description), "w");
if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
strbuf_release(&buf);
diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..a946a13 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -733,15 +733,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (cleanup_mode == CLEANUP_ALL)
status_printf(s, GIT_COLOR_NORMAL,
_("Please enter the commit message for your changes."
- " Lines starting\nwith '#' will be ignored, and an empty"
- " message aborts the commit.\n"));
+ " Lines starting\nwith '%c' will be ignored, and an empty"
+ " message aborts the commit.\n"), comment_line_char);
else /* CLEANUP_SPACE, that is. */
status_printf(s, GIT_COLOR_NORMAL,
- _("Please enter the commit message for your changes."
- " Lines starting\n"
- "with '#' will be kept; you may remove them"
- " yourself if you want to.\n"
- "An empty message aborts the commit.\n"));
+ _("Please enter the commit message for your changes."
+ " Lines starting\n"
+ "with '%c' will be kept; you may remove them"
+ " yourself if you want to.\n"
+ "An empty message aborts the commit.\n"),
+ comment_line_char);
if (only_include_assumed)
status_printf_ln(s, GIT_COLOR_NORMAL,
"%s", only_include_assumed);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index e2e27b2..2261e1f 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -463,8 +463,10 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
}
strbuf_complete_line(tagbuf);
if (sig->len) {
+ char comment_head[3];
+ sprintf(comment_head, "%c ", comment_line_char);
strbuf_addch(tagbuf, '\n');
- strbuf_add_lines(tagbuf, "# ", sig->buf, sig->len);
+ strbuf_add_lines(tagbuf, comment_head, sig->buf, sig->len);
}
}
diff --git a/builtin/merge.c b/builtin/merge.c
index 3a31c4b..632d860 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -788,17 +788,24 @@ static const char merge_editor_comment[] =
N_("Please enter a commit message to explain why this merge is necessary,\n"
"especially if it merges an updated upstream into a topic branch.\n"
"\n"
- "Lines starting with '#' will be ignored, and an empty message aborts\n"
+ "Lines starting with '%c' will be ignored, and an empty message aborts\n"
"the commit.\n");
static void prepare_to_commit(struct commit_list *remoteheads)
{
struct strbuf msg = STRBUF_INIT;
- const char *comment = _(merge_editor_comment);
+ const char *commentf = _(merge_editor_comment);
strbuf_addbuf(&msg, &merge_msg);
strbuf_addch(&msg, '\n');
- if (0 < option_edit)
- strbuf_add_lines(&msg, "# ", comment, strlen(comment));
+ if (0 < option_edit) {
+ struct strbuf hint = STRBUF_INIT;
+ char comment_head[3];
+
+ sprintf(comment_head, "%c ", comment_line_char);
+ strbuf_addf(&hint, commentf, comment_line_char);
+ strbuf_add_lines(&msg, comment_head, hint.buf, hint.len);
+ strbuf_release(&hint);
+ }
write_merge_msg(&msg);
if (run_hook(get_index_file(), "prepare-commit-msg",
git_path("MERGE_MSG"), "merge", NULL, NULL))
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index f16986c..600ca66 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -45,7 +45,7 @@ void stripspace(struct strbuf *sb, int skip_comments)
eol = memchr(sb->buf + i, '\n', sb->len - i);
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
- if (skip_comments && len && sb->buf[i] == '#') {
+ if (skip_comments && len && sb->buf[i] == comment_line_char) {
newlen = 0;
continue;
}
diff --git a/cache.h b/cache.h
index c257953..0b435a4 100644
--- a/cache.h
+++ b/cache.h
@@ -562,6 +562,12 @@ extern int core_preload_index;
extern int core_apply_sparse_checkout;
extern int precomposed_unicode;
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+extern char comment_line_char;
+
enum branch_track {
BRANCH_TRACK_UNSPECIFIED = -1,
BRANCH_TRACK_NEVER = 0,
diff --git a/config.c b/config.c
index 7b444b6..d873c59 100644
--- a/config.c
+++ b/config.c
@@ -717,6 +717,14 @@ static int git_default_core_config(const char *var, const char *value)
if (!strcmp(var, "core.editor"))
return git_config_string(&editor_program, var, value);
+ if (!strcmp(var, "core.commentchar")) {
+ const char *comment;
+ int ret = git_config_string(&comment, var, value);
+ if (!ret)
+ comment_line_char = comment[0];
+ return ret;
+ }
+
if (!strcmp(var, "core.askpass"))
return git_config_string(&askpass_program, var, value);
diff --git a/environment.c b/environment.c
index 85edd7f..a40c38b 100644
--- a/environment.c
+++ b/environment.c
@@ -62,6 +62,12 @@ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
struct startup_info *startup_info;
unsigned long pack_size_limit_cfg;
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+char comment_line_char = '#';
+
/* Parallel index stat data preload? */
int core_preload_index = 0;
diff --git a/wt-status.c b/wt-status.c
index 2a9658b..f6f197e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -45,7 +45,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
strbuf_vaddf(&sb, fmt, ap);
if (!sb.len) {
- strbuf_addch(&sb, '#');
+ strbuf_addch(&sb, comment_line_char);
if (!trail)
strbuf_addch(&sb, ' ');
color_print_strbuf(s->fp, color, &sb);
@@ -59,7 +59,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
strbuf_reset(&linebuf);
if (at_bol) {
- strbuf_addch(&linebuf, '#');
+ strbuf_addch(&linebuf, comment_line_char);
if (*line != '\n' && *line != '\t')
strbuf_addch(&linebuf, ' ');
}
@@ -760,8 +760,10 @@ static void wt_status_print_tracking(struct wt_status *s)
for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
- "# %.*s", (int)(ep - cp), cp);
- color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
+ "%c %.*s", comment_line_char,
+ (int)(ep - cp), cp);
+ color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
+ comment_line_char);
}
static int has_unmerged(struct wt_status *s)
--
1.8.1.351.g191b7b1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH] Allow custom "comment char"
2013-01-10 19:37 ` Re* " Junio C Hamano
@ 2013-01-15 18:50 ` Ralf Thielow
2013-01-15 19:12 ` Junio C Hamano
2013-01-16 19:18 ` [PATCH v2] " Ralf Thielow
0 siblings, 2 replies; 18+ messages in thread
From: Ralf Thielow @ 2013-01-15 18:50 UTC (permalink / raw)
To: gitster; +Cc: jrnieder, git, Ralf Thielow
From: Junio C Hamano <gitster@pobox.com>
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 #<bugid> 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 <gitster@pobox.com>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
Documentation/config.txt | 6 ++++
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 | 2 +-
builtin/tag.c | 35 ++++++++++++------------
cache.h | 6 ++++
config.c | 8 ++++++
environment.c | 6 ++++
git-submodule.sh | 14 +++++++---
strbuf.c | 38 ++++++++++++++++++++++++++
strbuf.h | 4 +++
t/t7502-commit.sh | 7 +++++
t/t7508-status.sh | 50 ++++++++++++++++++++++++++++++++++
wt-status.c | 10 ++++---
18 files changed, 198 insertions(+), 61 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/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt
index 84686b5..6767102 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_commented_addstr`::
+
+ Add a NUL-terminated string prepended by a comment character and a blank
+ to the buffer.
+
`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,
- "# Please edit the description for the branch\n"
- "# %s\n"
- "# Lines starting with '#' will be stripped.\n",
- branch_name);
+ strbuf_commented_addf(&buf,
+ "Please edit the description for the branch\n"
+ " %s\n"
+ "Lines starting with '%c' will be stripped.\n",
+ branch_name, comment_line_char);
fp = fopen(git_path(edit_description), "w");
if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
strbuf_release(&buf);
diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..f95f64a 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -733,15 +733,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (cleanup_mode == CLEANUP_ALL)
status_printf(s, GIT_COLOR_NORMAL,
_("Please enter the commit message for your changes."
- " Lines starting\nwith '#' will be ignored, and an empty"
- " message aborts the commit.\n"));
+ " Lines starting\nwith '%c' will be ignored, and an empty"
+ " message aborts the commit.\n"), comment_line_char);
else /* CLEANUP_SPACE, that is. */
status_printf(s, GIT_COLOR_NORMAL,
_("Please enter the commit message for your changes."
- " Lines starting\n"
- "with '#' will be kept; you may remove them"
- " yourself if you want to.\n"
- "An empty message aborts the commit.\n"));
+ " Lines starting\n"
+ "with '%c' will be kept; you may remove them"
+ " yourself if you want to.\n"
+ "An empty message aborts the commit.\n"), comment_line_char);
if (only_include_assumed)
status_printf_ln(s, GIT_COLOR_NORMAL,
"%s", only_include_assumed);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index d9af43c..d0fcd34 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -470,7 +470,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
strbuf_complete_line(tagbuf);
if (sig->len) {
strbuf_addch(tagbuf, '\n');
- strbuf_add_lines(tagbuf, "# ", sig->buf, sig->len);
+ strbuf_commented_addstr(tagbuf, sig->buf);
}
}
diff --git a/builtin/merge.c b/builtin/merge.c
index 9307e9c..7c8922c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -788,17 +788,16 @@ static const char merge_editor_comment[] =
N_("Please enter a commit message to explain why this merge is necessary,\n"
"especially if it merges an updated upstream into a topic branch.\n"
"\n"
- "Lines starting with '#' will be ignored, and an empty message aborts\n"
+ "Lines starting with '%c' will be ignored, and an empty message aborts\n"
"the commit.\n");
static void prepare_to_commit(struct commit_list *remoteheads)
{
struct strbuf msg = STRBUF_INIT;
- const char *comment = _(merge_editor_comment);
strbuf_addbuf(&msg, &merge_msg);
strbuf_addch(&msg, '\n');
if (0 < option_edit)
- strbuf_add_lines(&msg, "# ", comment, strlen(comment));
+ strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
write_merge_msg(&msg);
if (run_hook(get_index_file(), "prepare-commit-msg",
git_path("MERGE_MSG"), "merge", NULL, NULL))
diff --git a/builtin/notes.c b/builtin/notes.c
index 453457a..5e84e35 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -92,10 +92,7 @@ static const char * const git_notes_get_ref_usage[] = {
};
static const char note_template[] =
- "\n"
- "#\n"
- "# Write/edit the notes for the following object:\n"
- "#\n";
+ "Write/edit the notes for the following object:";
struct msg_arg {
int given;
@@ -129,7 +126,7 @@ static void write_commented_object(int fd, const unsigned char *object)
{"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
struct child_process show;
struct strbuf buf = STRBUF_INIT;
- FILE *show_out;
+ struct strbuf cbuf = STRBUF_INIT;
/* Invoke "git show --stat --no-notes $object" */
memset(&show, 0, sizeof(show));
@@ -142,21 +139,14 @@ static void write_commented_object(int fd, const unsigned char *object)
die(_("unable to start 'show' for object '%s'"),
sha1_to_hex(object));
- /* Open the output as FILE* so strbuf_getline() can be used. */
- show_out = xfdopen(show.out, "r");
- if (show_out == NULL)
- die_errno(_("can't fdopen 'show' output fd"));
+ if (strbuf_read(&buf, show.out, 0) < 0)
+ die_errno(_("could not read 'show' output"));
+ strbuf_commented_addstr(&cbuf, buf.buf);
+ write_or_die(fd, cbuf.buf, cbuf.len);
- /* Prepend "# " to each output line and write result to 'fd' */
- while (strbuf_getline(&buf, show_out, '\n') != EOF) {
- write_or_die(fd, "# ", 2);
- write_or_die(fd, buf.buf, buf.len);
- write_or_die(fd, "\n", 1);
- }
+ strbuf_release(&cbuf);
strbuf_release(&buf);
- if (fclose(show_out))
- die_errno(_("failed to close pipe to 'show' for object '%s'"),
- sha1_to_hex(object));
+
if (finish_command(&show))
die(_("failed to finish 'show' for object '%s'"),
sha1_to_hex(object));
@@ -170,6 +160,7 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
if (msg->use_editor || !msg->given) {
int fd;
+ struct strbuf buf = STRBUF_INIT;
/* write the template message before editing: */
path = git_pathdup("NOTES_EDITMSG");
@@ -181,11 +172,16 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
write_or_die(fd, msg->buf.buf, msg->buf.len);
else if (prev && !append_only)
write_note_data(fd, prev);
- write_or_die(fd, note_template, strlen(note_template));
+
+ strbuf_addf(&buf, "\n%c\n", comment_line_char);
+ strbuf_commented_addstr(&buf, note_template);
+ strbuf_addf(&buf, "\n%c\n", comment_line_char);
+ write_or_die(fd, buf.buf, buf.len);
write_commented_object(fd, object);
close(fd);
+ strbuf_release(&buf);
strbuf_reset(&(msg->buf));
if (launch_editor(path, &(msg->buf), NULL)) {
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index f16986c..600ca66 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -45,7 +45,7 @@ void stripspace(struct strbuf *sb, int skip_comments)
eol = memchr(sb->buf + i, '\n', sb->len - i);
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
- if (skip_comments && len && sb->buf[i] == '#') {
+ if (skip_comments && len && sb->buf[i] == comment_line_char) {
newlen = 0;
continue;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index 9c3e067..e1b72be 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -246,19 +246,13 @@ static int do_sign(struct strbuf *buffer)
}
static const char tag_template[] =
- N_("\n"
- "#\n"
- "# Write a tag message\n"
- "# Lines starting with '#' will be ignored.\n"
- "#\n");
+ N_("Write a tag message\n"
+ "Lines starting with '%c' will be ignored.");
static const char tag_template_nocleanup[] =
- N_("\n"
- "#\n"
- "# Write a tag message\n"
- "# Lines starting with '#' will be kept; you may remove them"
- " yourself if you want to.\n"
- "#\n");
+ N_("Write a tag message\n"
+ "Lines starting with '%c' will be kept; you may remove them"
+ " yourself if you want to.");
static int git_tag_config(const char *var, const char *value, void *cb)
{
@@ -346,14 +340,19 @@ static void create_tag(const unsigned char *object, const char *tag,
if (fd < 0)
die_errno(_("could not create file '%s'"), path);
- if (!is_null_sha1(prev))
+ if (!is_null_sha1(prev)) {
write_tag_body(fd, prev);
- else if (opt->cleanup_mode == CLEANUP_ALL)
- write_or_die(fd, _(tag_template),
- strlen(_(tag_template)));
- else
- write_or_die(fd, _(tag_template_nocleanup),
- strlen(_(tag_template_nocleanup)));
+ } else {
+ struct strbuf buf = STRBUF_INIT;
+ strbuf_addf(&buf, "\n%c\n", comment_line_char);
+ if (opt->cleanup_mode == CLEANUP_ALL)
+ strbuf_commented_addf(&buf, _(tag_template), comment_line_char);
+ else
+ strbuf_commented_addf(&buf, _(tag_template_nocleanup), comment_line_char);
+ strbuf_addf(&buf, "\n%c\n", comment_line_char);
+ write_or_die(fd, buf.buf, buf.len);
+ strbuf_release(&buf);
+ }
close(fd);
if (launch_editor(path, buf, NULL)) {
diff --git a/cache.h b/cache.h
index c257953..0b435a4 100644
--- a/cache.h
+++ b/cache.h
@@ -562,6 +562,12 @@ extern int core_preload_index;
extern int core_apply_sparse_checkout;
extern int precomposed_unicode;
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+extern char comment_line_char;
+
enum branch_track {
BRANCH_TRACK_UNSPECIFIED = -1,
BRANCH_TRACK_NEVER = 0,
diff --git a/config.c b/config.c
index 7b444b6..d873c59 100644
--- a/config.c
+++ b/config.c
@@ -717,6 +717,14 @@ static int git_default_core_config(const char *var, const char *value)
if (!strcmp(var, "core.editor"))
return git_config_string(&editor_program, var, value);
+ if (!strcmp(var, "core.commentchar")) {
+ const char *comment;
+ int ret = git_config_string(&comment, var, value);
+ if (!ret)
+ comment_line_char = comment[0];
+ return ret;
+ }
+
if (!strcmp(var, "core.askpass"))
return git_config_string(&askpass_program, var, value);
diff --git a/environment.c b/environment.c
index 85edd7f..a40c38b 100644
--- a/environment.c
+++ b/environment.c
@@ -62,6 +62,12 @@ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
struct startup_info *startup_info;
unsigned long pack_size_limit_cfg;
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+char comment_line_char = '#';
+
/* Parallel index stat data preload? */
int core_preload_index = 0;
diff --git a/git-submodule.sh b/git-submodule.sh
index 22ec5b6..1b8d95f 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -975,13 +975,19 @@ cmd_summary() {
echo
done |
if test -n "$for_status"; then
+ comment_char=`git config core.commentchar`
+ if [ ! -n "$comment_char" ]; then
+ comment_char='#'
+ elif [ ${#comment_char} -gt 1 ]; then
+ comment_char=`expr substr $comment_char 1 1`
+ fi
if [ -n "$files" ]; then
- gettextln "# Submodules changed but not updated:"
+ eval_gettextln "\$comment_char Submodules changed but not updated:"
else
- gettextln "# Submodule changes to be committed:"
+ eval_gettextln "\$comment_char Submodule changes to be committed:"
fi
- echo "#"
- sed -e 's|^|# |' -e 's|^# $|#|'
+ echo "$comment_char"
+ sed -e "s|^|$comment_char |" -e "s|^$comment_char $|$comment_char|"
else
cat
fi
diff --git a/strbuf.c b/strbuf.c
index 9a373be..8af4b4f 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -204,6 +204,44 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
va_end(ap);
}
+void strbuf_commented_addstr(struct strbuf *sb, const char *s)
+{
+ struct strbuf buf = STRBUF_INIT;
+ struct strbuf prefix = STRBUF_INIT;
+
+ strbuf_addf(&prefix, "%c ", comment_line_char);
+ strbuf_addstr(&buf, s);
+ strbuf_add_lines(sb, prefix.buf, buf.buf, buf.len);
+
+ // remove additional '\n' added by strbuf_add_lines()
+ if (sb->len && sb->buf[sb->len - 1] != buf.buf[buf.len - 1])
+ strbuf_remove(sb, sb->len - 1, 1);
+
+ strbuf_release(&prefix);
+ strbuf_release(&buf);
+}
+
+void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...)
+{
+ va_list params;
+ struct strbuf buf = STRBUF_INIT;
+ struct strbuf prefix = STRBUF_INIT;
+
+ va_start(params, fmt);
+ strbuf_vaddf(&buf, fmt, params);
+ va_end(params);
+
+ strbuf_addf(&prefix, "%c ", comment_line_char);
+ strbuf_add_lines(sb, prefix.buf, buf.buf, buf.len);
+
+ // remove additional '\n' added by strbuf_add_lines()
+ if (sb->len && sb->buf[sb->len - 1] != buf.buf[buf.len - 1])
+ strbuf_remove(sb, sb->len - 1, 1);
+
+ strbuf_release(&prefix);
+ strbuf_release(&buf);
+}
+
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)
{
int len;
diff --git a/strbuf.h b/strbuf.h
index ecae4e2..8d5afd5 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -110,6 +110,8 @@ extern void strbuf_remove(struct strbuf *, size_t pos, size_t len);
extern void strbuf_splice(struct strbuf *, size_t pos, size_t len,
const void *, size_t);
+extern void strbuf_commented_addstr(struct strbuf *sb, const char *s);
+
extern void strbuf_add(struct strbuf *, const void *, size_t);
static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
strbuf_add(sb, s, strlen(s));
@@ -131,6 +133,8 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *
__attribute__((format (printf,2,3)))
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
+__attribute__((format (printf, 2, 3)))
+extern void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...);
__attribute__((format (printf,2,0)))
extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 1a5cb69..6a2c67c 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -447,4 +447,11 @@ use_template="-t template"
try_commit_status_combo
+test_expect_success 'commit --status with custom comment character' '
+ test_when_finished "git config --unset core.commentchar" &&
+ git config core.commentchar ";" &&
+ try_commit --status &&
+ test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
+'
+
test_done
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e313ef1..a79c032 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1254,6 +1254,56 @@ test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary
'
cat > expect << EOF
+; On branch master
+; Changes to be committed:
+; (use "git reset HEAD <file>..." to unstage)
+;
+; modified: sm
+;
+; Changes not staged for commit:
+; (use "git add <file>..." to update what will be committed)
+; (use "git checkout -- <file>..." to discard changes in working directory)
+;
+; modified: dir1/modified
+; modified: sm (new commits)
+;
+; Submodule changes to be committed:
+;
+; * sm $head...$new_head (1):
+; > Add bar
+;
+; Submodules changed but not updated:
+;
+; * sm $new_head...$head2 (1):
+; > 2nd commit
+;
+; Untracked files:
+; (use "git add <file>..." to include in what will be committed)
+;
+; .gitmodules
+; dir1/untracked
+; dir2/modified
+; dir2/untracked
+; expect
+; output
+; untracked
+EOF
+
+test_expect_success "status (core.commentchar with submodule summary)" '
+ test_when_finished "git config --unset core.commentchar" &&
+ git config core.commentchar ";" &&
+ git status >output &&
+ test_i18ncmp expect output
+'
+
+test_expect_success "status (core.commentchar with two chars with submodule summary)" '
+ test_when_finished "git config --unset core.commentchar" &&
+ git config core.commentchar ";;" &&
+ git status >output &&
+ test_i18ncmp expect output
+'
+
+cat > expect << EOF
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
diff --git a/wt-status.c b/wt-status.c
index 2a9658b..f6f197e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -45,7 +45,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
strbuf_vaddf(&sb, fmt, ap);
if (!sb.len) {
- strbuf_addch(&sb, '#');
+ strbuf_addch(&sb, comment_line_char);
if (!trail)
strbuf_addch(&sb, ' ');
color_print_strbuf(s->fp, color, &sb);
@@ -59,7 +59,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
strbuf_reset(&linebuf);
if (at_bol) {
- strbuf_addch(&linebuf, '#');
+ strbuf_addch(&linebuf, comment_line_char);
if (*line != '\n' && *line != '\t')
strbuf_addch(&linebuf, ' ');
}
@@ -760,8 +760,10 @@ static void wt_status_print_tracking(struct wt_status *s)
for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
- "# %.*s", (int)(ep - cp), cp);
- color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
+ "%c %.*s", comment_line_char,
+ (int)(ep - cp), cp);
+ color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
+ comment_line_char);
}
static int has_unmerged(struct wt_status *s)
--
1.8.1.291.g185e8f6
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH] Allow custom "comment char"
2013-01-15 18:50 ` [PATCH] Allow custom "comment char" Ralf Thielow
@ 2013-01-15 19:12 ` Junio C Hamano
2013-01-16 6:23 ` Junio C Hamano
2013-01-16 19:18 ` [PATCH v2] " Ralf Thielow
1 sibling, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2013-01-15 19:12 UTC (permalink / raw)
To: Ralf Thielow; +Cc: jrnieder, git
Ralf Thielow <ralf.thielow@gmail.com> writes:
> From: Junio C Hamano <gitster@pobox.com>
>
> 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 #<bugid> 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 <gitster@pobox.com>
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
It would have helped if you said you finished the NEEDSWORK: in
builtin/branch.c in the earlier draft with strbuf_commented_*
functions ;-)
Looks like a good progress overall, except for nits here and there.
> diff --git a/builtin/notes.c b/builtin/notes.c
> index 453457a..5e84e35 100644
> --- a/builtin/notes.c
> +++ b/builtin/notes.c
> @@ -92,10 +92,7 @@ static const char * const git_notes_get_ref_usage[] = {
> };
>
> static const char note_template[] =
> - "\n"
> - "#\n"
> - "# Write/edit the notes for the following object:\n"
> - "#\n";
> + "Write/edit the notes for the following object:";
I think this (and its use site that manually adds "\n#\n") is a
symptom of strbuf_commented_add*() function not designed right.
When it iterates over lines and adds each of them in a commented out
form, it could check if the line is an empty one and refrain from
adding a trailing SP if that is the case. Then this can become
"\nWrite/edit the notes...\n\n";
You have to create the "\n" blank line at the beginning manually,
but that is logically outside the commented out block, so it is not
a problem.
> @@ -181,11 +172,16 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
> write_or_die(fd, msg->buf.buf, msg->buf.len);
> else if (prev && !append_only)
> write_note_data(fd, prev);
> - write_or_die(fd, note_template, strlen(note_template));
> +
> + strbuf_addf(&buf, "\n%c\n", comment_line_char);
> + strbuf_commented_addstr(&buf, note_template);
> + strbuf_addf(&buf, "\n%c\n", comment_line_char);
> + write_or_die(fd, buf.buf, buf.len);
> diff --git a/builtin/tag.c b/builtin/tag.c
> index 9c3e067..e1b72be 100644
> --- a/builtin/tag.c
> +++ b/builtin/tag.c
> @@ -246,19 +246,13 @@ static int do_sign(struct strbuf *buffer)
> }
>
> static const char tag_template[] =
> - N_("\n"
> - "#\n"
> - "# Write a tag message\n"
> - "# Lines starting with '#' will be ignored.\n"
> - "#\n");
> + N_("Write a tag message\n"
> + "Lines starting with '%c' will be ignored.");
> ...
> + else
> + strbuf_commented_addf(&buf, _(tag_template_nocleanup), comment_line_char);
> + strbuf_addf(&buf, "\n%c\n", comment_line_char);
> + write_or_die(fd, buf.buf, buf.len);
Same here.
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 22ec5b6..1b8d95f 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -975,13 +975,19 @@ cmd_summary() {
> echo
> done |
> if test -n "$for_status"; then
> + comment_char=`git config core.commentchar`
> + if [ ! -n "$comment_char" ]; then
> + comment_char='#'
> + elif [ ${#comment_char} -gt 1 ]; then
Not portable, I think.
> + echo "$comment_char"
> + sed -e "s|^|$comment_char |" -e "s|^$comment_char $|$comment_char|"
Can $comment_char be a '|'?
> diff --git a/strbuf.c b/strbuf.c
> index 9a373be..8af4b4f 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -204,6 +204,44 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
> va_end(ap);
> }
>
> +void strbuf_commented_addstr(struct strbuf *sb, const char *s)
> +{
> + struct strbuf buf = STRBUF_INIT;
> + struct strbuf prefix = STRBUF_INIT;
> +
> + strbuf_addf(&prefix, "%c ", comment_line_char);
> + strbuf_addstr(&buf, s);
> + strbuf_add_lines(sb, prefix.buf, buf.buf, buf.len);
> +
> + // remove additional '\n' added by strbuf_add_lines()
No C++ comments.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] Allow custom "comment char"
2013-01-15 19:12 ` Junio C Hamano
@ 2013-01-16 6:23 ` Junio C Hamano
2013-01-16 8:17 ` Ralf Thielow
0 siblings, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2013-01-16 6:23 UTC (permalink / raw)
To: Ralf Thielow; +Cc: jrnieder, git
Junio C Hamano <gitster@pobox.com> writes:
> Ralf Thielow <ralf.thielow@gmail.com> writes:
> ...
> Looks like a good progress overall, except for nits here and there.
>
>> diff --git a/builtin/notes.c b/builtin/notes.c
>> index 453457a..5e84e35 100644
>> --- a/builtin/notes.c
>> +++ b/builtin/notes.c
>> @@ -92,10 +92,7 @@ static const char * const git_notes_get_ref_usage[] = {
>> };
>>
>> static const char note_template[] =
>> - "\n"
>> - "#\n"
>> - "# Write/edit the notes for the following object:\n"
>> - "#\n";
>> + "Write/edit the notes for the following object:";
>
> I think this (and its use site that manually adds "\n#\n") is a
> symptom of strbuf_commented_add*() function not designed right.
> When it iterates over lines and adds each of them in a commented out
> form, it could check if the line is an empty one and refrain from
> adding a trailing SP if that is the case. Then this can become
>
> "\nWrite/edit the notes...\n\n";
>
> You have to create the "\n" blank line at the beginning manually,
> but that is logically outside the commented out block, so it is not
> a problem.
>> diff --git a/git-submodule.sh b/git-submodule.sh
>> index 22ec5b6..1b8d95f 100755
>> --- a/git-submodule.sh
>> +++ b/git-submodule.sh
>> @@ -975,13 +975,19 @@ cmd_summary() {
>> echo
>> done |
>> if test -n "$for_status"; then
>> + comment_char=`git config core.commentchar`
>> + if [ ! -n "$comment_char" ]; then
>> + comment_char='#'
>> + elif [ ${#comment_char} -gt 1 ]; then
>
> Not portable, I think.
>
>> + echo "$comment_char"
>> + sed -e "s|^|$comment_char |" -e "s|^$comment_char $|$comment_char|"
>
> Can $comment_char be a '|'?
I think it may be the easiest to teach one of the pure-helper
commands, e.g. "git stripspace", to do this kind of thing for you
with a new option.
To summarize, along the lines of the attached patch (on top of
jc/custom-comment-char topic).
builtin/branch.c | 20 +++++++++-----------
builtin/stripspace.c | 35 +++++++++++++++++++++++++++++------
strbuf.c | 42 +++++++++++++++++++++++++++++++++++++++++-
strbuf.h | 4 ++++
4 files changed, 83 insertions(+), 18 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 7f8865a..42de4c5 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -707,18 +707,16 @@ static int edit_branch_description(const char *branch_name)
if (!buf.len || buf.buf[buf.len-1] != '\n')
strbuf_addch(&buf, '\n');
/*
- * NEEDSWORK: introduce a strbuf_commented_addf(), possibly
- * sharing code with status_vprintf(), that makes each line
- * commented with comment_line_char, and use it here and from
- * other places (e.g. write_commented_object() and create_note()
- * in builtin/notes.c and create_tag() in builtin/tag.c).
+ * NEEDSWORK: convert more code to use this:
+ * (e.g. write_commented_object() and create_note() in
+ * builtin/notes.c and create_tag() in builtin/tag.c).
*/
- strbuf_addf(&buf,
- "%c Please edit the description for the branch\n"
- "%c %s\n"
- "%c Lines starting with '%c' will be stripped.\n",
- comment_line_char, comment_line_char,
- branch_name, comment_line_char, comment_line_char);
+ strbuf_commented_addf(&buf,
+ "Please edit the description for the branch\n"
+ " %s\n"
+ "Lines starting with '%c' will be stripped.\n",
+ branch_name, comment_line_char);
+
fp = fopen(git_path(edit_description), "w");
if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
strbuf_release(&buf);
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 600ca66..790b500 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -66,21 +66,44 @@ 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);
+}
+
int cmd_stripspace(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
int strip_comments = 0;
+ enum { INVAL = 0, STRIP_SPACE = 1, COMMENT_LINES = 2 } mode = STRIP_SPACE;
+
+ if (argc == 2) {
+ if (!strcmp(argv[1], "-s") ||
+ !strcmp(argv[1], "--strip-comments")) {
+ strip_comments = 1;
+ } else if (!strcmp(argv[1], "-c")) {
+ mode = COMMENT_LINES;
+ git_config(git_default_config, NULL);
+ } else {
+ mode = INVAL;
+ }
+ } else if (argc > 1)
+ mode = INVAL;
- if (argc == 2 && (!strcmp(argv[1], "-s") ||
- !strcmp(argv[1], "--strip-comments")))
- strip_comments = 1;
- else if (argc > 1)
- usage("git stripspace [-s | --strip-comments] < input");
+ if (mode == INVAL)
+ usage("git stripspace [-s|-c] <input");
if (strbuf_read(&buf, 0, 1024) < 0)
die_errno("could not read the input");
- stripspace(&buf, strip_comments);
+ if (mode == STRIP_SPACE)
+ stripspace(&buf, strip_comments);
+ else /* i.e. COMMENT_LINES */
+ comment_lines(&buf);
write_or_die(1, buf.buf, buf.len);
strbuf_release(&buf);
diff --git a/strbuf.c b/strbuf.c
index 9a373be..d0525c8 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -411,12 +411,17 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
return len;
}
-void strbuf_add_lines(struct strbuf *out, const char *prefix,
+static void add_lines(struct strbuf *out,
+ const char *prefix1,
+ const char *prefix2,
const char *buf, size_t size)
{
while (size) {
+ const char *prefix;
const char *next = memchr(buf, '\n', size);
next = next ? (next + 1) : (buf + size);
+
+ prefix = (prefix2 && buf[0] == '\n') ? prefix2 : prefix1;
strbuf_addstr(out, prefix);
strbuf_add(out, buf, next - buf);
size -= next - buf;
@@ -425,6 +430,41 @@ void strbuf_add_lines(struct strbuf *out, const char *prefix,
strbuf_complete_line(out);
}
+void strbuf_add_lines(struct strbuf *out, const char *prefix,
+ const char *buf, size_t size)
+{
+ add_lines(out, prefix, NULL, buf, size);
+}
+
+void strbuf_add_commented_lines(struct strbuf *out,
+ const char *buf, size_t size)
+{
+ static char prefix1[3];
+ static char prefix2[2];
+
+ if (prefix1[0] != comment_line_char) {
+ sprintf(prefix1, "%c ", comment_line_char);
+ sprintf(prefix2, "%c", comment_line_char);
+ }
+ add_lines(out, prefix1, prefix2, buf, size);
+}
+
+void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...)
+{
+ va_list params;
+ struct strbuf buf = STRBUF_INIT;
+ int incomplete_line = sb->len && sb->buf[sb->len - 1] != '\n';
+
+ va_start(params, fmt);
+ strbuf_vaddf(&buf, fmt, params);
+ va_end(params);
+
+ strbuf_add_commented_lines(sb, buf.buf, buf.len);
+ if (incomplete_line)
+ sb->buf[--sb->len] = '\0';
+ strbuf_release(&buf);
+}
+
void strbuf_addstr_xml_quoted(struct strbuf *buf, const char *s)
{
while (*s) {
diff --git a/strbuf.h b/strbuf.h
index ecae4e2..1eb0c75 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -131,10 +131,14 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *
__attribute__((format (printf,2,3)))
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
+__attribute__((format (printf,2,3)))
+extern void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...);
__attribute__((format (printf,2,0)))
extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size);
+extern void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size);
+
/*
* Append s to sb, with the characters '<', '>', '&' and '"' converted
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH] Allow custom "comment char"
2013-01-16 6:23 ` Junio C Hamano
@ 2013-01-16 8:17 ` Ralf Thielow
0 siblings, 0 replies; 18+ messages in thread
From: Ralf Thielow @ 2013-01-16 8:17 UTC (permalink / raw)
To: Junio C Hamano; +Cc: jrnieder, git
2013/1/16 Junio C Hamano <gitster@pobox.com>:
>>> diff --git a/git-submodule.sh b/git-submodule.sh
>>> index 22ec5b6..1b8d95f 100755
>>> --- a/git-submodule.sh
>>> +++ b/git-submodule.sh
>>> @@ -975,13 +975,19 @@ cmd_summary() {
>>> echo
>>> done |
>>> if test -n "$for_status"; then
>>> + comment_char=`git config core.commentchar`
>>> + if [ ! -n "$comment_char" ]; then
>>> + comment_char='#'
>>> + elif [ ${#comment_char} -gt 1 ]; then
>>
>> Not portable, I think.
>>
>>> + echo "$comment_char"
>>> + sed -e "s|^|$comment_char |" -e "s|^$comment_char $|$comment_char|"
>>
>> Can $comment_char be a '|'?
>
> I think it may be the easiest to teach one of the pure-helper
> commands, e.g. "git stripspace", to do this kind of thing for you
> with a new option.
>
> To summarize, along the lines of the attached patch (on top of
> jc/custom-comment-char topic).
Very good idea. I'll integrate.
Thanks
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2] Allow custom "comment char"
2013-01-15 18:50 ` [PATCH] Allow custom "comment char" Ralf Thielow
2013-01-15 19:12 ` Junio C Hamano
@ 2013-01-16 19:18 ` Ralf Thielow
2013-01-16 20:30 ` Junio C Hamano
2013-01-16 21:02 ` Jens Lehmann
1 sibling, 2 replies; 18+ messages in thread
From: Ralf Thielow @ 2013-01-16 19:18 UTC (permalink / raw)
To: gitster; +Cc: jrnieder, git, Ralf Thielow
From: Junio C Hamano <gitster@pobox.com>
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 #<bugid> 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 <gitster@pobox.com>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
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,
- "# Please edit the description for the branch\n"
- "# %s\n"
- "# Lines starting with '#' will be stripped.\n",
- branch_name);
+ strbuf_commented_addf(&buf,
+ "Please edit the description for the branch\n"
+ " %s\n"
+ "Lines starting with '%c' will be stripped.\n",
+ branch_name, comment_line_char);
fp = fopen(git_path(edit_description), "w");
if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
strbuf_release(&buf);
diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..f95f64a 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -733,15 +733,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (cleanup_mode == CLEANUP_ALL)
status_printf(s, GIT_COLOR_NORMAL,
_("Please enter the commit message for your changes."
- " Lines starting\nwith '#' will be ignored, and an empty"
- " message aborts the commit.\n"));
+ " Lines starting\nwith '%c' will be ignored, and an empty"
+ " message aborts the commit.\n"), comment_line_char);
else /* CLEANUP_SPACE, that is. */
status_printf(s, GIT_COLOR_NORMAL,
_("Please enter the commit message for your changes."
- " Lines starting\n"
- "with '#' will be kept; you may remove them"
- " yourself if you want to.\n"
- "An empty message aborts the commit.\n"));
+ " Lines starting\n"
+ "with '%c' will be kept; you may remove them"
+ " yourself if you want to.\n"
+ "An empty message aborts the commit.\n"), comment_line_char);
if (only_include_assumed)
status_printf_ln(s, GIT_COLOR_NORMAL,
"%s", only_include_assumed);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index d9af43c..b49612f 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -470,7 +470,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
strbuf_complete_line(tagbuf);
if (sig->len) {
strbuf_addch(tagbuf, '\n');
- strbuf_add_lines(tagbuf, "# ", sig->buf, sig->len);
+ strbuf_add_commented_lines(tagbuf, sig->buf, sig->len);
}
}
diff --git a/builtin/merge.c b/builtin/merge.c
index 9307e9c..7c8922c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -788,17 +788,16 @@ static const char merge_editor_comment[] =
N_("Please enter a commit message to explain why this merge is necessary,\n"
"especially if it merges an updated upstream into a topic branch.\n"
"\n"
- "Lines starting with '#' will be ignored, and an empty message aborts\n"
+ "Lines starting with '%c' will be ignored, and an empty message aborts\n"
"the commit.\n");
static void prepare_to_commit(struct commit_list *remoteheads)
{
struct strbuf msg = STRBUF_INIT;
- const char *comment = _(merge_editor_comment);
strbuf_addbuf(&msg, &merge_msg);
strbuf_addch(&msg, '\n');
if (0 < option_edit)
- strbuf_add_lines(&msg, "# ", comment, strlen(comment));
+ strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
write_merge_msg(&msg);
if (run_hook(get_index_file(), "prepare-commit-msg",
git_path("MERGE_MSG"), "merge", NULL, NULL))
diff --git a/builtin/notes.c b/builtin/notes.c
index 453457a..57748a6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -92,10 +92,7 @@ static const char * const git_notes_get_ref_usage[] = {
};
static const char note_template[] =
- "\n"
- "#\n"
- "# Write/edit the notes for the following object:\n"
- "#\n";
+ "\nWrite/edit the notes for the following object:\n";
struct msg_arg {
int given;
@@ -129,7 +126,7 @@ static void write_commented_object(int fd, const unsigned char *object)
{"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
struct child_process show;
struct strbuf buf = STRBUF_INIT;
- FILE *show_out;
+ struct strbuf cbuf = STRBUF_INIT;
/* Invoke "git show --stat --no-notes $object" */
memset(&show, 0, sizeof(show));
@@ -142,21 +139,14 @@ static void write_commented_object(int fd, const unsigned char *object)
die(_("unable to start 'show' for object '%s'"),
sha1_to_hex(object));
- /* Open the output as FILE* so strbuf_getline() can be used. */
- show_out = xfdopen(show.out, "r");
- if (show_out == NULL)
- die_errno(_("can't fdopen 'show' output fd"));
+ if (strbuf_read(&buf, show.out, 0) < 0)
+ die_errno(_("could not read 'show' output"));
+ strbuf_add_commented_lines(&cbuf, buf.buf, buf.len);
+ write_or_die(fd, cbuf.buf, cbuf.len);
- /* Prepend "# " to each output line and write result to 'fd' */
- while (strbuf_getline(&buf, show_out, '\n') != EOF) {
- write_or_die(fd, "# ", 2);
- write_or_die(fd, buf.buf, buf.len);
- write_or_die(fd, "\n", 1);
- }
+ strbuf_release(&cbuf);
strbuf_release(&buf);
- if (fclose(show_out))
- die_errno(_("failed to close pipe to 'show' for object '%s'"),
- sha1_to_hex(object));
+
if (finish_command(&show))
die(_("failed to finish 'show' for object '%s'"),
sha1_to_hex(object));
@@ -170,6 +160,7 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
if (msg->use_editor || !msg->given) {
int fd;
+ struct strbuf buf = STRBUF_INIT;
/* write the template message before editing: */
path = git_pathdup("NOTES_EDITMSG");
@@ -181,11 +172,16 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
write_or_die(fd, msg->buf.buf, msg->buf.len);
else if (prev && !append_only)
write_note_data(fd, prev);
- write_or_die(fd, note_template, strlen(note_template));
+
+ strbuf_addch(&buf, '\n');
+ strbuf_add_commented_lines(&buf, note_template, strlen(note_template));
+ strbuf_addch(&buf, '\n');
+ write_or_die(fd, buf.buf, buf.len);
write_commented_object(fd, object);
close(fd);
+ strbuf_release(&buf);
strbuf_reset(&(msg->buf));
if (launch_editor(path, &(msg->buf), NULL)) {
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index f16986c..234248b 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -30,7 +30,8 @@ static size_t cleanup(char *line, size_t len)
*
* If last line does not have a newline at the end, one is added.
*
- * Enable skip_comments to skip every line starting with "#".
+ * Enable skip_comments to skip every line starting with comment
+ * character.
*/
void stripspace(struct strbuf *sb, int skip_comments)
{
@@ -45,7 +46,7 @@ void stripspace(struct strbuf *sb, int skip_comments)
eol = memchr(sb->buf + i, '\n', sb->len - i);
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
- if (skip_comments && len && sb->buf[i] == '#') {
+ if (skip_comments && len && sb->buf[i] == comment_line_char) {
newlen = 0;
continue;
}
@@ -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);
+}
+
+static const char *usage_msg = "\n"
+" git stripspace [-s | --strip-comments] < input\n"
+" git stripspace [-c | --comment-lines] < input";
+
int cmd_stripspace(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
int strip_comments = 0;
+ enum { INVAL = 0, STRIP_SPACE = 1, COMMENT_LINES = 2 } mode = STRIP_SPACE;
+
+ if (argc == 2) {
+ if (!strcmp(argv[1], "-s") ||
+ !strcmp(argv[1], "--strip-comments")) {
+ strip_comments = 1;
+ } else if (!strcmp(argv[1], "-c") ||
+ !strcmp(argv[1], "--comment-lines")) {
+ mode = COMMENT_LINES;
+ } else {
+ mode = INVAL;
+ }
+ } else if (argc > 1) {
+ mode = INVAL;
+ }
+
+ if (mode == INVAL)
+ usage(usage_msg);
- if (argc == 2 && (!strcmp(argv[1], "-s") ||
- !strcmp(argv[1], "--strip-comments")))
- strip_comments = 1;
- else if (argc > 1)
- usage("git stripspace [-s | --strip-comments] < input");
+ if (strip_comments || mode == COMMENT_LINES)
+ git_config(git_default_config, NULL);
if (strbuf_read(&buf, 0, 1024) < 0)
die_errno("could not read the input");
- stripspace(&buf, strip_comments);
+ if (mode == STRIP_SPACE)
+ stripspace(&buf, strip_comments);
+ else
+ comment_lines(&buf);
write_or_die(1, buf.buf, buf.len);
strbuf_release(&buf);
diff --git a/builtin/tag.c b/builtin/tag.c
index 9c3e067..f826688 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -246,19 +246,13 @@ static int do_sign(struct strbuf *buffer)
}
static const char tag_template[] =
- N_("\n"
- "#\n"
- "# Write a tag message\n"
- "# Lines starting with '#' will be ignored.\n"
- "#\n");
+ N_("\nWrite a tag message\n"
+ "Lines starting with '%c' will be ignored.\n");
static const char tag_template_nocleanup[] =
- N_("\n"
- "#\n"
- "# Write a tag message\n"
- "# Lines starting with '#' will be kept; you may remove them"
- " yourself if you want to.\n"
- "#\n");
+ N_("\nWrite a tag message\n"
+ "Lines starting with '%c' will be kept; you may remove them"
+ " yourself if you want to.\n");
static int git_tag_config(const char *var, const char *value, void *cb)
{
@@ -346,14 +340,18 @@ static void create_tag(const unsigned char *object, const char *tag,
if (fd < 0)
die_errno(_("could not create file '%s'"), path);
- if (!is_null_sha1(prev))
+ if (!is_null_sha1(prev)) {
write_tag_body(fd, prev);
- else if (opt->cleanup_mode == CLEANUP_ALL)
- write_or_die(fd, _(tag_template),
- strlen(_(tag_template)));
- else
- write_or_die(fd, _(tag_template_nocleanup),
- strlen(_(tag_template_nocleanup)));
+ } else {
+ struct strbuf buf = STRBUF_INIT;
+ strbuf_addch(&buf, '\n');
+ if (opt->cleanup_mode == CLEANUP_ALL)
+ strbuf_commented_addf(&buf, _(tag_template), comment_line_char);
+ else
+ strbuf_commented_addf(&buf, _(tag_template_nocleanup), comment_line_char);
+ write_or_die(fd, buf.buf, buf.len);
+ strbuf_release(&buf);
+ }
close(fd);
if (launch_editor(path, buf, NULL)) {
diff --git a/cache.h b/cache.h
index c257953..0b435a4 100644
--- a/cache.h
+++ b/cache.h
@@ -562,6 +562,12 @@ extern int core_preload_index;
extern int core_apply_sparse_checkout;
extern int precomposed_unicode;
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+extern char comment_line_char;
+
enum branch_track {
BRANCH_TRACK_UNSPECIFIED = -1,
BRANCH_TRACK_NEVER = 0,
diff --git a/config.c b/config.c
index 7b444b6..d873c59 100644
--- a/config.c
+++ b/config.c
@@ -717,6 +717,14 @@ static int git_default_core_config(const char *var, const char *value)
if (!strcmp(var, "core.editor"))
return git_config_string(&editor_program, var, value);
+ if (!strcmp(var, "core.commentchar")) {
+ const char *comment;
+ int ret = git_config_string(&comment, var, value);
+ if (!ret)
+ comment_line_char = comment[0];
+ return ret;
+ }
+
if (!strcmp(var, "core.askpass"))
return git_config_string(&askpass_program, var, value);
diff --git a/environment.c b/environment.c
index 85edd7f..a40c38b 100644
--- a/environment.c
+++ b/environment.c
@@ -62,6 +62,12 @@ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
struct startup_info *startup_info;
unsigned long pack_size_limit_cfg;
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+char comment_line_char = '#';
+
/* Parallel index stat data preload? */
int core_preload_index = 0;
diff --git a/git-submodule.sh b/git-submodule.sh
index 22ec5b6..004c034 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -976,12 +976,12 @@ cmd_summary() {
done |
if test -n "$for_status"; then
if [ -n "$files" ]; then
- gettextln "# Submodules changed but not updated:"
+ gettextln "Submodules changed but not updated:" | git stripspace -c
else
- gettextln "# Submodule changes to be committed:"
+ gettextln "Submodule changes to be committed:" | git stripspace -c
fi
- echo "#"
- sed -e 's|^|# |' -e 's|^# $|#|'
+ printf "\n" | git stripspace -c
+ git stripspace -c
else
cat
fi
diff --git a/strbuf.c b/strbuf.c
index 9a373be..48e9abb 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -204,6 +204,54 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
va_end(ap);
}
+static void add_lines(struct strbuf *out,
+ const char *prefix1,
+ const char *prefix2,
+ const char *buf, size_t size)
+{
+ while (size) {
+ const char *prefix;
+ const char *next = memchr(buf, '\n', size);
+ next = next ? (next + 1) : (buf + size);
+
+ prefix = (prefix2 && buf[0] == '\n') ? prefix2 : prefix1;
+ strbuf_addstr(out, prefix);
+ strbuf_add(out, buf, next - buf);
+ size -= next - buf;
+ buf = next;
+ }
+ strbuf_complete_line(out);
+}
+
+void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size)
+{
+ static char prefix1[3];
+ static char prefix2[2];
+
+ if (prefix1[0] != comment_line_char) {
+ sprintf(prefix1, "%c ", comment_line_char);
+ sprintf(prefix2, "%c", comment_line_char);
+ }
+ add_lines(out, prefix1, prefix2, buf, size);
+}
+
+void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...)
+{
+ va_list params;
+ struct strbuf buf = STRBUF_INIT;
+ int incomplete_line = sb->len && sb->buf[sb->len - 1] != '\n';
+
+ va_start(params, fmt);
+ strbuf_vaddf(&buf, fmt, params);
+ va_end(params);
+
+ strbuf_add_commented_lines(sb, buf.buf, buf.len);
+ if (incomplete_line)
+ sb->buf[--sb->len] = '\0';
+
+ strbuf_release(&buf);
+}
+
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)
{
int len;
@@ -414,15 +462,7 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
void strbuf_add_lines(struct strbuf *out, const char *prefix,
const char *buf, size_t size)
{
- while (size) {
- const char *next = memchr(buf, '\n', size);
- next = next ? (next + 1) : (buf + size);
- strbuf_addstr(out, prefix);
- strbuf_add(out, buf, next - buf);
- size -= next - buf;
- buf = next;
- }
- strbuf_complete_line(out);
+ add_lines(out, prefix, NULL, buf, size);
}
void strbuf_addstr_xml_quoted(struct strbuf *buf, const char *s)
diff --git a/strbuf.h b/strbuf.h
index ecae4e2..958822c 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -110,6 +110,8 @@ extern void strbuf_remove(struct strbuf *, size_t pos, size_t len);
extern void strbuf_splice(struct strbuf *, size_t pos, size_t len,
const void *, size_t);
+extern void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size);
+
extern void strbuf_add(struct strbuf *, const void *, size_t);
static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
strbuf_add(sb, s, strlen(s));
@@ -131,6 +133,8 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *
__attribute__((format (printf,2,3)))
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
+__attribute__((format (printf, 2, 3)))
+extern void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...);
__attribute__((format (printf,2,0)))
extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
index ccb0a3c..a8e84d8 100755
--- a/t/t0030-stripspace.sh
+++ b/t/t0030-stripspace.sh
@@ -397,4 +397,39 @@ test_expect_success 'strip comments, too' '
test -z "$(echo "# comment" | git stripspace -s)"
'
+test_expect_success 'strip comments with changed comment char' '
+ test ! -z "$(echo "; comment" | git -c core.commentchar=";" stripspace)" &&
+ test -z "$(echo "; comment" | git -c core.commentchar=";" stripspace -s)"
+'
+
+test_expect_success '-c with single line' '
+ printf "# foo\n" >expect &&
+ printf "foo" | git stripspace -c >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '-c with single line followed by empty line' '
+ printf "# foo\n#\n" >expect &&
+ printf "foo\n\n" | git stripspace -c >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '-c with newline only' '
+ printf "#\n" >expect &&
+ printf "\n" | git stripspace -c >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--comment-lines with single line' '
+ printf "# foo\n" >expect &&
+ printf "foo" | git stripspace -c >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '-c with changed comment char' '
+ printf "; foo\n" >expect &&
+ printf "foo" | git -c core.commentchar=";" stripspace -c >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 1a5cb69..6a2c67c 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -447,4 +447,11 @@ use_template="-t template"
try_commit_status_combo
+test_expect_success 'commit --status with custom comment character' '
+ test_when_finished "git config --unset core.commentchar" &&
+ git config core.commentchar ";" &&
+ try_commit --status &&
+ test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
+'
+
test_done
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e313ef1..a79c032 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1254,6 +1254,56 @@ test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary
'
cat > expect << EOF
+; On branch master
+; Changes to be committed:
+; (use "git reset HEAD <file>..." to unstage)
+;
+; modified: sm
+;
+; Changes not staged for commit:
+; (use "git add <file>..." to update what will be committed)
+; (use "git checkout -- <file>..." to discard changes in working directory)
+;
+; modified: dir1/modified
+; modified: sm (new commits)
+;
+; Submodule changes to be committed:
+;
+; * sm $head...$new_head (1):
+; > Add bar
+;
+; Submodules changed but not updated:
+;
+; * sm $new_head...$head2 (1):
+; > 2nd commit
+;
+; Untracked files:
+; (use "git add <file>..." to include in what will be committed)
+;
+; .gitmodules
+; dir1/untracked
+; dir2/modified
+; dir2/untracked
+; expect
+; output
+; untracked
+EOF
+
+test_expect_success "status (core.commentchar with submodule summary)" '
+ test_when_finished "git config --unset core.commentchar" &&
+ git config core.commentchar ";" &&
+ git status >output &&
+ test_i18ncmp expect output
+'
+
+test_expect_success "status (core.commentchar with two chars with submodule summary)" '
+ test_when_finished "git config --unset core.commentchar" &&
+ git config core.commentchar ";;" &&
+ git status >output &&
+ test_i18ncmp expect output
+'
+
+cat > expect << EOF
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
diff --git a/wt-status.c b/wt-status.c
index 2a9658b..f6f197e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -45,7 +45,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
strbuf_vaddf(&sb, fmt, ap);
if (!sb.len) {
- strbuf_addch(&sb, '#');
+ strbuf_addch(&sb, comment_line_char);
if (!trail)
strbuf_addch(&sb, ' ');
color_print_strbuf(s->fp, color, &sb);
@@ -59,7 +59,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
strbuf_reset(&linebuf);
if (at_bol) {
- strbuf_addch(&linebuf, '#');
+ strbuf_addch(&linebuf, comment_line_char);
if (*line != '\n' && *line != '\t')
strbuf_addch(&linebuf, ' ');
}
@@ -760,8 +760,10 @@ static void wt_status_print_tracking(struct wt_status *s)
for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
- "# %.*s", (int)(ep - cp), cp);
- color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
+ "%c %.*s", comment_line_char,
+ (int)(ep - cp), cp);
+ color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
+ comment_line_char);
}
static int has_unmerged(struct wt_status *s)
--
1.8.1.291.g056e2eb
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v2] Allow custom "comment char"
2013-01-16 19:18 ` [PATCH v2] " Ralf Thielow
@ 2013-01-16 20:30 ` Junio C Hamano
2013-01-16 21:02 ` Jens Lehmann
1 sibling, 0 replies; 18+ messages in thread
From: Junio C Hamano @ 2013-01-16 20:30 UTC (permalink / raw)
To: Ralf Thielow; +Cc: jrnieder, git
Ralf Thielow <ralf.thielow@gmail.com> writes:
> From: Junio C Hamano <gitster@pobox.com>
>
> 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 #<bugid> 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 <gitster@pobox.com>
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
> 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.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2] Allow custom "comment char"
2013-01-16 19:18 ` [PATCH v2] " Ralf Thielow
2013-01-16 20:30 ` Junio C Hamano
@ 2013-01-16 21:02 ` Jens Lehmann
1 sibling, 0 replies; 18+ messages in thread
From: Jens Lehmann @ 2013-01-16 21:02 UTC (permalink / raw)
To: Ralf Thielow; +Cc: gitster, jrnieder, git
Am 16.01.2013 20:18, schrieb Ralf Thielow:
> From: Junio C Hamano <gitster@pobox.com>
>
> 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 #<bugid> 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 <gitster@pobox.com>
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
> 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)
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2013-01-16 21:02 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-08 20:16 [PATCH] commit: make default of "cleanup" option configurable Ralf Thielow
2013-01-08 21:18 ` Junio C Hamano
2013-01-09 7:29 ` Jonathan Nieder
2013-01-09 8:16 ` Ralf Thielow
2013-01-09 8:28 ` Jonathan Nieder
2013-01-09 15:40 ` Junio C Hamano
2013-01-09 15:56 ` Junio C Hamano
2013-01-10 19:37 ` Re* " Junio C Hamano
2013-01-15 18:50 ` [PATCH] Allow custom "comment char" Ralf Thielow
2013-01-15 19:12 ` Junio C Hamano
2013-01-16 6:23 ` Junio C Hamano
2013-01-16 8:17 ` Ralf Thielow
2013-01-16 19:18 ` [PATCH v2] " Ralf Thielow
2013-01-16 20:30 ` Junio C Hamano
2013-01-16 21:02 ` Jens Lehmann
2013-01-09 19:36 ` [PATCHv2] commit: make default of "cleanup" option configurable Ralf Thielow
2013-01-10 0:17 ` Junio C Hamano
2013-01-10 17:45 ` [PATCHv3] " Ralf Thielow
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).