Skip to content

Commit 9b66ec0

Browse files
author
Linus Torvalds
committed
Add "--pretty=full" format that also shows committer.
Also move the common implementation of parsing the --pretty argument format into commit.c rather than having duplicates in diff-tree.c and rev-list.c.
1 parent f336e71 commit 9b66ec0

File tree

4 files changed

+25
-32
lines changed

4 files changed

+25
-32
lines changed

commit.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55

66
const char *commit_type = "commit";
77

8+
enum cmit_fmt get_commit_format(const char *arg)
9+
{
10+
if (!*arg)
11+
return CMIT_FMT_DEFAULT;
12+
if (!strcmp(arg, "=raw"))
13+
return CMIT_FMT_RAW;
14+
if (!strcmp(arg, "=medium"))
15+
return CMIT_FMT_MEDIUM;
16+
if (!strcmp(arg, "=short"))
17+
return CMIT_FMT_SHORT;
18+
if (!strcmp(arg, "=full"))
19+
return CMIT_FMT_FULL;
20+
die("invalid --pretty format");
21+
}
22+
823
static struct commit *check_commit(struct object *obj, const unsigned char *sha1)
924
{
1025
if (obj->type != commit_type) {
@@ -196,22 +211,21 @@ static int get_one_line(const char *msg, unsigned long len)
196211
return ret;
197212
}
198213

199-
static int add_author_info(enum cmit_fmt fmt, char *buf, const char *line, int len)
214+
static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const char *line)
200215
{
201216
char *date;
202217
unsigned int namelen;
203218
unsigned long time;
204219
int tz, ret;
205220

206-
line += strlen("author ");
207221
date = strchr(line, '>');
208222
if (!date)
209223
return 0;
210224
namelen = ++date - line;
211225
time = strtoul(date, &date, 10);
212226
tz = strtol(date, NULL, 10);
213227

214-
ret = sprintf(buf, "Author: %.*s\n", namelen, line);
228+
ret = sprintf(buf, "%s: %.*s\n", what, namelen, line);
215229
if (fmt == CMIT_FMT_MEDIUM)
216230
ret += sprintf(buf + ret, "Date: %s\n", show_date(time, tz));
217231
return ret;
@@ -284,7 +298,11 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned l
284298
offset += add_parent_info(fmt, buf + offset, line, ++parents);
285299
}
286300
if (!memcmp(line, "author ", 7))
287-
offset += add_author_info(fmt, buf + offset, line, linelen);
301+
offset += add_user_info("Author", fmt, buf + offset, line + 7);
302+
if (fmt == CMIT_FMT_FULL) {
303+
if (!memcmp(line, "committer ", 10))
304+
offset += add_user_info("Commit", fmt, buf + offset, line + 10);
305+
}
288306
continue;
289307
}
290308

commit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ enum cmit_fmt {
3737
CMIT_FMT_RAW,
3838
CMIT_FMT_MEDIUM,
3939
CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
40-
CMIT_FMT_SHORT
40+
CMIT_FMT_SHORT,
41+
CMIT_FMT_FULL,
4142
};
4243

44+
extern enum cmit_fmt get_commit_format(const char *arg);
4345
extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned long len, char *buf, unsigned long space);
4446

4547
void insert_by_date(struct commit_list **list, struct commit *item);

diff-tree.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,6 @@ static int diff_tree_stdin(char *line)
397397
static char *diff_tree_usage =
398398
"git-diff-tree [-p] [-r] [-z] [--stdin] [-m] [-s] [-v] [--pretty] [-t] [-R] [-B] [-M] [-C] [--find-copies-header] [-O<orderfile>] [-S<string>] [--pickaxe-all] <tree-ish> <tree-ish>";
399399

400-
static enum cmit_fmt get_commit_format(const char *arg)
401-
{
402-
if (!*arg)
403-
return CMIT_FMT_DEFAULT;
404-
if (!strcmp(arg, "=raw"))
405-
return CMIT_FMT_RAW;
406-
if (!strcmp(arg, "=medium"))
407-
return CMIT_FMT_MEDIUM;
408-
if (!strcmp(arg, "=short"))
409-
return CMIT_FMT_SHORT;
410-
usage(diff_tree_usage);
411-
}
412-
413400
int main(int argc, const char **argv)
414401
{
415402
int nr_sha1;

rev-list.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,6 @@ struct commit_list *limit_list(struct commit_list *list)
307307
return newlist;
308308
}
309309

310-
static enum cmit_fmt get_commit_format(const char *arg)
311-
{
312-
if (!*arg)
313-
return CMIT_FMT_DEFAULT;
314-
if (!strcmp(arg, "=raw"))
315-
return CMIT_FMT_RAW;
316-
if (!strcmp(arg, "=medium"))
317-
return CMIT_FMT_MEDIUM;
318-
if (!strcmp(arg, "=short"))
319-
return CMIT_FMT_SHORT;
320-
usage(rev_list_usage);
321-
}
322-
323-
324310
int main(int argc, char **argv)
325311
{
326312
struct commit_list *list = NULL;

0 commit comments

Comments
 (0)