config: allow giving different author and committer idents
v3 cover config: allow giving different author and committer idents
All,
this version of the patch adds more test cases, combines the tests into the main patch, creates the static set_ident function, updates the documentation and fixes some formatting.
It also applies against master.
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 | 6 +++ ident.c | 92 ++++++++++++++++++++++++++++++++--- log-tree.c | 3 +- sequencer.c | 5 +- t/t7517-per-repo-email.sh | 74 ++++++++++++++++++++++++++++ 10 files changed, 200 insertions(+), 23 deletions(-)
Signature · 1 line
2.19.2
PATCH v3 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 | 6 +++ ident.c | 92 ++++++++++++++++++++++++++++++++--- log-tree.c | 3 +- sequencer.c | 5 +- t/t7517-per-repo-email.sh | 74 ++++++++++++++++++++++++++++ 10 files changed, 200 insertions(+), 23 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 +6 -0
@@ -1484,6 +1484,12 @@ int git_default_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"author." )) +return git_ident_config (var, value, cb); + +if (starts_with (var,"committer." )) +return git_ident_config (var, value, cb); +/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
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
Re: [PATCH v3 1/1] config: allow giving separate author and committer idents
cache.h int date_overflows(timestamp_t date); · line 1501
Quoted 13 lines · William Hubbs
cache.h +5
-0@@ -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 ,
I do not recall we crossed the bridge to allow trailing comma here at the end of enum definition.
cache.h int date_overflows(timestamp_t date); · line 1509
Quoted 7 lines
cache.h +5
-0+}; +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 );
Nice interface.
Quoted 5 lines
config.c +0
-0
config.c int git_default_config(const char *var, const char *value, void *cb) · line 1492
Quoted 9 lines
config.c +6
-0@@ -1484,6 +1484,12 @@ int git_default_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"author." )) +return git_ident_config (var, value, cb); + +if (starts_with (var,"committer." )) +return git_ident_config (var, value, cb); +
I'd rather see this done close to where "user." is already handled, perhaps like
- if (starts_with(var, "user."))
+ if (starts_with(var, "user.") ||
+ starts_with(var, "author.") ||
+ starts_with(var, "committer."))
return git_ident_config(...);Quoted 33 lines
config.c +29
-3-int git_ident_config (const char *var,const char *value,void *data) +static int set_ident (const char *var,const char *value) { -if (!strcmp (var,"user.useconfigonly" )) { - ident_use_config_only =git_config_bool (var, value); +if (!strcmp (var,"author.name" )) { +if (!value) +return config_error_nonbool (var); +strbuf_reset (&git_author_name); +strbuf_addstr (&git_author_name, value); + author_ident_explicitly_given |=IDENT_NAME_GIVEN ; + ident_config_given |=IDENT_NAME_GIVEN ; +return 0 ; + } + +if (!strcmp (var,"author.email" )) { +if (!value) +return config_error_nonbool (var); +strbuf_reset (&git_author_email); +strbuf_addstr (&git_author_email, value); + author_ident_explicitly_given |=IDENT_MAIL_GIVEN ; + ident_config_given |=IDENT_MAIL_GIVEN ; +return 0 ; + } + +if (!strcmp (var,"committer.name" )) { +if (!value) +return config_error_nonbool (var); +strbuf_reset (&git_committer_name); +strbuf_addstr (&git_committer_name, value); + committer_ident_explicitly_given |=IDENT_NAME_GIVEN ; + ident_config_given |=IDENT_NAME_GIVEN ; +return 0 ;
config.c int git_default_config(const char *var, const char *value, void *cb)
Quoted 10 lines
config.c +9
-0+ } + +if (!strcmp (var,"committer.email" )) { +if (!value) +return config_error_nonbool (var); +strbuf_reset (&git_committer_email); +strbuf_addstr (&git_committer_email, value); + committer_ident_explicitly_given |=IDENT_MAIL_GIVEN ; + ident_config_given |=IDENT_MAIL_GIVEN ;return 0 ;
So, when we see "committer.phone", git_default_config() would call git_ident_config() which in turn would call this, and the unknown variable is silently ignored, which is good.
log-tree.c void show_log(struct rev_info *opt) · line 690
Quoted 11 lines
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 ));
Very nice.
Re: [PATCH v3 1/1] config: allow giving separate author and committer idents
Hi Junio,
Quoted 18 lines · Junio C Hamano
cache.h int date_overflows(timestamp_t date); · line 1501
Quoted 13 lines · William Hubbs
cache.h +5
-0@@ -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 ,I do not recall we crossed the bridge to allow trailing comma here at the end of enum definition.
In advice.c:
enum color_advice {
ADVICE_COLOR_RESET = 0,
ADVICE_COLOR_HINT = 1,
};In builtin/pack-objects.c:
enum missing_action {
MA_ERROR = 0, /* fail if any missing objects are encountered */
MA_ALLOW_ANY, /* silently allow ALL missing objects */
MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
};
In builtin/rev-list.c:
enum missing_action {
MA_ERROR = 0, /* fail if any missing objects are encountered */
MA_ALLOW_ANY, /* silently allow ALL missing objects */
MA_PRINT, /* print ALL missing objects in special section */
MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
};
... and I will stop here. You are correct that the majority of our enums does not let its last item end in a comma. But we did cross that bridge.
Ciao,
Dscho
Re: [PATCH v3 1/1] config: allow giving separate author and committer idents
Quoted 27 lines · Johannes Schindelin
Quoted 2 lines
I do not recall we crossed the bridge to allow trailing comma here at the end of enum definition.
In
advice.c:enum color_advice { ADVICE_COLOR_RESET = 0, ADVICE_COLOR_HINT = 1, };In
builtin/pack-objects.c:enum
missing_action{
MA_ERROR= 0, /* fail if any missing objects are encountered */
MA_ALLOW_ANY, /* silently allow ALL missing objects */
MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
};In
builtin/rev-list.c:enum
missing_action{
MA_ERROR= 0, /* fail if any missing objects are encountered */
MA_ALLOW_ANY, /* silently allow ALL missing objects */
MA_PRINT, /* print ALL missing objects in special section */
MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
};
Quoted 2 lines
... and I will stop here. You are correct that the majority of our enums does not let its last item end in a comma. But we did cross that bridge.
Good. Thanks for eyeballing.
I do not think any of these can be compiled out on a platform with a picker compiler, and the one in rev-list.c is from late 2017, so it probably be a safe assumption that nobody would mind the trailing comma.