annotate src/org/tmatesoft/hg/repo/Revlog.java @ 695:053bb4397bf9

Refactoring: nice Revlog.indexWalk() implementation
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 05 Aug 2013 18:45:16 +0200
parents 7efabe0cddcf
children
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 /*
534
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
2 * Copyright (c) 2010-2013 TMate Software Ltd
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
4 * This program is free software; you can redistribute it and/or modify
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
5 * it under the terms of the GNU General Public License as published by
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
6 * the Free Software Foundation; version 2 of the License.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
8 * This program is distributed in the hope that it will be useful,
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
13 * For information on how to redistribute this software under
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 88
diff changeset
15 * contact TMate Software at support@hg4j.com
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
17 package org.tmatesoft.hg.repo;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.*;
456
909306e412e2 Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 437
diff changeset
20 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn;
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
21
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
22 import java.io.IOException;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
23 import java.nio.ByteBuffer;
317
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
24 import java.util.ArrayList;
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
25 import java.util.Arrays;
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
26 import java.util.List;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
27
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
28 import org.tmatesoft.hg.core.Nodeid;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
29 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
30 import org.tmatesoft.hg.internal.Experimental;
448
2e402c12ebc6 Issue 31: Revlog#walk() fails with AIOOBE when start > 0
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
31 import org.tmatesoft.hg.internal.IntMap;
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
32 import org.tmatesoft.hg.internal.Preview;
600
46f29b73e51e Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
33 import org.tmatesoft.hg.internal.RevisionLookup;
695
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
34 import org.tmatesoft.hg.internal.RevlogDelegate;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
35 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
36 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>
parents: 51 135
diff changeset
37 import org.tmatesoft.hg.util.ByteChannel;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
38 import org.tmatesoft.hg.util.CancelSupport;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
39 import org.tmatesoft.hg.util.CancelledException;
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
40 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>
parents: 51 135
diff changeset
41 import org.tmatesoft.hg.util.ProgressSupport;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
42
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
43
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 /**
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
45 * Base class for all Mercurial entities that are serialized in a so called revlog format (changelog, manifest, data files).
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
46 *
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
47 * Implementation note:
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
48 * Hides actual actual revlog stream implementation and its access methods (i.e. RevlogStream.Inspector), iow shall not expose anything internal
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
49 * in public methods.
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
50 *
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
51 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
52 * @author TMate Software Ltd.
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
54 abstract class Revlog {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
56 private final HgRepository repo;
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
57 protected final RevlogStream content;
600
46f29b73e51e Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
58 protected final boolean useRevisionLookup;
46f29b73e51e Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
59 protected RevisionLookup revisionLookup;
607
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
60 private final RevlogStream.Observer revisionLookupCleaner;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
600
46f29b73e51e Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
62 protected Revlog(HgRepository hgRepo, RevlogStream contentStream, boolean needRevisionLookup) {
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;
600
46f29b73e51e Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
71 useRevisionLookup = needRevisionLookup;
607
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
72 if (needRevisionLookup) {
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
73 revisionLookupCleaner = new RevlogStream.Observer() {
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
74
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
75 public void reloaded(RevlogStream src) {
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
76 revisionLookup = null;
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
77 }
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
78 };
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
79 } else {
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
80 revisionLookupCleaner = null;
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
81 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
82 }
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
83
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
84 // invalid Revlog
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
85 protected Revlog(HgRepository hgRepo) {
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
86 repo = hgRepo;
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
87 content = null;
600
46f29b73e51e Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
88 useRevisionLookup = false;
607
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
89 revisionLookupCleaner = null;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 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
93 return repo;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
96 /**
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
97 * @return total number of revisions kept in this revlog
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
98 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
99 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
100 */
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
101 public final int getRevisionCount() throws HgRuntimeException {
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
102 return content.revisionCount();
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
103 }
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
104
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
105 /**
534
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
106 * @return index of last known revision, a.k.a. {@link HgRepository#TIP}, or {@link HgRepository#NO_REVISION} if revlog is empty
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
107 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
108 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
109 */
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
110 public final int getLastRevision() throws HgRuntimeException {
534
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
111 // although old code gives correct result when revlog is empty (NO_REVISION deliberately == -1),
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
112 // it's still better to be explicit
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
113 int revCount = content.revisionCount();
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
114 return revCount == 0 ? NO_REVISION : revCount - 1;
135
3959bffb14e9 explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
115 }
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
116
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
117 /**
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
118 * 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
119 *
437
32184ddcf46d Better argument names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 433
diff changeset
120 * @param revisionIndex 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
121 * @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
122 *
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
123 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
124 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
125 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
126 */
437
32184ddcf46d Better argument names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 433
diff changeset
127 public final Nodeid getRevision(int revisionIndex) throws HgRuntimeException {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
128 // XXX cache nodeids? Rather, if context.getCache(this).getRevisionMap(create == false) != null, use it
437
32184ddcf46d Better argument names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 433
diff changeset
129 return Nodeid.fromBinary(content.nodeid(revisionIndex), 0);
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
130 }
317
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
131
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
132 /**
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
133 * Effective alternative to map few revision indexes to corresponding nodeids at once.
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
134 * <p>Note, there are few aspects to be careful about when using this method<ul>
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
135 * <li>ordering of the revisions in the return list is unspecified, it's likely won't match that of the method argument
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
136 * <li>supplied array get modified (sorted)</ul>
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
137 * @return list of mapped revisions in no particular order
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
138 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
139 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
140 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
141 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
142 public final List<Nodeid> getRevisions(int... revisions) throws HgRuntimeException {
317
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
143 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
144 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
145 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
146 return rv;
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
147 }
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
148
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
149 /*package-local*/ void getRevisionsInternal(final List<Nodeid> retVal, int[] sortedRevs) throws HgRuntimeException {
317
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
150 // 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
151 // 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
152 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
153
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
154 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
155 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
156 }
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
157 });
09628675bcee Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
158 }
37
e45e75e22523 Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 31
diff changeset
159
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
160 /**
368
8107b95f4280 Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
161 * 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
162 * 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
163 *
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
164 * For occasional queries, this method works with decent performance, despite its O(n/2) approach.
433
be697c3e951e Revlog.RevisionMap helper class got promoted as TLC, renamed to HgRevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 432
diff changeset
165 * Alternatively, if you need to perform multiple queries (e.g. at least 15-20), {@link HgRevisionMap} 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
166 *
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
167 * @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
168 * @return revision local index in this revlog
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
169 * @throws HgInvalidRevisionException if revision was not found in this revlog. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
170 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
171 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
172 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
173 public final int getRevisionIndex(Nodeid nid) throws HgRuntimeException {
604
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
174 final int revision = doFindWithCache(nid);
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
175 if (revision == BAD_REVISION) {
393
728708de3597 Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
176 // 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
177 // are fine with default (class name)
728708de3597 Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
178 // Perhaps, more tailored description method would be suitable here
728708de3597 Resolve FIXMEs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
179 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
180 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
181 return revision;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
182 }
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
183
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
184 private int doFindWithCache(Nodeid nid) throws HgRuntimeException {
604
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
185 if (useRevisionLookup) {
607
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
186 if (revisionLookup == null || content.shallDropDerivedCaches()) {
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
187 content.detach(revisionLookupCleaner);
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
188 setRevisionLookup(RevisionLookup.createFor(content));
604
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
189 }
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
190 return revisionLookup.findIndex(nid);
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
191 } else {
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
192 return content.findRevisionIndex(nid);
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
193 }
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
194 }
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
195
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
196 /**
607
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
197 * use selected helper for revision lookup, register appropriate listeners to clear cache on revlog changes
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
198 * @param rl not <code>null</code>
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
199 */
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
200 protected void setRevisionLookup(RevisionLookup rl) {
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
201 assert rl != null;
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
202 revisionLookup = rl;
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
203 content.attach(revisionLookupCleaner);
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
204 }
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
205
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 604
diff changeset
206 /**
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
207 * 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
208 *
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
209 * @param nodeid
419
7f136a3fa671 Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 418
diff changeset
210 * @return <code>true</code> if revision is part of this revlog
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
211 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
212 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
213 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
214 public final boolean isKnown(Nodeid nodeid) throws HgRuntimeException {
604
c3505001a42a Use nodeid reverse lookup speedup cache for #isKnown, if available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 601
diff changeset
215 final int rn = doFindWithCache(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
216 if (BAD_REVISION == rn) {
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
217 return false;
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
218 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
219 if (rn < 0 || rn >= content.revisionCount()) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
220 // 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
221 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
222 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
223 return true;
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
224 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
225
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
226 /**
394
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
227 * 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
228 *
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
229 * @param nodeid revision to retrieve
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
230 * @param sink data destination
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
231 *
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
232 * @see #rawContent(int, ByteChannel)
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
233 *
394
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
234 * @throws CancelledException if content retrieval operation was cancelled
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
235 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
236 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
237 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
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
238 */
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
239 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws CancelledException, HgRuntimeException {
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
240 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
241 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
242
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
243 /**
394
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
244 * 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
245 *
416
d30083c80d52 Better names - non-confusing and aligned with the rest of API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
246 * @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
247 * @param sink data destination
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
248 *
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
249 * @throws CancelledException if content retrieval operation was cancelled
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
250 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
251 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
252 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
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
253 */
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
254 protected void rawContent(int revisionIndex, ByteChannel sink) throws CancelledException, HgRuntimeException {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
255 if (sink == null) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
256 throw new IllegalArgumentException();
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
257 }
394
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
258 try {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 471
diff changeset
259 ContentPipe insp = new ContentPipe(sink, 0, repo.getSessionContext().getLog());
394
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
260 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
261 content.iterate(revisionIndex, revisionIndex, true, insp);
394
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
262 insp.checkFailed();
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
263 } 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
264 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
265 e.setRevisionIndex(revisionIndex);
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 607
diff changeset
266 // TODO [post 1.1] e.setFileName(content.getIndexFile() or this.getHumanFriendlyPath()) - shall decide whether
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
267 // 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
268 // Do the same (add file name) below
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
269 throw e;
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
270 } catch (HgInvalidControlFileException ex) {
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
271 throw ex.isRevisionIndexSet() ? ex : ex.setRevisionIndex(revisionIndex);
394
f52ca9530774 Resolve FIXMEs: more consistent exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 393
diff changeset
272 }
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
273 }
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
274
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
275 /**
405
866fc3b597a0 Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
276 * 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
277 *
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
278 * @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
279 * @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
280 * @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
281 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
282 * @throws IllegalArgumentException if passed arrays can't fit requested data
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
283 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
284 */
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
285 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) throws HgRuntimeException, IllegalArgumentException {
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
286 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
287 throw new HgInvalidRevisionException(revision);
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
288 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
289 if (parentRevisions == null || parentRevisions.length < 2) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
290 throw new IllegalArgumentException(String.valueOf(parentRevisions));
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
291 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
292 if (parent1 != null && parent1.length < 20) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
293 throw new IllegalArgumentException(parent1.toString());
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
294 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
295 if (parent2 != null && parent2.length < 20) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
296 throw new IllegalArgumentException(parent2.toString());
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
297 }
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
298 class ParentCollector implements RevlogStream.Inspector {
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
299 public int p1 = -1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
300 public int p2 = -1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
301 public byte[] nodeid;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
302
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
303 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
304 p1 = parent1Revision;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
305 p2 = parent2Revision;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
306 this.nodeid = new byte[20];
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
307 // 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
308 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
309 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
310 };
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
311 ParentCollector pc = new ParentCollector();
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
312 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
313 // 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
314 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
315 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
316 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
317 if (parentRevisions[0] == NO_REVISION) {
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
318 Arrays.fill(parent1, 0, 20, (byte) 0);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
319 } else {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
320 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
321 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
322 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
323 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
324 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
325 if (parentRevisions[1] == NO_REVISION) {
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
326 Arrays.fill(parent2, 0, 20, (byte) 0);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
327 } else {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
328 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
329 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
330 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
331 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
332 }
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
333
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
334 /**
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
335 * EXPERIMENTAL CODE, DO NOT USE
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
336 *
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
337 * Alternative revlog iteration
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
338 * There's an implicit ordering of inspectors. Less inspector needs, earlier its invocation occurs.
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
339 * E.g. ParentInspector goes after RevisionInspector. LinkRevisionInspector goes before RevisionInspector
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
340 *
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
341 * @param start
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
342 * @param end
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
343 * @param inspector
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
344 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
345 */
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
346 @Experimental
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456 448
diff changeset
347 public final void indexWalk(int start, int end, final Revlog.Inspector inspector) throws HgRuntimeException {
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
348 int lastRev = getLastRevision();
448
2e402c12ebc6 Issue 31: Revlog#walk() fails with AIOOBE when start > 0
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
349 final int _start = start == TIP ? lastRev : start;
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
350 if (end == TIP) {
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
351 end = lastRev;
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
352 }
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
353 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
354 final ParentInspector parentInsp = Adaptable.Factory.getAdapter(inspector, ParentInspector.class, null);
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
355 final LinkRevisionInspector linkRevInspector = Adaptable.Factory.getAdapter(inspector, LinkRevisionInspector.class, null);
695
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
356
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
357 // instantiate implementors in reverse order
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
358 RevlogDelegate head = parentInsp == null ? null : new ParentDelegate(parentInsp, null, _start, end);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
359 if (revisionInsp != null) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
360 head = new RevisionDelegate(revisionInsp, head);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
361 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
362 if (linkRevInspector != null) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
363 head = new LinkRevDelegate(linkRevInspector, head);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
364 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
365 // first to get notified is created last
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
366
695
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
367 assert head != null; // we know all subclasses of Revlog.Inspector
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
368 head.walk(getRepo(), content, _start, end);
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
369 }
695
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
370
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
371 /**
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
372 * MARKER
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
373 */
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
374 @Experimental
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
375 public interface Inspector {
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
376 }
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
377
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
378 @Experimental
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
379 public interface RevisionInspector extends Inspector {
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
380 void next(int revisionIndex, Nodeid revision, int linkedRevisionIndex) throws HgRuntimeException;
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
381 }
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
382
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
383 @Experimental
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
384 public interface LinkRevisionInspector extends Inspector {
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
385 void next(int revisionIndex, int linkedRevisionIndex) throws HgRuntimeException;
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
386 }
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
387
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 693
diff changeset
388 @Experimental
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
389 public interface ParentInspector extends Inspector {
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
390 // XXX document whether parentX is -1 or a constant (BAD_REVISION? or dedicated?)
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
391 void next(int revisionIndex, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) throws HgRuntimeException;
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
392 }
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 317
diff changeset
393
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
394 protected HgParentChildMap<? extends Revlog> getParentWalker() throws HgRuntimeException {
432
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
395 HgParentChildMap<Revlog> pw = new HgParentChildMap<Revlog>(this);
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
396 pw.init();
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
397 return pw;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
398 }
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
399
433
be697c3e951e Revlog.RevisionMap helper class got promoted as TLC, renamed to HgRevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 432
diff changeset
400 /*
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 607
diff changeset
401 * class with cancel and few other exceptions support.
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 607
diff changeset
402 * TODO [post-1.1] consider general superclass to share with e.g. HgManifestCommand.Mediator
243
0e01f9182e16 External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
403 */
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
404 protected abstract static class ErrorHandlingInspector implements RevlogStream.Inspector, CancelSupport {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
405 private Exception failure;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
406 private CancelSupport cancelSupport;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
407
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
408 protected void setCancelSupport(CancelSupport cs) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
409 assert cancelSupport == null; // no reason to set it twice
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
410 cancelSupport = cs;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
411 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
412
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
413 protected void recordFailure(Exception ex) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
414 assert failure == null;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
415 failure = ex;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
416 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
417
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
418 public void checkFailed() throws HgRuntimeException, IOException, CancelledException {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
419 if (failure == null) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
420 return;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
421 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
422 if (failure instanceof IOException) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
423 throw (IOException) failure;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
424 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
425 if (failure instanceof CancelledException) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
426 throw (CancelledException) failure;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
427 }
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
428 if (failure instanceof HgRuntimeException) {
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
429 throw (HgRuntimeException) failure;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
430 }
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
431 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>
parents: 51 135
diff changeset
432 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
433
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
434 public void checkCancelled() throws CancelledException {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
435 if (cancelSupport != null) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
436 cancelSupport.checkCancelled();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
437 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
438 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
439 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
440
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
441 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
442 private final ByteChannel sink;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
443 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
444 private final LogFacility logFacility;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
445
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
446 /**
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
447 * @param _sink - cannot be <code>null</code>
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
448 * @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
449 * @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
450 */
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
451 public ContentPipe(ByteChannel _sink, int seekOffset, LogFacility log) {
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
452 assert _sink != null;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
453 sink = _sink;
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
454 setCancelSupport(CancelSupport.Factory.get(_sink));
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
455 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
456 logFacility = log;
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
457 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
458
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
459 protected void prepare(int revisionNumber, DataAccess da) throws IOException {
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
460 if (offset > 0) { // save few useless reset/rewind operations
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
461 da.seek(offset);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
462 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
463 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
464
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
465 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
466 try {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
467 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
468 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
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 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
478 }
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
479 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
480 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
481 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
482 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
483 } 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
484 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
485 }
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
486 while (!da.isEmpty()) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
487 checkCancelled();
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
488 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
489 buf.flip(); // post: position == 0
277
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
490 // 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
491
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
492 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
493 if ((consumed == 0 || consumed != buf.position()) && logFacility != null) {
456
909306e412e2 Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 437
diff changeset
494 logFacility.dump(getClass(), Warn, "Bad data sink when reading revision %d. Reported %d bytes consumed, byt actually read %d", revisionNumber, consumed, buf.position());
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
495 }
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
496 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
497 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
498 }
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
499 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
500 progressSupport.worked(consumed);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
501 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
502 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
503 } catch (IOException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
504 recordFailure(ex);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
505 } catch (CancelledException ex) {
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
506 recordFailure(ex);
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
507 }
74e7493a042a Favor delegation over generalization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
508 }
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51 135
diff changeset
509 }
695
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
510
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
511
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
512 private static final class LinkRevDelegate extends RevlogDelegate {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
513 private final LinkRevisionInspector insp;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
514
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
515 public LinkRevDelegate(LinkRevisionInspector inspector, RevlogDelegate next) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
516 super(next);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
517 assert inspector != null;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
518 insp = inspector;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
519 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
520 @Override
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
521 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgRuntimeException {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
522 insp.next(revisionIndex, linkRevision);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
523 super.next(revisionIndex, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, nodeid, data);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
524 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
525 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
526
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
527 private static final class RevisionDelegate extends RevlogDelegate {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
528 private final RevisionInspector insp;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
529 public RevisionDelegate(RevisionInspector inspector, RevlogDelegate next) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
530 super(next);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
531 assert inspector != null;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
532 insp = inspector;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
533 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
534 @Override
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
535 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgRuntimeException {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
536 Nodeid nid = getRevision(nodeid);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
537 insp.next(revisionIndex, nid, linkRevision);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
538 super.next(revisionIndex, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, nodeid, data);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
539 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
540 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
541
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
542 private static class ParentDelegate extends RevlogDelegate {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
543 private final ParentInspector insp;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
544 private int i = 0;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
545 private final Nodeid[] allRevisions;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
546 // next are to build set of parent indexes that are not part of the range iteration
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
547 // i.e. those parents we need to read separately. See Issue 31 for details.
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
548 private final int[] firstParentIndexes;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
549 private final int[] secondParentIndexes;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
550 private final IntMap<Nodeid> missingParents;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
551 private final int start;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
552
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
553 public ParentDelegate(ParentInspector inspector, RevlogDelegate next, int _start, int end) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
554 super(next);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
555 insp = inspector;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
556 start = _start;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
557 allRevisions = new Nodeid[end - _start + 1];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
558 firstParentIndexes = _start == 0 ? null : new int[allRevisions.length];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
559 secondParentIndexes = _start == 0 ? null : new int[allRevisions.length];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
560 missingParents = _start == 0 ? null : new IntMap<Nodeid>(16);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
561 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
562 @Override
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
563 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1RevIndex, int parent2RevIndex, byte[] nodeid, DataAccess data) throws HgRuntimeException {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
564 allRevisions[i] = getRevision(nodeid);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
565 if (start > 0) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
566 // there are chances we don't know parents here,
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
567 // postpone parent dispatching for later, now just collect what's missing
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
568 firstParentIndexes[i] = parent1RevIndex;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
569 secondParentIndexes[i] = parent2RevIndex;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
570 if (parent1RevIndex < start && parent1RevIndex >= 0) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
571 missingParents.put(parent1RevIndex, null);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
572 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
573 if (parent2RevIndex < start && parent2RevIndex >= 0) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
574 missingParents.put(parent2RevIndex, null);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
575 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
576 } else {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
577 // we iterate from the very beginning, got every index we'll need
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
578 Nodeid p1 = parent1RevIndex == -1 ? Nodeid.NULL : allRevisions[parent1RevIndex];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
579 Nodeid p2 = parent2RevIndex == -1 ? Nodeid.NULL : allRevisions[parent2RevIndex];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
580 insp.next(revisionIndex, allRevisions[i], parent1RevIndex, parent2RevIndex, p1, p2);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
581 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
582 i++;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
583 super.next(revisionIndex, actualLen, baseRevision, linkRevision, parent1RevIndex, parent2RevIndex, nodeid, data);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
584 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
585
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
586 @Override
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
587 protected void postWalk(HgRepository hgRepo) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
588 if (start > 0) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
589 complete(hgRepo);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
590 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
591 super.postWalk(hgRepo);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
592 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
593
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
594 private void complete(HgRepository repo) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
595 if (missingParents.size() > 0) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
596 // it's possible to get empty missingParents when _start > 0 e.g. when n-th file revision
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
597 // is a copy of another file and hence got -1,-1 parents in this revlog, and we indexWalk(n,n)
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
598 for (int k = missingParents.firstKey(), l = missingParents.lastKey(); k <= l; k++) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
599 // TODO [post-1.1] int[] IntMap#keys() or even sort of iterator that can modify values
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
600 if (missingParents.containsKey(k)) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
601 Nodeid nid = repo.getChangelog().getRevision(k);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
602 missingParents.put(k, nid);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
603 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
604 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
605 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
606
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
607 for (int i = 0, revNum = start; i < allRevisions.length; i++, revNum++) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
608 int riP1 = firstParentIndexes[i];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
609 int riP2 = secondParentIndexes[i];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
610 Nodeid p1, p2;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
611 p1 = p2 = Nodeid.NULL;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
612 if (riP1 >= start) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
613 // p1 of revNum's revision is out of iterated range
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
614 // (don't check for riP1<end as I assume parents come prior to children in the changelog)
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
615 p1 = allRevisions[riP1 - start];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
616 } else if (riP1 != -1) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
617 assert riP1 >=0 && riP1 < start;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
618 p1 = missingParents.get(riP1);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
619 assert p1 != null;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
620 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
621 // same for Pp2
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
622 if (riP2 >= start) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
623 p2 = allRevisions[riP2 - start];
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
624 } else if (riP2 != -1) {
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
625 assert riP2 >= 0 && riP2 < start;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
626 p2 = missingParents.get(riP2);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
627 assert p2 != null;
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
628 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
629 insp.next(revNum, allRevisions[i], riP1, riP2, p1, p2);
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
630 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
631 }
053bb4397bf9 Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 694
diff changeset
632 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
633 }