@matheusbsbs / matheus-bagliano / commits / 36407548a2
Fork 0

Give short-hands to --pretty=tformat:%formatstring

Allow --pretty="%h %s" (and --format="%h %s") as shorthand for an often used option --pretty=tformat:"%h %s". Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nanako Shiraishi committed Feb 24, 2009 at 18:59 UTC 36407548a2825462a91b456755412a65fd611fc0
2 files changed +23 -6
Documentation/pretty-formats.txt
+9
@@ -152,3 +152,12 @@ $ git log -2 --pretty=tformat:%h 4da45bef \
152 4da45be
153 7134973
154 ---------------------
155 ++
156 +In addition, any unrecognized string that has a `%` in it is interpreted
157 +as if it has `tformat:` in front of it. For example, these two are
158 +equivalent:
159 ++
160 +---------------------
161 +$ git log -2 --pretty=tformat:%h 4da45bef
162 +$ git log -2 --pretty=%h 4da45bef
163 +---------------------
pretty.c
+14 -6
@@ -10,6 +10,15 @@
10
11 static char *user_format;
12
13 +static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
14 +{
15 + free(user_format);
16 + user_format = xstrdup(cp);
17 + if (is_tformat)
18 + rev->use_terminator = 1;
19 + rev->commit_format = CMIT_FMT_USERFORMAT;
20 +}
21 +
22 void get_commit_format(const char *arg, struct rev_info *rev)
23 {
24 int i;
@@ -33,12 +42,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
42 return;
43 }
44 if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
36 - const char *cp = strchr(arg, ':') + 1;
37 - free(user_format);
38 - user_format = xstrdup(cp);
39 - if (arg[0] == 't')
40 - rev->use_terminator = 1;
41 - rev->commit_format = CMIT_FMT_USERFORMAT;
45 + save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
46 return;
47 }
48 for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
@@ -50,6 +54,10 @@ void get_commit_format(const char *arg, struct rev_info *rev)
54 return;
55 }
56 }
57 + if (strchr(arg, '%')) {
58 + save_user_format(rev, arg, 1);
59 + return;
60 + }
61
62 die("invalid --pretty format: %s", arg);
63 }