summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 636991b)
raw | patch | inline | side by side (parent: 636991b)
author | Stephen Boyd <bebarino@gmail.com> | |
Mon, 23 Mar 2009 02:14:01 +0000 (19:14 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 23 Mar 2009 04:32:13 +0000 (21:32 -0700) |
This specifier represents the sanitized and filename friendly subject
line of a commit. No checks are made against the length of the string,
so users may need to trim the result to the desired length if using as a
filename. This is commonly used by format-patch to massage commit
subjects into filenames and output patches to files.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
line of a commit. No checks are made against the length of the string,
so users may need to trim the result to the desired length if using as a
filename. This is commonly used by format-patch to massage commit
subjects into filenames and output patches to files.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/pretty-formats.txt | patch | blob | history | |
pretty.c | patch | blob | history |
index 5c6e678aa3d9e75570d5a5578e38b0a45bae720e..2a845b1e57590a6f18f05fd3efa858b736c1071a 100644 (file)
- '%d': ref names, like the --decorate option of linkgit:git-log[1]
- '%e': encoding
- '%s': subject
+- '%f': sanitized subject line, suitable for a filename
- '%b': body
- '%Cred': switch color to red
- '%Cgreen': switch color to green
diff --git a/pretty.c b/pretty.c
index efa70245f19ef3493cd701ea20505203a466d65e..c57cef47c93912a709fc67fe98cdcff15ed34dc6 100644 (file)
--- a/pretty.c
+++ b/pretty.c
context->commit_header_parsed = 1;
}
+static int istitlechar(char c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || c == '.' || c == '_';
+}
+
+static void format_sanitized_subject(struct strbuf *sb, const char *msg)
+{
+ size_t trimlen;
+ int space = 2;
+
+ for (; *msg && *msg != '\n'; msg++) {
+ if (istitlechar(*msg)) {
+ if (space == 1)
+ strbuf_addch(sb, '-');
+ space = 0;
+ strbuf_addch(sb, *msg);
+ if (*msg == '.')
+ while (*(msg+1) == '.')
+ msg++;
+ } else
+ space |= 1;
+ }
+
+ /* trim any trailing '.' or '-' characters */
+ trimlen = 0;
+ while (sb->buf[sb->len - 1 - trimlen] == '.'
+ || sb->buf[sb->len - 1 - trimlen] == '-')
+ trimlen++;
+ strbuf_remove(sb, sb->len - trimlen, trimlen);
+}
+
const char *format_subject(struct strbuf *sb, const char *msg,
const char *line_separator)
{
case 's': /* subject */
format_subject(sb, msg + c->subject_off, " ");
return 1;
+ case 'f': /* sanitized subject */
+ format_sanitized_subject(sb, msg + c->subject_off);
+ return 1;
case 'b': /* body */
strbuf_addstr(sb, msg + c->body_off);
return 1;