Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RevlogStreamFactory.java @ 621:99ad1e3a4e4d
RevlogStream: be aware of existence (not HgDataFile), facilitate use of an added HgDataFile over a commit; Rollback: be more sensitive about file changes (file size is not enough: write/rollback leaves it intact); tests
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Sat, 18 May 2013 22:23:57 +0200 |
| parents | e1b29756f901 |
| children |
comparison
equal
deleted
inserted
replaced
| 620:272ecffccc8a | 621:99ad1e3a4e4d |
|---|---|
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
| 18 | 18 |
| 19 import java.io.File; | 19 import java.io.File; |
| 20 import java.io.IOException; | |
| 21 import java.lang.ref.SoftReference; | 20 import java.lang.ref.SoftReference; |
| 22 import java.util.HashMap; | 21 import java.util.HashMap; |
| 23 | 22 |
| 24 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | |
| 25 import org.tmatesoft.hg.util.Path; | 23 import org.tmatesoft.hg.util.Path; |
| 26 | 24 |
| 27 /** | 25 /** |
| 28 * Factory to create {@link RevlogStream RevlogStreams}, cache-capable. | 26 * Factory to create {@link RevlogStream RevlogStreams}, cache-capable. |
| 29 * | 27 * |
| 55 /** | 53 /** |
| 56 * Perhaps, should be separate interface, like ContentLookup | 54 * Perhaps, should be separate interface, like ContentLookup |
| 57 * @param path - normalized file name | 55 * @param path - normalized file name |
| 58 * @return <code>null</code> if path doesn't resolve to a existing file | 56 * @return <code>null</code> if path doesn't resolve to a existing file |
| 59 */ | 57 */ |
| 60 /*package-local*/ RevlogStream resolveStoreFile(Path path) { | 58 /*package-local*/ RevlogStream getStoreFile(Path path, boolean onlyIfExists) { |
| 61 final SoftReference<RevlogStream> ref = shallCacheRevlogs() ? streamsCache.get(path) : null; | 59 final SoftReference<RevlogStream> ref = shallCacheRevlogs() ? streamsCache.get(path) : null; |
| 62 RevlogStream cached = ref == null ? null : ref.get(); | 60 RevlogStream cached = ref == null ? null : ref.get(); |
| 63 if (cached != null) { | 61 if (cached != null) { |
| 64 return cached; | 62 return cached; |
| 65 } | 63 } |
| 66 File f = repo.getFileFromDataDir(path); | 64 File f = repo.getFileFromDataDir(path); |
| 67 if (f.exists()) { | 65 if (!onlyIfExists || f.exists()) { |
| 68 RevlogStream s = create(f); | 66 RevlogStream s = create(f); |
| 69 if (shallCacheRevlogs()) { | 67 if (shallCacheRevlogs()) { |
| 70 streamsCache.put(path, new SoftReference<RevlogStream>(s)); | 68 streamsCache.put(path, new SoftReference<RevlogStream>(s)); |
| 71 } | 69 } |
| 72 return s; | 70 return s; |
| 73 } | 71 } |
| 74 return null; | 72 return null; |
| 75 } | 73 } |
| 76 | 74 |
| 77 /*package-local*/ RevlogStream createStoreFile(Path path) throws HgInvalidControlFileException { | |
| 78 File f = repo.getFileFromDataDir(path); | |
| 79 try { | |
| 80 if (!f.exists()) { | |
| 81 f.getParentFile().mkdirs(); | |
| 82 f.createNewFile(); | |
| 83 } | |
| 84 RevlogStream s = create(f); | |
| 85 if (shallCacheRevlogs()) { | |
| 86 streamsCache.put(path, new SoftReference<RevlogStream>(s)); | |
| 87 } | |
| 88 return s; | |
| 89 } catch (IOException ex) { | |
| 90 throw new HgInvalidControlFileException("Can't create a file in the storage", ex, f); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 private boolean shallCacheRevlogs() { | 75 private boolean shallCacheRevlogs() { |
| 95 return streamsCache != null; | 76 return streamsCache != null; |
| 96 } | 77 } |
| 97 } | 78 } |
