Skip to content

Commit 4ad4fce

Browse files
committed
Merge branch 'jc/prettier-pretty-note'
Emit the notes attached to the commit in "format-patch --notes" output after three-dashes. * jc/prettier-pretty-note: format-patch: add a blank line between notes and diffstat Doc User-Manual: Patch cover letter, three dashes, and --notes Doc format-patch: clarify --notes use case Doc notes: Include the format-patch --notes option Doc SubmittingPatches: Mention --notes option after "cover letter" Documentation: decribe format-patch --notes format-patch --notes: show notes after three-dashes format-patch: append --signature after notes pretty_print_commit(): do not append notes message pretty: prepare notes message at a centralized place format_note(): simplify API pretty: remove reencode_commit_message()
2 parents 159a5a2 + 1d34c50 commit 4ad4fce

File tree

13 files changed

+100
-47
lines changed

13 files changed

+100
-47
lines changed

Documentation/SubmittingPatches

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ message starts, you can put a "From: " line to name that person.
179179

180180
You often want to add additional explanation about the patch,
181181
other than the commit message itself. Place such "cover letter"
182-
material between the three dash lines and the diffstat.
182+
material between the three dash lines and the diffstat. Git-notes
183+
can also be inserted using the `--notes` option.
183184

184185
Do not attach the patch as a MIME attachment, compressed or not.
185186
Do not let your e-mail client send quoted-printable. Do not let

Documentation/git-format-patch.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SYNOPSIS
2020
[--ignore-if-in-upstream]
2121
[--subject-prefix=Subject-Prefix]
2222
[--to=<email>] [--cc=<email>]
23-
[--cover-letter] [--quiet]
23+
[--cover-letter] [--quiet] [--notes[=<ref>]]
2424
[<common diff options>]
2525
[ <since> | <revision range> ]
2626

@@ -191,6 +191,18 @@ will want to ensure that threading is disabled for `git send-email`.
191191
containing the shortlog and the overall diffstat. You can
192192
fill in a description in the file before sending it out.
193193

194+
--notes[=<ref>]::
195+
Append the notes (see linkgit:git-notes[1]) for the commit
196+
after the three-dash line.
197+
+
198+
The expected use case of this is to write supporting explanation for
199+
the commit that does not belong to the commit log message proper,
200+
and include it with the patch submission. While one can simply write
201+
these explanations after `format-patch` has run but before sending,
202+
keeping them as git notes allows them to be maintained between versions
203+
of the patch series (but see the discussion of the `notes.rewrite`
204+
configuration options in linkgit:git-notes[1] to use this workflow).
205+
194206
--[no]-signature=<signature>::
195207
Add a signature to each message produced. Per RFC 3676 the signature
196208
is separated from the body by a line with '-- ' on it. If the

Documentation/git-notes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ message stored in the commit object, the notes are indented like the
3939
message, after an unindented line saying "Notes (<refname>):" (or
4040
"Notes:" for `refs/notes/commits`).
4141

42+
Notes can also be added to patches prepared with `git format-patch` by
43+
using the `--notes` option. Such notes are added as a patch commentary
44+
after a three dash separator line.
45+
4246
To change which notes are shown by 'git log', see the
4347
"notes.displayRef" configuration in linkgit:git-log[1].
4448

Documentation/user-manual.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,13 @@ $ git format-patch origin
17871787
will produce a numbered series of files in the current directory, one
17881788
for each patch in the current branch but not in origin/HEAD.
17891789

1790+
`git format-patch` can include an initial "cover letter". You can insert
1791+
commentary on individual patches after the three dash line which
1792+
`format-patch` places after the commit message but before the patch
1793+
itself. If you use `git notes` to track your cover letter material,
1794+
`git format-patch --notes` will include the commit's notes in a similar
1795+
manner.
1796+
17901797
You can then import these into your mail client and send them by
17911798
hand. However, if you have a lot to send at once, you may prefer to
17921799
use the linkgit:git-send-email[1] script to automate the process.

builtin/blame.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ static void get_commit_info(struct commit *commit,
14251425
int detailed)
14261426
{
14271427
int len;
1428-
const char *subject;
1428+
const char *subject, *encoding;
14291429
char *reencoded, *message;
14301430
static char author_name[1024];
14311431
static char author_mail[1024];
@@ -1446,7 +1446,8 @@ static void get_commit_info(struct commit *commit,
14461446
die("Cannot read commit %s",
14471447
sha1_to_hex(commit->object.sha1));
14481448
}
1449-
reencoded = reencode_commit_message(commit, NULL);
1449+
encoding = get_log_output_encoding();
1450+
reencoded = logmsg_reencode(commit, encoding);
14501451
message = reencoded ? reencoded : commit->buffer;
14511452
ret->author = author_name;
14521453
ret->author_mail = author_mail;

commit.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct pretty_print_context {
8686
enum date_mode date_mode;
8787
unsigned date_mode_explicit:1;
8888
int need_8bit_cte;
89-
int show_notes;
89+
char *notes_message;
9090
struct reflog_walk_info *reflog_info;
9191
const char *output_encoding;
9292
};
@@ -99,8 +99,6 @@ extern int has_non_ascii(const char *text);
9999
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
100100
extern char *logmsg_reencode(const struct commit *commit,
101101
const char *output_encoding);
102-
extern char *reencode_commit_message(const struct commit *commit,
103-
const char **encoding_p);
104102
extern void get_commit_format(const char *arg, struct rev_info *);
105103
extern const char *format_subject(struct strbuf *sb, const char *msg,
106104
const char *line_separator);

log-tree.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ void show_log(struct rev_info *opt)
540540
struct pretty_print_context ctx = {0};
541541

542542
opt->loginfo = NULL;
543-
ctx.show_notes = opt->show_notes;
544543
if (!opt->verbose_header) {
545544
graph_show_commit(opt->graph);
546545

@@ -648,6 +647,18 @@ void show_log(struct rev_info *opt)
648647
if (!commit->buffer)
649648
return;
650649

650+
if (opt->show_notes) {
651+
int raw;
652+
struct strbuf notebuf = STRBUF_INIT;
653+
654+
raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
655+
format_display_notes(commit->object.sha1, &notebuf,
656+
get_log_output_encoding(), raw);
657+
ctx.notes_message = notebuf.len
658+
? strbuf_detach(&notebuf, NULL)
659+
: xcalloc(1, 1);
660+
}
661+
651662
/*
652663
* And then the pretty-printed message itself
653664
*/
@@ -664,6 +675,16 @@ void show_log(struct rev_info *opt)
664675

665676
if (opt->add_signoff)
666677
append_signoff(&msgbuf, opt->add_signoff);
678+
679+
if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
680+
ctx.notes_message && *ctx.notes_message) {
681+
if (ctx.fmt == CMIT_FMT_EMAIL) {
682+
strbuf_addstr(&msgbuf, "---\n");
683+
opt->shown_dashes = 1;
684+
}
685+
strbuf_addstr(&msgbuf, ctx.notes_message);
686+
}
687+
667688
if (opt->show_log_size) {
668689
printf("log size %i\n", (int)msgbuf.len);
669690
graph_show_oneline(opt->graph);
@@ -689,10 +710,12 @@ void show_log(struct rev_info *opt)
689710
}
690711

691712
strbuf_release(&msgbuf);
713+
free(ctx.notes_message);
692714
}
693715

694716
int log_tree_diff_flush(struct rev_info *opt)
695717
{
718+
opt->shown_dashes = 0;
696719
diffcore_std(&opt->diffopt);
697720

698721
if (diff_queue_is_empty()) {
@@ -704,25 +727,37 @@ int log_tree_diff_flush(struct rev_info *opt)
704727
}
705728

706729
if (opt->loginfo && !opt->no_commit_id) {
707-
/* When showing a verbose header (i.e. log message),
708-
* and not in --pretty=oneline format, we would want
709-
* an extra newline between the end of log and the
710-
* output for readability.
711-
*/
712730
show_log(opt);
713731
if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
714732
opt->verbose_header &&
715733
opt->commit_format != CMIT_FMT_ONELINE) {
734+
/*
735+
* When showing a verbose header (i.e. log message),
736+
* and not in --pretty=oneline format, we would want
737+
* an extra newline between the end of log and the
738+
* diff/diffstat output for readability.
739+
*/
716740
int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
717741
if (opt->diffopt.output_prefix) {
718742
struct strbuf *msg = NULL;
719743
msg = opt->diffopt.output_prefix(&opt->diffopt,
720744
opt->diffopt.output_prefix_data);
721745
fwrite(msg->buf, msg->len, 1, stdout);
722746
}
723-
if ((pch & opt->diffopt.output_format) == pch) {
747+
748+
/*
749+
* We may have shown three-dashes line early
750+
* between notes and the log message, in which
751+
* case we only want a blank line after the
752+
* notes without (an extra) three-dashes line.
753+
* Otherwise, we show the three-dashes line if
754+
* we are showing the patch with diffstat, but
755+
* in that case, there is no extra blank line
756+
* after the three-dashes line.
757+
*/
758+
if (!opt->shown_dashes &&
759+
(pch & opt->diffopt.output_format) == pch)
724760
printf("---");
725-
}
726761
putchar('\n');
727762
}
728763
}

notes.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,10 +1193,11 @@ void free_notes(struct notes_tree *t)
11931193
* If the given notes_tree is NULL, the internal/default notes_tree will be
11941194
* used instead.
11951195
*
1196-
* 'flags' is a bitwise combination of the flags for format_display_notes.
1196+
* (raw != 0) gives the %N userformat; otherwise, the note message is given
1197+
* for human consumption.
11971198
*/
11981199
static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
1199-
struct strbuf *sb, const char *output_encoding, int flags)
1200+
struct strbuf *sb, const char *output_encoding, int raw)
12001201
{
12011202
static const char utf8[] = "utf-8";
12021203
const unsigned char *sha1;
@@ -1233,7 +1234,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
12331234
if (msglen && msg[msglen - 1] == '\n')
12341235
msglen--;
12351236

1236-
if (flags & NOTES_SHOW_HEADER) {
1237+
if (!raw) {
12371238
const char *ref = t->ref;
12381239
if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
12391240
strbuf_addstr(sb, "\nNotes:\n");
@@ -1249,7 +1250,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
12491250
for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
12501251
linelen = strchrnul(msg_p, '\n') - msg_p;
12511252

1252-
if (flags & NOTES_INDENT)
1253+
if (!raw)
12531254
strbuf_addstr(sb, " ");
12541255
strbuf_add(sb, msg_p, linelen);
12551256
strbuf_addch(sb, '\n');
@@ -1259,13 +1260,13 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
12591260
}
12601261

12611262
void format_display_notes(const unsigned char *object_sha1,
1262-
struct strbuf *sb, const char *output_encoding, int flags)
1263+
struct strbuf *sb, const char *output_encoding, int raw)
12631264
{
12641265
int i;
12651266
assert(display_notes_trees);
12661267
for (i = 0; display_notes_trees[i]; i++)
12671268
format_note(display_notes_trees[i], object_sha1, sb,
1268-
output_encoding, flags);
1269+
output_encoding, raw);
12691270
}
12701271

12711272
int copy_note(struct notes_tree *t,

notes.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,6 @@ void prune_notes(struct notes_tree *t, int flags);
237237
*/
238238
void free_notes(struct notes_tree *t);
239239

240-
/* Flags controlling how notes are formatted */
241-
#define NOTES_SHOW_HEADER 1
242-
#define NOTES_INDENT 2
243-
244240
struct string_list;
245241

246242
struct display_notes_opt {
@@ -274,7 +270,7 @@ void init_display_notes(struct display_notes_opt *opt);
274270
* You *must* call init_display_notes() before using this function.
275271
*/
276272
void format_display_notes(const unsigned char *object_sha1,
277-
struct strbuf *sb, const char *output_encoding, int flags);
273+
struct strbuf *sb, const char *output_encoding, int raw);
278274

279275
/*
280276
* Load the notes tree from each ref listed in 'refs'. The output is

pretty.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
11001100
}
11011101
return 0; /* unknown %g placeholder */
11021102
case 'N':
1103-
if (c->pretty_ctx->show_notes) {
1104-
format_display_notes(commit->object.sha1, sb,
1105-
get_log_output_encoding(), 0);
1103+
if (c->pretty_ctx->notes_message) {
1104+
strbuf_addstr(sb, c->pretty_ctx->notes_message);
11061105
return 1;
11071106
}
11081107
return 0;
@@ -1414,16 +1413,6 @@ void pp_remainder(const struct pretty_print_context *pp,
14141413
}
14151414
}
14161415

1417-
char *reencode_commit_message(const struct commit *commit, const char **encoding_p)
1418-
{
1419-
const char *encoding;
1420-
1421-
encoding = get_log_output_encoding();
1422-
if (encoding_p)
1423-
*encoding_p = encoding;
1424-
return logmsg_reencode(commit, encoding);
1425-
}
1426-
14271416
void pretty_print_commit(const struct pretty_print_context *pp,
14281417
const struct commit *commit,
14291418
struct strbuf *sb)
@@ -1440,7 +1429,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,
14401429
return;
14411430
}
14421431

1443-
reencoded = reencode_commit_message(commit, &encoding);
1432+
encoding = get_log_output_encoding();
1433+
reencoded = logmsg_reencode(commit, encoding);
14441434
if (reencoded) {
14451435
msg = reencoded;
14461436
}
@@ -1500,10 +1490,6 @@ void pretty_print_commit(const struct pretty_print_context *pp,
15001490
if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
15011491
strbuf_addch(sb, '\n');
15021492

1503-
if (pp->show_notes)
1504-
format_display_notes(commit->object.sha1, sb, encoding,
1505-
NOTES_SHOW_HEADER | NOTES_INDENT);
1506-
15071493
free(reencoded);
15081494
}
15091495

0 commit comments

Comments
 (0)