# HG changeset patch # User Artem Tikhomirov # Date 1351693041 -3600 # Node ID 0bd2d0441d8f7f0cdb1f245af7924272296a3702 # Parent 37d97854c6adaace32fad580b2acfc27e6db8e91 Add lookup of remote paths from repository's .hg/hgrc, respect default (origin) diff -r 37d97854c6ad -r 0bd2d0441d8f src/org/tmatesoft/hg/repo/HgLookup.java --- 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 NOT USED YET 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 null 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); }