annotate src/org/tmatesoft/hg/repo/Revlog.java @ 320:678e326fd27c

Issue 15: Exception accessing oddly named file from history
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 30 Sep 2011 06:22:11 +0200
parents 09628675bcee
children 283b294d1079
rev   line source
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
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
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.TIP;
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
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 135
diff changeset
22 import java.io.IOException;
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 135
diff changeset
23 import java.nio.ByteBuffer;
317
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
24 import java.util.ArrayList;
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
25 import java.util.Arrays;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
26 import java.util.Collection;
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
27 import java.util.HashSet;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
28 import java.util.LinkedList;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
29 import java.util.List;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
30
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 135
diff changeset
31 import org.tmatesoft.hg.core.HgBadStateException;
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 135
diff changeset
32 import org.tmatesoft.hg.core.HgException;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
33 import org.tmatesoft.hg.core.Nodeid;
307
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
34 import org.tmatesoft.hg.internal.ArrayHelper;
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 135
diff changeset
35 import org.tmatesoft.hg.internal.DataAccess;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
36 import org.tmatesoft.hg.internal.RevlogStream;
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 135
diff changeset
37 import org.tmatesoft.hg.util.ByteChannel;
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 135
diff changeset
38 import org.tmatesoft.hg.util.CancelSupport;
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 135
diff changeset
39 import org.tmatesoft.hg.util.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 135
diff changeset
40 import org.tmatesoft.hg.util.ProgressSupport;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
41
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
42
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 /**
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 135
diff changeset
44 * Base class for all Mercurial entities that are serialized in a so called revlog format (changelog, manifest, data files).
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 135
diff changeset
45 *
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 135
diff changeset
46 * Implementation note:
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 135
diff changeset
47 * Hides actual actual revlog stream implementation and its access methods (i.e. RevlogStream.Inspector), iow shall not expose anything internal
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 135
diff changeset
48 * in public methods.
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 135
diff changeset
49 *
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
50 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
51 * @author TMate Software Ltd.
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
53 abstract class Revlog {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
55 private final HgRepository repo;
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
56 protected final RevlogStream content;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
58 protected Revlog(HgRepository hgRepo, RevlogStream contentStream) {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 if (hgRepo == null) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
60 throw new IllegalArgumentException();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
61 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
62 if (contentStream == null) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
63 throw new IllegalArgumentException();
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
65 repo = hgRepo;
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
66 content = contentStream;
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
67 }
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
68
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
69 // invalid Revlog
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
70 protected Revlog(HgRepository hgRepo) {
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
71 repo = hgRepo;
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
72 content = null;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 public final HgRepository getRepo() {
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
76 return repo;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
79 public final int getRevisionCount() {
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
80 return content.revisionCount();
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
81 }
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
82
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
83 public final int getLastRevision() {
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
84 return content.revisionCount() - 1;
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
85 }
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
86
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
87 public final Nodeid getRevision(int revision) {
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
88 // XXX cache nodeids?
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
89 return Nodeid.fromBinary(content.nodeid(revision), 0);
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
90 }
317
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
91
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
92 public final List<Nodeid> getRevisions(int... revisions) {
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
93 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(revisions.length);
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
94 Arrays.sort(revisions);
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
95 getRevisionsInternal(rv, revisions);
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
96 return rv;
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
97 }
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
98
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
99 /*package-local*/ void getRevisionsInternal(final List<Nodeid> retVal, int[] sortedRevs) {
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
100 // once I have getRevisionMap and may find out whether it is avalable from cache,
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
101 // may use it, perhaps only for small number of revisions
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
102 content.iterate(sortedRevs, false, new RevlogStream.Inspector() {
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
103
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
104 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
105 retVal.add(Nodeid.fromBinary(nodeid, 0));
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
106 }
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
107 });
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
108 }
37
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
109
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
110 /**
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
111 * Get local revision number (index) of the specified revision.
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
112 *
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
113 * For occasional queries, this method works with decent performance, despite its O(n/2) approach.
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
114 * Alternatively, if you need to perform multiple queries (e.g. at least 15-20), {@link RevisionMap} may come handy.
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
115 *
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
116 * @param nid revision to look up
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
117 * @return revision index, or {@link HgRepository#BAD_REVISION} if specified revision not found.
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
118 */
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
119 public final int getLocalRevision(Nodeid nid) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
120 int revision = content.findLocalRevisionNumber(nid);
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
121 if (revision == BAD_REVISION) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
122 throw new IllegalArgumentException(String.format("%s doesn't represent a revision of %s", nid.toString(), this /*XXX HgDataFile.getPath might be more suitable here*/));
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
123 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
124 return revision;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
125 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
126
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
127 // Till now, i follow approach that NULL nodeid is never part of revlog
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
128 public final boolean isKnown(Nodeid nodeid) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
129 final int rn = content.findLocalRevisionNumber(nodeid);
218
047b1dec7a04 Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 200
diff changeset
130 if (BAD_REVISION == rn) {
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
131 return false;
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
132 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
133 if (rn < 0 || rn >= content.revisionCount()) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
134 // Sanity check
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
135 throw new IllegalStateException();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
136 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
137 return true;
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
138 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
139
37
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
140 /**
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
141 * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries)
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
142 * @param nodeid
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
143 */
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 135
diff changeset
144 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgException, 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 135
diff changeset
145 rawContent(getLocalRevision(nodeid), sink);
37
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
146 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
147
37
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
148 /**
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
149 * @param revision - repo-local index of this file change (not a changelog revision number!)
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
150 */
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 135
diff changeset
151 protected void rawContent(int revision, ByteChannel sink) throws HgException, 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 135
diff changeset
152 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 135
diff changeset
153 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 135
diff changeset
154 }
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 135
diff changeset
155 ContentPipe 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 135
diff changeset
156 insp.checkCancelled();
37
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
157 content.iterate(revision, revision, true, insp);
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
158 insp.checkFailed();
37
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
159 }
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
160
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
161 /**
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
162 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query?
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
163 *
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
164 * @param revision - revision to query parents, or {@link HgRepository#TIP}
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
165 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1})
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
166 * @param parent1 - byte[20] or null, if parent's nodeid is not needed
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
167 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
168 * @return
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
169 */
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
170 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
171 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
172 throw new IllegalArgumentException(String.valueOf(revision));
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
173 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
174 if (parentRevisions == null || parentRevisions.length < 2) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
175 throw new IllegalArgumentException(String.valueOf(parentRevisions));
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
176 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
177 if (parent1 != null && parent1.length < 20) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
178 throw new IllegalArgumentException(parent1.toString());
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
179 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
180 if (parent2 != null && parent2.length < 20) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
181 throw new IllegalArgumentException(parent2.toString());
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
182 }
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
183 class ParentCollector implements RevlogStream.Inspector {
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
184 public int p1 = -1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
185 public int p2 = -1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
186 public byte[] nodeid;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
187
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 135
diff changeset
188 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) {
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
189 p1 = parent1Revision;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
190 p2 = parent2Revision;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
191 this.nodeid = new byte[20];
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
192 // nodeid arg now comes in 32 byte from (as in file format description), however upper 12 bytes are zeros.
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
193 System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
194 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
195 };
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
196 ParentCollector pc = new ParentCollector();
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
197 content.iterate(revision, revision, false, pc);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
198 parentRevisions[0] = pc.p1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
199 parentRevisions[1] = pc.p2;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
200 if (parent1 != null) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
201 if (parentRevisions[0] == -1) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
202 Arrays.fill(parent1, 0, 20, (byte) 0);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
203 } else {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
204 content.iterate(parentRevisions[0], parentRevisions[0], false, pc);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
205 System.arraycopy(pc.nodeid, 0, parent1, 0, 20);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
206 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
207 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
208 if (parent2 != null) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
209 if (parentRevisions[1] == -1) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
210 Arrays.fill(parent2, 0, 20, (byte) 0);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
211 } else {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
212 content.iterate(parentRevisions[1], parentRevisions[1], false, pc);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
213 System.arraycopy(pc.nodeid, 0, parent2, 0, 20);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
214 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
215 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
216 }
317
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
217
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
218 /*
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
219 * XXX think over if it's better to do either:
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
220 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
221 * or
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
222 * add Revlog#getParentWalker(), static class, make cons() and #init package-local, and keep SoftReference to allow walker reuse.
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
223 *
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
224 * and yes, walker is not a proper name
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
225 */
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
226 public final class ParentWalker {
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
227
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
228
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
229 private Nodeid[] sequential; // natural repository order, childrenOf rely on ordering
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
230 private Nodeid[] sorted; // for binary search
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
231 private int[] sorted2natural;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
232 private Nodeid[] firstParent;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
233 private Nodeid[] secondParent;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
234
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
235 // Nodeid instances shall be shared between all arrays
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
236
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
237 public ParentWalker() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
238 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
239
192
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
240 public HgRepository getRepo() {
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
241 return Revlog.this.getRepo();
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
242 }
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
243
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
244 public void init() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
245 final RevlogStream stream = Revlog.this.content;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
246 final int revisionCount = stream.revisionCount();
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
247 firstParent = new Nodeid[revisionCount];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
248 // although branches/merges are less frequent, and most of secondParent would be -1/null, some sort of
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
249 // SparseOrderedList might be handy, provided its inner structures do not overweight simplicity of an array
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
250 secondParent = new Nodeid[revisionCount];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
251 //
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
252 sequential = new Nodeid[revisionCount];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
253 sorted = new Nodeid[revisionCount];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
254
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
255 RevlogStream.Inspector insp = new RevlogStream.Inspector() {
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
256
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
257 int ix = 0;
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 135
diff changeset
258 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) {
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
259 if (ix != revisionNumber) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
260 // XXX temp code, just to make sure I understand what's going on here
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
261 // FIXME check against cpython or another tool-mangled repository
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
262 throw new IllegalStateException();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
263 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
264 if (parent1Revision >= revisionNumber || parent2Revision >= revisionNumber) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
265 throw new IllegalStateException(); // sanity, revisions are sequential
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
266 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
267 final Nodeid nid = new Nodeid(nodeid, true);
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
268 sequential[ix] = sorted[ix] = nid;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
269 if (parent1Revision != -1) {
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
270 assert parent1Revision < ix;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
271 firstParent[ix] = sequential[parent1Revision];
183
9807bf8f3a9c Do not assume second parent can be set only when first one is set
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
272 }
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
273 if (parent2Revision != -1) { // revlog of DataAccess.java has p2 set when p1 is -1
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
274 assert parent2Revision < ix;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
275 secondParent[ix] = sequential[parent2Revision];
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
276 }
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
277 ix++;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
278 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
279 };
197
3a7696fb457c Investigate optimization options to allow fast processing of huge repositories. Fix defect in StatusCollector that lead to wrong result comparing first revision to empty repo (-1 to 0), due to same TIP constant value
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
280 stream.iterate(0, TIP, false, insp);
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
281 Arrays.sort(sorted);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
282 sorted2natural = new int[revisionCount];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
283 for (int i = 0; i < revisionCount; i++) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
284 Nodeid n = sequential[i];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
285 int x = Arrays.binarySearch(sorted, n);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
286 assertSortedIndex(x);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
287 sorted2natural[x] = i;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
288 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
289 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
290
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
291 private void assertSortedIndex(int x) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
292 if (x < 0) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
293 throw new HgBadStateException();
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
294 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
295 }
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
296
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
297 // FIXME need to decide whether Nodeid(00 * 20) is always known or not
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
298 // right now Nodeid.NULL is not recognized as known if passed to this method,
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
299 // caller is supposed to make explicit check
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
300 public boolean knownNode(Nodeid nid) {
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
301 return Arrays.binarySearch(sorted, nid) >= 0;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
302 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
303
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
304 /**
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
305 * null if none. only known nodes (as per #knownNode) are accepted as arguments
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
306 */
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
307 public Nodeid firstParent(Nodeid nid) {
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
308 int x = Arrays.binarySearch(sorted, nid);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
309 assertSortedIndex(x);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
310 int i = sorted2natural[x];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
311 return firstParent[i];
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
312 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
313
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
314 // never null, Nodeid.NULL if none known
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
315 public Nodeid safeFirstParent(Nodeid nid) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
316 Nodeid rv = firstParent(nid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
317 return rv == null ? Nodeid.NULL : rv;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
318 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
319
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
320 public Nodeid secondParent(Nodeid nid) {
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
321 int x = Arrays.binarySearch(sorted, nid);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
322 assertSortedIndex(x);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
323 int i = sorted2natural[x];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
324 return secondParent[i];
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
325 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
326
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
327 public Nodeid safeSecondParent(Nodeid nid) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
328 Nodeid rv = secondParent(nid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
329 return rv == null ? Nodeid.NULL : rv;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
330 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
331
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
332 public boolean appendParentsOf(Nodeid nid, Collection<Nodeid> c) {
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
333 int x = Arrays.binarySearch(sorted, nid);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
334 assertSortedIndex(x);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
335 int i = sorted2natural[x];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
336 Nodeid p1 = firstParent[i];
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
337 boolean modified = false;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
338 if (p1 != null) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
339 modified = c.add(p1);
191
b777502a06f5 Do not assume second parent can be set only when first one is set, again
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 183
diff changeset
340 }
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
341 Nodeid p2 = secondParent[i];
191
b777502a06f5 Do not assume second parent can be set only when first one is set, again
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 183
diff changeset
342 if (p2 != null) {
b777502a06f5 Do not assume second parent can be set only when first one is set, again
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 183
diff changeset
343 modified = c.add(p2) || modified;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
344 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
345 return modified;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
346 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
347
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
348 // XXX alternative (and perhaps more reliable) approach would be to make a copy of allNodes and remove
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
349 // nodes, their parents and so on.
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
350
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
351 // @return ordered collection of all children rooted at supplied nodes. Nodes shall not be descendants of each other!
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
352 // Nodeids shall belong to this revlog
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
353 public List<Nodeid> childrenOf(List<Nodeid> roots) {
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
354 HashSet<Nodeid> parents = new HashSet<Nodeid>();
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
355 LinkedList<Nodeid> result = new LinkedList<Nodeid>();
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
356 int earliestRevision = Integer.MAX_VALUE;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
357 assert sequential.length == firstParent.length && firstParent.length == secondParent.length;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
358 // first, find earliest index of roots in question, as there's no sense
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
359 // to check children among nodes prior to branch's root node
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
360 for (Nodeid r : roots) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
361 int x = Arrays.binarySearch(sorted, r);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
362 assertSortedIndex(x);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
363 int i = sorted2natural[x];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
364 if (i < earliestRevision) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
365 earliestRevision = i;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
366 }
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
367 parents.add(sequential[i]); // add canonical instance in hope equals() is bit faster when can do a ==
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
368 }
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
369 for (int i = earliestRevision + 1; i < sequential.length; i++) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
370 if (parents.contains(firstParent[i]) || parents.contains(secondParent[i])) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
371 parents.add(sequential[i]); // to find next child
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
372 result.add(sequential[i]);
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
373 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
374 }
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
375 return result;
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
376 }
192
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
377
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
378 /**
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
379 * @return revisions that have supplied revision as their immediate parent
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
380 */
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
381 public List<Nodeid> directChildren(Nodeid nid) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
382 LinkedList<Nodeid> result = new LinkedList<Nodeid>();
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
383 int x = Arrays.binarySearch(sorted, nid);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
384 assertSortedIndex(x);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
385 nid = sorted[x]; // canonical instance
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
386 int start = sorted2natural[x];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
387 for (int i = start + 1; i < sequential.length; i++) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
388 if (nid == firstParent[i] || nid == secondParent[i]) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
389 result.add(sequential[i]);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
390 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
391 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
392 return result;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
393 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
394
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 307
diff changeset
395 /**
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
396 * @param nid possibly parent node, shall be {@link #knownNode(Nodeid) known} in this revlog.
192
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
397 * @return <code>true</code> if there's any node in this revlog that has specified node as one of its parents.
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
398 */
200
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
399 public boolean hasChildren(Nodeid nid) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
400 int x = Arrays.binarySearch(sorted, nid);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
401 assertSortedIndex(x);
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
402 int i = sorted2natural[x];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
403 assert firstParent.length == secondParent.length; // just in case later I implement sparse array for secondParent
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
404 assert firstParent.length == sequential.length;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
405 // to use == instead of equals, take the same Nodeid instance we used to fill all the arrays.
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
406 final Nodeid canonicalNode = sequential[i];
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
407 i++; // no need to check node itself. child nodes may appear in sequential only after revision in question
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
408 for (; i < sequential.length; i++) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
409 // FIXME likely, not very effective.
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
410 // May want to optimize it with another (Tree|Hash)Set, created on demand on first use,
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
411 // however, need to be careful with memory usage
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
412 if (firstParent[i] == canonicalNode || secondParent[i] == canonicalNode) {
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
413 return true;
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
414 }
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
415 }
114c9fe7b643 Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 197
diff changeset
416 return false;
192
e5407b5a586a Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 191
diff changeset
417 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
418 }
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 135
diff changeset
419
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
420 /**
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
421 * Effective int to Nodeid and vice versa translation. It's advised to use this class instead of
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
422 * multiple {@link Revlog#getLocalRevision(Nodeid)} calls.
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
423 *
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
424 * getLocalRevision(Nodeid) with straightforward lookup approach performs O(n/2)
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
425 * #localRevision() is log(n), plus initialization is O(n)
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
426 */
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
427 public final class RevisionMap {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
428 /*
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
429 * in fact, initialization is much slower as it instantiates Nodeids, while #getLocalRevision
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
430 * compares directly against byte buffer. Measuring cpython with 70k+ gives 3 times difference (47 vs 171)
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
431 * for complete changelog iteration.
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
432 */
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
433
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
434 /*
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
435 * XXX 3 * (x * 4) bytes. Can I do better?
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
436 */
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
437 private Nodeid[] sequential; // natural repository order, childrenOf rely on ordering
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
438 private Nodeid[] sorted; // for binary search
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
439 private int[] sorted2natural;
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
440
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
441 public RevisionMap() {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
442 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
443
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
444 public HgRepository getRepo() {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
445 return Revlog.this.getRepo();
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
446 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
447
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
448 /**
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
449 * @return <code>this</code> for convenience.
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
450 */
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
451 public RevisionMap init(/*XXX Pool<Nodeid> to reuse nodeids, if possible. */) {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
452 // XXX HgRepository.register((RepoChangeListener) this); // listen to changes in repo, re-init if needed?
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
453 final int revisionCount = Revlog.this.content.revisionCount();
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
454 sequential = new Nodeid[revisionCount];
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
455 sorted = new Nodeid[revisionCount];
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
456 RevlogStream.Inspector insp = new RevlogStream.Inspector() {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
457
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
458 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
459 final Nodeid nid = new Nodeid(nodeid, true);
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
460 sequential[revisionNumber] = sorted[revisionNumber] = nid;
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
461 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
462 };
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
463 Revlog.this.content.iterate(0, TIP, false, insp);
307
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
464 // next is alternative to Arrays.sort(sorted), and build sorted2natural looking up each element of sequential in sorted.
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
465 // the way sorted2natural was build is O(n*log n).
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
466 final ArrayHelper ah = new ArrayHelper();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
467 ah.sort(sorted);
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
468 // note, values in ArrayHelper#getReversed are 1-based indexes, not 0-based
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
469 sorted2natural = ah.getReverse();
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
470 return this;
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
471 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
472
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
473 public Nodeid revision(int localRevision) {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
474 return sequential[localRevision];
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
475 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
476 public int localRevision(Nodeid revision) {
274
9fb50c04f03c Use Nodeid.isNull check instead of NULL.equals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 243
diff changeset
477 if (revision == null || revision.isNull()) {
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
478 return BAD_REVISION;
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
479 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
480 int x = Arrays.binarySearch(sorted, revision);
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
481 if (x < 0) {
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
482 return BAD_REVISION;
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
483 }
307
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 277
diff changeset
484 return sorted2natural[x]-1;
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
485 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
486 }
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
487
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
488 protected abstract static class ErrorHandlingInspector implements RevlogStream.Inspector, CancelSupport {
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 135
diff changeset
489 private Exception failure;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
490 private CancelSupport cancelSupport;
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 135
diff changeset
491
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
492 protected void setCancelSupport(CancelSupport cs) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
493 assert cancelSupport == null; // no reason to set it twice
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
494 cancelSupport = cs;
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 135
diff changeset
495 }
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 135
diff changeset
496
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 135
diff changeset
497 protected void recordFailure(Exception 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 135
diff changeset
498 assert failure == 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 135
diff changeset
499 failure = 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 135
diff changeset
500 }
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 135
diff changeset
501
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 135
diff changeset
502 public void checkFailed() throws HgException, 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 135
diff changeset
503 if (failure == 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 135
diff changeset
504 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 135
diff changeset
505 }
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 135
diff changeset
506 if (failure instanceof IOException) {
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 135
diff changeset
507 throw (IOException) failure;
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 135
diff changeset
508 }
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 135
diff changeset
509 if (failure instanceof 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 135
diff changeset
510 throw (CancelledException) failure;
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 135
diff changeset
511 }
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 135
diff changeset
512 if (failure instanceof HgException) {
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 135
diff changeset
513 throw (HgException) failure;
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 135
diff changeset
514 }
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 135
diff changeset
515 throw new HgBadStateException(failure);
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 135
diff changeset
516 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
517
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
518 public void checkCancelled() throws CancelledException {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
519 if (cancelSupport != null) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
520 cancelSupport.checkCancelled();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
521 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
522 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
523 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
524
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
525 protected static class ContentPipe extends ErrorHandlingInspector implements RevlogStream.Inspector, CancelSupport {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
526 private final ByteChannel sink;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
527 private final int offset;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
528
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
529 /**
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
530 * @param _sink - cannot be <code>null</code>
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
531 * @param seekOffset - when positive, orders to pipe bytes to the sink starting from specified offset, not from the first byte available in DataAccess
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
532 */
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
533 public ContentPipe(ByteChannel _sink, int seekOffset) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
534 assert _sink != null;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
535 sink = _sink;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
536 setCancelSupport(CancelSupport.Factory.get(_sink));
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
537 offset = seekOffset;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
538 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
539
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
540 protected void prepare(int revisionNumber, DataAccess da) throws HgException, IOException {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
541 if (offset > 0) { // save few useless reset/rewind operations
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
542 da.seek(offset);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
543 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
544 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
545
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
546 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
547 try {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
548 prepare(revisionNumber, da); // XXX perhaps, prepare shall return DA (sliced, if needed)
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
549 final ProgressSupport progressSupport = ProgressSupport.Factory.get(sink);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
550 ByteBuffer buf = ByteBuffer.allocate(512);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
551 progressSupport.start(da.length());
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
552 while (!da.isEmpty()) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
553 checkCancelled();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
554 da.readBytes(buf);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
555 buf.flip();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
556 // XXX I may not rely on returned number of bytes but track change in buf position instead.
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
557 int consumed = sink.write(buf);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
558 // FIXME in fact, bad sink implementation (that consumes no bytes) would result in endless loop. Need to account for this
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
559 buf.compact();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
560 progressSupport.worked(consumed);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
561 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
562 progressSupport.done(); // XXX shall specify whether #done() is invoked always or only if completed successfully.
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
563 } catch (IOException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
564 recordFailure(ex);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
565 } catch (CancelledException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
566 recordFailure(ex);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
567 } catch (HgException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
568 recordFailure(ex);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
569 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
570 }
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 135
diff changeset
571 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
572 }