Skip to content

Commit

Permalink
pretty: add infrastructure for commit format aliases
Browse files Browse the repository at this point in the history
Allow named commit formats to alias one another; find_commit_format() will
recursively dereference aliases when they are specified.  At this point,
there are no aliases specified and there is no way to specify an alias,
but the support is there for any which are added.

If an alias loop is detected, the function die()s.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Will Palmer authored and Junio C Hamano committed May 3, 2010
1 parent 4095789 commit 2d7671e
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ static struct cmt_fmt_map {
const char *name;
enum cmit_fmt format;
int is_tformat;
int is_alias;
const char *user_format;
} *commit_formats;
static size_t commit_formats_len;
static struct cmt_fmt_map *find_commit_format(const char *sought);
Expand Down Expand Up @@ -46,14 +48,18 @@ static void setup_commit_formats(void)
sizeof(*builtin_formats)*ARRAY_SIZE(builtin_formats));
}

static struct cmt_fmt_map *find_commit_format(const char *sought)
static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
const char *original,
int num_redirections)
{
struct cmt_fmt_map *found = NULL;
size_t found_match_len = 0;
int i;

if (!commit_formats)
setup_commit_formats();
if (num_redirections >= commit_formats_len)
die("invalid --pretty format: "
"'%s' references an alias which points to itself",
original);

for (i = 0; i < commit_formats_len; i++) {
size_t match_len;
Expand All @@ -67,9 +73,24 @@ static struct cmt_fmt_map *find_commit_format(const char *sought)
found_match_len = match_len;
}
}

if (found && found->is_alias) {
found = find_commit_format_recursive(found->user_format,
original,
num_redirections+1);
}

return found;
}

static struct cmt_fmt_map *find_commit_format(const char *sought)
{
if (!commit_formats)
setup_commit_formats();

return find_commit_format_recursive(sought, sought, 0);
}

void get_commit_format(const char *arg, struct rev_info *rev)
{
struct cmt_fmt_map *commit_format;
Expand Down

0 comments on commit 2d7671e

Please sign in to comment.