config: allow giving separate author and committer idents
v4 cover config: allow giving separate author and committer idents
All,
this implements the changes requested in v3 of this patch:
- removes an extra comma from the enum
- reworks the logic for config handling so that the author and committer variables are handled along with the user variables.
Please review.
William Hubbs (1):
config: allow giving separate author and committer idents
Documentation/config/user.txt | 23 ++++++--- blame.c | 3 +- builtin/am.c | 1 + builtin/commit.c | 3 +- cache.h | 13 ++++- config.c | 4 +- ident.c | 92 ++++++++++++++++++++++++++++++++--- log-tree.c | 3 +- sequencer.c | 5 +- t/t7517-per-repo-email.sh | 74 ++++++++++++++++++++++++++++ 10 files changed, 197 insertions(+), 24 deletions(-)
Signature · 1 line
2.19.2
PATCH v4 1/1 config: allow giving separate author and committer idents
The author.email, author.name, committer.email and committer.name settings are analogous to the GIT_AUTHOR_* and GIT_COMMITTER_* environment variables, but for the git config system. This allows them to be set separately for each repository.
Git supports setting different authorship and committer information with environment variables. However, environment variables are set in the shell, so if different authorship and committer information is needed for different repositories an external tool is required.
This adds support to git config for author.email, author.name, committer.email and committer.name settings so this information can be set per repository.
Also, it generalizes the fmt_ident function so it can handle author vs committer identification.
--- Documentation/config/user.txt | 23 ++++++--- blame.c | 3 +- builtin/am.c | 1 + builtin/commit.c | 3 +- cache.h | 13 ++++- config.c | 4 +- ident.c | 92 ++++++++++++++++++++++++++++++++--- log-tree.c | 3 +- sequencer.c | 5 +- t/t7517-per-repo-email.sh | 74 ++++++++++++++++++++++++++++ 10 files changed, 197 insertions(+), 24 deletions(-)
Documentation/config/user.txt +15 -8
@@ -1,12 +1,19 @@ -user.email:: - Your email address to be recorded in any newly created commits. - Can be overridden by the `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_EMAIL`, and - `EMAIL` environment variables. See linkgit:git-commit-tree[1]. - user.name:: - Your full name to be recorded in any newly created commits. - Can be overridden by the `GIT_AUTHOR_NAME` and `GIT_COMMITTER_NAME` - environment variables. See linkgit:git-commit-tree[1]. +user.email:: +author.name:: +author.email:: +committer.name:: +committer.email:: + The `user.name` and `user.email` variables determine what ends + up in the `author` and `committer` field of commit + objects. + If you need the `author` or `committer` to be different, the + `author.name`, `author.email`, `committer.name` or + `committer.email` variables can be set. + Also, all of these can be overridden by the `GIT_AUTHOR_NAME`, + `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME` and + `GIT_COMMITTER_EMAIL` environment variables. + See linkgit:git-commit-tree[1] for more information. user.useConfigOnly:: Instruct Git to avoid trying to guess defaults for `user.email`
blame.c +2 -1
@@ -204,7 +204,8 @@ static struct commit *fake_working_tree_commit(struct repository *r, origin =make_origin (commit, path); - ident =fmt_ident ("Not Committed Yet" ,"not.committed.yet" ,NULL ,0 ); + ident =fmt_ident ("Not Committed Yet" ,"not.committed.yet" , +WANT_BLANK_IDENT ,NULL ,0 );strbuf_addstr (&msg,"tree 0000000000000000000000000000000000000000\n" );for (parent = commit->parents; parent; parent = parent->next) strbuf_addf(&msg, "parent %s\n",
builtin/am.c +1 -0
@@ -1594,6 +1594,7 @@ static void do_commit(const struct am_state *state) } author =fmt_ident (state->author_name, state->author_email, +WANT_AUTHOR_IDENT , state->ignore_date ?NULL : state->author_date,IDENT_STRICT );
builtin/commit.c +2 -1
@@ -608,7 +608,8 @@ static void determine_author_info(struct strbuf *author_ident)set_ident_var (&date,strbuf_detach (&date_buf,NULL )); } -strbuf_addstr (author_ident,fmt_ident (name, email, date,IDENT_STRICT )); +strbuf_addstr (author_ident,fmt_ident (name, email,WANT_AUTHOR_IDENT , date, +IDENT_STRICT ));assert_split_ident (&author, author_ident);export_one ("GIT_AUTHOR_NAME" , author.name_begin, author.name_end,0 );export_one ("GIT_AUTHOR_EMAIL" , author.mail_begin, author.mail_end,0 );
cache.h +11 -2
@@ -1494,10 +1494,19 @@ int date_overflows(timestamp_t date);#define IDENT_STRICT 1#define IDENT_NO_DATE 2#define IDENT_NO_NAME 4 + +enum want_ident { +WANT_BLANK_IDENT , +WANT_AUTHOR_IDENT , +WANT_COMMITTER_IDENT +}; +extern const char *git_author_info (int );extern const char *git_committer_info (int ); -extern const char *fmt_ident (const char *name,const char *email,const char *date_str,int ); -extern const char *fmt_name (const char *name,const char *email); +extern const char *fmt_ident (const char *name,const char *email, +enum want_ident whose_ident, +const char *date_str,int ); +extern const char *fmt_name (enum want_ident );extern const char *ident_default_name (void );extern const char *ident_default_email (void );extern const char *git_editor (void );
config.c +3 -1
@@ -1445,7 +1445,9 @@ int git_default_config(const char *var, const char *value, void *cb)if (starts_with (var,"core." ))return git_default_core_config (var, value, cb); -if (starts_with (var,"user." )) +if (starts_with (var,"user." ) || +starts_with (var,"author." ) || +starts_with (var,"committer." ))return git_ident_config (var, value, cb);if (starts_with (var,"i18n." ))
ident.c +86 -6
148 lines not on this page · raw message
log-tree.c +1 -2
@@ -687,8 +687,7 @@ void show_log(struct rev_info *opt)*/ if (ctx.need_8bit_cte >=0 && opt->add_signoff) ctx.need_8bit_cte = -has_non_ascii (fmt_name (getenv ("GIT_COMMITTER_NAME" ), -getenv ("GIT_COMMITTER_EMAIL" ))); +has_non_ascii (fmt_name (WANT_COMMITTER_IDENT )); ctx.date_mode = opt->date_mode; ctx.date_mode_explicit = opt->date_mode_explicit; ctx.abbrev = opt->diffopt.abbrev;
sequencer.c +2 -3
@@ -837,7 +837,7 @@ static const char *read_author_ident(struct strbuf *buf) }strbuf_reset (&out); -strbuf_addstr (&out,fmt_ident (name, email, date,0 )); +strbuf_addstr (&out,fmt_ident (name, email,WANT_AUTHOR_IDENT , date,0 ));strbuf_swap (buf, &out);strbuf_release (&out);free (name);
@@ -4094,8 +4094,7 @@ void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag)int has_footer;strbuf_addstr (&sob, sign_off_header); -strbuf_addstr (&sob,fmt_name (getenv ("GIT_COMMITTER_NAME" ), -getenv ("GIT_COMMITTER_EMAIL" ))); +strbuf_addstr (&sob,fmt_name (WANT_COMMITTER_IDENT ));strbuf_addch (&sob,'\n' );if (!ignore_footer)
t/t7517-per-repo-email.sh +74 -0
78 lines not on this page · raw message
Signature · 1 line
2.19.2
Hi William,
Quoted 19 lines · William Hubbs
Documentation/config/user.txt +5
-8@@ -1,12 +1,19 @@ -user.email:: - Your email address to be recorded in any newly created commits. - Can be overridden by the `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_EMAIL`, and - `EMAIL` environment variables. See linkgit:git-commit-tree[1]. - user.name:: - Your full name to be recorded in any newly created commits. - Can be overridden by the `GIT_AUTHOR_NAME` and `GIT_COMMITTER_NAME` - environment variables. See linkgit:git-commit-tree[1]. +user.email:: +author.name:: +author.email:: +committer.name:: +committer.email::
Documentation/config/user.txt line 16
Quoted 10 lines
Documentation/config/user.txt +10
-0+ The `user.name` and `user.email` variables determine what ends + up in the `author` and `committer` field of commit + objects. + If you need the `author` or `committer` to be different, the + `author.name`, `author.email`, `committer.name` or + `committer.email` variables can be set. + Also, all of these can be overridden by the `GIT_AUTHOR_NAME`, + `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME` and + `GIT_COMMITTER_EMAIL` environment variables. + See linkgit:git-commit-tree[1] for more information.
This no longer talks about the EMAIL variable. Maybe we can add that back?
The rest looks very clean to me.
Thanks,
Johannes