# HG changeset patch # User Artem Tikhomirov # Date 1350570452 -7200 # Node ID e4eaa23e34426183acddef9dd7566432a3d8ec9f # Parent 4a670f76e7d1dfccc479e218e3dcd26d35035f9d Leave path as close as possible to one supplied by user. No need to keep it as canonical diff -r 4a670f76e7d1 -r e4eaa23e3442 src/org/tmatesoft/hg/repo/HgLookup.java --- a/src/org/tmatesoft/hg/repo/HgLookup.java Tue Oct 16 21:07:27 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgLookup.java Thu Oct 18 16:27:32 2012 +0200 @@ -19,7 +19,6 @@ import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; import java.io.File; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -58,28 +57,22 @@ // look up in specified location and above public HgRepository detect(File location) throws HgRepositoryNotFoundException { - try { - File dir = location.getAbsoluteFile(); - File repository; - do { - repository = new File(dir, ".hg"); - if (repository.exists() && repository.isDirectory()) { - break; - } - repository = null; - dir = dir.getParentFile(); - - } while(dir != null); - if (repository == null) { - throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); + File dir = location.getAbsoluteFile(); + File repository; + do { + repository = new File(dir, ".hg"); + if (repository.exists() && repository.isDirectory()) { + break; } - String repoPath = repository.getParentFile().getCanonicalPath(); - return new HgRepository(getContext(), repoPath, repository); - } catch (IOException ex) { - HgRepositoryNotFoundException t = new HgRepositoryNotFoundException("Failed to access repository"); - t.setLocation(location.getPath()).initCause(ex); - throw t; + repository = null; + dir = dir.getParentFile(); + + } while(dir != null); + if (repository == null) { + throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); } + String repoPath = repository.getParentFile().getAbsolutePath(); + return new HgRepository(getContext(), repoPath, repository); } public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException {