Mercurial > hg4j
annotate src/com/tmate/hgkit/ll/Revlog.java @ 55:05829a70b30b
Status operation extracted into separate, cache-friendly class
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 17 Jan 2011 04:45:09 +0100 |
parents | 26e3eeaa3962 |
children | 9429c7bd1920 576d6e8a09f6 |
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 /* |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
21
diff
changeset
|
2 * Copyright (c) 2010, 2011 Artem Tikhomirov |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 */ |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 package com.tmate.hgkit.ll; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
6 import java.util.Collection; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
7 import java.util.Collections; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
8 import java.util.HashMap; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
9 import java.util.LinkedHashSet; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
10 import java.util.Map; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
11 import java.util.Set; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
12 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 /** |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * @author artem |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 public abstract class Revlog { |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 private final HgRepository hgRepo; |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
20 protected final RevlogStream content; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
22 protected Revlog(HgRepository hgRepo, RevlogStream content) { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 if (hgRepo == null) { |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 throw new NullPointerException(); |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 this.hgRepo = hgRepo; |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
27 this.content = content; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 public final HgRepository getRepo() { |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 return hgRepo; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
34 public int getRevisionCount() { |
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
35 return content.revisionCount(); |
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
36 } |
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
|
37 |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
38 public int getLocalRevisionNumber(Nodeid nid) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
39 int revision = content.findLocalRevisionNumber(nid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
40 if (revision == Integer.MIN_VALUE) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
41 throw new IllegalArgumentException(String.format("%s doesn't represent a revision of %s", nid.toString(), this /*XXX HgDataFile.getPath might be more suitable here*/)); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
42 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
43 return revision; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
44 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
45 |
39
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
46 // Till now, i follow approach that NULL nodeid is never part of revlog |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
47 public boolean isKnown(Nodeid nodeid) { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
48 final int rn = content.findLocalRevisionNumber(nodeid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
49 if (Integer.MIN_VALUE == rn) { |
39
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
50 return false; |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
51 } |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
52 if (rn < 0 || rn >= content.revisionCount()) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
53 // Sanity check |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
54 throw new IllegalStateException(); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
55 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
56 return true; |
39
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
57 } |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
58 |
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
|
59 /** |
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
|
60 * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries) |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
31
diff
changeset
|
61 * @param nodeid |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
31
diff
changeset
|
62 */ |
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
|
63 public byte[] content(Nodeid nodeid) { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
64 return content(getLocalRevisionNumber(nodeid)); |
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
|
65 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
66 |
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
|
67 /** |
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
|
68 * @param revision - repo-local index of this file change (not a changelog revision number!) |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
31
diff
changeset
|
69 */ |
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
|
70 public byte[] content(int revision) { |
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
|
71 final byte[][] dataPtr = new byte[1][]; |
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
|
72 Revlog.Inspector insp = new Revlog.Inspector() { |
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
|
73 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
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
|
74 dataPtr[0] = data; |
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
|
75 } |
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
|
76 }; |
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
|
77 content.iterate(revision, revision, true, insp); |
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
|
78 return dataPtr[0]; |
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
|
79 } |
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
|
80 |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
21
diff
changeset
|
81 // FIXME byte[] data might be too expensive, for few usecases it may be better to have intermediate Access object (when we don't need full data |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
21
diff
changeset
|
82 // instantly - e.g. calculate hash, or comparing two revisions |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
83 // XXX seems that RevlogStream is better place for this class. |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 public interface Inspector { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
85 // XXX boolean retVal to indicate whether to continue? |
24
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
86 // TODO specify nodeid and data length, and reuse policy (i.e. if revlog stream doesn't reuse nodeid[] for each call) |
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
87 void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*20*/] nodeid, byte[] data); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
89 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
90 /* |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
91 * XXX think over if it's better to do either: |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
92 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
93 * or |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
94 * add Revlog#getParentWalker(), static class, make cons() and #init package-local, and keep SoftReference to allow walker reuse. |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
95 * |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
96 * and yes, walker is not a proper name |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
97 */ |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
98 public final class ParentWalker { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
99 private Map<Nodeid, Nodeid> firstParent; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
100 private Map<Nodeid, Nodeid> secondParent; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
101 private Set<Nodeid> allNodes; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
102 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
103 public ParentWalker() { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
104 firstParent = secondParent = Collections.emptyMap(); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
105 allNodes = Collections.emptySet(); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
106 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
107 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
108 public void init() { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
109 final RevlogStream stream = Revlog.this.content; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
110 final int revisionCount = stream.revisionCount(); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
111 firstParent = new HashMap<Nodeid, Nodeid>(revisionCount); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
112 secondParent = new HashMap<Nodeid, Nodeid>(firstParent.size() >> 1); // assume branches/merges are less frequent |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
113 allNodes = new LinkedHashSet<Nodeid>(); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
114 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
115 Inspector insp = new Inspector() { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
116 final Nodeid[] sequentialRevisionNodeids = new Nodeid[revisionCount]; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
117 int ix = 0; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
118 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
119 if (ix != revisionNumber) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
120 // XXX temp code, just to make sure I understand what's going on here |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
121 throw new IllegalStateException(); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
122 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
123 if (parent1Revision >= revisionNumber || parent2Revision >= revisionNumber) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
124 throw new IllegalStateException(); // sanity, revisions are sequential |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
125 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
126 final Nodeid nid = new Nodeid(nodeid, true); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
127 sequentialRevisionNodeids[ix++] = nid; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
128 allNodes.add(nid); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
129 if (parent1Revision != -1) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
130 firstParent.put(nid, sequentialRevisionNodeids[parent1Revision]); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
131 if (parent2Revision != -1) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
132 secondParent.put(nid, sequentialRevisionNodeids[parent2Revision]); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
133 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
134 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
135 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
136 }; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
137 stream.iterate(0, -1, false, insp); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
138 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
139 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
140 public Set<Nodeid> allNodes() { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
141 return Collections.unmodifiableSet(allNodes); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
142 } |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
143 |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
144 // FIXME need to decide whether Nodeid(00 * 20) is always known or not |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
145 public boolean knownNode(Nodeid nid) { |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
146 return allNodes.contains(nid); |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
29
diff
changeset
|
147 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
148 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
149 // null if none |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
150 public Nodeid firstParent(Nodeid nid) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
151 return firstParent.get(nid); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
152 } |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
153 |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
154 // never null, Nodeid.NULL if none known |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
155 public Nodeid safeFirstParent(Nodeid nid) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
156 Nodeid rv = firstParent(nid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
157 return rv == null ? Nodeid.NULL : rv; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
158 } |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
159 |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
160 public Nodeid secondParent(Nodeid nid) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
161 return secondParent.get(nid); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
162 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
163 |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
164 public Nodeid safeSecondParent(Nodeid nid) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
165 Nodeid rv = secondParent(nid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
166 return rv == null ? Nodeid.NULL : rv; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
167 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
168 |
29
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
169 public boolean appendParentsOf(Nodeid nid, Collection<Nodeid> c) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
170 Nodeid p1 = firstParent(nid); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
171 boolean modified = false; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
172 if (p1 != null) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
173 modified = c.add(p1); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
174 Nodeid p2 = secondParent(nid); |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
175 if (p2 != null) { |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
176 modified = c.add(p2) || modified; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
177 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
178 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
179 return modified; |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
180 } |
6cce719bbb62
Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
181 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 } |