comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 148:1a7a9a20e1f9

Exceptions, javadoc. Initial cancel and progress support
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 23 Feb 2011 22:36:28 +0100
parents a3a2e5deb320
children 305ee74c0aa6
comparison
equal deleted inserted replaced
147:a05145db4d0c 148:1a7a9a20e1f9
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
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;
21
22 import org.tmatesoft.hg.core.HgException;
20 23
21 /** 24 /**
25 * Utility methods to find Mercurial repository at a given location
22 * 26 *
23 * @author Artem Tikhomirov 27 * @author Artem Tikhomirov
24 * @author TMate Software Ltd. 28 * @author TMate Software Ltd.
25 */ 29 */
26 public class HgLookup { 30 public class HgLookup {
27 31
28 public HgRepository detectFromWorkingDir() throws Exception { 32 public HgRepository detectFromWorkingDir() throws HgException {
29 return detect(System.getProperty("user.dir")); 33 return detect(System.getProperty("user.dir"));
30 } 34 }
31 35
32 public HgRepository detect(String location) throws Exception /*FIXME Exception type, RepoInitException? */ { 36 public HgRepository detect(String location) throws HgException {
33 return detect(new File(location)); 37 return detect(new File(location));
34 } 38 }
35 39
36 // look up in specified location and above 40 // look up in specified location and above
37 public HgRepository detect(File location) throws Exception { 41 public HgRepository detect(File location) throws HgException {
38 File dir = location; 42 File dir = location;
39 File repository; 43 File repository;
40 do { 44 do {
41 repository = new File(dir, ".hg"); 45 repository = new File(dir, ".hg");
42 if (repository.exists() && repository.isDirectory()) { 46 if (repository.exists() && repository.isDirectory()) {
48 } while(dir != null); 52 } while(dir != null);
49 if (repository == null) { 53 if (repository == null) {
50 // return invalid repository 54 // return invalid repository
51 return new HgRepository(location.getPath()); 55 return new HgRepository(location.getPath());
52 } 56 }
53 return new HgRepository(repository); 57 try {
58 String repoPath = repository.getParentFile().getCanonicalPath();
59 return new HgRepository(repoPath, repository);
60 } catch (IOException ex) {
61 throw new HgException(location.toString(), ex);
62 }
54 } 63 }
55 } 64 }