comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 171:2c3e96674e2a

Towards outgoing changes - initial detection logic, get connected with remote repo stub
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 25 Mar 2011 00:05:52 +0100
parents 71ddbf8603e8
children 87f40938c9b2
comparison
equal deleted inserted replaced
170:71ddbf8603e8 171:2c3e96674e2a
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;
21 import java.net.URL; 22 import java.net.URL;
22 23
23 import org.tmatesoft.hg.core.HgException; 24 import org.tmatesoft.hg.core.HgException;
25 import org.tmatesoft.hg.internal.ConfigFile;
24 import org.tmatesoft.hg.internal.DataAccessProvider; 26 import org.tmatesoft.hg.internal.DataAccessProvider;
27 import org.tmatesoft.hg.internal.Internals;
25 28
26 /** 29 /**
27 * Utility methods to find Mercurial repository at a given location 30 * Utility methods to find Mercurial repository at a given location
28 * 31 *
29 * @author Artem Tikhomirov 32 * @author Artem Tikhomirov
70 } 73 }
71 return new HgBundle(new DataAccessProvider(), location); 74 return new HgBundle(new DataAccessProvider(), location);
72 } 75 }
73 76
74 public HgRemoteRepository detect(URL url) throws HgException { 77 public HgRemoteRepository detect(URL url) throws HgException {
78 if (url == null) {
79 throw new IllegalArgumentException();
80 }
75 if (Boolean.FALSE.booleanValue()) { 81 if (Boolean.FALSE.booleanValue()) {
76 throw HgRepository.notImplemented(); 82 throw HgRepository.notImplemented();
77 } 83 }
78 return null; 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);
79 } 100 }
80 } 101 }