@matheusbsbs / matheus-bagliano / commits / 6cdfd17974
Fork 0

commit: allow --pretty= args to be abbreviated

Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed May 14, 2006 at 17:20 UTC 6cdfd1797486138f50f1929c39e77a2cd1e3e033
1 file changed +24 -14
commit.c
+24 -14
@@ -22,23 +22,33 @@ struct sort_node
22
23 const char *commit_type = "commit";
24
25 +struct cmt_fmt_map {
26 + const char *n;
27 + size_t cmp_len;
28 + enum cmit_fmt v;
29 +} cmt_fmts[] = {
30 + { "raw", 1, CMIT_FMT_RAW },
31 + { "medium", 1, CMIT_FMT_MEDIUM },
32 + { "short", 1, CMIT_FMT_SHORT },
33 + { "full", 5, CMIT_FMT_FULL },
34 + { "fuller", 5, CMIT_FMT_FULLER },
35 + { "oneline", 1, CMIT_FMT_ONELINE },
36 +};
37 +
38 enum cmit_fmt get_commit_format(const char *arg)
39 {
27 - if (!*arg)
40 + int i;
41 +
42 + if (!arg || !*arg)
43 return CMIT_FMT_DEFAULT;
29 - if (!strcmp(arg, "=raw"))
30 - return CMIT_FMT_RAW;
31 - if (!strcmp(arg, "=medium"))
32 - return CMIT_FMT_MEDIUM;
33 - if (!strcmp(arg, "=short"))
34 - return CMIT_FMT_SHORT;
35 - if (!strcmp(arg, "=full"))
36 - return CMIT_FMT_FULL;
37 - if (!strcmp(arg, "=fuller"))
38 - return CMIT_FMT_FULLER;
39 - if (!strcmp(arg, "=oneline"))
40 - return CMIT_FMT_ONELINE;
41 - die("invalid --pretty format");
44 + if (*arg == '=')
45 + arg++;
46 + for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
47 + if (!strncmp(arg, cmt_fmts[i].n, cmt_fmts[i].cmp_len))
48 + return cmt_fmts[i].v;
49 + }
50 +
51 + die("invalid --pretty format: %s", arg);
52 }
53
54 static struct commit *check_commit(struct object *obj,