Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgManifest.java @ 417:ccd7d25e5aea
New and better name for HgFileInformer - HgChangesetFileSneaker. Explain (comments) ties between HgManifest, HgDataFile, HgChangesetFileSneaker and reasons for method placement
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 22 Mar 2012 20:14:06 +0100 |
parents | ee8264d80747 |
children | 7f136a3fa671 |
comparison
equal
deleted
inserted
replaced
416:d30083c80d52 | 417:ccd7d25e5aea |
---|---|
26 import java.util.Arrays; | 26 import java.util.Arrays; |
27 import java.util.HashMap; | 27 import java.util.HashMap; |
28 import java.util.Map; | 28 import java.util.Map; |
29 | 29 |
30 import org.tmatesoft.hg.core.HgBadStateException; | 30 import org.tmatesoft.hg.core.HgBadStateException; |
31 import org.tmatesoft.hg.core.HgChangesetFileSneaker; | |
31 import org.tmatesoft.hg.core.HgException; | 32 import org.tmatesoft.hg.core.HgException; |
32 import org.tmatesoft.hg.core.HgInvalidControlFileException; | 33 import org.tmatesoft.hg.core.HgInvalidControlFileException; |
33 import org.tmatesoft.hg.core.HgInvalidRevisionException; | 34 import org.tmatesoft.hg.core.HgInvalidRevisionException; |
34 import org.tmatesoft.hg.core.Nodeid; | 35 import org.tmatesoft.hg.core.Nodeid; |
35 import org.tmatesoft.hg.internal.DataAccess; | 36 import org.tmatesoft.hg.internal.DataAccess; |
241 return revisionMap.at(changesetRevisionIndex); | 242 return revisionMap.at(changesetRevisionIndex); |
242 } | 243 } |
243 | 244 |
244 /** | 245 /** |
245 * Extracts file revision as it was known at the time of given changeset. | 246 * Extracts file revision as it was known at the time of given changeset. |
247 * For more thorough details about file at specific changeset, use {@link HgChangesetFileSneaker}. | |
246 * | 248 * |
249 * @see HgChangesetFileSneaker | |
247 * @param changelogRevisionIndex local changeset index | 250 * @param changelogRevisionIndex local changeset index |
248 * @param file path to file in question | 251 * @param file path to file in question |
249 * @return file revision or <code>null</code> if manifest at specified revision doesn't list such file | 252 * @return file revision or <code>null</code> if manifest at specified revision doesn't list such file |
250 * @throws HgInvalidRevisionException if method argument specifies non-existent revision index | 253 * @throws HgInvalidRevisionException if method argument specifies non-existent revision index |
251 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | 254 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
252 */ | 255 */ |
253 @Experimental(reason="Perhaps, HgDataFile shall own this method, or get a delegate?") | |
254 public Nodeid getFileRevision(int changelogRevisionIndex, final Path file) throws HgInvalidRevisionException, HgInvalidControlFileException { | 256 public Nodeid getFileRevision(int changelogRevisionIndex, final Path file) throws HgInvalidRevisionException, HgInvalidControlFileException { |
257 // there's no need for HgDataFile to own this method, or get a delegate | |
258 // as most of HgDataFile API is using file revision indexes, and there's easy step from file revision index to | |
259 // both file revision and changeset revision index. But there's no easy way to go from changesetRevisionIndex to | |
260 // file revision (the task this method solves), exept for HgFileInformer | |
261 // I feel methods dealing with changeset indexes shall be more exposed in HgChangelog and HgManifest API. | |
255 return getFileRevisions(file, changelogRevisionIndex).get(changelogRevisionIndex); | 262 return getFileRevisions(file, changelogRevisionIndex).get(changelogRevisionIndex); |
256 } | 263 } |
257 | 264 |
258 // XXX package-local, IntMap, and HgDataFile getFileRevisionAt(int... localChangelogRevisions) | 265 // XXX package-local or better API |
259 @Experimental(reason="@see #getFileRevision") | 266 @Experimental(reason="Map as return value isn't that good") |
260 public Map<Integer, Nodeid> getFileRevisions(final Path file, int... changelogRevisionIndexes) throws HgInvalidRevisionException, HgInvalidControlFileException { | 267 public Map<Integer, Nodeid> getFileRevisions(final Path file, int... changelogRevisionIndexes) throws HgInvalidRevisionException, HgInvalidControlFileException { |
268 // FIXME in fact, walk(Inspectr, path, int[]) might be better alternative than get() | |
261 // TODO need tests | 269 // TODO need tests |
262 int[] manifestRevisionIndexes = toManifestRevisionIndexes(changelogRevisionIndexes, null); | 270 int[] manifestRevisionIndexes = toManifestRevisionIndexes(changelogRevisionIndexes, null); |
263 IntMap<Nodeid> resMap = new IntMap<Nodeid>(changelogRevisionIndexes.length); | 271 IntMap<Nodeid> resMap = new IntMap<Nodeid>(changelogRevisionIndexes.length); |
264 content.iterate(manifestRevisionIndexes, true, new FileLookupInspector(encodingHelper, file, resMap, null)); | 272 content.iterate(manifestRevisionIndexes, true, new FileLookupInspector(encodingHelper, file, resMap, null)); |
265 // IntMap to HashMap, | 273 // IntMap to HashMap, |
267 resMap.fill(rv); | 275 resMap.fill(rv); |
268 return rv; | 276 return rv; |
269 } | 277 } |
270 | 278 |
271 /** | 279 /** |
272 * {@link HgDataFile#getFlags(int)} is public API | 280 * Extract file {@link Flags flags} as they were recorded in appropriate manifest version. |
273 * | 281 * |
282 * @see HgDataFile#getFlags(int) | |
274 * @param changesetRevIndex changeset revision index | 283 * @param changesetRevIndex changeset revision index |
275 * @param file path to look up | 284 * @param file path to look up |
276 * @return one of predefined enum values, or null if file was not known in the specified revision | 285 * @return one of predefined enum values, or <code>null</code> if file was not known in the specified revision |
277 * FIXME EXCEPTIONS | 286 * FIXME EXCEPTIONS |
278 * @throws HgInvalidControlFileException | 287 * @throws HgInvalidControlFileException |
279 * @throws HgInvalidRevisionException | 288 * @throws HgInvalidRevisionException |
280 */ | 289 */ |
281 /*package-local*/ Flags extractFlags(int changesetRevIndex, Path file) throws HgInvalidRevisionException, HgInvalidControlFileException { | 290 public Flags getFileFlags(int changesetRevIndex, Path file) throws HgInvalidRevisionException, HgInvalidControlFileException { |
282 int manifestRevIdx = fromChangelog(changesetRevIndex); | 291 int manifestRevIdx = fromChangelog(changesetRevIndex); |
283 IntMap<Flags> resMap = new IntMap<Flags>(2); | 292 IntMap<Flags> resMap = new IntMap<Flags>(2); |
284 content.iterate(manifestRevIdx, manifestRevIdx, true, new FileLookupInspector(encodingHelper, file, null, resMap)); | 293 content.iterate(manifestRevIdx, manifestRevIdx, true, new FileLookupInspector(encodingHelper, file, null, resMap)); |
285 return resMap.get(changesetRevIndex); | 294 return resMap.get(changesetRevIndex); |
286 } | 295 } |