annotate src/com/tmate/hgkit/ll/Revlog.java @ 37:e45e75e22523

Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 14 Jan 2011 00:49:58 +0100
parents 346b66add79d
children 4e9b66b07a28
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
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
38 /**
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
39 * 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
40 * @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
41 */
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
42 public byte[] content(Nodeid 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
43 int revision = content.findLocalRevisionNumber(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
44 return content(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
45 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
46
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
47 /**
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
48 * @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
49 */
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
50 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
51 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
52 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
53 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
54 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
55 }
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
56 };
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
57 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
58 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
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
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
diff changeset
61 // 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
62 // 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
63 // 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
64 public interface Inspector {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
65 // 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
66 // 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
67 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
68 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
69
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
70 /*
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
71 * 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
72 * 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
73 * or
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
74 * 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
75 *
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
76 * 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
77 */
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
78 public final class ParentWalker {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
79 private Map<Nodeid, Nodeid> firstParent;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
80 private Map<Nodeid, Nodeid> secondParent;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
81 private Set<Nodeid> allNodes;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
82
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
83 public ParentWalker() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
84 firstParent = secondParent = Collections.emptyMap();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
85 allNodes = Collections.emptySet();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
86 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
87
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
88 public void init() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
89 final RevlogStream stream = Revlog.this.content;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
90 final int revisionCount = stream.revisionCount();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
91 firstParent = new HashMap<Nodeid, Nodeid>(revisionCount);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
92 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
93 allNodes = new LinkedHashSet<Nodeid>();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
94
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
95 Inspector insp = new Inspector() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
96 final Nodeid[] sequentialRevisionNodeids = new Nodeid[revisionCount];
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
97 int ix = 0;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
98 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
99 if (ix != revisionNumber) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
100 // 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
101 throw new IllegalStateException();
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 if (parent1Revision >= revisionNumber || parent2Revision >= revisionNumber) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
104 throw new IllegalStateException(); // sanity, revisions are sequential
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
105 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
106 final Nodeid nid = new Nodeid(nodeid, true);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
107 sequentialRevisionNodeids[ix++] = nid;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
108 allNodes.add(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
109 if (parent1Revision != -1) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
110 firstParent.put(nid, sequentialRevisionNodeids[parent1Revision]);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
111 if (parent2Revision != -1) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
112 secondParent.put(nid, sequentialRevisionNodeids[parent2Revision]);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
113 }
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 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
116 };
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
117 stream.iterate(0, -1, false, insp);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
118 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
119
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
120 public Set<Nodeid> allNodes() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
121 return Collections.unmodifiableSet(allNodes);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
122 }
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
123
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
124 // 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
125 public boolean knownNode(Nodeid nid) {
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
126 return allNodes.contains(nid);
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
127 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
128
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
129 // null if none
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
130 public Nodeid firstParent(Nodeid nid) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
131 return firstParent.get(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
132 }
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 public Nodeid secondParent(Nodeid nid) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
135 return secondParent.get(nid);
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
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
138 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
139 Nodeid p1 = firstParent(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
140 boolean modified = false;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
141 if (p1 != null) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
142 modified = c.add(p1);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
143 Nodeid p2 = secondParent(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
144 if (p2 != null) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
145 modified = c.add(p2) || modified;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
146 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
147 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
148 return modified;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
149 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
150 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 }