Mercurial > hg4j
changeset 503:0bd2d0441d8f
Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 31 Oct 2012 15:17:21 +0100 |
parents | 37d97854c6ad |
children | bf352ce2b97f |
files | src/org/tmatesoft/hg/repo/HgLookup.java |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgLookup.java Mon Oct 29 20:06:16 2012 +0100 +++ b/src/org/tmatesoft/hg/repo/HgLookup.java Wed Oct 31 15:17:21 2012 +0100 @@ -28,6 +28,7 @@ import org.tmatesoft.hg.internal.BasicSessionContext; import org.tmatesoft.hg.internal.ConfigFile; import org.tmatesoft.hg.internal.DataAccessProvider; +import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection; /** * Utility methods to find Mercurial repository at a given location @@ -83,9 +84,10 @@ } /** - * Try to instantiate remote server. - * @param key either URL or a key from configuration file that points to remote server - * @param hgRepo <em>NOT USED YET<em> local repository that may have extra config, or default remote location + * Try to instantiate remote server using an immediate url or an url from configuration files + * + * @param key either URL or a key from configuration file that points to remote server; if <code>null</code> or empty string, default remote location of the supplied repository (if any) is looked up + * @param hgRepo optional local repository to get default or otherwise configured remote location * @return an instance featuring access to remote repository, check {@link HgRemoteRepository#isInvalid()} before actually using it * @throws HgBadArgumentException if anything is wrong with the remote server's URL */ @@ -100,7 +102,16 @@ toReport = ex; } if (url == null) { - String server = getGlobalConfig().getSection("paths").get(key); + String server = null; + if (hgRepo != null && !hgRepo.isInvalid()) { + PathsSection ps = hgRepo.getConfiguration().getPaths(); + server = key == null || key.trim().isEmpty() ? ps.getDefault() : ps.getString(key, null); + } else if (key == null || key.trim().length() == 0) { + throw new HgBadArgumentException("Can't look up empty key in a global configuration", null); + } + if (server == null) { + server = getGlobalConfig().getSection("paths").get(key); + } if (server == null) { throw new HgBadArgumentException(String.format("Can't find server %s specification in the config", key), toReport); }