comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 172:87f40938c9b2

Configuration handling out of HgLookup (bad idea to use URL to pass keys)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 25 Mar 2011 00:13:37 +0100
parents 2c3e96674e2a
children cd3371670f0b
comparison
equal deleted inserted replaced
171:2c3e96674e2a 172:87f40938c9b2
16 */ 16 */
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import java.io.File; 19 import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.net.MalformedURLException;
22 import java.net.URL; 21 import java.net.URL;
23 22
24 import org.tmatesoft.hg.core.HgException; 23 import org.tmatesoft.hg.core.HgException;
25 import org.tmatesoft.hg.internal.ConfigFile;
26 import org.tmatesoft.hg.internal.DataAccessProvider; 24 import org.tmatesoft.hg.internal.DataAccessProvider;
27 import org.tmatesoft.hg.internal.Internals;
28 25
29 /** 26 /**
30 * Utility methods to find Mercurial repository at a given location 27 * Utility methods to find Mercurial repository at a given location
31 * 28 *
32 * @author Artem Tikhomirov 29 * @author Artem Tikhomirov
79 throw new IllegalArgumentException(); 76 throw new IllegalArgumentException();
80 } 77 }
81 if (Boolean.FALSE.booleanValue()) { 78 if (Boolean.FALSE.booleanValue()) {
82 throw HgRepository.notImplemented(); 79 throw HgRepository.notImplemented();
83 } 80 }
84 if (url.getProtocol() == null) {
85 // try configuration keys
86 String key = url.getHost();
87 ConfigFile cfg = new Internals().newConfigFile();
88 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc"));
89 String server = cfg.getSection("paths").get(key);
90 if (server == null) {
91 throw new HgException(String.format("Can't find server %s specification in the config", key));
92 }
93 try {
94 url = new URL(server);
95 } catch (MalformedURLException ex) {
96 throw new HgException(ex);
97 }
98 }
99 return new HgRemoteRepository(url); 81 return new HgRemoteRepository(url);
100 } 82 }
101 } 83 }