Mercurial > hg4j
annotate src/org/tmatesoft/hg/repo/Revlog.java @ 424:6437d261048a
Deprecated code removed
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 28 Mar 2012 15:42:15 +0200 |
parents | 9c9c442b5f2e |
children | 48f993aa2f41 |
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 /* |
388
b015f3918120
Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
385
diff
changeset
|
2 * Copyright (c) 2010-2012 TMate Software Ltd |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
13 * For information on how to redistribute this software under |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
88
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
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; |
405
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
21 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
|
22 |
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>
diff
changeset
|
23 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>
diff
changeset
|
24 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
|
25 import java.util.ArrayList; |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
26 import java.util.Arrays; |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 import java.util.List; |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
31 |
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>
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>
diff
changeset
|
35 import org.tmatesoft.hg.internal.DataAccess; |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
36 import org.tmatesoft.hg.internal.Experimental; |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
37 import org.tmatesoft.hg.internal.Preview; |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
38 import org.tmatesoft.hg.internal.RevlogStream; |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
39 import org.tmatesoft.hg.util.Adaptable; |
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>
diff
changeset
|
40 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>
diff
changeset
|
41 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>
diff
changeset
|
42 import org.tmatesoft.hg.util.CancelledException; |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
43 import org.tmatesoft.hg.util.LogFacility; |
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>
diff
changeset
|
44 import org.tmatesoft.hg.util.ProgressSupport; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
45 |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
46 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 /** |
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>
diff
changeset
|
48 * 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>
diff
changeset
|
49 * |
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>
diff
changeset
|
50 * 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>
diff
changeset
|
51 * 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>
diff
changeset
|
52 * 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>
diff
changeset
|
53 * |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
54 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
55 * @author TMate Software Ltd. |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
57 abstract class Revlog { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 |
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
59 private final HgRepository repo; |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
60 protected final RevlogStream content; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
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 protected Revlog(HgRepository hgRepo, RevlogStream contentStream) { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 if (hgRepo == null) { |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
64 throw new IllegalArgumentException(); |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
65 } |
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
66 if (contentStream == null) { |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
56
diff
changeset
|
67 throw new IllegalArgumentException(); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 } |
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
69 repo = hgRepo; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
70 content = contentStream; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
71 } |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
72 |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
73 // invalid Revlog |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
74 protected Revlog(HgRepository hgRepo) { |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
75 repo = hgRepo; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
76 content = null; |
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 |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 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
|
80 return repo; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
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 getRevisionCount() { |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
84 return content.revisionCount(); |
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
85 } |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
86 |
135
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 int getLastRevision() { |
3959bffb14e9
explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
88 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
|
89 } |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
90 |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
91 /** |
388
b015f3918120
Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
385
diff
changeset
|
92 * Map revision index to unique revision identifier (nodeid). |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
93 * |
388
b015f3918120
Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
385
diff
changeset
|
94 * @param revision index of the entry in this revlog, may be {@link HgRepository#TIP} |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
95 * @return revision nodeid of the entry |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
96 * |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
97 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
98 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
99 */ |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
356
diff
changeset
|
100 public final Nodeid getRevision(int revision) throws HgInvalidRevisionException, HgInvalidControlFileException { |
328
a674b8590362
Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
327
diff
changeset
|
101 // XXX cache nodeids? Rather, if context.getCache(this).getRevisionMap(create == false) != null, use it |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
102 return Nodeid.fromBinary(content.nodeid(revision), 0); |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
103 } |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
104 |
328
a674b8590362
Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
327
diff
changeset
|
105 /** |
a674b8590362
Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
327
diff
changeset
|
106 * FIXME need to be careful about (1) ordering of the revisions in the return list; (2) modifications (sorting) of the argument array |
a674b8590362
Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
327
diff
changeset
|
107 */ |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
356
diff
changeset
|
108 public final List<Nodeid> getRevisions(int... revisions) throws HgInvalidRevisionException, HgInvalidControlFileException { |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 return rv; |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
113 } |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
114 |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
356
diff
changeset
|
115 /*package-local*/ void getRevisionsInternal(final List<Nodeid> retVal, int[] sortedRevs) throws HgInvalidRevisionException, HgInvalidControlFileException { |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
116 // 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
|
117 // 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
|
118 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
|
119 |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
120 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
|
121 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
|
122 } |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
123 }); |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
124 } |
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
|
125 |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
126 /** |
368
8107b95f4280
Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
127 * Get local index of the specified revision. |
347
8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
328
diff
changeset
|
128 * If unsure, use {@link #isKnown(Nodeid)} to find out whether nodeid belongs to this revlog. |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
129 * |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
130 * For occasional queries, this method works with decent performance, despite its O(n/2) approach. |
419
7f136a3fa671
Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
131 * Alternatively, if you need to perform multiple queries (e.g. at least 15-20), {@link Revlog.RevisionMap} may come handy. |
347
8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
328
diff
changeset
|
132 * |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
133 * @param nid revision to look up |
347
8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
328
diff
changeset
|
134 * @return revision local index in this revlog |
8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
328
diff
changeset
|
135 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
136 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
137 */ |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
138 public final int getRevisionIndex(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { |
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
139 int revision = content.findRevisionIndex(nid); |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
140 if (revision == BAD_REVISION) { |
393
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
141 // using toString() to identify revlog. HgDataFile.toString includes path, HgManifest and HgChangelog instances |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
142 // are fine with default (class name) |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
143 // Perhaps, more tailored description method would be suitable here |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
144 throw new HgInvalidRevisionException(String.format("Can't find revision %s in %s", nid.shortNotation(), this), nid, null); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
145 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
146 return revision; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
147 } |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
148 |
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
149 /** |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
150 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog. |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
151 * |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
152 * @param nodeid |
419
7f136a3fa671
Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
153 * @return <code>true</code> if revision is part of this revlog |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
154 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
155 */ |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
347
diff
changeset
|
156 public final boolean isKnown(Nodeid nodeid) throws HgInvalidControlFileException { |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
157 final int rn = content.findRevisionIndex(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
|
158 if (BAD_REVISION == rn) { |
39
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
159 return false; |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
160 } |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
161 if (rn < 0 || rn >= content.revisionCount()) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
162 // Sanity check |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
163 throw new HgInvalidStateException(String.format("Revision index %d found for nodeid %s is not from the range [0..%d]", rn, nodeid.shortNotation(), content.revisionCount()-1)); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
164 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
165 return true; |
39
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
166 } |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
167 |
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
|
168 /** |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
169 * Access to revision data as is, equivalent to <code>rawContent(getRevisionIndex(nodeid), sink)</code> |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
170 * |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
171 * @param nodeid revision to retrieve |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
172 * @param sink data destination |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
173 * |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
174 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
175 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
176 * @throws CancelledException if content retrieval operation was cancelled |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
177 * |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
178 * @see #rawContent(int, ByteChannel) |
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
|
179 */ |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
180 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgInvalidControlFileException, CancelledException, HgInvalidRevisionException { |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
181 rawContent(getRevisionIndex(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
|
182 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
183 |
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
|
184 /** |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
185 * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries). |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
186 * |
416
d30083c80d52
Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
405
diff
changeset
|
187 * @param revisionIndex index of this revlog change (not a changelog revision index), non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense. |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
188 * @param sink data destination |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
189 * |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
190 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
191 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
192 * @throws CancelledException if content retrieval operation was cancelled |
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
|
193 */ |
416
d30083c80d52
Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
405
diff
changeset
|
194 protected void rawContent(int revisionIndex, ByteChannel sink) throws HgInvalidControlFileException, CancelledException, HgInvalidRevisionException { |
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>
diff
changeset
|
195 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>
diff
changeset
|
196 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>
diff
changeset
|
197 } |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
198 try { |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
199 ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog()); |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
200 insp.checkCancelled(); |
416
d30083c80d52
Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
405
diff
changeset
|
201 content.iterate(revisionIndex, revisionIndex, true, insp); |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
202 insp.checkFailed(); |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
203 } catch (IOException ex) { |
416
d30083c80d52
Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
405
diff
changeset
|
204 HgInvalidControlFileException e = new HgInvalidControlFileException(String.format("Access to revision %d content failed", revisionIndex), ex, null); |
d30083c80d52
Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
405
diff
changeset
|
205 e.setRevisionIndex(revisionIndex); |
418
528b6780a8bd
A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
416
diff
changeset
|
206 // TODO post 1.0 e.setFileName(content.getIndexFile() or this.getHumanFriendlyPath()) - shall decide whether |
528b6780a8bd
A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
416
diff
changeset
|
207 // protected abstract getHFPath() with impl in HgDataFile, HgManifest and HgChangelog or path is data of either Revlog or RevlogStream |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
208 // Do the same (add file name) below |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
209 throw e; |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
210 } catch (HgInvalidControlFileException ex) { |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
211 throw ex; |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
212 } catch (HgException ex) { |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
213 HgInvalidControlFileException e = new HgInvalidControlFileException(ex.getClass().getSimpleName(), ex, null); |
416
d30083c80d52
Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
405
diff
changeset
|
214 e.setRevisionIndex(revisionIndex); |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
215 throw e; |
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
216 } |
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
|
217 } |
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
|
218 |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
219 /** |
405
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
220 * Fills supplied arguments with information about revision parents. |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
221 * |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
222 * @param revision - revision to query parents, or {@link HgRepository#TIP} |
405
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
223 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1}), {@link HgRepository#NO_REVISION} indicates parent not set |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
224 * @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
|
225 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed |
347
8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
328
diff
changeset
|
226 * @throws HgInvalidRevisionException |
418
528b6780a8bd
A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
416
diff
changeset
|
227 * @throws HgInvalidControlFileException FIXME EXCEPTIONS |
347
8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
328
diff
changeset
|
228 * @throws IllegalArgumentException |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
229 */ |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
356
diff
changeset
|
230 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) throws HgInvalidRevisionException, HgInvalidControlFileException { |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
231 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) { |
347
8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
328
diff
changeset
|
232 throw new HgInvalidRevisionException(revision); |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
233 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
234 if (parentRevisions == null || parentRevisions.length < 2) { |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
235 throw new IllegalArgumentException(String.valueOf(parentRevisions)); |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
236 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
237 if (parent1 != null && parent1.length < 20) { |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
238 throw new IllegalArgumentException(parent1.toString()); |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
239 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
240 if (parent2 != null && parent2.length < 20) { |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
241 throw new IllegalArgumentException(parent2.toString()); |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
242 } |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
243 class ParentCollector implements RevlogStream.Inspector { |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
244 public int p1 = -1; |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
245 public int p2 = -1; |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
246 public byte[] nodeid; |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
247 |
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>
diff
changeset
|
248 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
|
249 p1 = parent1Revision; |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
250 p2 = parent2Revision; |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
251 this.nodeid = new byte[20]; |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
252 // 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
|
253 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
|
254 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
255 }; |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
256 ParentCollector pc = new ParentCollector(); |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
257 content.iterate(revision, revision, false, pc); |
405
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
258 // although next code looks odd (NO_REVISION *is* -1), it's safer to be explicit |
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
259 parentRevisions[0] = pc.p1 == -1 ? NO_REVISION : pc.p1; |
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
260 parentRevisions[1] = pc.p2 == -1 ? NO_REVISION : pc.p2; |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
261 if (parent1 != null) { |
405
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
262 if (parentRevisions[0] == NO_REVISION) { |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
263 Arrays.fill(parent1, 0, 20, (byte) 0); |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
264 } else { |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
265 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
|
266 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
|
267 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
268 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
269 if (parent2 != null) { |
405
866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
403
diff
changeset
|
270 if (parentRevisions[1] == NO_REVISION) { |
56
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
271 Arrays.fill(parent2, 0, 20, (byte) 0); |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
272 } else { |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
273 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
|
274 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
|
275 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
276 } |
576d6e8a09f6
Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
277 } |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
278 |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
279 @Experimental |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
356
diff
changeset
|
280 public void walk(int start, int end, final Revlog.Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
281 int lastRev = getLastRevision(); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
282 if (start == TIP) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
283 start = lastRev; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
284 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
285 if (end == TIP) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
286 end = lastRev; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
287 } |
356
91d75e1bac9f
Consistent approach to deal with adaptable objects. Give adaptable precedence over instanceof to allow conditional response when classes do implement desired interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
355
diff
changeset
|
288 final RevisionInspector revisionInsp = Adaptable.Factory.getAdapter(inspector, RevisionInspector.class, null); |
91d75e1bac9f
Consistent approach to deal with adaptable objects. Give adaptable precedence over instanceof to allow conditional response when classes do implement desired interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
355
diff
changeset
|
289 final ParentInspector parentInsp = Adaptable.Factory.getAdapter(inspector, ParentInspector.class, null); |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
290 final Nodeid[] allRevisions = parentInsp == null ? null : new Nodeid[end - start + 1]; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
291 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
292 content.iterate(start, end, false, new RevlogStream.Inspector() { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
293 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
294 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
295 Nodeid nid = Nodeid.fromBinary(nodeid, 0); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
296 if (revisionInsp != null) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
297 revisionInsp.next(revisionNumber, nid, linkRevision); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
298 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
299 if (parentInsp != null) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
300 Nodeid p1 = parent1Revision == -1 ? Nodeid.NULL : allRevisions[parent1Revision]; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
301 Nodeid p2 = parent2Revision == -1 ? Nodeid.NULL : allRevisions[parent2Revision]; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
302 allRevisions[revisionNumber] = nid; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
303 parentInsp.next(revisionNumber, nid, parent1Revision, parent2Revision, p1, p2); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
304 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
305 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
306 }); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
307 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
308 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
309 /** |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
310 * MARKER |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
311 */ |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
312 @Experimental |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
313 public interface Inspector { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
314 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
315 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
316 @Experimental |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
317 public interface RevisionInspector extends Inspector { |
368
8107b95f4280
Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
318 void next(int revisionIndex, Nodeid revision, int linkedRevisionIndex); |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
319 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
320 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
321 @Experimental |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
322 public interface ParentInspector extends Inspector { |
327
3f09b8c19142
Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
323 // XXX document whether parentX is -1 or a constant (BAD_REVISION? or dedicated?) |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
324 void next(int revisionIndex, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2); |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
325 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
326 |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
327 /* |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
328 * 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
|
329 * 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
|
330 * or |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
331 * 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
|
332 * |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
333 * 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
|
334 */ |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
335 public final class ParentWalker implements ParentInspector { |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
336 |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
337 |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
338 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
|
339 private Nodeid[] sorted; // for binary search |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
340 private int[] sorted2natural; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
341 private Nodeid[] firstParent; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
342 private Nodeid[] secondParent; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
343 |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
344 // 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
|
345 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
346 public ParentWalker() { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
347 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
348 |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
191
diff
changeset
|
349 public HgRepository getRepo() { |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
191
diff
changeset
|
350 return Revlog.this.getRepo(); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
191
diff
changeset
|
351 } |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
191
diff
changeset
|
352 |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
353 public void next(int revisionNumber, Nodeid revision, int parent1Revision, int parent2Revision, Nodeid nidParent1, Nodeid nidParent2) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
354 if (parent1Revision >= revisionNumber || parent2Revision >= revisionNumber) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
355 throw new IllegalStateException(); // sanity, revisions are sequential |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
356 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
357 int ix = revisionNumber; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
358 sequential[ix] = sorted[ix] = revision; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
359 if (parent1Revision != -1) { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
360 firstParent[ix] = sequential[parent1Revision]; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
361 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
362 if (parent2Revision != -1) { // revlog of DataAccess.java has p2 set when p1 is -1 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
363 secondParent[ix] = sequential[parent2Revision]; |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
364 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
365 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
366 |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
356
diff
changeset
|
367 public void init() throws HgInvalidControlFileException { |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
368 final int revisionCount = Revlog.this.getRevisionCount(); |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
369 firstParent = new Nodeid[revisionCount]; |
393
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
370 // TODO [post 1.0] Branches/merges are less frequent, and most of secondParent would be -1/null, hence |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
371 // IntMap might be better alternative here, but need to carefully analyze (test) whether this brings |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
372 // real improvement (IntMap has 2n capacity, and element lookup is log(n) instead of array's constant) |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
373 secondParent = new Nodeid[revisionCount]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
374 // |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
375 sequential = new Nodeid[revisionCount]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
376 sorted = new Nodeid[revisionCount]; |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
377 Revlog.this.walk(0, TIP, this); |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
378 Arrays.sort(sorted); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
379 sorted2natural = new int[revisionCount]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
380 for (int i = 0; i < revisionCount; i++) { |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
381 Nodeid n = sequential[i]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
382 int x = Arrays.binarySearch(sorted, n); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
383 assertSortedIndex(x); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
384 sorted2natural[x] = i; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
385 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
386 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
387 |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
388 private void assertSortedIndex(int x) { |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
389 if (x < 0) { |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
390 throw new HgInvalidStateException(String.format("Bad index", x)); |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
391 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
392 } |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
393 |
393
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
394 /** |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
395 * Tells whether supplied revision is from the walker's associated revlog. |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
396 * Note, {@link Nodeid#NULL}, although implicitly present as parent of a first revision, is not recognized as known. |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
397 * @param nid revision to check, not <code>null</code> |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
398 * @return <code>true</code> if revision matches any revision in this revlog |
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
399 */ |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
400 public boolean knownNode(Nodeid nid) { |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
401 return Arrays.binarySearch(sorted, nid) >= 0; |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
402 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
403 |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
404 /** |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
405 * 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
|
406 */ |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
407 public Nodeid firstParent(Nodeid nid) { |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
408 int x = Arrays.binarySearch(sorted, nid); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
409 assertSortedIndex(x); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
410 int i = sorted2natural[x]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
411 return firstParent[i]; |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
412 } |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
413 |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
414 // 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
|
415 public Nodeid safeFirstParent(Nodeid nid) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
416 Nodeid rv = firstParent(nid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
417 return rv == null ? Nodeid.NULL : rv; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
418 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
419 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
420 public Nodeid secondParent(Nodeid nid) { |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
421 int x = Arrays.binarySearch(sorted, nid); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
422 assertSortedIndex(x); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
423 int i = sorted2natural[x]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
424 return secondParent[i]; |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
425 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
426 |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
427 public Nodeid safeSecondParent(Nodeid nid) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
428 Nodeid rv = secondParent(nid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
429 return rv == null ? Nodeid.NULL : rv; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
430 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
431 |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
432 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
|
433 int x = Arrays.binarySearch(sorted, nid); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
434 assertSortedIndex(x); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
435 int i = sorted2natural[x]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
436 Nodeid p1 = firstParent[i]; |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
437 boolean modified = false; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
438 if (p1 != null) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
439 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
|
440 } |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
441 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
|
442 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
|
443 modified = c.add(p2) || modified; |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
444 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
445 return modified; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
446 } |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
447 |
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
448 // 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
|
449 // 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
|
450 |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
451 // @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
|
452 // Nodeids shall belong to this revlog |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
453 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
|
454 HashSet<Nodeid> parents = new HashSet<Nodeid>(); |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
455 LinkedList<Nodeid> result = new LinkedList<Nodeid>(); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
456 int earliestRevision = Integer.MAX_VALUE; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
457 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
|
458 // 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
|
459 // 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
|
460 for (Nodeid r : roots) { |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
461 int x = Arrays.binarySearch(sorted, r); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
462 assertSortedIndex(x); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
463 int i = sorted2natural[x]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
464 if (i < earliestRevision) { |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
465 earliestRevision = i; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
466 } |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
467 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
|
468 } |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 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
|
473 } |
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
474 } |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
475 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
|
476 } |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
191
diff
changeset
|
477 |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
191
diff
changeset
|
478 /** |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
479 * @return revisions that have supplied revision as their immediate parent |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
480 */ |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
481 public List<Nodeid> directChildren(Nodeid nid) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
482 LinkedList<Nodeid> result = new LinkedList<Nodeid>(); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
483 int x = Arrays.binarySearch(sorted, nid); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
484 assertSortedIndex(x); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
485 nid = sorted[x]; // canonical instance |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
486 int start = sorted2natural[x]; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
487 for (int i = start + 1; i < sequential.length; i++) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
488 if (nid == firstParent[i] || nid == secondParent[i]) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
489 result.add(sequential[i]); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
490 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
491 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
492 return result; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
493 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
494 |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
307
diff
changeset
|
495 /** |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
496 * @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
|
497 * @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
|
498 */ |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
499 public boolean hasChildren(Nodeid nid) { |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
500 int x = Arrays.binarySearch(sorted, nid); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
501 assertSortedIndex(x); |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
502 int i = sorted2natural[x]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
503 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
|
504 assert firstParent.length == sequential.length; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
505 // 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
|
506 final Nodeid canonicalNode = sequential[i]; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
507 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
|
508 for (; i < sequential.length; i++) { |
393
728708de3597
Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
388
diff
changeset
|
509 // TODO [post 1.0] likely, not very effective. |
200
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
510 // 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
|
511 // 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
|
512 if (firstParent[i] == canonicalNode || secondParent[i] == canonicalNode) { |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
513 return true; |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
514 } |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
515 } |
114c9fe7b643
Performance optimization: reduce memory ParentWalker hogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
197
diff
changeset
|
516 return false; |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
191
diff
changeset
|
517 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
518 } |
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>
diff
changeset
|
519 |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
520 /** |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
521 * Effective int to Nodeid and vice versa translation. It's advised to use this class instead of |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
522 * multiple {@link Revlog#getRevisionIndex(Nodeid)} calls. |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
523 * |
368
8107b95f4280
Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
524 * {@link Revlog#getRevisionIndex(Nodeid)} with straightforward lookup approach performs O(n/2) |
8107b95f4280
Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
525 * {@link RevisionMap#revisionIndex(Nodeid)} is log(n), plus initialization is O(n) (just once). |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
526 */ |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
527 public final class RevisionMap implements RevisionInspector { |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
528 /* |
368
8107b95f4280
Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
529 * in fact, initialization is much slower as it instantiates Nodeids, while #getRevisionIndex |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
530 * 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
|
531 * for complete changelog iteration. |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
532 */ |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
533 |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
534 /* |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
535 * XXX 3 * (x * 4) bytes. Can I do better? |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
536 * It seems, yes. Don't need to keep sorted, always can emulate it with indirect access to sequential through sorted2natural. |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
537 * i.e. instead sorted[mid].compareTo(toFind), do sequential[sorted2natural[mid]].compareTo(toFind) |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
538 */ |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
539 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
|
540 private Nodeid[] sorted; // for binary search |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
541 private int[] sorted2natural; |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
542 |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
543 public RevisionMap() { |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
544 } |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
545 |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
546 public HgRepository getRepo() { |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
547 return Revlog.this.getRepo(); |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
548 } |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
549 |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
550 public void next(int revisionIndex, Nodeid revision, int linkedRevision) { |
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
551 sequential[revisionIndex] = sorted[revisionIndex] = revision; |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
552 } |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
553 |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
554 /** |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
555 * @return <code>this</code> for convenience. |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
556 */ |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
356
diff
changeset
|
557 public RevisionMap init(/*XXX Pool<Nodeid> to reuse nodeids, if possible. */) throws HgInvalidControlFileException{ |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
558 // XXX HgRepository.register((RepoChangeListener) this); // listen to changes in repo, re-init if needed? |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
559 final int revisionCount = Revlog.this.getRevisionCount(); |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
560 sequential = new Nodeid[revisionCount]; |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
561 sorted = new Nodeid[revisionCount]; |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
562 Revlog.this.walk(0, TIP, this); |
307
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
277
diff
changeset
|
563 // 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
|
564 // 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
|
565 final ArrayHelper ah = new ArrayHelper(); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
277
diff
changeset
|
566 ah.sort(sorted); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
277
diff
changeset
|
567 // 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
|
568 sorted2natural = ah.getReverse(); |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
569 return this; |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
570 } |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
571 |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
572 public Nodeid revision(int revisionIndex) { |
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
573 return sequential[revisionIndex]; |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
574 } |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
575 public int revisionIndex(Nodeid revision) { |
274
9fb50c04f03c
Use Nodeid.isNull check instead of NULL.equals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
243
diff
changeset
|
576 if (revision == null || revision.isNull()) { |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
577 return BAD_REVISION; |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
578 } |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
579 int x = Arrays.binarySearch(sorted, revision); |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
580 if (x < 0) { |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
581 return BAD_REVISION; |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
582 } |
307
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
277
diff
changeset
|
583 return sorted2natural[x]-1; |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
584 } |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
585 } |
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
586 |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
587 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>
diff
changeset
|
588 private Exception failure; |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
589 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>
diff
changeset
|
590 |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
591 protected void setCancelSupport(CancelSupport cs) { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
592 assert cancelSupport == null; // no reason to set it twice |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
593 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>
diff
changeset
|
594 } |
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>
diff
changeset
|
595 |
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>
diff
changeset
|
596 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>
diff
changeset
|
597 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>
diff
changeset
|
598 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>
diff
changeset
|
599 } |
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>
diff
changeset
|
600 |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
601 // FIXME is HgException of any use here now? |
394
f52ca9530774
Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
393
diff
changeset
|
602 // TODO consider if IOException in addition to HgException is of any real utility |
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>
diff
changeset
|
603 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>
diff
changeset
|
604 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>
diff
changeset
|
605 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>
diff
changeset
|
606 } |
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>
diff
changeset
|
607 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>
diff
changeset
|
608 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>
diff
changeset
|
609 } |
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>
diff
changeset
|
610 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>
diff
changeset
|
611 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>
diff
changeset
|
612 } |
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>
diff
changeset
|
613 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>
diff
changeset
|
614 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>
diff
changeset
|
615 } |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
616 throw new HgInvalidStateException(failure.toString()); |
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>
diff
changeset
|
617 } |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
618 |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
619 public void checkCancelled() throws CancelledException { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
620 if (cancelSupport != null) { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
621 cancelSupport.checkCancelled(); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
622 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
623 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
624 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
625 |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
626 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
|
627 private final ByteChannel sink; |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
628 private final int offset; |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
629 private final LogFacility logFacility; |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
630 |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
631 /** |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
632 * @param _sink - cannot be <code>null</code> |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
633 * @param seekOffset - when positive, orders to pipe bytes to the sink starting from specified offset, not from the first byte available in DataAccess |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
634 * @param log optional facility to put warnings/debug messages into, may be null. |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
635 */ |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
636 public ContentPipe(ByteChannel _sink, int seekOffset, LogFacility log) { |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
637 assert _sink != null; |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
638 sink = _sink; |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
639 setCancelSupport(CancelSupport.Factory.get(_sink)); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
640 offset = seekOffset; |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
641 logFacility = log; |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
642 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
643 |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
644 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
|
645 if (offset > 0) { // save few useless reset/rewind operations |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
646 da.seek(offset); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
647 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
648 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
649 |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
650 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
|
651 try { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
652 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
|
653 final ProgressSupport progressSupport = ProgressSupport.Factory.get(sink); |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
654 ByteBuffer buf = ByteBuffer.allocate(actualLen > 8192 ? 8192 : actualLen); |
356
91d75e1bac9f
Consistent approach to deal with adaptable objects. Give adaptable precedence over instanceof to allow conditional response when classes do implement desired interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
355
diff
changeset
|
655 Preview p = Adaptable.Factory.getAdapter(sink, Preview.class, null); |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
656 if (p != null) { |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
657 progressSupport.start(2 * da.length()); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
658 while (!da.isEmpty()) { |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
659 checkCancelled(); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
660 da.readBytes(buf); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
661 p.preview(buf); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
662 buf.clear(); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
663 } |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
664 da.reset(); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
665 prepare(revisionNumber, da); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
666 progressSupport.worked(da.length()); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
667 buf.clear(); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
668 } else { |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
669 progressSupport.start(da.length()); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
670 } |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
671 while (!da.isEmpty()) { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
672 checkCancelled(); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
673 da.readBytes(buf); |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
674 buf.flip(); // post: position == 0 |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
675 // XXX I may not rely on returned number of bytes but track change in buf position instead. |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
676 |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
677 int consumed = sink.write(buf); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
678 if ((consumed == 0 || consumed != buf.position()) && logFacility != null) { |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
679 logFacility.warn(getClass(), "Bad data sink when reading revision %d. Reported %d bytes consumed, byt actually read %d", revisionNumber, consumed, buf.position()); |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
680 } |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
681 if (buf.position() == 0) { |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
682 throw new HgInvalidStateException("Bad sink implementation (consumes no bytes) results in endless loop"); |
355
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
683 } |
f2c11fe7f3e9
Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
684 buf.compact(); // ensure (a) there's space for new (b) data starts at 0 |
277
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
685 progressSupport.worked(consumed); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
686 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
687 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
|
688 } catch (IOException ex) { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
689 recordFailure(ex); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
690 } catch (CancelledException ex) { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
691 recordFailure(ex); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
692 } catch (HgException ex) { |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
693 recordFailure(ex); |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
694 } |
74e7493a042a
Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
695 } |
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>
diff
changeset
|
696 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
697 } |