diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-09-02 17:45:28 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-09-02 17:45:28 -0700 |
commit | 1c12b38601b5b4da61a2e90540a8de56261d93af (patch) | |
tree | 8e08f3c26cd54c859d1e58c742e75aa2d53cc932 | |
parent | 14e8607c4129b4470f46f6f59e29103f620f3a73 (diff) | |
parent | 146ea068a0434a7423d8b0d77f27ccff0a584ac4 (diff) | |
download | git-1c12b38601b5b4da61a2e90540a8de56261d93af.tar.gz git-1c12b38601b5b4da61a2e90540a8de56261d93af.tar.xz |
Merge branch 'jc/author-nickname'
* jc/author-nickname:
git commit --author=$name: look $name up in existing commits
-rw-r--r-- | Documentation/git-commit.txt | 6 | ||||
-rw-r--r-- | builtin-commit.c | 28 |
2 files changed, 32 insertions, 2 deletions
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 0e25bb862..eb05b0f49 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -75,8 +75,10 @@ OPTIONS read the message from the standard input. --author=<author>:: - Override the author name used in the commit. Use - `A U Thor <author@example.com>` format. + Override the author name used in the commit. You can use the + standard `A U Thor <author@example.com>` format. Otherwise, + an existing commit that matches the given string and its author + name is used. -m <msg>:: --message=<msg>:: diff --git a/builtin-commit.c b/builtin-commit.c index b75d5e931..8165bb3d3 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) |