Merge branch 'nd/commit-editor-cleanup'
"git commit --cleanup=<mode>" learned a new mode, scissors. * nd/commit-editor-cleanup: commit: add --cleanup=scissors wt-status.c: move cut-line print code out to wt_status_add_cut_line wt-status.c: make cut_line[] const to shrink .data section a bit
This commit is contained in:
@ -176,7 +176,7 @@ OPTIONS
|
|||||||
--cleanup=<mode>::
|
--cleanup=<mode>::
|
||||||
This option determines how the supplied commit message should be
|
This option determines how the supplied commit message should be
|
||||||
cleaned up before committing. The '<mode>' can be `strip`,
|
cleaned up before committing. The '<mode>' can be `strip`,
|
||||||
`whitespace`, `verbatim`, or `default`.
|
`whitespace`, `verbatim`, `scissors` or `default`.
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
strip::
|
strip::
|
||||||
@ -186,6 +186,12 @@ whitespace::
|
|||||||
Same as `strip` except #commentary is not removed.
|
Same as `strip` except #commentary is not removed.
|
||||||
verbatim::
|
verbatim::
|
||||||
Do not change the message at all.
|
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::
|
default::
|
||||||
Same as `strip` if the message is to be edited.
|
Same as `strip` if the message is to be edited.
|
||||||
Otherwise `whitespace`.
|
Otherwise `whitespace`.
|
||||||
|
@ -113,6 +113,7 @@ static char *sign_commit;
|
|||||||
static enum {
|
static enum {
|
||||||
CLEANUP_SPACE,
|
CLEANUP_SPACE,
|
||||||
CLEANUP_NONE,
|
CLEANUP_NONE,
|
||||||
|
CLEANUP_SCISSORS,
|
||||||
CLEANUP_ALL
|
CLEANUP_ALL
|
||||||
} cleanup_mode;
|
} cleanup_mode;
|
||||||
static const char *cleanup_arg;
|
static const char *cleanup_arg;
|
||||||
@ -755,7 +756,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
|||||||
int ident_shown = 0;
|
int ident_shown = 0;
|
||||||
int saved_color_setting;
|
int saved_color_setting;
|
||||||
char *ai_tmp, *ci_tmp;
|
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,
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
||||||
whence == FROM_MERGE
|
whence == FROM_MERGE
|
||||||
? _("\n"
|
? _("\n"
|
||||||
@ -771,6 +774,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
|||||||
git_path(whence == FROM_MERGE
|
git_path(whence == FROM_MERGE
|
||||||
? "MERGE_HEAD"
|
? "MERGE_HEAD"
|
||||||
: "CHERRY_PICK_HEAD"));
|
: "CHERRY_PICK_HEAD"));
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(s->fp, "\n");
|
fprintf(s->fp, "\n");
|
||||||
if (cleanup_mode == CLEANUP_ALL)
|
if (cleanup_mode == CLEANUP_ALL)
|
||||||
@ -778,6 +782,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
|||||||
_("Please enter the commit message for your changes."
|
_("Please enter the commit message for your changes."
|
||||||
" Lines starting\nwith '%c' will be ignored, and an empty"
|
" Lines starting\nwith '%c' will be ignored, and an empty"
|
||||||
" message aborts the commit.\n"), comment_line_char);
|
" message aborts the commit.\n"), comment_line_char);
|
||||||
|
else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
|
||||||
|
wt_status_add_cut_line(s->fp);
|
||||||
else /* CLEANUP_SPACE, that is. */
|
else /* CLEANUP_SPACE, that is. */
|
||||||
status_printf(s, GIT_COLOR_NORMAL,
|
status_printf(s, GIT_COLOR_NORMAL,
|
||||||
_("Please enter the commit message for your changes."
|
_("Please enter the commit message for your changes."
|
||||||
@ -1133,6 +1139,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
|
|||||||
cleanup_mode = CLEANUP_SPACE;
|
cleanup_mode = CLEANUP_SPACE;
|
||||||
else if (!strcmp(cleanup_arg, "strip"))
|
else if (!strcmp(cleanup_arg, "strip"))
|
||||||
cleanup_mode = CLEANUP_ALL;
|
cleanup_mode = CLEANUP_ALL;
|
||||||
|
else if (!strcmp(cleanup_arg, "scissors"))
|
||||||
|
cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
|
||||||
else
|
else
|
||||||
die(_("Invalid cleanup mode %s"), cleanup_arg);
|
die(_("Invalid cleanup mode %s"), cleanup_arg);
|
||||||
|
|
||||||
@ -1605,8 +1613,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||||||
die(_("could not read commit message: %s"), strerror(saved_errno));
|
die(_("could not read commit message: %s"), strerror(saved_errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Truncate the message just before the diff, if any. */
|
if (verbose || /* Truncate the message just before the diff, if any. */
|
||||||
if (verbose)
|
cleanup_mode == CLEANUP_SCISSORS)
|
||||||
wt_status_truncate_message_at_cut_line(&sb);
|
wt_status_truncate_message_at_cut_line(&sb);
|
||||||
|
|
||||||
if (cleanup_mode != CLEANUP_NONE)
|
if (cleanup_mode != CLEANUP_NONE)
|
||||||
|
@ -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)' '
|
test_expect_success 'cleanup commit messages (strip option,-F)' '
|
||||||
|
|
||||||
echo >>negative &&
|
echo >>negative &&
|
||||||
|
21
wt-status.c
21
wt-status.c
@ -17,7 +17,7 @@
|
|||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
static char cut_line[] =
|
static const char cut_line[] =
|
||||||
"------------------------ >8 ------------------------\n";
|
"------------------------ >8 ------------------------\n";
|
||||||
|
|
||||||
static char default_wt_status_colors[][COLOR_MAXLEN] = {
|
static char default_wt_status_colors[][COLOR_MAXLEN] = {
|
||||||
@ -841,6 +841,17 @@ void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
|
|||||||
strbuf_release(&pattern);
|
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)
|
static void wt_status_print_verbose(struct wt_status *s)
|
||||||
{
|
{
|
||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
@ -866,14 +877,8 @@ static void wt_status_print_verbose(struct wt_status *s)
|
|||||||
* diff before committing.
|
* diff before committing.
|
||||||
*/
|
*/
|
||||||
if (s->fp != stdout) {
|
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;
|
rev.diffopt.use_color = 0;
|
||||||
fprintf(s->fp, "%c %s", comment_line_char, cut_line);
|
wt_status_add_cut_line(s->fp);
|
||||||
strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
|
|
||||||
fputs(buf.buf, s->fp);
|
|
||||||
strbuf_release(&buf);
|
|
||||||
}
|
}
|
||||||
run_diff_index(&rev, 1);
|
run_diff_index(&rev, 1);
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ struct wt_status_state {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void wt_status_truncate_message_at_cut_line(struct strbuf *);
|
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_prepare(struct wt_status *s);
|
||||||
void wt_status_print(struct wt_status *s);
|
void wt_status_print(struct wt_status *s);
|
||||||
void wt_status_collect(struct wt_status *s);
|
void wt_status_collect(struct wt_status *s);
|
||||||
|
Reference in New Issue
Block a user