Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 492:e4eaa23e3442
Leave path as close as possible to one supplied by user. No need to keep it as canonical
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 18 Oct 2012 16:27:32 +0200 |
parents | e31e85cf4d4c |
children | 0bd2d0441d8f |
comparison
equal
deleted
inserted
replaced
491:4a670f76e7d1 | 492:e4eaa23e3442 |
---|---|
17 package org.tmatesoft.hg.repo; | 17 package org.tmatesoft.hg.repo; |
18 | 18 |
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; | 19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; |
20 | 20 |
21 import java.io.File; | 21 import java.io.File; |
22 import java.io.IOException; | |
23 import java.net.MalformedURLException; | 22 import java.net.MalformedURLException; |
24 import java.net.URL; | 23 import java.net.URL; |
25 | 24 |
26 import org.tmatesoft.hg.core.HgBadArgumentException; | 25 import org.tmatesoft.hg.core.HgBadArgumentException; |
27 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; | 26 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; |
56 return detect(new File(location)); | 55 return detect(new File(location)); |
57 } | 56 } |
58 | 57 |
59 // look up in specified location and above | 58 // look up in specified location and above |
60 public HgRepository detect(File location) throws HgRepositoryNotFoundException { | 59 public HgRepository detect(File location) throws HgRepositoryNotFoundException { |
61 try { | 60 File dir = location.getAbsoluteFile(); |
62 File dir = location.getAbsoluteFile(); | 61 File repository; |
63 File repository; | 62 do { |
64 do { | 63 repository = new File(dir, ".hg"); |
65 repository = new File(dir, ".hg"); | 64 if (repository.exists() && repository.isDirectory()) { |
66 if (repository.exists() && repository.isDirectory()) { | 65 break; |
67 break; | |
68 } | |
69 repository = null; | |
70 dir = dir.getParentFile(); | |
71 | |
72 } while(dir != null); | |
73 if (repository == null) { | |
74 throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); | |
75 } | 66 } |
76 String repoPath = repository.getParentFile().getCanonicalPath(); | 67 repository = null; |
77 return new HgRepository(getContext(), repoPath, repository); | 68 dir = dir.getParentFile(); |
78 } catch (IOException ex) { | 69 |
79 HgRepositoryNotFoundException t = new HgRepositoryNotFoundException("Failed to access repository"); | 70 } while(dir != null); |
80 t.setLocation(location.getPath()).initCause(ex); | 71 if (repository == null) { |
81 throw t; | 72 throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); |
82 } | 73 } |
74 String repoPath = repository.getParentFile().getAbsolutePath(); | |
75 return new HgRepository(getContext(), repoPath, repository); | |
83 } | 76 } |
84 | 77 |
85 public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException { | 78 public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException { |
86 if (location == null || !location.canRead()) { | 79 if (location == null || !location.canRead()) { |
87 throw new HgRepositoryNotFoundException(String.format("Can't read file %s", location)).setLocation(String.valueOf(location)); | 80 throw new HgRepositoryNotFoundException(String.format("Can't read file %s", location)).setLocation(String.valueOf(location)); |