Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 456:909306e412e2
Refactor LogFacility and SessionContext, better API for both
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Mon, 18 Jun 2012 16:54:00 +0200 |
| parents | 12f668401613 |
| children | 3ca4ae7bdd38 |
comparison
equal
deleted
inserted
replaced
| 454:36fd1fd06492 | 456:909306e412e2 |
|---|---|
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
| 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 static org.tmatesoft.hg.util.LogFacility.Severity.*; | |
| 20 | |
| 19 import java.io.File; | 21 import java.io.File; |
| 20 import java.io.IOException; | 22 import java.io.IOException; |
| 21 import java.io.StringReader; | 23 import java.io.StringReader; |
| 22 import java.lang.ref.SoftReference; | 24 import java.lang.ref.SoftReference; |
| 23 import java.util.ArrayList; | 25 import java.util.ArrayList; |
| 199 hgTags.content(i, sink); | 201 hgTags.content(i, sink); |
| 200 final String content = new String(sink.toArray(), "UTF8"); | 202 final String content = new String(sink.toArray(), "UTF8"); |
| 201 tags.readGlobal(new StringReader(content)); | 203 tags.readGlobal(new StringReader(content)); |
| 202 } catch (CancelledException ex) { | 204 } catch (CancelledException ex) { |
| 203 // IGNORE, can't happen, we did not configure cancellation | 205 // IGNORE, can't happen, we did not configure cancellation |
| 204 getContext().getLog().debug(getClass(), ex, null); | 206 getContext().getLog().dump(getClass(), Debug, ex, null); |
| 205 } catch (IOException ex) { | 207 } catch (IOException ex) { |
| 206 // UnsupportedEncodingException can't happen (UTF8) | 208 // UnsupportedEncodingException can't happen (UTF8) |
| 207 // only from readGlobal. Need to reconsider exceptions thrown from there: | 209 // only from readGlobal. Need to reconsider exceptions thrown from there: |
| 208 // BufferedReader wraps String and unlikely to throw IOException, perhaps, log is enough? | 210 // BufferedReader wraps String and unlikely to throw IOException, perhaps, log is enough? |
| 209 getContext().getLog().error(getClass(), ex, null); | 211 getContext().getLog().dump(getClass(), Error, ex, null); |
| 210 // XXX need to decide what to do this. failure to read single revision shall not break complete cycle | 212 // XXX need to decide what to do this. failure to read single revision shall not break complete cycle |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 } | 215 } |
| 214 File file2read = null; | 216 File file2read = null; |
| 216 file2read = new File(getWorkingDir(), ".hgtags"); | 218 file2read = new File(getWorkingDir(), ".hgtags"); |
| 217 tags.readGlobal(file2read); // XXX replace with HgDataFile.workingCopy | 219 tags.readGlobal(file2read); // XXX replace with HgDataFile.workingCopy |
| 218 file2read = new File(repoDir, "localtags"); | 220 file2read = new File(repoDir, "localtags"); |
| 219 tags.readLocal(file2read); | 221 tags.readLocal(file2read); |
| 220 } catch (IOException ex) { | 222 } catch (IOException ex) { |
| 221 getContext().getLog().error(getClass(), ex, null); | 223 getContext().getLog().dump(getClass(), Error, ex, null); |
| 222 throw new HgInvalidControlFileException("Failed to read tags", ex, file2read); | 224 throw new HgInvalidControlFileException("Failed to read tags", ex, file2read); |
| 223 } | 225 } |
| 224 } | 226 } |
| 225 return tags; | 227 return tags; |
| 226 } | 228 } |
| 312 try { | 314 try { |
| 313 ConfigFile configFile = impl.readConfiguration(this, getRepositoryRoot()); | 315 ConfigFile configFile = impl.readConfiguration(this, getRepositoryRoot()); |
| 314 repoConfig = new HgRepoConfig(configFile); | 316 repoConfig = new HgRepoConfig(configFile); |
| 315 } catch (IOException ex) { | 317 } catch (IOException ex) { |
| 316 String m = "Errors while reading user configuration file"; | 318 String m = "Errors while reading user configuration file"; |
| 317 getContext().getLog().warn(getClass(), ex, m); | 319 getContext().getLog().dump(getClass(), Warn, ex, m); |
| 318 return new HgRepoConfig(new ConfigFile()); // empty config, do not cache, allow to try once again | 320 return new HgRepoConfig(new ConfigFile()); // empty config, do not cache, allow to try once again |
| 319 //throw new HgInvalidControlFileException(m, ex, null); | 321 //throw new HgInvalidControlFileException(m, ex, null); |
| 320 } | 322 } |
| 321 } | 323 } |
| 322 return repoConfig; | 324 return repoConfig; |
| 359 ignore = new HgIgnore(getToRepoPathHelper()); | 361 ignore = new HgIgnore(getToRepoPathHelper()); |
| 360 File ignoreFile = new File(getWorkingDir(), ".hgignore"); | 362 File ignoreFile = new File(getWorkingDir(), ".hgignore"); |
| 361 try { | 363 try { |
| 362 final List<String> errors = ignore.read(ignoreFile); | 364 final List<String> errors = ignore.read(ignoreFile); |
| 363 if (errors != null) { | 365 if (errors != null) { |
| 364 getContext().getLog().warn(getClass(), "Syntax errors parsing .hgignore:\n%s", Internals.join(errors, ",\n")); | 366 getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing .hgignore:\n%s", Internals.join(errors, ",\n")); |
| 365 } | 367 } |
| 366 } catch (IOException ex) { | 368 } catch (IOException ex) { |
| 367 final String m = "Error reading .hgignore file"; | 369 final String m = "Error reading .hgignore file"; |
| 368 getContext().getLog().warn(getClass(), ex, m); | 370 getContext().getLog().dump(getClass(), Warn, ex, m); |
| 369 // throw new HgInvalidControlFileException(m, ex, ignoreFile); | 371 // throw new HgInvalidControlFileException(m, ex, ignoreFile); |
| 370 } | 372 } |
| 371 } | 373 } |
| 372 return ignore; | 374 return ignore; |
| 373 } | 375 } |
| 398 try { | 400 try { |
| 399 File fake = File.createTempFile(f.getName(), null); | 401 File fake = File.createTempFile(f.getName(), null); |
| 400 fake.deleteOnExit(); | 402 fake.deleteOnExit(); |
| 401 return new RevlogStream(dataAccess, fake); | 403 return new RevlogStream(dataAccess, fake); |
| 402 } catch (IOException ex) { | 404 } catch (IOException ex) { |
| 403 getContext().getLog().info(getClass(), ex, null); | 405 getContext().getLog().dump(getClass(), Info, ex, null); |
| 404 } | 406 } |
| 405 } | 407 } |
| 406 } | 408 } |
| 407 return null; // XXX empty stream instead? | 409 return null; // XXX empty stream instead? |
| 408 } | 410 } |
