annotate src/org/tmatesoft/hg/repo/HgDataFile.java @ 316:ee6b467c1a5f

Supply HGFileRevision with copy information when possible, calculate it otherwise
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 28 Sep 2011 13:09:16 +0200
parents 971baa95fb07
children 09628675bcee
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 /*
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
2 * Copyright (c) 2010-2011 TMate Software Ltd
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
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
19 import static org.tmatesoft.hg.repo.HgInternals.wrongLocalRevision;
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.*;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
21
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
22 import java.io.ByteArrayOutputStream;
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
23 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
24 import java.io.FileInputStream;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
25 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
26 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
27 import java.nio.channels.FileChannel;
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
28 import java.util.ArrayList;
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 import java.util.Collection;
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
31 import java.util.Collections;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
32 import java.util.List;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
33 import java.util.NoSuchElementException;
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
34
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
35 import org.tmatesoft.hg.core.HgDataStreamException;
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.core.HgException;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
37 import org.tmatesoft.hg.core.Nodeid;
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
38 import org.tmatesoft.hg.internal.DataAccess;
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
39 import org.tmatesoft.hg.internal.Experimental;
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;
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
42 import org.tmatesoft.hg.internal.IntMap;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
43 import org.tmatesoft.hg.internal.RevlogStream;
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
44 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
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;
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
48 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
49 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
50 import org.tmatesoft.hg.util.ProgressSupport;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
51
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
52
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
53
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 /**
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 * ? name:HgFileNode?
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
56 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
57 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
58 * @author TMate Software Ltd.
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 */
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 public class HgDataFile extends Revlog {
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
62 // absolute from repo root?
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
63 // slashes, unix-style?
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
64 // 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
65 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
66 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
67
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
68 /*package-local*/HgDataFile(HgRepository hgRepo, Path filePath, RevlogStream content) {
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 17
diff changeset
69 super(hgRepo, content);
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
70 path = filePath;
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
71 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
72
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) {
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
74 super(hgRepo);
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
75 path = filePath;
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
76 }
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 // exists is not the best name possible. now it means no file with such name was ever known to the repo.
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
79 // it might be confused with files existed before but lately removed.
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
80 public boolean exists() {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
81 return content != null; // XXX need better impl
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
84 // human-readable (i.e. "COPYING", not "store/data/_c_o_p_y_i_n_g.i")
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
85 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
86 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
87 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88
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
89 /**
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
90 * @return size of the file content at the given revision
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
91 */
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
92 public int length(Nodeid nodeid) throws HgDataStreamException {
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
93 return length(getLocalRevision(nodeid));
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
94
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
95 }
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
96
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 /**
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
98 * @return size of the file content at the revision identified by local revision number.
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
99 */
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
100 public int length(int localRev) throws HgDataStreamException {
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
101 if (metadata == null || !metadata.checked(localRev)) {
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 checkAndRecordMetadata(localRev);
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
103 }
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 final int dataLen = content.dataLength(localRev);
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
105 if (metadata.known(localRev)) {
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
106 return dataLen - metadata.dataOffset(localRev);
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
107 }
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
108 return dataLen;
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
diff changeset
109 }
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
diff changeset
110
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
111 /**
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
112 * 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
113 * any filters is supplied through the sink. If file does not exist in the working dir, this method provides content of a 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
114 * as if it would be refreshed in the working copy, i.e. its corresponding revision
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
115 * (XXX according to dirstate? file tip?) is read from the repository, and filters repo -> working copy get applied.
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
116 *
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
117 * @param sink where to pipe content to
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
118 * @throws HgDataStreamException to indicate troubles reading repository 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
119 * @throws CancelledException if operation was cancelled
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
120 */
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
121 public void workingCopy(ByteChannel sink) throws HgDataStreamException, CancelledException {
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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 ByteBuffer buf = ByteBuffer.allocate(bsize);
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
130 FileChannel fc = null;
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
131 try {
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
132 fc = new FileInputStream(f).getChannel();
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
133 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
134 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
135 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
136 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
137 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
138 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
139 }
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
140 } catch (IOException ex) {
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
141 throw new HgDataStreamException(getPath(), ex);
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
142 } 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
143 progress.done();
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
144 if (fc != null) {
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
145 try {
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
146 fc.close();
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
147 } catch (IOException ex) {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
148 getRepo().getContext().getLog().info(getClass(), ex, 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
149 }
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 }
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
151 }
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
152 } else {
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
153 contentWithFilters(TIP, 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
154 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
156
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
157 // public void content(int revision, ByteChannel sink, boolean applyFilters) throws HgDataStreamException, IOException, CancelledException {
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
158 // byte[] content = content(revision);
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
159 // final CancelSupport cancelSupport = CancelSupport.Factory.get(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
160 // final ProgressSupport progressSupport = ProgressSupport.Factory.get(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
161 // ByteBuffer buf = ByteBuffer.allocate(512);
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
162 // int left = content.length;
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
163 // progressSupport.start(left);
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
164 // int offset = 0;
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
165 // cancelSupport.checkCancelled();
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
166 // ByteChannel _sink = applyFilters ? new FilterByteChannel(sink, getRepo().getFiltersFromRepoToWorkingDir(getPath())) : 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
167 // do {
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
168 // buf.put(content, offset, Math.min(left, buf.remaining()));
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
169 // buf.flip();
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
170 // cancelSupport.checkCancelled();
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
171 // // XXX I may not rely on returned number of bytes but track change in buf position instead.
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
172 // int consumed = _sink.write(buf);
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
173 // buf.compact();
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
174 // offset += consumed;
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
175 // left -= consumed;
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
176 // progressSupport.worked(consumed);
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
177 // } while (left > 0);
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
178 // progressSupport.done(); // XXX shall specify whether #done() is invoked always or only if completed successfully.
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
179 // }
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
180
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
181 /*XXX not sure distinct method contentWithFilters() is the best way to do, perhaps, callers shall add filters themselves?*/
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
182 public void contentWithFilters(int revision, ByteChannel sink) throws HgDataStreamException, CancelledException {
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 if (revision == WORKING_COPY) {
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 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
185 } else {
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
186 content(revision, new FilterByteChannel(sink, getRepo().getFiltersFromRepoToWorkingDir(getPath())));
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 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
188 }
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
diff changeset
189
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
190 // for data files need to check heading of the file content for possible metadata
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
191 // @see http://mercurial.selenic.com/wiki/FileFormats#data.2BAC8-
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
192 public void content(int revision, ByteChannel sink) throws HgDataStreamException, CancelledException {
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
193 if (revision == TIP) {
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 134
diff changeset
194 revision = 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
195 }
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
196 if (revision == 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
197 // 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
198 // 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
199 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
200 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
201 }
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
202 if (wrongLocalRevision(revision) || revision == BAD_REVISION) {
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
203 throw new IllegalArgumentException(String.valueOf(revision));
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 135
diff changeset
204 }
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
205 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
206 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
207 }
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
208 if (metadata == null) {
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
209 metadata = new Metadata();
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
210 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
211 ErrorHandlingInspector insp;
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
212 if (metadata.none(revision)) {
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
213 insp = new ContentPipe(sink, 0);
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
214 } else if (metadata.known(revision)) {
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
215 insp = new ContentPipe(sink, metadata.dataOffset(revision));
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
216 } 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
217 // do not know if there's metadata
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
218 insp = new MetadataInspector(metadata, getPath(), new ContentPipe(sink, 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
219 }
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
220 insp.checkCancelled();
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
221 super.content.iterate(revision, revision, true, insp);
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
222 try {
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
223 insp.checkFailed(); // XXX is there real need to throw IOException from ContentPipe?
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
224 } catch (HgDataStreamException ex) {
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
225 throw ex;
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
226 } catch (IOException ex) {
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
227 throw new HgDataStreamException(getPath(), ex);
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
228 } catch (HgException ex) {
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
229 // shall not happen, unless we changed ContentPipe or its subclass
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 163
diff changeset
230 throw new HgDataStreamException(getPath(), ex.getClass().getName(), ex);
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
231 }
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
232 }
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
233
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
234 @Experimental(reason="Investigate approaches to build complete file history log")
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
235 public interface HistoryWalker {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
236 void next();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
237 boolean hasNext();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
238 Nodeid changesetRevision();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
239 RawChangeset changeset();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
240 boolean isFork();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
241 boolean isJoin();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
242 Pair<Nodeid, Nodeid> parentChangesets();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
243 Collection<Nodeid> childChangesets();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
244 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
245
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
246 public HistoryWalker history() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
247 final boolean[] needsSorting = { false };
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
248 class HistoryNode {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
249 int changeset;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
250 Nodeid cset;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
251 HistoryNode parent1, parent2;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
252 List<HistoryNode> children;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
253
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
254 public HistoryNode(int cs, HistoryNode p1, HistoryNode p2) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
255 changeset = cs;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
256 parent1 = p1;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
257 parent2 = p2;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
258 if (p1 != null) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
259 p1.addChild(this);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
260 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
261 if (p2 != null) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
262 p2.addChild(this);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
263 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
264 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
265
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
266 public Nodeid changesetRevision() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
267 if (cset == null) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
268 cset = getRepo().getChangelog().getRevision(changeset);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
269 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
270 return cset;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
271 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
272
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
273 public void addChild(HistoryNode child) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
274 if (children == null) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
275 children = new ArrayList<HistoryNode>(2);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
276 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
277 children.add(child);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
278 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
279 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
280 final HistoryNode[] completeHistory = new HistoryNode[getRevisionCount()];
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
281 final int[] commitRevisions = new int[completeHistory.length];
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
282 RevlogStream.Inspector insp = new RevlogStream.Inspector() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
283 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
284 if (revisionNumber > 0) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
285 if (commitRevisions[revisionNumber-1] > linkRevision) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
286 needsSorting[0] = true;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
287 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
288 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
289 HistoryNode p1 = null, p2 = null;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
290 if (parent1Revision != -1) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
291 p1 = completeHistory[parent1Revision];
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
292 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
293 if (parent2Revision != -1) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
294 p2 = completeHistory[parent2Revision];
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
295 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
296 completeHistory[revisionNumber] = new HistoryNode(linkRevision, p1, p2);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
297 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
298 };
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
299 content.iterate(0, getLastRevision(), false, insp);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
300 // XXX may read changeset revisions at once (to avoid numerous changelog.getRevision reads)
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
301 // but perhaps just nodeids, not RawChangeset (changelog.iterate(data=false)
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
302 // XXX sort completeHistory according to changeset numbers?
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
303 return new HistoryWalker() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
304 private int index = -1;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
306 public void next() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
307 if (!hasNext()) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
308 throw new NoSuchElementException();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
309 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
310 index++;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
311 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
312
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
313 public boolean hasNext() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
314 return index+1 < completeHistory.length;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
315 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
316
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
317 public Pair<Nodeid, Nodeid> parentChangesets() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
318 HistoryNode p;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
319 Nodeid p1, p2;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
320 if ((p = completeHistory[index].parent1) != null) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
321 p1 = p.changesetRevision();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
322 } else {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
323 p1 = Nodeid.NULL;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
324 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
325 if ((p = completeHistory[index].parent2) != null) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
326 p2 = p.changesetRevision();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
327 } else {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
328 p2 = Nodeid.NULL;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
329 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
330 return new Pair<Nodeid, Nodeid>(p1, p2);
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
331 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
332
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
333 public boolean isJoin() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
334 return completeHistory[index].parent1 != null && completeHistory[index].parent2 != null;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
335 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
336
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
337 public boolean isFork() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
338 HistoryNode n = completeHistory[index];
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
339 return n.children != null && n.children.size() > 1;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
340 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
341
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
342 public Collection<Nodeid> childChangesets() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
343 HistoryNode n = completeHistory[index];
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
344 if (n.children == null) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
345 return Collections.emptyList();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
346 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
347 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(n.children.size());
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
348 for (HistoryNode hn : n.children) {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
349 rv.add(hn.changesetRevision());
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
350 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
351 return rv;
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
352 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
353
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
354 public Nodeid changesetRevision() {
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
355 return completeHistory[index].changesetRevision();
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
356 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
357
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
358 public RawChangeset changeset() {
306
971baa95fb07 Experimental code to build file history, handy access to changeset added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 305
diff changeset
359 final int cs = completeHistory[index].changeset;
971baa95fb07 Experimental code to build file history, handy access to changeset added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 305
diff changeset
360 return getRepo().getChangelog().range(cs, cs).get(0);
305
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
361 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
362 };
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
363 }
ae8d116f4ee2 Experimental code to build file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
364
129
645829962785 core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 121
diff changeset
365 public void history(HgChangelog.Inspector inspector) {
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 134
diff changeset
366 history(0, getLastRevision(), inspector);
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
367 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
368
129
645829962785 core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 121
diff changeset
369 public void history(int start, int end, HgChangelog.Inspector inspector) {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
370 if (!exists()) {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
371 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
372 }
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 134
diff changeset
373 final int last = getLastRevision();
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
374 if (end == TIP) {
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
375 end = last;
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
376 }
300
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
377 if (start == TIP) {
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
378 start = last;
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
379 }
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
380 HgInternals.checkRevlogRange(start, end, last);
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
381
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
382 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
383 final boolean[] needsSorting = { false };
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
384 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
385 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
386 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
387 if (count > 0) {
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
388 if (commitRevisions[count -1] > linkRevision) {
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
389 needsSorting[0] = true;
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
390 }
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
391 }
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
392 commitRevisions[count++] = linkRevision;
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
393 }
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
394 };
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
395 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
396 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
397 if (needsSorting[0]) {
ad6a046943be Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 240
diff changeset
398 // 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
399 // (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
400 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
401 }
245
2fb439375ddc Avoid sorting revision range twice
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 242
diff changeset
402 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
403 }
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
404
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
405 // for a given local revision of the file, find out local revision in the changelog
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
406 public int getChangesetLocalRevision(int revision) {
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
407 return content.linkRevision(revision);
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
408 }
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
409
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
410 public Nodeid getChangesetRevision(Nodeid nid) {
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
411 int changelogRevision = getChangesetLocalRevision(getLocalRevision(nid));
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
412 return getRepo().getChangelog().getRevision(changelogRevision);
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
413 }
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
414
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
415 public boolean isCopy() throws HgDataStreamException {
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
416 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
417 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
418 }
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
419 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
420 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
421 }
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
422 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
423 }
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
424
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
425 public Path getCopySourceName() throws HgDataStreamException {
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
426 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
427 return Path.create(metadata.find(0, "copy"));
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
428 }
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
429 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
430 }
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
431
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
432 public Nodeid getCopySourceRevision() throws HgDataStreamException {
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
433 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
434 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
435 }
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
436 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
437 }
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
438
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
439 @Override
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
440 public String toString() {
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
441 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
442 sb.append('(');
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
443 sb.append(getPath());
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
444 sb.append(')');
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
445 return sb.toString();
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
446 }
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
447
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
448 private void checkAndRecordMetadata(int localRev) throws HgDataStreamException {
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
449 // content() always initializes metadata.
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
450 // FIXME this is expensive way to find out metadata, distinct RevlogStream.Iterator would be better.
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
451 // Alternatively, may parameterize MetadataContentPipe to do prepare only.
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
452 // For reference, when throwing CancelledException, hg status -A --rev 3:80 takes 70 ms
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
453 // however, if we just consume buffer instead (buffer.position(buffer.limit()), same command takes ~320ms
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
454 // (compared to command-line counterpart of 190ms)
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
455 try {
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
456 content(localRev, new ByteChannel() { // No-op channel
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
457 public int write(ByteBuffer buffer) throws IOException, CancelledException {
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
458 throw new CancelledException();
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
459 }
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
460 });
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
461 } catch (CancelledException ex) {
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
462 // it's ok, we did that
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
463 } catch (Exception ex) {
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
464 throw new HgDataStreamException(getPath(), "Can't initialize metadata", ex).setRevisionNumber(localRev);
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
465 }
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
466 }
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
467
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 79
diff changeset
468 private static final class MetadataEntry {
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
469 private final String entry;
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
470 private final int valueStart;
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
471 /*package-local*/MetadataEntry(String key, String value) {
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
472 entry = key + value;
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
473 valueStart = key.length();
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
474 }
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
475 /*package-local*/boolean matchKey(String key) {
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
476 return key.length() == valueStart && entry.startsWith(key);
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
477 }
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
478 // uncomment once/if needed
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
479 // public String key() {
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
480 // return entry.substring(0, valueStart);
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
481 // }
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
482 public String value() {
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
483 return entry.substring(valueStart);
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
484 }
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
485 }
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
486
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
487 private static class Metadata {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
488 private static class Record {
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
489 public final int offset;
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
490 public final MetadataEntry[] entries;
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
491
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
492 public Record(int off, MetadataEntry[] entr) {
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
493 offset = off;
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
494 entries = entr;
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
495 }
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
496 }
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
497 // XXX sparse array needed
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
498 private final IntMap<Record> entries = new IntMap<Record>(5);
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
499
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
500 private final Record NONE = new Record(-1, null); // don't want statics
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
501
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
502 // true when there's metadata for given revision
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
503 boolean known(int revision) {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
504 Record i = entries.get(revision);
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
505 return i != null && NONE != i;
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
506 }
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
507
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
508 // true when revision has been checked for metadata presence.
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
509 public boolean checked(int revision) {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
510 return entries.containsKey(revision);
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
511 }
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
512
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
513 // true when revision has been checked and found not having any metadata
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
514 boolean none(int revision) {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
515 Record i = entries.get(revision);
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
516 return i == NONE;
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
517 }
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
518
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
519 // mark revision as having no metadata.
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
520 void recordNone(int revision) {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
521 Record i = entries.get(revision);
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
522 if (i == NONE) {
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
523 return; // already there
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
524 }
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
525 if (i != null) {
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
526 throw new IllegalStateException(String.format("Trying to override Metadata state for revision %d (known offset: %d)", revision, i));
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
527 }
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
528 entries.put(revision, NONE);
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
529 }
afac8ddc5dd2 Keep record if we tried and found no metadata for a given revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
530
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
531 // since this is internal class, callers are supposed to ensure arg correctness (i.e. ask known() before)
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
532 int dataOffset(int revision) {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
533 return entries.get(revision).offset;
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
534 }
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
535 void add(int revision, int dataOffset, Collection<MetadataEntry> e) {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
536 assert !entries.containsKey(revision);
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
537 entries.put(revision, new Record(dataOffset, e.toArray(new MetadataEntry[e.size()])));
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 }
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
539
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
540 String find(int revision, String key) {
276
6355ecda1f08 Tailored Map implementation with int keys
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
541 for (MetadataEntry me : entries.get(revision).entries) {
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
542 if (me.matchKey(key)) {
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
543 return me.value();
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
544 }
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
545 }
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
546 return 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
547 }
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
548 }
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
549
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
550 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
551 private final Metadata metadata;
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 163
diff changeset
552 private final Path fname; // need this only for error reporting
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
553 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
554
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
555 public MetadataInspector(Metadata _metadata, Path file, 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
556 metadata = _metadata;
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 163
diff changeset
557 fname = file;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
558 delegate = chain;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
559 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
560 }
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
561
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
562 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
563 try {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
564 final int daLength = data.length();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
565 if (daLength < 4 || data.readByte() != 1 || data.readByte() != 10) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
566 metadata.recordNone(revisionNumber);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
567 data.reset();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
568 } else {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
569 ArrayList<MetadataEntry> _metadata = new ArrayList<MetadataEntry>();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
570 int offset = parseMetadata(data, daLength, _metadata);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
571 metadata.add(revisionNumber, offset, _metadata);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
572 // 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
573 // 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
574 // and we need to ensure predictable result.
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
575 data.reset();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
576 data = new FilterDataAccess(data, offset, daLength - offset);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
577 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
578 if (delegate != null) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
579 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
580 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
581 } catch (IOException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
582 recordFailure(ex);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
583 } catch (HgDataStreamException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
584 recordFailure(ex.setRevisionNumber(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
585 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
586 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
587
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
588 private int parseMetadata(DataAccess data, final int daLength, ArrayList<MetadataEntry> _metadata) throws IOException, HgDataStreamException {
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
589 int lastEntryStart = 2;
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
590 int lastColon = -1;
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
591 // XXX in fact, need smth like ByteArrayBuilder, similar to StringBuilder,
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
592 // which can't be used here because we can't convert bytes to chars as we read them
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
593 // (there might be multi-byte encoding), and we need to collect all bytes before converting to string
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
594 ByteArrayOutputStream bos = new ByteArrayOutputStream();
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
595 String key = null, value = 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
596 boolean byteOne = false;
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
597 for (int i = 2; i < daLength; i++) {
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
598 byte b = data.readByte();
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
599 if (b == '\n') {
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
600 if (byteOne) { // i.e. \n follows 1
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
601 lastEntryStart = i+1;
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
602 // XXX is it possible to have here incomplete key/value (i.e. if last pair didn't end with \n)
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
603 break;
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
604 }
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
605 if (key == null || lastColon == -1 || i <= lastColon) {
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
606 throw new IllegalStateException(); // FIXME log instead and record null key in the metadata. Ex just to fail fast during dev
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
607 }
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
608 value = new String(bos.toByteArray()).trim();
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
609 bos.reset();
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
610 _metadata.add(new MetadataEntry(key, value));
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
611 key = value = 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
612 lastColon = -1;
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
613 lastEntryStart = i+1;
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
614 continue;
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
615 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
616 // byteOne has to be consumed up to this line, if not yet, consume it
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
617 if (byteOne) {
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
618 // insert 1 we've read on previous step into the byte builder
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
619 bos.write(1);
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
620 byteOne = false;
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
621 // fall-through to consume current byte
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
622 }
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
623 if (b == (int) ':') {
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
624 assert value == 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
625 key = new String(bos.toByteArray());
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
626 bos.reset();
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
627 lastColon = i;
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
628 } else if (b == 1) {
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
629 byteOne = true;
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
630 } 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
631 bos.write(b);
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
632 }
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
633 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
634 if (data.isEmpty() || !byteOne) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
635 throw new HgDataStreamException(fname, "Metadata is not closed properly", null);
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
636 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 276
diff changeset
637 return lastEntryStart;
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
638 }
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
639 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
640 }