Skip to content

Commit 965993d

Browse files
committed
Merge branch 'bm/interpret-trailers-cut-line-is-eom'
"git interpret-trailers", when used as GIT_EDITOR for "git commit -v", looked for and appended to a trailer block at the very end, i.e. at the end of the "diff" output. The command has been corrected to pay attention to the cut-mark line "commit -v" adds to the buffer---the real trailer block should appear just before it. * bm/interpret-trailers-cut-line-is-eom: interpret-trailers: honor the cut line
2 parents 6f7f11f + d76650b commit 965993d

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17391739

17401740
if (verbose || /* Truncate the message just before the diff, if any. */
17411741
cleanup_mode == CLEANUP_SCISSORS)
1742-
wt_status_truncate_message_at_cut_line(&sb);
1742+
strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));
17431743

17441744
if (cleanup_mode != CLEANUP_NONE)
17451745
strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);

commit.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "commit-slab.h"
1212
#include "prio-queue.h"
1313
#include "sha1-lookup.h"
14+
#include "wt-status.h"
1415

1516
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
1617

@@ -1648,10 +1649,9 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
16481649
/*
16491650
* Inspect the given string and determine the true "end" of the log message, in
16501651
* order to find where to put a new Signed-off-by: line. Ignored are
1651-
* trailing comment lines and blank lines, and also the traditional
1652-
* "Conflicts:" block that is not commented out, so that we can use
1653-
* "git commit -s --amend" on an existing commit that forgot to remove
1654-
* it.
1652+
* trailing comment lines and blank lines. To support "git commit -s
1653+
* --amend" on an existing commit, we also ignore "Conflicts:". To
1654+
* support "git commit -v", we truncate at cut lines.
16551655
*
16561656
* Returns the number of bytes from the tail to ignore, to be fed as
16571657
* the second parameter to append_signoff().
@@ -1661,8 +1661,9 @@ int ignore_non_trailer(const char *buf, size_t len)
16611661
int boc = 0;
16621662
int bol = 0;
16631663
int in_old_conflicts_block = 0;
1664+
size_t cutoff = wt_status_locate_end(buf, len);
16641665

1665-
while (bol < len) {
1666+
while (bol < cutoff) {
16661667
const char *next_line = memchr(buf + bol, '\n', len - bol);
16671668

16681669
if (!next_line)
@@ -1688,5 +1689,5 @@ int ignore_non_trailer(const char *buf, size_t len)
16881689
}
16891690
bol = next_line - buf;
16901691
}
1691-
return boc ? len - boc : 0;
1692+
return boc ? len - boc : len - cutoff;
16921693
}

t/t7513-interpret-trailers.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,4 +1258,21 @@ test_expect_success 'with no command and no key' '
12581258
test_cmp expected actual
12591259
'
12601260

1261+
test_expect_success 'with cut line' '
1262+
cat >expected <<-\EOF &&
1263+
my subject
1264+
1265+
review: Brian
1266+
sign: A U Thor <[email protected]>
1267+
# ------------------------ >8 ------------------------
1268+
ignore this
1269+
EOF
1270+
git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1271+
my subject
1272+
# ------------------------ >8 ------------------------
1273+
ignore this
1274+
EOF
1275+
test_cmp expected actual
1276+
'
1277+
12611278
test_done

wt-status.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,17 +896,18 @@ static void wt_longstatus_print_other(struct wt_status *s,
896896
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
897897
}
898898

899-
void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
899+
size_t wt_status_locate_end(const char *s, size_t len)
900900
{
901901
const char *p;
902902
struct strbuf pattern = STRBUF_INIT;
903903

904904
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
905-
if (starts_with(buf->buf, pattern.buf + 1))
906-
strbuf_setlen(buf, 0);
907-
else if ((p = strstr(buf->buf, pattern.buf)))
908-
strbuf_setlen(buf, p - buf->buf + 1);
905+
if (starts_with(s, pattern.buf + 1))
906+
len = 0;
907+
else if ((p = strstr(s, pattern.buf)))
908+
len = p - s + 1;
909909
strbuf_release(&pattern);
910+
return len;
910911
}
911912

912913
void wt_status_add_cut_line(FILE *fp)

wt-status.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct wt_status_state {
112112
unsigned char cherry_pick_head_sha1[20];
113113
};
114114

115-
void wt_status_truncate_message_at_cut_line(struct strbuf *);
115+
size_t wt_status_locate_end(const char *s, size_t len);
116116
void wt_status_add_cut_line(FILE *fp);
117117
void wt_status_prepare(struct wt_status *s);
118118
void wt_status_print(struct wt_status *s);

0 commit comments

Comments
 (0)