From: "Shawn O. Pearce" <spearce@spearce.org>
To: Yann Simon <yann.simon.fr@gmail.com>
Cc: Robin Rosenberg <robin.rosenberg.lists@dewire.com>,
git <git@vger.kernel.org>
Subject: Re: [PATCH JGIT] Compute the author/commiter name and email from the git configuration
Date: Tue, 3 Feb 2009 15:13:57 -0800 [thread overview]
Message-ID: <20090203231357.GZ26880@spearce.org> (raw)
In-Reply-To: <1233695594.8042.6.camel@localhost>
Yann Simon <yann.simon.fr@gmail.com> wrote:
> index 7df90cd..5821f83 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
> @@ -50,6 +50,8 @@
> import java.io.InputStreamReader;
> import java.io.OutputStreamWriter;
> import java.io.PrintWriter;
> +import java.net.InetAddress;
> +import java.net.UnknownHostException;
> import java.util.ArrayList;
> import java.util.Collections;
> import java.util.HashMap;
> @@ -98,6 +100,8 @@ public static RepositoryConfig openUserConfig() {
>
> private Map<String, Object> byName;
>
> + private String hostname;
> +
> private static final String MAGIC_EMPTY_VALUE = "%%magic%%empty%%";
>
> RepositoryConfig(final Repository repo) {
> @@ -308,6 +312,83 @@ public String getString(final String section, String subsection, final String na
> return result;
> }
>
> + /**
> + * @return the author name as defined in the git variables
> + * and configurations. If no name could be found, try
> + * to use the system user name instead.
> + */
> + public String getAuthorName() {
> + return getUsernameInternal(Constants.GIT_AUTHOR_NAME_KEY);
> + }
> +
> + /**
> + * @return the commiter name as defined in the git variables
> + * and configurations. If no name could be found, try
> + * to use the system user name instead.
> + */
> + public String getCommiterName() {
> + return getUsernameInternal(Constants.GIT_COMMITER_NAME_KEY);
> + }
> +
> + private String getUsernameInternal(String gitVariableKey) {
> + // try to get the user name from the local and global configurations.
> + String username = getString("user", null, "name");
> +
> + if (username == null) {
> + // try to get the user name for the system property GIT_XXX_NAME
> + username = System.getProperty(gitVariableKey);
Shouldn't that be System.getenv()?
> + private String getUserEmailInternal(String gitVariableKey, boolean author) {
> + // try to get the email from the local and global configs.
> + String email = getString("user", null, "email");
> +
> + if (email == null) {
> + // try to get the email for the system property GIT_XXX_EMAIL
> + email = System.getProperty(gitVariableKey);
Again, System.getenv()?
> + public String getHostname() {
> + if (hostname == null) {
> + InetAddress localMachine;
> + try {
> + localMachine = InetAddress.getLocalHost();
> + hostname = localMachine.getHostName();
> + } catch (UnknownHostException e) {
> + // we do nothing
> + }
> + }
> + return hostname;
Do we want getHostName() or getCanonicalHostName() here?
I think we'd want getCanonicalHostName().
Should we be caching this at the RepositoryConfig level, or at the
whole JVM level (in a static). If the application is long-running
its likely to keep the same RepositoryConfig instance around for
the life of that JVM, so we'd only make this request once. Thus any
change in hostname while the application is running would probably
not take effect until after restart. But any long running app is
also likely to access more than one Repository, and thus more than
one RepositoryConfig, so they should at least use consistent names,
even if the underlying hostname has changed.
IMHO, just cache it in a static on first demand.
--
Shawn.
next prev parent reply other threads:[~2009-02-03 23:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-03 21:13 [PATCH JGIT] Compute the author/commiter name and email from the git configuration Yann Simon
2009-02-03 23:13 ` Shawn O. Pearce [this message]
2009-02-03 23:20 ` Johannes Schindelin
2009-02-04 0:55 ` Robin Rosenberg
2009-02-04 1:01 ` Shawn O. Pearce
2009-02-04 0:59 ` Shawn O. Pearce
2009-02-04 1:04 ` Robin Rosenberg
2009-02-04 8:14 ` Yann Simon
2009-02-04 8:42 ` Yann Simon
2009-02-04 8:08 ` Yann Simon
-- strict thread matches above, loose matches on Subject: below --
2009-02-04 12:28 Yann Simon
2009-02-04 17:36 ` Shawn O. Pearce
2009-02-05 9:27 Yann Simon
2009-02-05 10:44 Yann Simon
2009-02-05 15:38 ` Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090203231357.GZ26880@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg.lists@dewire.com \
--cc=yann.simon.fr@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.