annotate src/org/tmatesoft/hg/repo/HgDataFile.java @ 619:868b2ffdcd5c

Close FIS, not FileChannel, to clear both references to FileDescriptor right away
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 17 May 2013 22:04:23 +0200
parents e1b29756f901
children 99ad1e3a4e4d
rev   line source
17
571e1b2cc3f7 Query file for its parents. Demo of recently added ignore and digest support from within cat cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 5
diff changeset
1 /*
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
2 * Copyright (c) 2010-2013 TMate Software Ltd
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
4 * This program is free software; you can redistribute it and/or modify
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
5 * it under the terms of the GNU General Public License as published by
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
6 * the Free Software Foundation; version 2 of the License.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
8 * This program is distributed in the hope that it will be useful,
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
13 * For information on how to redistribute this software under
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 88
diff changeset
15 * contact TMate Software at support@hg4j.com
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
17 package org.tmatesoft.hg.repo;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
19 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew;
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
20 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
21 import static org.tmatesoft.hg.repo.HgRepository.*;
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Info;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
23
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
24 import java.io.File;
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
25 import java.io.FileInputStream;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
26 import java.io.IOException;
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
27 import java.nio.ByteBuffer;
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
28 import java.nio.channels.FileChannel;
240
29231022fec8 Do not expect file history to be ordered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
29 import java.util.Arrays;
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
30
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
31 import org.tmatesoft.hg.core.HgCallbackTargetException;
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
32 import org.tmatesoft.hg.core.HgChangesetFileSneaker;
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
33 import org.tmatesoft.hg.core.HgIterateDirection;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
34 import org.tmatesoft.hg.core.Nodeid;
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
35 import org.tmatesoft.hg.internal.BlameHelper;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
36 import org.tmatesoft.hg.internal.DataAccess;
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
37 import org.tmatesoft.hg.internal.FileHistory;
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
38 import org.tmatesoft.hg.internal.FileRevisionHistoryChunk;
619
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
39 import org.tmatesoft.hg.internal.FileUtils;
121
b1d6208fb517 Conditionally apply filters to file content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
40 import org.tmatesoft.hg.internal.FilterByteChannel;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
41 import org.tmatesoft.hg.internal.FilterDataAccess;
420
6c22bdc0bdfd Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 417
diff changeset
42 import org.tmatesoft.hg.internal.Internals;
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
43 import org.tmatesoft.hg.internal.Metadata;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
44 import org.tmatesoft.hg.internal.RevlogStream;
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
45 import org.tmatesoft.hg.util.ByteChannel;
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
46 import org.tmatesoft.hg.util.CancelSupport;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
47 import org.tmatesoft.hg.util.CancelledException;
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
48 import org.tmatesoft.hg.util.LogFacility;
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
49 import org.tmatesoft.hg.util.Pair;
133
4a948ec83980 core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
50 import org.tmatesoft.hg.util.Path;
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
51 import org.tmatesoft.hg.util.ProgressSupport;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
52
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
53
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 /**
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
55 * Regular user data file stored in the repository.
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
56 *
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
57 * <p> Note, most methods accept index in the file's revision history, not that of changelog. Easy way to obtain
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
58 * changeset revision index from file's is to use {@link #getChangesetRevisionIndex(int)}. To obtain file's revision
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
59 * index for a given changeset, {@link HgManifest#getFileRevision(int, Path)} or {@link HgChangesetFileSneaker} may
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
60 * come handy.
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
61 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
62 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
63 * @author TMate Software Ltd.
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 */
426
063b0663495a HgManifest#getFileRevisions refactored into #walkFileRevisions to match pattern throught rest of the library
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
65 public final class HgDataFile extends Revlog {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
67 // absolute from repo root?
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
68 // slashes, unix-style?
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
69 // repo location agnostic, just to give info to user, not to access real storage
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
70 private final Path path;
134
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
71 private Metadata metadata; // get initialized on first access to file content.
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
73 /*package-local*/HgDataFile(HgRepository hgRepo, Path filePath, RevlogStream content) {
600
46f29b73e51e Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 571
diff changeset
74 super(hgRepo, content, false);
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
75 path = filePath;
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
76 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
77
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
78 /*package-local*/HgDataFile(HgRepository hgRepo, Path filePath) {
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
79 super(hgRepo);
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
80 path = filePath;
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
81 }
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
82
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
83 // exists is not the best name possible. now it means no file with such name was ever known to the repo.
426
063b0663495a HgManifest#getFileRevisions refactored into #walkFileRevisions to match pattern throught rest of the library
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
84 // it might be confused with files existed before but lately removed. TODO HgFileNode.exists makes more sense.
063b0663495a HgManifest#getFileRevisions refactored into #walkFileRevisions to match pattern throught rest of the library
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
85 // or HgDataFile.known()
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
86 public boolean exists() {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
87 return content != null; // XXX need better impl
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
426
063b0663495a HgManifest#getFileRevisions refactored into #walkFileRevisions to match pattern throught rest of the library
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
90 /**
063b0663495a HgManifest#getFileRevisions refactored into #walkFileRevisions to match pattern throught rest of the library
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
91 * Human-readable file name, i.e. "COPYING", not "store/data/_c_o_p_y_i_n_g.i"
063b0663495a HgManifest#getFileRevisions refactored into #walkFileRevisions to match pattern throught rest of the library
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
92 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
93 public Path getPath() {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
94 return path; // hgRepo.backresolve(this) -> name? In this case, what about hashed long names?
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
97 /**
416
d30083c80d52 Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
98 * Handy shorthand for {@link #getLength(int) length(getRevisionIndex(nodeid))}
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
99 *
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
100 * @param nodeid revision of the file
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
101 *
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
102 * @return size of the file content at the given revision
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
103 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
104 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
105 public int getLength(Nodeid nodeid) throws HgRuntimeException {
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
106 try {
416
d30083c80d52 Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
107 return getLength(getRevisionIndex(nodeid));
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
108 } catch (HgInvalidControlFileException ex) {
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
109 throw ex.isRevisionSet() ? ex : ex.setRevision(nodeid);
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
110 } catch (HgInvalidRevisionException ex) {
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
111 throw ex.isRevisionSet() ? ex : ex.setRevision(nodeid);
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
112 }
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
113 }
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
114
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
115 /**
368
8107b95f4280 Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
116 * @param fileRevisionIndex - revision local index, non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense.
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
117 * @return size of the file content at the revision identified by local revision number.
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
118 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
119 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
120 public int getLength(int fileRevisionIndex) throws HgRuntimeException {
401
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
121 if (wrongRevisionIndex(fileRevisionIndex) || fileRevisionIndex == BAD_REVISION) {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
122 throw new HgInvalidRevisionException(fileRevisionIndex);
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
123 }
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
124 if (fileRevisionIndex == TIP) {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
125 fileRevisionIndex = getLastRevision();
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
126 } else if (fileRevisionIndex == WORKING_COPY) {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
127 File f = getRepo().getFile(this);
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
128 if (f.exists()) {
420
6c22bdc0bdfd Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 417
diff changeset
129 // single revision can't be greater than 2^32, shall be safe to cast to int
6c22bdc0bdfd Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 417
diff changeset
130 return Internals.ltoi(f.length());
401
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
131 }
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
132 Nodeid fileRev = getWorkingCopyRevision();
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
133 if (fileRev == null) {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
134 throw new HgInvalidRevisionException(String.format("File %s is not part of working copy", getPath()), null, fileRevisionIndex);
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
135 }
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
136 fileRevisionIndex = getRevisionIndex(fileRev);
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
137 }
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
138 if (metadata == null || !metadata.checked(fileRevisionIndex)) {
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
139 checkAndRecordMetadata(fileRevisionIndex);
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
140 }
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
141 final int dataLen = content.dataLength(fileRevisionIndex);
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
142 if (metadata.known(fileRevisionIndex)) {
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
143 return dataLen - metadata.dataOffset(fileRevisionIndex);
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
144 }
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
145 return dataLen;
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
diff changeset
146 }
416
d30083c80d52 Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
147
d30083c80d52 Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
148 /**
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
149 * Reads content of the file from working directory. If file present in the working directory, its actual content without
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
150 * any filters is supplied through the sink. If file does not exist in the working dir, this method provides content of a file
401
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
151 * as if it would be refreshed in the working copy, i.e. its corresponding revision (according to dirstate) is read from the
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
152 * repository, and filters repo -> working copy get applied.
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
153 *
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
154 * NOTE, if file is missing from the working directory and is not part of the dirstate (but otherwise legal repository file,
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
155 * e.g. from another branch), no content would be supplied.
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
156 *
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
157 * @param sink content consumer
380
9517df1ef7ec Comments/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
158 * @throws CancelledException if execution of the operation was cancelled
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
159 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
160 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
161 public void workingCopy(ByteChannel sink) throws CancelledException, HgRuntimeException {
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
162 File f = getRepo().getFile(this);
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
163 if (f.exists()) {
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
164 final CancelSupport cs = CancelSupport.Factory.get(sink);
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
165 final ProgressSupport progress = ProgressSupport.Factory.get(sink);
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
166 final long flength = f.length();
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
167 final int bsize = (int) Math.min(flength, 32*1024);
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
168 progress.start((int) (flength > Integer.MAX_VALUE ? flength >>> 15 /*32 kb buf size*/ : flength));
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
169 ByteBuffer buf = ByteBuffer.allocate(bsize);
619
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
170 FileInputStream fis = null;
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
171 try {
619
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
172 fis = new FileInputStream(f);
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
173 FileChannel fc = fis.getChannel();
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
174 while (fc.read(buf) != -1) {
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
175 cs.checkCancelled();
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
176 buf.flip();
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
177 int consumed = sink.write(buf);
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
178 progress.worked(flength > Integer.MAX_VALUE ? 1 : consumed);
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
179 buf.compact();
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
180 }
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
181 } catch (IOException ex) {
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
182 throw new HgInvalidFileException("Working copy read failed", ex, f);
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
183 } finally {
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
184 progress.done();
619
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
185 if (fis != null) {
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
186 new FileUtils(getRepo().getSessionContext().getLog()).closeQuietly(fis);
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
187 }
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
188 }
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
189 } else {
401
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
190 Nodeid fileRev = getWorkingCopyRevision();
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
191 if (fileRev == null) {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
192 // no content for this data file in the working copy - it is not part of the actual working state.
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
193 // XXX perhaps, shall report this to caller somehow, not silently pass no data?
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
194 return;
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
195 }
401
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
196 final int fileRevIndex = getRevisionIndex(fileRev);
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
197 contentWithFilters(fileRevIndex, sink);
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
198 }
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
199 }
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
200
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
201 /**
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
202 * @return file revision as recorded in repository manifest for dirstate parent, or <code>null</code> if no file revision can be found
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
203 */
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
204 private Nodeid getWorkingCopyRevision() throws HgInvalidControlFileException {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
205 final Pair<Nodeid, Nodeid> wcParents = getRepo().getWorkingCopyParents();
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
206 Nodeid p = wcParents.first().isNull() ? wcParents.second() : wcParents.first();
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
207 final HgChangelog clog = getRepo().getChangelog();
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
208 final int csetRevIndex;
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
209 if (p.isNull()) {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
210 // no dirstate parents
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
211 getRepo().getSessionContext().getLog().dump(getClass(), Info, "No dirstate parents, resort to TIP", getPath());
401
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
212 // if it's a repository with no dirstate, use TIP then
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
213 csetRevIndex = clog.getLastRevision();
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
214 if (csetRevIndex == -1) {
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
215 // shall not happen provided there's .i for this data file (hence at least one cset)
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
216 // and perhaps exception is better here. However, null as "can't find" indication seems reasonable.
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
217 return null;
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
218 }
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
219 } else {
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
220 // common case to avoid searching complete changelog for nodeid match
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
221 final Nodeid tipRev = clog.getRevision(TIP);
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
222 if (tipRev.equals(p)) {
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
223 csetRevIndex = clog.getLastRevision();
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
224 } else {
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
225 // bad luck, need to search honestly
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
226 csetRevIndex = getRepo().getChangelog().getRevisionIndex(p);
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
227 }
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
228 }
401
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
229 Nodeid fileRev = getRepo().getManifest().getFileRevision(csetRevIndex, getPath());
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
230 // it's possible for a file to be in working dir and have store/.i but to belong e.g. to a different
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
231 // branch than the one from dirstate. Thus it's possible to get null fileRev
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
232 // which would serve as an indication this data file is not part of working copy
a57a21aa4190 Support WORKING_COPY constant for dataFile.length() operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
233 return fileRev;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
235
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
236 /**
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
237 * Access content of a file revision
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
238 * XXX not sure distinct method contentWithFilters() is the best way to do, perhaps, callers shall add filters themselves?
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
239 *
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
240 * @param fileRevisionIndex - revision local index, non-negative. From predefined constants, {@link HgRepository#TIP} and {@link HgRepository#WORKING_COPY} make sense.
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
241 * @param sink content consumer
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
242 *
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
243 * @throws CancelledException if execution of the operation was cancelled
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
244 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
245 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
246 public void contentWithFilters(int fileRevisionIndex, ByteChannel sink) throws CancelledException, HgRuntimeException {
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
247 if (fileRevisionIndex == WORKING_COPY) {
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
248 workingCopy(sink); // pass un-mangled sink
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
249 } else {
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
250 content(fileRevisionIndex, new FilterByteChannel(sink, getRepo().getFiltersFromRepoToWorkingDir(getPath())));
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
251 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
252 }
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
diff changeset
253
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
254 /**
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
255 * Retrieve content of specific revision. Content is provided as is, without any filters (e.g. keywords, eol, etc.) applied.
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
256 * For filtered content, use {@link #contentWithFilters(int, ByteChannel)}.
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
257 *
368
8107b95f4280 Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
258 * @param fileRevisionIndex - revision local index, non-negative. From predefined constants, {@link HgRepository#TIP} and {@link HgRepository#WORKING_COPY} make sense.
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
259 * @param sink content consumer
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
260 *
380
9517df1ef7ec Comments/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
261 * @throws CancelledException if execution of the operation was cancelled
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
262 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
263 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
264 public void content(int fileRevisionIndex, ByteChannel sink) throws CancelledException, HgRuntimeException {
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
265 // for data files need to check heading of the file content for possible metadata
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
266 // @see http://mercurial.selenic.com/wiki/FileFormats#data.2BAC8-
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
267 if (fileRevisionIndex == TIP) {
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
268 fileRevisionIndex = getLastRevision();
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
269 }
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
270 if (fileRevisionIndex == WORKING_COPY) {
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
271 // sink is supposed to come into workingCopy without filters
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
272 // thus we shall not get here (into #content) from #contentWithFilters(WC)
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
273 workingCopy(sink);
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
274 return;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
275 }
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
276 if (wrongRevisionIndex(fileRevisionIndex) || fileRevisionIndex == BAD_REVISION) {
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
277 throw new HgInvalidRevisionException(fileRevisionIndex);
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
278 }
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
279 if (sink == null) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
280 throw new IllegalArgumentException();
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
281 }
134
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
282 if (metadata == null) {
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
283 metadata = new Metadata(getRepo());
134
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
284 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
285 ErrorHandlingInspector insp;
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
286 final LogFacility lf = getRepo().getSessionContext().getLog();
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
287 if (metadata.none(fileRevisionIndex)) {
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
288 insp = new ContentPipe(sink, 0, lf);
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
289 } else if (metadata.known(fileRevisionIndex)) {
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
290 insp = new ContentPipe(sink, metadata.dataOffset(fileRevisionIndex), lf);
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
291 } else {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
292 // do not know if there's metadata
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
293 insp = new MetadataInspector(metadata, new ContentPipe(sink, 0, lf));
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
294 }
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
295 insp.checkCancelled();
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
296 super.content.iterate(fileRevisionIndex, fileRevisionIndex, true, insp);
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
297 try {
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
298 insp.checkFailed();
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
299 } catch (HgInvalidControlFileException ex) {
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
300 ex = ex.setFileName(getPath());
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
301 throw ex.isRevisionIndexSet() ? ex : ex.setRevisionIndex(fileRevisionIndex);
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 233
diff changeset
302 } catch (IOException ex) {
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
303 HgInvalidControlFileException e = new HgInvalidControlFileException("Revision content access failed", ex, null);
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
304 throw content.initWithIndexFile(e).setFileName(getPath()).setRevisionIndex(fileRevisionIndex);
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
305 }
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
306 }
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
307
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
308 /**
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
309 * Walk complete change history of the file.
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
310 * @param inspector callback to visit changesets
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
311 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
312 */
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
313 public void history(HgChangelog.Inspector inspector) throws HgRuntimeException {
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 134
diff changeset
314 history(0, getLastRevision(), inspector);
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
315 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
316
417
ccd7d25e5aea New and better name for HgFileInformer - HgChangesetFileSneaker. Explain (comments) ties between HgManifest, HgDataFile, HgChangesetFileSneaker and reasons for method placement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 416
diff changeset
317 /**
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
318 * Walk subset of the file's change history.
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
319 * @param start revision local index, inclusive; non-negative or {@link HgRepository#TIP}
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
320 * @param end revision local index, inclusive; non-negative or {@link HgRepository#TIP}
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
321 * @param inspector callback to visit changesets
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
322 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
417
ccd7d25e5aea New and better name for HgFileInformer - HgChangesetFileSneaker. Explain (comments) ties between HgManifest, HgDataFile, HgChangesetFileSneaker and reasons for method placement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 416
diff changeset
323 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
324 public void history(int start, int end, HgChangelog.Inspector inspector) throws HgRuntimeException {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
325 if (!exists()) {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
326 throw new IllegalStateException("Can't get history of invalid repository file node");
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
327 }
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 134
diff changeset
328 final int last = getLastRevision();
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
329 if (end == TIP) {
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
330 end = last;
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
331 }
300
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
332 if (start == TIP) {
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
333 start = last;
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
334 }
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
335 HgInternals.checkRevlogRange(start, end, last);
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
336
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
337 final int[] commitRevisions = new int[end - start + 1];
242
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
338 final boolean[] needsSorting = { false };
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
339 RevlogStream.Inspector insp = new RevlogStream.Inspector() {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
340 int count = 0;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
341 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {
242
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
342 if (count > 0) {
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
343 if (commitRevisions[count -1] > linkRevision) {
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
344 needsSorting[0] = true;
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
345 }
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
346 }
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
347 commitRevisions[count++] = linkRevision;
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
348 }
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
349 };
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
350 content.iterate(start, end, false, insp);
233
1d389c0cb0a5 Optimize file history walk not to iterat over whole changelog for sparse and distant revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
351 final HgChangelog changelog = getRepo().getChangelog();
242
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
352 if (needsSorting[0]) {
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
353 // automatic tools (svnmerge?) produce unnatural file history
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
354 // (e.g. cpython/Lib/doctest.py, revision 164 points to cset 63509, 165 - to 38453)
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
355 Arrays.sort(commitRevisions);
233
1d389c0cb0a5 Optimize file history walk not to iterat over whole changelog for sparse and distant revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
356 }
245
2fb439375ddc Avoid sorting revision range twice
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 242
diff changeset
357 changelog.rangeInternal(inspector, commitRevisions);
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
358 }
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
359
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
360 /**
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
361 * For a given revision of the file (identified with revision index), find out index of the corresponding changeset.
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
362 *
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
363 * @return changeset revision index
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
364 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
365 */
437
32184ddcf46d Better argument names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 426
diff changeset
366 public int getChangesetRevisionIndex(int fileRevisionIndex) throws HgRuntimeException {
32184ddcf46d Better argument names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 426
diff changeset
367 return content.linkRevision(fileRevisionIndex);
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
368 }
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
369
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
370 /**
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
371 * Complements {@link #getChangesetRevisionIndex(int)} to get changeset revision that corresponds to supplied file revision
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
372 *
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
373 * @param nid revision of the file
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
374 * @return changeset revision
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
375 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
376 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
377 public Nodeid getChangesetRevision(Nodeid nid) throws HgRuntimeException {
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
378 int changelogRevision = getChangesetRevisionIndex(getRevisionIndex(nid));
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
379 return getRepo().getChangelog().getRevision(changelogRevision);
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
380 }
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
381
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
382 /**
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
383 * Tells whether this file originates from another repository file
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
384 * @return <code>true</code> if this file is a copy of another from the repository
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
385 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
386 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
387 public boolean isCopy() throws HgRuntimeException {
134
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
388 if (metadata == null || !metadata.checked(0)) {
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
389 checkAndRecordMetadata(0);
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
390 }
134
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
391 if (!metadata.known(0)) {
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
392 return false;
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
393 }
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
394 return metadata.find(0, "copy") != null;
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
395 }
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
396
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
397 /**
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
398 * Get name of the file this one was copied from.
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
399 *
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
400 * @return name of the file origin
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
401 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
402 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
403 public Path getCopySourceName() throws HgRuntimeException {
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
404 if (isCopy()) {
571
e4ee4bf4c7d0 Let session context control creation of Path instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 495
diff changeset
405 Path.Source ps = getRepo().getSessionContext().getPathFactory();
e4ee4bf4c7d0 Let session context control creation of Path instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 495
diff changeset
406 return ps.path(metadata.find(0, "copy"));
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
407 }
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
408 throw new UnsupportedOperationException(); // XXX REVISIT, think over if Exception is good (clients would check isCopy() anyway, perhaps null is sufficient?)
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
409 }
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
410
415
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
411 /**
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
412 *
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
413 * @return revision this file was copied from
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
414 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
415
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
415 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
416 public Nodeid getCopySourceRevision() throws HgRuntimeException {
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
417 if (isCopy()) {
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
418 return Nodeid.fromAscii(metadata.find(0, "copyrev")); // XXX reuse/cache Nodeid
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
419 }
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
420 throw new UnsupportedOperationException();
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
421 }
417
ccd7d25e5aea New and better name for HgFileInformer - HgChangesetFileSneaker. Explain (comments) ties between HgManifest, HgDataFile, HgChangesetFileSneaker and reasons for method placement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 416
diff changeset
422
415
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
423 /**
417
ccd7d25e5aea New and better name for HgFileInformer - HgChangesetFileSneaker. Explain (comments) ties between HgManifest, HgDataFile, HgChangesetFileSneaker and reasons for method placement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 416
diff changeset
424 * Get file flags recorded in the manifest
416
d30083c80d52 Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
425 * @param fileRevisionIndex - revision local index, non-negative, or {@link HgRepository#TIP}.
417
ccd7d25e5aea New and better name for HgFileInformer - HgChangesetFileSneaker. Explain (comments) ties between HgManifest, HgDataFile, HgChangesetFileSneaker and reasons for method placement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 416
diff changeset
426 * @see HgManifest#getFileFlags(int, Path)
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
427 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
415
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
428 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
429 public HgManifest.Flags getFlags(int fileRevisionIndex) throws HgRuntimeException {
415
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
430 int changesetRevIndex = getChangesetRevisionIndex(fileRevisionIndex);
417
ccd7d25e5aea New and better name for HgFileInformer - HgChangesetFileSneaker. Explain (comments) ties between HgManifest, HgDataFile, HgChangesetFileSneaker and reasons for method placement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 416
diff changeset
431 return getRepo().getManifest().getFileFlags(changesetRevIndex, getPath());
415
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 401
diff changeset
432 }
416
d30083c80d52 Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
433
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
434 /**
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
435 * mimic 'hg diff -r clogRevIndex1 -r clogRevIndex2'
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
436 */
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
437 public void diff(int clogRevIndex1, int clogRevIndex2, HgBlameInspector insp) throws HgCallbackTargetException {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
438 // FIXME clogRevIndex1 and clogRevIndex2 may point to different files, need to decide whether to throw an exception
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
439 // or to attempt to look up correct file node (tricky)
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
440 int fileRevIndex1 = fileRevIndex(this, clogRevIndex1);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
441 int fileRevIndex2 = fileRevIndex(this, clogRevIndex2);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
442 BlameHelper bh = new BlameHelper(insp, 5);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
443 bh.useFileUpTo(this, clogRevIndex2);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
444 bh.diff(fileRevIndex1, clogRevIndex1, fileRevIndex2, clogRevIndex2);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
445 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
446
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
447 /**
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
448 * Walk file history up/down to revision at given changeset and report changes for each revision
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
449 */
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
450 public void annotate(int changelogRevisionIndex, HgBlameInspector insp, HgIterateDirection iterateOrder) throws HgCallbackTargetException {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
451 annotate(0, changelogRevisionIndex, insp, iterateOrder);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
452 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
453
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
454 /**
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
455 * Walk file history range and report changes for each revision
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
456 */
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
457 public void annotate(int changelogRevIndexStart, int changelogRevIndexEnd, HgBlameInspector insp, HgIterateDirection iterateOrder) throws HgCallbackTargetException {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
458 if (wrongRevisionIndex(changelogRevIndexStart) || wrongRevisionIndex(changelogRevIndexEnd)) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
459 throw new IllegalArgumentException();
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
460 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
461 // Note, changelogRevIndexEnd may be TIP, while the code below doesn't tolerate constants
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
462 //
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
463 int lastRevision = getRepo().getChangelog().getLastRevision();
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
464 if (changelogRevIndexEnd == TIP) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
465 changelogRevIndexEnd = lastRevision;
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
466 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
467 HgInternals.checkRevlogRange(changelogRevIndexStart, changelogRevIndexEnd, lastRevision);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
468 if (!exists()) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
469 return;
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
470 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
471 FileHistory fileHistory = new FileHistory(this, changelogRevIndexStart, changelogRevIndexEnd);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
472 fileHistory.build();
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
473 BlameHelper bh = new BlameHelper(insp, 10);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
474 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(OldToNew)) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
475 // iteration order is not important here
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
476 bh.useFileUpTo(fhc.getFile(), fhc.getEndChangeset());
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
477 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
478 int[] fileClogParentRevs = new int[2];
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
479 int[] fileParentRevs = new int[2];
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
480 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(iterateOrder)) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
481 for (int fri : fhc.fileRevisions(iterateOrder)) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
482 int clogRevIndex = fhc.changeset(fri);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
483 // the way we built fileHistory ensures we won't walk past [changelogRevIndexStart..changelogRevIndexEnd]
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
484 assert clogRevIndex >= changelogRevIndexStart;
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
485 assert clogRevIndex <= changelogRevIndexEnd;
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
486 fhc.fillFileParents(fri, fileParentRevs);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
487 fhc.fillCsetParents(fri, fileClogParentRevs);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
488 bh.annotateChange(fri, clogRevIndex, fileParentRevs, fileClogParentRevs);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
489 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
490 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
491 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
492
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
493 /**
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
494 * Annotates changes of the file against its parent(s).
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
495 * Unlike {@link #annotate(HgDataFile, int, Inspector, HgIterateDirection)}, doesn't
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
496 * walk file history, looks at the specified revision only. Handles both parents (if merge revision).
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
497 */
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
498 public void annotateSingleRevision(int changelogRevisionIndex, HgBlameInspector insp) throws HgCallbackTargetException {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
499 // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
500 int fileRevIndex = fileRevIndex(this, changelogRevisionIndex);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
501 int[] fileRevParents = new int[2];
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
502 parents(fileRevIndex, fileRevParents, null, null);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
503 if (changelogRevisionIndex == TIP) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
504 changelogRevisionIndex = getChangesetRevisionIndex(fileRevIndex);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
505 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
506 BlameHelper bh = new BlameHelper(insp, 5);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
507 bh.useFileUpTo(this, changelogRevisionIndex);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
508 int[] fileClogParentRevs = new int[2];
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
509 fileClogParentRevs[0] = fileRevParents[0] == NO_REVISION ? NO_REVISION : getChangesetRevisionIndex(fileRevParents[0]);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
510 fileClogParentRevs[1] = fileRevParents[1] == NO_REVISION ? NO_REVISION : getChangesetRevisionIndex(fileRevParents[1]);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
511 bh.annotateChange(fileRevIndex, changelogRevisionIndex, fileRevParents, fileClogParentRevs);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
512 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
513
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
514 @Override
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
515 public String toString() {
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
516 StringBuilder sb = new StringBuilder(getClass().getSimpleName());
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
517 sb.append('(');
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
518 sb.append(getPath());
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
519 sb.append(')');
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
520 return sb.toString();
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
521 }
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
522
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
523 private void checkAndRecordMetadata(int localRev) throws HgInvalidControlFileException {
495
abfbe81154b5 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
524 if (metadata == null) {
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
525 metadata = new Metadata(getRepo());
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
526 }
495
abfbe81154b5 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
527 // use MetadataInspector without delegate to process metadata only
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
528 RevlogStream.Inspector insp = new MetadataInspector(metadata, null);
495
abfbe81154b5 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
529 super.content.iterate(localRev, localRev, true, insp);
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 245
diff changeset
530 }
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
531
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
532
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
533 private static int fileRevIndex(HgDataFile df, int csetRevIndex) {
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
534 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(csetRevIndex, df.getPath());
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
535 return df.getRevisionIndex(fileRev);
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
536 }
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
537
78
c25c5c348d1b Skip metadata in the beginning of a file content. Parse metadata, recognize copies/renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
538
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
539 private static class MetadataInspector extends ErrorHandlingInspector implements RevlogStream.Inspector {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
540 private final Metadata metadata;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
541 private final RevlogStream.Inspector delegate;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
542
495
abfbe81154b5 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
543 /**
abfbe81154b5 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
544 * @param _metadata never <code>null</code>
abfbe81154b5 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
545 * @param chain <code>null</code> if no further data processing other than metadata is desired
abfbe81154b5 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
546 */
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
547 public MetadataInspector(Metadata _metadata, RevlogStream.Inspector chain) {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
548 metadata = _metadata;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
549 delegate = chain;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
550 setCancelSupport(CancelSupport.Factory.get(chain));
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
551 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
552
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 420
diff changeset
553 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
554 try {
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
555 if (metadata.tryRead(revisionNumber, data)) {
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
556 // da is in prepared state (i.e. we consumed all bytes up to metadata end).
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
557 // However, it's not safe to assume delegate won't call da.reset() for some reason,
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
558 // and we need to ensure predictable result.
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
559 data.reset();
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
560 int offset = metadata.dataOffset(revisionNumber);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
561 data = new FilterDataAccess(data, offset, data.length() - offset);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
562 } else {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 600
diff changeset
563 data.reset();
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
564 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
565 if (delegate != null) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
566 delegate.next(revisionNumber, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, nodeid, data);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
567 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
568 } catch (IOException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
569 recordFailure(ex);
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
570 } catch (HgInvalidControlFileException ex) {
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
571 recordFailure(ex.isRevisionIndexSet() ? ex : ex.setRevisionIndex(revisionNumber));
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 148
diff changeset
572 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
573 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
574
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
575 @Override
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
576 public void checkFailed() throws HgRuntimeException, IOException, CancelledException {
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
577 super.checkFailed();
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
578 if (delegate instanceof ErrorHandlingInspector) {
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
579 // TODO need to add ErrorDestination (ErrorTarget/Acceptor?) and pass it around (much like CancelSupport get passed)
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
580 // so that delegate would be able report its failures directly to caller without this hack
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
581 ((ErrorHandlingInspector) delegate).checkFailed();
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
582 }
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
583 }
17
571e1b2cc3f7 Query file for its parents. Demo of recently added ignore and digest support from within cat cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 5
diff changeset
584 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
585 }