| 1435 | } |
| 1436 | |
| 1437 | static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ |
| 1438 | const char *placeholder, |
| 1439 | void *context) |
| 1440 | { |
| 1441 | struct format_commit_context *c = context; |
| 1442 | const struct commit *commit = c->commit; |
| 1443 | const char *msg = c->message; |
| 1444 | struct commit_list *p; |
| 1445 | const char *arg, *eol; |
| 1446 | size_t res; |
| 1447 | char **slot; |
| 1448 | |
| 1449 | /* these are independent of the commit */ |
| 1450 | res = strbuf_expand_literal(sb, placeholder); |
| 1451 | if (res) |
| 1452 | return res; |
| 1453 | |
| 1454 | switch (placeholder[0]) { |
| 1455 | case 'C': |
| 1456 | if (starts_with(placeholder + 1, "(auto)")) { |
| 1457 | c->auto_color = c->pretty_ctx->color; |
| 1458 | if (want_color(c->auto_color) && sb->len) |
| 1459 | strbuf_addstr(sb, GIT_COLOR_RESET); |
| 1460 | return 7; /* consumed 7 bytes, "C(auto)" */ |
| 1461 | } else { |
| 1462 | int ret = parse_color(sb, placeholder, c); |
| 1463 | if (ret) |
| 1464 | c->auto_color = GIT_COLOR_NEVER; |
| 1465 | /* |
| 1466 | * Otherwise, we decided to treat %C<unknown> |
| 1467 | * as a literal string, and the previous |
| 1468 | * %C(auto) is still valid. |
| 1469 | */ |
| 1470 | return ret; |
| 1471 | } |
| 1472 | case 'w': |
| 1473 | if (placeholder[1] == '(') { |
| 1474 | unsigned long width = 0, indent1 = 0, indent2 = 0; |
| 1475 | char *next; |
| 1476 | const char *start = placeholder + 2; |
| 1477 | const char *end = strchr(start, ')'); |
| 1478 | if (!end) |
| 1479 | return 0; |
| 1480 | if (end > start) { |
| 1481 | width = strtoul(start, &next, 10); |
| 1482 | if (*next == ',') { |
| 1483 | indent1 = strtoul(next + 1, &next, 10); |
| 1484 | if (*next == ',') { |
| 1485 | indent2 = strtoul(next + 1, |
| 1486 | &next, 10); |
| 1487 | } |
| 1488 | } |
| 1489 | if (*next != ')') |
| 1490 | return 0; |
| 1491 | } |
| 1492 | |
| 1493 | /* |
| 1494 | * We need to limit the format here as it allows the |
no test coverage detected