diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-08-26 23:13:13 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-08-30 21:04:50 -0700 |
commit | 146ea068a0434a7423d8b0d77f27ccff0a584ac4 (patch) | |
tree | 67a5e1fe2e6125a8209d7f6ce9e5d9eb358954f2 /builtin-commit.c | |
parent | 53d1589ff6bd336e3ece39e0a963a3d2a537cf96 (diff) | |
download | git-146ea068a0434a7423d8b0d77f27ccff0a584ac4.tar.gz |
git commit --author=$name: look $name up in existing commits
This allows "git commit --author=$name" to accept a name that is not in
the required "A U Thor <author@example.xz>" format, and use that to look
up an author name that matches from existing commits.
When using this feature, it is the user's responsibility to give a name
that uniquely matches the name s/he wants, as the logic returns the name
from the first matching commit.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-commit.c')
-rw-r--r-- | builtin-commit.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/builtin-commit.c b/builtin-commit.c index c870037b07..4182686b90 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -710,6 +710,31 @@ static int message_is_empty(struct strbuf *sb, int start) return 1; } +static const char *find_author_by_nickname(const char *name) +{ + struct rev_info revs; + struct commit *commit; + struct strbuf buf = STRBUF_INIT; + const char *av[20]; + int ac = 0; + + init_revisions(&revs, NULL); + strbuf_addf(&buf, "--author=%s", name); + av[++ac] = "--all"; + av[++ac] = "-i"; + av[++ac] = buf.buf; + av[++ac] = NULL; + setup_revisions(ac, av, &revs, NULL); + prepare_revision_walk(&revs); + commit = get_revision(&revs); + if (commit) { + strbuf_release(&buf); + format_commit_message(commit, "%an <%ae>", &buf, DATE_NORMAL); + return strbuf_detach(&buf, NULL); + } + die("No existing author found with '%s'", name); +} + static int parse_and_validate_options(int argc, const char *argv[], const char * const usage[], const char *prefix) @@ -720,6 +745,9 @@ static int parse_and_validate_options(int argc, const char *argv[], logfile = parse_options_fix_filename(prefix, logfile); template_file = parse_options_fix_filename(prefix, template_file); + if (force_author && !strchr(force_author, '>')) + force_author = find_author_by_nickname(force_author); + if (logfile || message.len || use_message) use_editor = 0; if (edit_flag) |