All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] commit --cleanup=<scissors marker>
@ 2014-02-16  3:37 Nguyễn Thái Ngọc Duy
  2014-02-16  3:37 ` [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-16  3:37 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

I've been bitten by --cleanup=default stripping my "#" lines a few
times. Cutting "git status" with a long scissors marker line reduces
chances of that happening. Most of the code is already there in
1a72cfd. This is just to add the UI.

Nguyễn Thái Ngọc Duy (3):
  wt-status.c: make cut_lines[] const to shrink .data section a bit
  wt-status.c: move cut-line print code out to wt_status_add_cut_line
  commit: add --cleanup=scissors

 Documentation/git-commit.txt |  7 ++++++-
 builtin/commit.c             |  9 +++++++--
 t/t7502-commit.sh            | 16 ++++++++++++++++
 wt-status.c                  | 21 +++++++++++++--------
 wt-status.h                  |  1 +
 5 files changed, 43 insertions(+), 11 deletions(-)

-- 
1.8.5.2.240.g8478abd

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

* [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit
  2014-02-16  3:37 [PATCH 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
@ 2014-02-16  3:37 ` Nguyễn Thái Ngọc Duy
  2014-02-16 16:21   ` brian m. carlson
  2014-02-16  3:37 ` [PATCH 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-16  3:37 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 wt-status.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/wt-status.c b/wt-status.c
index 4e55810..65e35c3 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -17,7 +17,7 @@
 #include "strbuf.h"
 #include "utf8.h"
 
-static char cut_line[] =
+static const char cut_line[] =
 "------------------------ >8 ------------------------\n";
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
-- 
1.8.5.2.240.g8478abd

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

* [PATCH 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line
  2014-02-16  3:37 [PATCH 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
  2014-02-16  3:37 ` [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
@ 2014-02-16  3:37 ` Nguyễn Thái Ngọc Duy
  2014-02-16  3:37 ` [PATCH 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
  2014-02-17 12:15 ` [PATCH v2 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
  3 siblings, 0 replies; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-16  3:37 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 wt-status.c | 19 ++++++++++++-------
 wt-status.h |  1 +
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 65e35c3..ed31b6a 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -808,6 +808,17 @@ void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
 	strbuf_release(&pattern);
 }
 
+void wt_status_add_cut_line(FILE *fp)
+{
+	const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
+	struct strbuf buf = STRBUF_INIT;
+
+	fprintf(fp, "%c %s", comment_line_char, cut_line);
+	strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
+	fputs(buf.buf, fp);
+	strbuf_release(&buf);
+}
+
 static void wt_status_print_verbose(struct wt_status *s)
 {
 	struct rev_info rev;
@@ -833,14 +844,8 @@ static void wt_status_print_verbose(struct wt_status *s)
 	 * diff before committing.
 	 */
 	if (s->fp != stdout) {
-		const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
-		struct strbuf buf = STRBUF_INIT;
-
 		rev.diffopt.use_color = 0;
-		fprintf(s->fp, "%c %s", comment_line_char, cut_line);
-		strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
-		fputs(buf.buf, s->fp);
-		strbuf_release(&buf);
+		wt_status_add_cut_line(s->fp);
 	}
 	run_diff_index(&rev, 1);
 }
diff --git a/wt-status.h b/wt-status.h
index 30a4812..b56ce3f 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -92,6 +92,7 @@ struct wt_status_state {
 };
 
 void wt_status_truncate_message_at_cut_line(struct strbuf *);
+void wt_status_add_cut_line(FILE *fp);
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
-- 
1.8.5.2.240.g8478abd

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

* [PATCH 3/3] commit: add --cleanup=scissors
  2014-02-16  3:37 [PATCH 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
  2014-02-16  3:37 ` [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
  2014-02-16  3:37 ` [PATCH 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
@ 2014-02-16  3:37 ` Nguyễn Thái Ngọc Duy
  2014-02-16  3:44   ` Eric Sunshine
  2014-02-17 12:15 ` [PATCH v2 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
  3 siblings, 1 reply; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-16  3:37 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Since 1a72cfd (commit -v: strip diffs and submodule shortlogs from the
commit message - 2013-12-05) we have a less fragile way to cut out
"git status" at the end of a commit message but it's only enabled for
stripping submodule shortlogs. Add new cleanup option that reuses the
same mechanism for the entire "git status" without accidentally remove
lines starting with '#'

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-commit.txt |  7 ++++++-
 builtin/commit.c             |  9 +++++++--
 t/t7502-commit.sh            | 16 ++++++++++++++++
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 1a7616c..98f976a 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -176,7 +176,7 @@ OPTIONS
 --cleanup=<mode>::
 	This option determines how the supplied commit message should be
 	cleaned up before committing.  The '<mode>' can be `strip`,
-	`whitespace`, `verbatim`, or `default`.
+	`whitespace`, `verbatim`, `scissors` or `default`.
 +
 --
 strip::
@@ -186,6 +186,11 @@ whitespace::
 	Same as `strip` except #commentary is not removed.
 verbatim::
 	Do not change the message at all.
+scissors::
+	Same as `whitespace`, except that everything from the line
+	"`# ------------------------ >8 ------------------------`"
+	is truncated if the message is to be edited. "`#`" could be
+	customized with core.commentChar.
 default::
 	Same as `strip` if the message is to be edited.
 	Otherwise `whitespace`.
diff --git a/builtin/commit.c b/builtin/commit.c
index 3767478..ea2912f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -113,6 +113,7 @@ static char *sign_commit;
 static enum {
 	CLEANUP_SPACE,
 	CLEANUP_NONE,
+	CLEANUP_SCISSORS,
 	CLEANUP_ALL
 } cleanup_mode;
 static const char *cleanup_arg;
@@ -777,6 +778,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 				_("Please enter the commit message for your changes."
 				  " Lines starting\nwith '%c' will be ignored, and an empty"
 				  " message aborts the commit.\n"), comment_line_char);
+		else if (cleanup_mode == CLEANUP_SCISSORS)
+			wt_status_add_cut_line(s->fp);
 		else /* CLEANUP_SPACE, that is. */
 			status_printf(s, GIT_COLOR_NORMAL,
 				_("Please enter the commit message for your changes."
@@ -1132,6 +1135,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
 		cleanup_mode = CLEANUP_SPACE;
 	else if (!strcmp(cleanup_arg, "strip"))
 		cleanup_mode = CLEANUP_ALL;
+	else if (!strcmp(cleanup_arg, "scissors"))
+		cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
@@ -1600,8 +1605,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		die(_("could not read commit message: %s"), strerror(saved_errno));
 	}
 
-	/* Truncate the message just before the diff, if any. */
-	if (verbose)
+	if (verbose || /* Truncate the message just before the diff, if any. */
+	    cleanup_mode == CLEANUP_SCISSORS)
 		wt_status_truncate_message_at_cut_line(&sb);
 
 	if (cleanup_mode != CLEANUP_NONE)
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 6313da2..9a3f3a1 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -223,6 +223,22 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' '
 
 '
 
+test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
+
+	echo >>negative &&
+	cat >text <<EOF &&
+
+# to be kept
+# ------------------------ >8 ------------------------
+to be removed
+EOF
+	echo "# to be kept" >expect &&
+	git commit --cleanup=scissors -e -F text -a &&
+	git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
+	test_cmp expect actual
+
+'
+
 test_expect_success 'cleanup commit messages (strip option,-F)' '
 
 	echo >>negative &&
-- 
1.8.5.2.240.g8478abd

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

* Re: [PATCH 3/3] commit: add --cleanup=scissors
  2014-02-16  3:37 ` [PATCH 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
@ 2014-02-16  3:44   ` Eric Sunshine
  0 siblings, 0 replies; 14+ messages in thread
From: Eric Sunshine @ 2014-02-16  3:44 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: Git List

On Sat, Feb 15, 2014 at 10:37 PM, Nguyễn Thái Ngọc Duy
<pclouds@gmail.com> wrote:
> Since 1a72cfd (commit -v: strip diffs and submodule shortlogs from the
> commit message - 2013-12-05) we have a less fragile way to cut out
> "git status" at the end of a commit message but it's only enabled for
> stripping submodule shortlogs. Add new cleanup option that reuses the
> same mechanism for the entire "git status" without accidentally remove

s/remove/removing/

> lines starting with '#'
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
> index 1a7616c..98f976a 100644
> --- a/Documentation/git-commit.txt
> +++ b/Documentation/git-commit.txt
> @@ -176,7 +176,7 @@ OPTIONS
>  --cleanup=<mode>::
>         This option determines how the supplied commit message should be
>         cleaned up before committing.  The '<mode>' can be `strip`,
> -       `whitespace`, `verbatim`, or `default`.
> +       `whitespace`, `verbatim`, `scissors` or `default`.
>  +
>  --
>  strip::
> @@ -186,6 +186,11 @@ whitespace::
>         Same as `strip` except #commentary is not removed.
>  verbatim::
>         Do not change the message at all.
> +scissors::
> +       Same as `whitespace`, except that everything from the line
> +       "`# ------------------------ >8 ------------------------`"

Would it make sense to be more explicit and say that the 'cut' line is
also removed?

    Same as `whitespace`, except that the line
    `# ------------------------ >8 ------------------------`
    and all lines following it are removed ...

> +       is truncated if the message is to be edited. "`#`" could be

s/could/can/

> +       customized with core.commentChar.
>  default::
>         Same as `strip` if the message is to be edited.
>         Otherwise `whitespace`.

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

* Re: [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit
  2014-02-16  3:37 ` [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
@ 2014-02-16 16:21   ` brian m. carlson
  0 siblings, 0 replies; 14+ messages in thread
From: brian m. carlson @ 2014-02-16 16:21 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

On Sun, Feb 16, 2014 at 10:37:18AM +0700, Nguyễn Thái Ngọc Duy wrote:
> -static char cut_line[] =
> +static const char cut_line[] =

Your subject says cut_lines[], but the variable is cut_line[] (no "s").

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* [PATCH v2 0/3] commit --cleanup=<scissors marker>
  2014-02-16  3:37 [PATCH 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
                   ` (2 preceding siblings ...)
  2014-02-16  3:37 ` [PATCH 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
@ 2014-02-17 12:15 ` Nguyễn Thái Ngọc Duy
  2014-02-17 12:15   ` [PATCH v2 1/3] wt-status.c: make cut_line[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
                     ` (2 more replies)
  3 siblings, 3 replies; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-17 12:15 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Slight changes in git-commit.txt and some commit messages after Brian
and Eric's comments.

Nguyễn Thái Ngọc Duy (3):
  wt-status.c: make cut_line[] const to shrink .data section a bit
  wt-status.c: move cut-line print code out to wt_status_add_cut_line
  commit: add --cleanup=scissors

 Documentation/git-commit.txt |  8 +++++++-
 builtin/commit.c             |  9 +++++++--
 t/t7502-commit.sh            | 16 ++++++++++++++++
 wt-status.c                  | 21 +++++++++++++--------
 wt-status.h                  |  1 +
 5 files changed, 44 insertions(+), 11 deletions(-)

-- 
1.8.5.2.240.g8478abd

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

* [PATCH v2 1/3] wt-status.c: make cut_line[] const to shrink .data section a bit
  2014-02-17 12:15 ` [PATCH v2 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
@ 2014-02-17 12:15   ` Nguyễn Thái Ngọc Duy
  2014-02-17 12:15   ` [PATCH v2 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
  2014-02-17 12:15   ` [PATCH v2 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
  2 siblings, 0 replies; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-17 12:15 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 wt-status.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/wt-status.c b/wt-status.c
index 4e55810..65e35c3 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -17,7 +17,7 @@
 #include "strbuf.h"
 #include "utf8.h"
 
-static char cut_line[] =
+static const char cut_line[] =
 "------------------------ >8 ------------------------\n";
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
-- 
1.8.5.2.240.g8478abd

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

* [PATCH v2 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line
  2014-02-17 12:15 ` [PATCH v2 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
  2014-02-17 12:15   ` [PATCH v2 1/3] wt-status.c: make cut_line[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
@ 2014-02-17 12:15   ` Nguyễn Thái Ngọc Duy
  2014-02-17 12:15   ` [PATCH v2 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
  2 siblings, 0 replies; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-17 12:15 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 wt-status.c | 19 ++++++++++++-------
 wt-status.h |  1 +
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 65e35c3..ed31b6a 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -808,6 +808,17 @@ void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
 	strbuf_release(&pattern);
 }
 
+void wt_status_add_cut_line(FILE *fp)
+{
+	const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
+	struct strbuf buf = STRBUF_INIT;
+
+	fprintf(fp, "%c %s", comment_line_char, cut_line);
+	strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
+	fputs(buf.buf, fp);
+	strbuf_release(&buf);
+}
+
 static void wt_status_print_verbose(struct wt_status *s)
 {
 	struct rev_info rev;
@@ -833,14 +844,8 @@ static void wt_status_print_verbose(struct wt_status *s)
 	 * diff before committing.
 	 */
 	if (s->fp != stdout) {
-		const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
-		struct strbuf buf = STRBUF_INIT;
-
 		rev.diffopt.use_color = 0;
-		fprintf(s->fp, "%c %s", comment_line_char, cut_line);
-		strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
-		fputs(buf.buf, s->fp);
-		strbuf_release(&buf);
+		wt_status_add_cut_line(s->fp);
 	}
 	run_diff_index(&rev, 1);
 }
diff --git a/wt-status.h b/wt-status.h
index 30a4812..b56ce3f 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -92,6 +92,7 @@ struct wt_status_state {
 };
 
 void wt_status_truncate_message_at_cut_line(struct strbuf *);
+void wt_status_add_cut_line(FILE *fp);
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
-- 
1.8.5.2.240.g8478abd

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

* [PATCH v2 3/3] commit: add --cleanup=scissors
  2014-02-17 12:15 ` [PATCH v2 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
  2014-02-17 12:15   ` [PATCH v2 1/3] wt-status.c: make cut_line[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
  2014-02-17 12:15   ` [PATCH v2 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
@ 2014-02-17 12:15   ` Nguyễn Thái Ngọc Duy
  2014-02-22  0:58     ` Duy Nguyen
  2 siblings, 1 reply; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-17 12:15 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Since 1a72cfd (commit -v: strip diffs and submodule shortlogs from the
commit message - 2013-12-05) we have a less fragile way to cut out
"git status" at the end of a commit message but it's only enabled for
stripping submodule shortlogs. Add new cleanup option that reuses the
same mechanism for the entire "git status" without accidentally
removing lines starting with '#'

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-commit.txt |  8 +++++++-
 builtin/commit.c             |  9 +++++++--
 t/t7502-commit.sh            | 16 ++++++++++++++++
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 1a7616c..7948233 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -176,7 +176,7 @@ OPTIONS
 --cleanup=<mode>::
 	This option determines how the supplied commit message should be
 	cleaned up before committing.  The '<mode>' can be `strip`,
-	`whitespace`, `verbatim`, or `default`.
+	`whitespace`, `verbatim`, `scissors` or `default`.
 +
 --
 strip::
@@ -186,6 +186,12 @@ whitespace::
 	Same as `strip` except #commentary is not removed.
 verbatim::
 	Do not change the message at all.
+scissors::
+	Same as `whitespace`, except that everything from (and
+	including) the line
+	"`# ------------------------ >8 ------------------------`"
+	is truncated if the message is to be edited. "`#`" can be
+	customized with core.commentChar.
 default::
 	Same as `strip` if the message is to be edited.
 	Otherwise `whitespace`.
diff --git a/builtin/commit.c b/builtin/commit.c
index 3767478..ea2912f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -113,6 +113,7 @@ static char *sign_commit;
 static enum {
 	CLEANUP_SPACE,
 	CLEANUP_NONE,
+	CLEANUP_SCISSORS,
 	CLEANUP_ALL
 } cleanup_mode;
 static const char *cleanup_arg;
@@ -777,6 +778,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 				_("Please enter the commit message for your changes."
 				  " Lines starting\nwith '%c' will be ignored, and an empty"
 				  " message aborts the commit.\n"), comment_line_char);
+		else if (cleanup_mode == CLEANUP_SCISSORS)
+			wt_status_add_cut_line(s->fp);
 		else /* CLEANUP_SPACE, that is. */
 			status_printf(s, GIT_COLOR_NORMAL,
 				_("Please enter the commit message for your changes."
@@ -1132,6 +1135,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
 		cleanup_mode = CLEANUP_SPACE;
 	else if (!strcmp(cleanup_arg, "strip"))
 		cleanup_mode = CLEANUP_ALL;
+	else if (!strcmp(cleanup_arg, "scissors"))
+		cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
 	else
 		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
@@ -1600,8 +1605,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		die(_("could not read commit message: %s"), strerror(saved_errno));
 	}
 
-	/* Truncate the message just before the diff, if any. */
-	if (verbose)
+	if (verbose || /* Truncate the message just before the diff, if any. */
+	    cleanup_mode == CLEANUP_SCISSORS)
 		wt_status_truncate_message_at_cut_line(&sb);
 
 	if (cleanup_mode != CLEANUP_NONE)
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 6313da2..9a3f3a1 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -223,6 +223,22 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' '
 
 '
 
+test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
+
+	echo >>negative &&
+	cat >text <<EOF &&
+
+# to be kept
+# ------------------------ >8 ------------------------
+to be removed
+EOF
+	echo "# to be kept" >expect &&
+	git commit --cleanup=scissors -e -F text -a &&
+	git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
+	test_cmp expect actual
+
+'
+
 test_expect_success 'cleanup commit messages (strip option,-F)' '
 
 	echo >>negative &&
-- 
1.8.5.2.240.g8478abd

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

* Re: [PATCH v2 3/3] commit: add --cleanup=scissors
  2014-02-17 12:15   ` [PATCH v2 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
@ 2014-02-22  0:58     ` Duy Nguyen
  2014-02-24 17:20       ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Duy Nguyen @ 2014-02-22  0:58 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

On Mon, Feb 17, 2014 at 07:15:32PM +0700, Nguyễn Thái Ngọc Duy wrote:
> @@ -777,6 +778,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  				_("Please enter the commit message for your changes."
>  				  " Lines starting\nwith '%c' will be ignored, and an empty"
>  				  " message aborts the commit.\n"), comment_line_char);
> +		else if (cleanup_mode == CLEANUP_SCISSORS)
> +			wt_status_add_cut_line(s->fp);
>  		else /* CLEANUP_SPACE, that is. */
>  			status_printf(s, GIT_COLOR_NORMAL,
>  				_("Please enter the commit message for your changes."

This cut line does not cover the merge conflict message before it. The
following patch should be squashed in to move the cut line up in that
case.

-- 8< --
diff --git a/builtin/commit.c b/builtin/commit.c
index ea2912f..1033c50 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -755,7 +755,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
 	if (use_editor && include_status) {
 		char *ai_tmp, *ci_tmp;
-		if (whence != FROM_COMMIT)
+		if (whence != FROM_COMMIT) {
+			if (cleanup_mode == CLEANUP_SCISSORS)
+				wt_status_add_cut_line(s->fp);
 			status_printf_ln(s, GIT_COLOR_NORMAL,
 			    whence == FROM_MERGE
 				? _("\n"
@@ -771,6 +773,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 				git_path(whence == FROM_MERGE
 					 ? "MERGE_HEAD"
 					 : "CHERRY_PICK_HEAD"));
+		}
 
 		fprintf(s->fp, "\n");
 		if (cleanup_mode == CLEANUP_ALL)
@@ -778,7 +781,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 				_("Please enter the commit message for your changes."
 				  " Lines starting\nwith '%c' will be ignored, and an empty"
 				  " message aborts the commit.\n"), comment_line_char);
-		else if (cleanup_mode == CLEANUP_SCISSORS)
+		else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
 			wt_status_add_cut_line(s->fp);
 		else /* CLEANUP_SPACE, that is. */
 			status_printf(s, GIT_COLOR_NORMAL,
-- 8< --

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

* Re: [PATCH v2 3/3] commit: add --cleanup=scissors
  2014-02-22  0:58     ` Duy Nguyen
@ 2014-02-24 17:20       ` Junio C Hamano
  2014-02-24 23:28         ` Duy Nguyen
  0 siblings, 1 reply; 14+ messages in thread
From: Junio C Hamano @ 2014-02-24 17:20 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: git

Duy Nguyen <pclouds@gmail.com> writes:

> On Mon, Feb 17, 2014 at 07:15:32PM +0700, Nguyễn Thái Ngọc Duy wrote:
>> @@ -777,6 +778,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>  				_("Please enter the commit message for your changes."
>>  				  " Lines starting\nwith '%c' will be ignored, and an empty"
>>  				  " message aborts the commit.\n"), comment_line_char);
>> +		else if (cleanup_mode == CLEANUP_SCISSORS)
>> +			wt_status_add_cut_line(s->fp);
>>  		else /* CLEANUP_SPACE, that is. */
>>  			status_printf(s, GIT_COLOR_NORMAL,
>>  				_("Please enter the commit message for your changes."
>
> This cut line does not cover the merge conflict message before it. The
> following patch should be squashed in to move the cut line up in that
> case.

I somehow thought that it was a policy decision we made in very
early days that these conflict messages are meant to be edited with
explanation of how they were resolved, not to be simply edited away?

The other stuff (commented out instructions and patch text) are
meant to aid humans while editing the log message, and stripping
away automatically after they are done editing like your patch does
is perfectly fine, but I find this change questionable.

> -- 8< --
> diff --git a/builtin/commit.c b/builtin/commit.c
> index ea2912f..1033c50 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -755,7 +755,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
>  	if (use_editor && include_status) {
>  		char *ai_tmp, *ci_tmp;
> -		if (whence != FROM_COMMIT)
> +		if (whence != FROM_COMMIT) {
> +			if (cleanup_mode == CLEANUP_SCISSORS)
> +				wt_status_add_cut_line(s->fp);
>  			status_printf_ln(s, GIT_COLOR_NORMAL,
>  			    whence == FROM_MERGE
>  				? _("\n"
> @@ -771,6 +773,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  				git_path(whence == FROM_MERGE
>  					 ? "MERGE_HEAD"
>  					 : "CHERRY_PICK_HEAD"));
> +		}
>  
>  		fprintf(s->fp, "\n");
>  		if (cleanup_mode == CLEANUP_ALL)
> @@ -778,7 +781,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  				_("Please enter the commit message for your changes."
>  				  " Lines starting\nwith '%c' will be ignored, and an empty"
>  				  " message aborts the commit.\n"), comment_line_char);
> -		else if (cleanup_mode == CLEANUP_SCISSORS)
> +		else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
>  			wt_status_add_cut_line(s->fp);
>  		else /* CLEANUP_SPACE, that is. */
>  			status_printf(s, GIT_COLOR_NORMAL,
> -- 8< --

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

* Re: [PATCH v2 3/3] commit: add --cleanup=scissors
  2014-02-24 17:20       ` Junio C Hamano
@ 2014-02-24 23:28         ` Duy Nguyen
  2014-02-25  0:18           ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Duy Nguyen @ 2014-02-24 23:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Tue, Feb 25, 2014 at 12:20 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Duy Nguyen <pclouds@gmail.com> writes:
>
>> On Mon, Feb 17, 2014 at 07:15:32PM +0700, Nguyễn Thái Ngọc Duy wrote:
>>> @@ -777,6 +778,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>>                              _("Please enter the commit message for your changes."
>>>                                " Lines starting\nwith '%c' will be ignored, and an empty"
>>>                                " message aborts the commit.\n"), comment_line_char);
>>> +            else if (cleanup_mode == CLEANUP_SCISSORS)
>>> +                    wt_status_add_cut_line(s->fp);
>>>              else /* CLEANUP_SPACE, that is. */
>>>                      status_printf(s, GIT_COLOR_NORMAL,
>>>                              _("Please enter the commit message for your changes."
>>
>> This cut line does not cover the merge conflict message before it. The
>> following patch should be squashed in to move the cut line up in that
>> case.
>
> I somehow thought that it was a policy decision we made in very
> early days that these conflict messages are meant to be edited with
> explanation of how they were resolved, not to be simply edited away?
>
> The other stuff (commented out instructions and patch text) are
> meant to aid humans while editing the log message, and stripping
> away automatically after they are done editing like your patch does
> is perfectly fine, but I find this change questionable.

I think I described it incorrectly as "conflict message" while it's
not. This is the part to be cut out by the patch

# It looks like you may be committing a merge.
# If this is not correct, please remove the file.
#     MERGE_HEAD
# and try again.

(similar message for CHERRY_PICK_HEAD).

>
>> -- 8< --
>> diff --git a/builtin/commit.c b/builtin/commit.c
>> index ea2912f..1033c50 100644
>> --- a/builtin/commit.c
>> +++ b/builtin/commit.c
>> @@ -755,7 +755,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>       strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
>>       if (use_editor && include_status) {
>>               char *ai_tmp, *ci_tmp;
>> -             if (whence != FROM_COMMIT)
>> +             if (whence != FROM_COMMIT) {
>> +                     if (cleanup_mode == CLEANUP_SCISSORS)
>> +                             wt_status_add_cut_line(s->fp);
>>                       status_printf_ln(s, GIT_COLOR_NORMAL,
>>                           whence == FROM_MERGE
>>                               ? _("\n"
>> @@ -771,6 +773,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>                               git_path(whence == FROM_MERGE
>>                                        ? "MERGE_HEAD"
>>                                        : "CHERRY_PICK_HEAD"));
>> +             }
>>
>>               fprintf(s->fp, "\n");
>>               if (cleanup_mode == CLEANUP_ALL)
>> @@ -778,7 +781,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>                               _("Please enter the commit message for your changes."
>>                                 " Lines starting\nwith '%c' will be ignored, and an empty"
>>                                 " message aborts the commit.\n"), comment_line_char);
>> -             else if (cleanup_mode == CLEANUP_SCISSORS)
>> +             else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
>>                       wt_status_add_cut_line(s->fp);
>>               else /* CLEANUP_SPACE, that is. */
>>                       status_printf(s, GIT_COLOR_NORMAL,
>> -- 8< --



-- 
Duy

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

* Re: [PATCH v2 3/3] commit: add --cleanup=scissors
  2014-02-24 23:28         ` Duy Nguyen
@ 2014-02-25  0:18           ` Junio C Hamano
  0 siblings, 0 replies; 14+ messages in thread
From: Junio C Hamano @ 2014-02-25  0:18 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List

Duy Nguyen <pclouds@gmail.com> writes:

> I think I described it incorrectly as "conflict message" while it's
> not. This is the part to be cut out by the patch
>
> # It looks like you may be committing a merge.
> # If this is not correct, please remove the file.
> #     MERGE_HEAD
> # and try again.
>
> (similar message for CHERRY_PICK_HEAD).

Ahh, OK.  That should be removed, of course.

Will squash in (but not tonight).  Thanks.

>
>>
>>> -- 8< --
>>> diff --git a/builtin/commit.c b/builtin/commit.c
>>> index ea2912f..1033c50 100644
>>> --- a/builtin/commit.c
>>> +++ b/builtin/commit.c
>>> @@ -755,7 +755,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>>       strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
>>>       if (use_editor && include_status) {
>>>               char *ai_tmp, *ci_tmp;
>>> -             if (whence != FROM_COMMIT)
>>> +             if (whence != FROM_COMMIT) {
>>> +                     if (cleanup_mode == CLEANUP_SCISSORS)
>>> +                             wt_status_add_cut_line(s->fp);
>>>                       status_printf_ln(s, GIT_COLOR_NORMAL,
>>>                           whence == FROM_MERGE
>>>                               ? _("\n"
>>> @@ -771,6 +773,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>>                               git_path(whence == FROM_MERGE
>>>                                        ? "MERGE_HEAD"
>>>                                        : "CHERRY_PICK_HEAD"));
>>> +             }
>>>
>>>               fprintf(s->fp, "\n");
>>>               if (cleanup_mode == CLEANUP_ALL)
>>> @@ -778,7 +781,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>>                               _("Please enter the commit message for your changes."
>>>                                 " Lines starting\nwith '%c' will be ignored, and an empty"
>>>                                 " message aborts the commit.\n"), comment_line_char);
>>> -             else if (cleanup_mode == CLEANUP_SCISSORS)
>>> +             else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
>>>                       wt_status_add_cut_line(s->fp);
>>>               else /* CLEANUP_SPACE, that is. */
>>>                       status_printf(s, GIT_COLOR_NORMAL,
>>> -- 8< --

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

end of thread, other threads:[~2014-02-25  0:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-16  3:37 [PATCH 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
2014-02-16  3:37 ` [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
2014-02-16 16:21   ` brian m. carlson
2014-02-16  3:37 ` [PATCH 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
2014-02-16  3:37 ` [PATCH 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
2014-02-16  3:44   ` Eric Sunshine
2014-02-17 12:15 ` [PATCH v2 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
2014-02-17 12:15   ` [PATCH v2 1/3] wt-status.c: make cut_line[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
2014-02-17 12:15   ` [PATCH v2 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
2014-02-17 12:15   ` [PATCH v2 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
2014-02-22  0:58     ` Duy Nguyen
2014-02-24 17:20       ` Junio C Hamano
2014-02-24 23:28         ` Duy Nguyen
2014-02-25  0:18           ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.