Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 628:6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 22 May 2013 15:52:31 +0200 |
parents | 4e6179bde4fc |
children | 822f3a83ff57 |
comparison
equal
deleted
inserted
replaced
627:5153eb73b18d | 628:6526d8adbc0f |
---|---|
21 import java.io.File; | 21 import java.io.File; |
22 import java.net.MalformedURLException; | 22 import java.net.MalformedURLException; |
23 import java.net.URL; | 23 import java.net.URL; |
24 | 24 |
25 import org.tmatesoft.hg.core.HgBadArgumentException; | 25 import org.tmatesoft.hg.core.HgBadArgumentException; |
26 import org.tmatesoft.hg.core.HgIOException; | |
26 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; | 27 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; |
27 import org.tmatesoft.hg.core.SessionContext; | 28 import org.tmatesoft.hg.core.SessionContext; |
28 import org.tmatesoft.hg.internal.BasicSessionContext; | 29 import org.tmatesoft.hg.internal.BasicSessionContext; |
29 import org.tmatesoft.hg.internal.ConfigFile; | 30 import org.tmatesoft.hg.internal.ConfigFile; |
30 import org.tmatesoft.hg.internal.DataAccessProvider; | 31 import org.tmatesoft.hg.internal.DataAccessProvider; |
78 | 79 |
79 } while(dir != null); | 80 } while(dir != null); |
80 if (repository == null) { | 81 if (repository == null) { |
81 throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); | 82 throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); |
82 } | 83 } |
83 String repoPath = repository.getParentFile().getAbsolutePath(); | 84 try { |
84 HgRepository rv = new HgRepository(getSessionContext(), repoPath, repository); | 85 String repoPath = repository.getParentFile().getAbsolutePath(); |
85 int requiresFlags = rv.getImplHelper().getRequiresFlags(); | 86 HgRepository rv = new HgRepository(getSessionContext(), repoPath, repository); |
86 if ((requiresFlags & RequiresFile.REVLOGV1) == 0) { | 87 int requiresFlags = rv.getImplHelper().getRequiresFlags(); |
87 throw new HgRepositoryNotFoundException(String.format("%s: repository version is not supported (Mercurial <0.9?)", repoPath)).setLocation(location.getPath()); | 88 if ((requiresFlags & RequiresFile.REVLOGV1) == 0) { |
89 throw new HgRepositoryNotFoundException(String.format("%s: repository version is not supported (Mercurial <0.9?)", repoPath)).setLocation(location.getPath()); | |
90 } | |
91 return rv; | |
92 } catch (HgRuntimeException ex) { | |
93 HgRepositoryNotFoundException e = new HgRepositoryNotFoundException("Failed to initialize Hg4J library").setLocation(location.getPath()); | |
94 e.initCause(ex); | |
95 throw e; | |
88 } | 96 } |
89 return rv; | |
90 } | 97 } |
91 | 98 |
92 public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException { | 99 public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException { |
93 if (location == null || !location.canRead()) { | 100 if (location == null || !location.canRead()) { |
94 throw new HgRepositoryNotFoundException(String.format("Can't read file %s", location)).setLocation(String.valueOf(location)); | 101 throw new HgRepositoryNotFoundException(String.format("Can't read file %s", location)).setLocation(String.valueOf(location)); |
150 private ConfigFile getGlobalConfig() { | 157 private ConfigFile getGlobalConfig() { |
151 if (globalCfg == null) { | 158 if (globalCfg == null) { |
152 globalCfg = new ConfigFile(getSessionContext()); | 159 globalCfg = new ConfigFile(getSessionContext()); |
153 try { | 160 try { |
154 globalCfg.addLocation(new File(System.getProperty("user.home"), ".hgrc")); | 161 globalCfg.addLocation(new File(System.getProperty("user.home"), ".hgrc")); |
155 } catch (HgInvalidFileException ex) { | 162 } catch (HgIOException ex) { |
156 // XXX perhaps, makes sense to let caller/client know that we've failed to read global config? | 163 // XXX perhaps, makes sense to let caller/client know that we've failed to read global config? |
157 getSessionContext().getLog().dump(getClass(), Warn, ex, null); | 164 getSessionContext().getLog().dump(getClass(), Warn, ex, null); |
158 } | 165 } |
159 } | 166 } |
160 return globalCfg; | 167 return globalCfg; |