Skip to content

Conversation

u-quark
Copy link
Contributor

@u-quark u-quark commented Dec 21, 2023

When creating an action signature (e.g. for a commit author and committer) read the following environment variables that can override the configuration options:

  • GIT_AUTHOR_NAME is the human-readable name in the "author" field.
  • GIT_AUTHOR_EMAIL is the email for the "author" field.
  • GIT_AUTHOR_DATE is the timestamp used for the "author" field.
  • GIT_COMMITTER_NAME sets the human name for the "committer" field.
  • GIT_COMMITTER_EMAIL is the email address for the "committer" field.
  • GIT_COMMITTER_DATE is used for the timestamp in the "committer" field.
  • EMAIL is the fallback email address in case the user.email configuration value isn't set. If this isn't set, Git falls back to the system user and host names.

This is taken from the git documentation chapter "10.8 Environment Variables":

https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

This PR adds support for reading these environment variables by adding two new functions git_signature_default_author and git_signature_default_committer and deprecates the git_signature_default function.

Fixes: #3751

Prior work:

@ethomson
Copy link
Member

Thank you for the PR - I agree that we need this functionality. I took a quick first pass on the changes and overall, this is an excellent PR. I will take a closer look 🔜 — thanks again.

@u-quark
Copy link
Contributor Author

u-quark commented Dec 24, 2023

Hi, thanks for looking into this!

I am also keen on getting this functionality merged! Please let me know if you want a different approach of some specific implementation on this PR, I don't mind changing it.

I am not sure I recreated 100% the CI build environment but I managed to compile with clang with similar features enabled on cmake so hopefully this time CI will pass.

Cheers.

@@ -56,11 +102,13 @@ GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const c
* based on that information. It will return GIT_ENOTFOUND if either the
* user.name or user.email are not set.
*
* @deprecated use git_signature_default_author or git_signature_default_committer instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not deprecate it per se - at least not yet - typically, we would compile that out of builds when DEPRECATE_HARD is defined. It's usually the thing that we do before its eventual removal. Instead, let's adjust the documentation to suggest that git_signature_default_author are probably what people actually want. We can deprecate in a future release if we think that's wise.

And it may be - but I think that there are likely a lot of people who are using this API at the moment. So let's give them some time to adjust.

@ethomson
Copy link
Member

A few minor tweaks requested - thanks for putting this together, I think that this is a really useful improvement. 🙏

When creating an action signature (e.g. for a commit author and
committer) read the following environment variables that can override
the configuration options:

 * `GIT_AUTHOR_NAME` is the human-readable name in the "author" field.
 * `GIT_AUTHOR_EMAIL` is the email for the "author" field.
 * `GIT_AUTHOR_DATE` is the timestamp used for the "author" field.
 * `GIT_COMMITTER_NAME` sets the human name for the "committer" field.
 * `GIT_COMMITTER_EMAIL` is the email address for the "committer" field.
 * `GIT_COMMITTER_DATE` is used for the timestamp in the "committer"
   field.
 * `EMAIL` is the fallback email address in case the user.email
   configuration value isn't set. If this isn't set, Git falls back to
   the system user and host names.

This is taken from the git documentation chapter "10.8 Environment
Variables":

https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

This PR adds support for reading these environment variables by adding
two new functions `git_signature_default_author` and
`git_signature_default_committer` and deprecates the
`git_signature_default` function.

Fixes: libgit2#3751

Prior work:
 * libgit2#4409
 * libgit2#5479
 * libgit2#6290
Also fix some comment formatting.
@u-quark u-quark force-pushed the signature-use-env-vars branch from 42ae9fc to 0802483 Compare January 14, 2024 12:17
@u-quark
Copy link
Contributor Author

u-quark commented Jan 14, 2024

Thanks of the review @ethomson!

@csware
Copy link
Contributor

csware commented Feb 24, 2024

The usage of environment variables should always be opt-in in libgit2

ethomson added 2 commits June 14, 2024 12:49
Making the various pieces that create commits automatically (eg, rebase)
start paying attention to the environment variables is a Big Change.
For now, this is a big change in defaults; we should treat it as
breaking. We don't move to this by default; we may add `from_env` or
`honor_env` type of API surface in the future.
People who are doing a commit expect a unified timestamp between
author and committer information when we're using the current timestamp.
Provide a single function that returns both author and committer
information so that they can have an identical timestamp when none is
specified in the environment.
@ethomson
Copy link
Member

Sorry, I've been slow to look at this. One of the things that I've found is that if you want to emulate git commit (for example), then you really want to a) look at the environment variables, but b) fall back to the same time for both author and committer if you're using the current timestamp. I think that this needs to be a single API to get both instead of individual APIs.

Per @csware 's comment, I also think that switching all the behavior of the things that produce commits internally to look at the environment variables is a Big Change that would be unexpected in a small release. I would suggest that we keep the current behavior (wherein it does not honor the GIT_AUTHOR_ and GIT_COMMITTER_ environment variables for now. We can potentially make this opt-in (you can imagine a rebase option that says that it should honor the environment variable). We could also change the behavior of libgit2 to start paying attention to environment variables by default in a future release, with an explicit opt-out. But for now, I think that it needs to remain opt-in.

I'm going to push up a commit to this based on this to adjust...

@u-quark
Copy link
Contributor Author

u-quark commented Jun 17, 2024

Thanks for looking at this @ethomson, I've also been busy and didn't chase this.

I understand your points and they make sense! Both changes LGTM. I will have a closer look later this week and we should be able to merge this.

@ethomson
Copy link
Member

Thanks - sorry to bring the chaotic energy and just push a commit on top of your branch. I appreciate you opening this PR and apologize again for the delay.

ZhangLyndon added a commit to ZhangLyndon/libgit2 that referenced this pull request Jul 7, 2024
@ethomson
Copy link
Member

Thanks again for the PR!

@ethomson ethomson merged commit f3518ee into libgit2:main Jul 10, 2024
u-quark added a commit to u-quark/gg that referenced this pull request Jul 24, 2024
With libgit2/libgit2#6706 merged in we can now
use libgit2 from master. Small changes were needed.

This is needed in order to have stable hashes for e2e tests.

Previously we needed to use a patched version from:
https://github.com/u-quark/libgit2/commits/gg
@u-quark
Copy link
Contributor Author

u-quark commented Jul 24, 2024

I just had some time to look into this. This is great! Works for me like a charm!

Thanks for merging this and sorry again for the late response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function to parse author and committer information from environment
3 participants