Add a config option to add a comment to S-o-b lines
PATCH 1/1 Add a config option to add a comment to S-o-b lines
As an employee of a consultant company I'm often requested to mention the customer name in the Signed-off-by line. Add a config knob "user.signoffcomment" to configure this and use it in automatically generated S-o-b lines.
--- ident.c | 26 ++++++++++++++++++++++---- ident.h | 3 ++- sequencer.c | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-)
ident.c +22 -4
@@ -20,6 +20,7 @@ static struct strbuf git_author_name = STRBUF_INIT;static struct strbuf git_author_email =STRBUF_INIT ;static struct strbuf git_committer_name =STRBUF_INIT ;static struct strbuf git_committer_email =STRBUF_INIT ; +static struct strbuf git_sob_comment =STRBUF_INIT ;static int default_email_is_bogus;static int default_name_is_bogus;
@@ -468,7 +469,8 @@ const char *fmt_ident(const char *name, const char *email,if (!email) {if (whose_ident ==WANT_AUTHOR_IDENT && git_author_email.len) email = git_author_email.buf; -else if (whose_ident ==WANT_COMMITTER_IDENT && git_committer_email.len) +else if ((whose_ident ==WANT_COMMITTER_IDENT || whose_ident ==WANT_SOB_IDENT ) && + git_committer_email.len) email = git_committer_email.buf; }if (!email) {
@@ -489,8 +491,9 @@ const char *fmt_ident(const char *name, const char *email,if (!name) {if (whose_ident ==WANT_AUTHOR_IDENT && git_author_name.len) name = git_author_name.buf; -else if (whose_ident ==WANT_COMMITTER_IDENT && - git_committer_name.len) +else if ((whose_ident ==WANT_COMMITTER_IDENT || + whose_ident ==WANT_SOB_IDENT ) && + git_committer_name.len) name = git_committer_name.buf; }if (!name) {
@@ -523,7 +526,13 @@ const char *fmt_ident(const char *name, const char *email,strbuf_reset (ident);if (want_name) {strbuf_addstr_without_crud (ident, name); -strbuf_addstr (ident," <" ); +strbuf_addstr (ident," " ); +if (whose_ident ==WANT_SOB_IDENT ) { +strbuf_addstr (ident,"(" ); +strbuf_addstr_without_crud (ident, git_sob_comment.buf); +strbuf_addstr (ident,") " ); + } +strbuf_addstr (ident,"<" ); }strbuf_addstr_without_crud (ident, email);if (want_name)
@@ -554,6 +563,7 @@ const char *fmt_name(enum want_ident whose_ident) email =getenv ("GIT_AUTHOR_EMAIL" );break ;case WANT_COMMITTER_IDENT : +case WANT_SOB_IDENT : name =getenv ("GIT_COMMITTER_NAME" ); email =getenv ("GIT_COMMITTER_EMAIL" );break ;
@@ -671,6 +681,14 @@ static int set_ident(const char *var, const char *value)return 0 ; } +if (!strcmp (var,"user.signoffcomment" )) { +if (!value) +return config_error_nonbool (var); +strbuf_reset (&git_sob_comment); +strbuf_addstr (&git_sob_comment, value); +return 0 ; + } +return 0 ; }
ident.h +2 -1
@@ -21,7 +21,8 @@ struct ident_split {enum want_ident {WANT_BLANK_IDENT ,WANT_AUTHOR_IDENT , -WANT_COMMITTER_IDENT +WANT_COMMITTER_IDENT , +WANT_SOB_IDENT , };const char *ident_default_name (void );
sequencer.c +1 -1
@@ -5635,7 +5635,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 (WANT_COMMITTER_IDENT )); +strbuf_addstr (&sob,fmt_name (WANT_SOB_IDENT ));strbuf_addch (&sob,'\n' );if (!ignore_footer)
Signature · 1 line
2.47.3
Quoted 2 lines · Uwe Kleine-König
As an employee of a consultant company I'm often requested to mention the customer name in the Signed-off-by line. Add a config knob
And this is a widespread practice?
Looking at the Linux Kernel there does seem to be a fair few hits.
Quoted 6 lines
"user.signoffcomment" to configure this and use it in automatically generated S-o-b lines.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>---
[snip]
What are the alternatives? I imagine that the commit-msg hook with git-interpret-trailers(1) could do the same thing.
Adding extra-ident data doesn’t seem to harmonize with grouping by trailers (git-shortlog(1) with --group=trailer:) in the case where the same person contributes under different orgs or something across the years. The mailmap can’t be used for trailers. In that light should git(1) implicitly encourage such a practice over the alternatives like a separate trailer pre/post the -by trailer?
I know it’s not the same thing—just an extension—but git-commit(1) now says:
Git does not (and will not) have a configuration variable to enable the --signoff command line option by default; see the commit.signoff entry in gitfaq(7) for more details.
This does not configure a signoff but it does put more stuff on top of a “historical mistake”.
Quoted 7 lines · Uwe Kleine-König
As an employee of a consultant company I'm often requested to mention the customer name in the Signed-off-by line. Add a config knob "user.signoffcomment" to configure this and use it in automatically generated S-o-b lines.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>---
I know it is not the thrust of this patch, but I think you should think about this question at the same time, eh, rather, I do not think we want to add a feature like this without thinking things like the following through:
How should this practice interact with commands like "git log --author=", "git shortlog", and friends?
Would projects accepting contributions signed like so want to have a feature to easily strip the comments without having to add new entries to their .mailmap every time a known contributor works for a new client?
And then there is a question of "what shape of comment do we want? is it OK for us to dictate that it comes after the author's human readable name identity enclosed in parentheses?".
Shouldn't interpret-trailers be a good place to do this, instead of a configuration option?
Thanks.
Quoted 23 lines · Junio C Hamano
Quoted 7 lines · Uwe Kleine-König
As an employee of a consultant company I'm often requested to mention the customer name in the Signed-off-by line. Add a config knob "user.signoffcomment" to configure this and use it in automatically generated S-o-b lines.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>---
I know it is not the thrust of this patch, but I think you should think about this question at the same time, eh, rather, I do not think we want to add a feature like this without thinking things like the following through:
How should this practice interact with commands like "git log --author=", "git shortlog", and friends?
Would projects accepting contributions signed like so want to have a feature to easily strip the comments without having to add new entries to their .mailmap every time a known contributor works for a new client?
Quoted 6 lines
And then there is a question of "what shape of comment do we want? is it OK for us to dictate that it comes after the author's human readable name identity enclosed in parentheses?".
Shouldn't interpret-trailers be a good place to do this, instead of a configuration option?
Another tangent. Stepping back a bit, these names and e-mail addresses come from:
[user] name = Uwe Kleine-König email = u.kleine-koenig@...
It is plausible that a single user may want to use different identities depending on where the identities are used. It may take a form of three-level configuration variable name, i.e.,
user.<context>.name
user.<context>.email
where obvious candidates for <context> are things like "author" (used for commit author ident), "committer", and "tagger".
It is not too inconceivable to have an entry dedicated for "sign-off", perhaps in addition to the above user.{name,email} entries you already have in your $HOME/.gitconfig, you may throw something like this in the project .git/config file:
[user "sign-off"]
name = Uwe Kleine-König (Current Sponsor)
ident.c::fmt_ident() and ident.c::fmt_name() take "enum want_ident" that lets our callers say "I want AUTHOR_IDENT" etc., and it would be natural to extend the set of WANT_*_IDENT enumeration to support more kind of names, if we really wanted to.
Having said that, wishing to be known under different identities to different communities is one thing, but I am not yet convinced that it is a good idea to use different identities in a single project depending where the ident appears.
Thanks.