18
int is_alias;
19
const char *user_format;
20
} *commit_formats;
21
+static size_t builtin_formats_len;
22
static size_t commit_formats_len;
23
+static size_t commit_formats_alloc;
24
static struct cmt_fmt_map *find_commit_format(const char *sought);
25
26
static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
32
rev->commit_format = CMIT_FMT_USERFORMAT;
33
}
34
35
+static int git_pretty_formats_config(const char *var, const char *value, void *cb)
36
+{
37
+ struct cmt_fmt_map *commit_format = NULL;
38
+ const char *name;
39
+ const char *fmt;
40
+ int i;
41
+
42
+ if (prefixcmp(var, "pretty."))
43
+ return 0;
44
+
45
+ name = var + strlen("pretty.");
46
+ for (i = 0; i < builtin_formats_len; i++) {
47
+ if (!strcmp(commit_formats[i].name, name))
48
+ return 0;
49
+ }
50
+
51
+ for (i = builtin_formats_len; i < commit_formats_len; i++) {
52
+ if (!strcmp(commit_formats[i].name, name)) {
53
+ commit_format = &commit_formats[i];
54
+ break;
55
+ }
56
+ }
57
+
58
+ if (!commit_format) {
59
+ ALLOC_GROW(commit_formats, commit_formats_len+1,
60
+ commit_formats_alloc);
61
+ commit_format = &commit_formats[commit_formats_len];
62
+ commit_formats_len++;
63
+ }
64
+
65
+ commit_format->name = xstrdup(name);
66
+ commit_format->format = CMIT_FMT_USERFORMAT;
67
+ git_config_string(&fmt, var, value);
68
+ if (!prefixcmp(fmt, "format:") || !prefixcmp(fmt, "tformat:")) {
69
+ commit_format->is_tformat = fmt[0] == 't';
70
+ fmt = strchr(fmt, ':') + 1;
71
+ } else if (strchr(fmt, '%'))
72
+ commit_format->is_tformat = 1;
73
+ else
74
+ commit_format->is_alias = 1;
75
+ commit_format->user_format = fmt;
76
+
77
+ return 0;
78
+}
79
+
80
static void setup_commit_formats(void)
81
{
82
struct cmt_fmt_map builtin_formats[] = {
89
{ "oneline", CMIT_FMT_ONELINE, 1 }
90
};
91
commit_formats_len = ARRAY_SIZE(builtin_formats);
45
- commit_formats = xmalloc(commit_formats_len *
46
- sizeof(*builtin_formats));
92
+ builtin_formats_len = commit_formats_len;
93
+ ALLOC_GROW(commit_formats, commit_formats_len, commit_formats_alloc);
94
memcpy(commit_formats, builtin_formats,
95
sizeof(*builtin_formats)*ARRAY_SIZE(builtin_formats));
96
+
97
+ git_config(git_pretty_formats_config, NULL);
98
}
99
100
static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
165
166
rev->commit_format = commit_format->format;
167
rev->use_terminator = commit_format->is_tformat;
168
+ if (commit_format->format == CMIT_FMT_USERFORMAT) {
169
+ save_user_format(rev, commit_format->user_format,
170
+ commit_format->is_tformat);
171
+ }
172
}
173
174
/*