path: root/builtin/commit.c
diff options
authorJeff King <>2015-06-25 16:55:02 (GMT)
committerJunio C Hamano <>2015-06-29 18:39:07 (GMT)
commita5481a6c9438cbd9c246cfa59ff49c31a0926fb6 (patch)
tree7992773f5ae1687c910e602b6286f3f1cbe116aa /builtin/commit.c
parentb7c1e11dc43e3dbd9eb2da20476c4c55dda5e84b (diff)
convert "enum date_mode" into a struct
In preparation for adding date modes that may carry extra information beyond the mode itself, this patch converts the date_mode enum into a struct. Most of the conversion is fairly straightforward; we pass the struct as a pointer and dereference the type field where necessary. Locations that declare a date_mode can use a "{}" constructor. However, the tricky case is where we use the enum labels as constants, like: show_date(t, tz, DATE_NORMAL); Ideally we could say: show_date(t, tz, &{ DATE_NORMAL }); but of course C does not allow that. Likewise, we cannot cast the constant to a struct, because we need to pass an actual address. Our options are basically: 1. Manually add a "struct date_mode d = { DATE_NORMAL }" definition to each caller, and pass "&d". This makes the callers uglier, because they sometimes do not even have their own scope (e.g., they are inside a switch statement). 2. Provide a pre-made global "date_normal" struct that can be passed by address. We'd also need "date_rfc2822", "date_iso8601", and so forth. But at least the ugliness is defined in one place. 3. Provide a wrapper that generates the correct struct on the fly. The big downside is that we end up pointing to a single global, which makes our wrapper non-reentrant. But show_date is already not reentrant, so it does not matter. This patch implements 3, along with a minor macro to keep the size of the callers sane. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/commit.c')
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index 254477f..7314f33 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -856,7 +856,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
"Date: %s"),
ident_shown++ ? "" : "\n",
- show_ident_date(&ai, DATE_NORMAL));
+ show_ident_date(&ai, DATE_MODE(NORMAL)));
if (!committer_ident_sufficiently_given())
status_printf_ln(s, GIT_COLOR_NORMAL,
@@ -1046,7 +1046,7 @@ static const char *find_author_by_nickname(const char *name)
commit = get_revision(&revs);
if (commit) {
struct pretty_print_context ctx = {0};
- ctx.date_mode = DATE_NORMAL;
+ ctx.date_mode.type = DATE_NORMAL;
format_commit_message(commit, "%aN <%aE>", &buf, &ctx);