annotate src/com/tmate/hgkit/ll/Revlog.java @ 58:4cfc47bc14cc

Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 17 Jan 2011 23:01:19 +0100
parents 576d6e8a09f6
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 /*
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
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
6 import static com.tmate.hgkit.ll.HgRepository.TIP;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
7
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
8 import java.util.Arrays;
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
9 import java.util.Collection;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
10 import java.util.Collections;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
11 import java.util.HashMap;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
12 import java.util.LinkedHashSet;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
13 import java.util.Map;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
14 import java.util.Set;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
15
2
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 *
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18 * @author artem
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 */
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 public abstract class Revlog {
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 private final HgRepository hgRepo;
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
23 protected final RevlogStream content;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
25 protected Revlog(HgRepository hgRepo, RevlogStream content) {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 if (hgRepo == null) {
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 throw new NullPointerException();
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 this.hgRepo = hgRepo;
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
30 this.content = content;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 }
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 public final HgRepository getRepo() {
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 return hgRepo;
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
21
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
37 public int getRevisionCount() {
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
38 return content.revisionCount();
e929cecae4e1 Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
39 }
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
40
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
41 public int getLocalRevisionNumber(Nodeid nid) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
42 int revision = content.findLocalRevisionNumber(nid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
43 if (revision == Integer.MIN_VALUE) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
44 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
45 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
46 return revision;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
47 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
48
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
49 // 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
50 public boolean isKnown(Nodeid nodeid) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
51 final int rn = content.findLocalRevisionNumber(nodeid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
52 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
53 return false;
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
54 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
55 if (rn < 0 || rn >= content.revisionCount()) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
56 // Sanity check
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
57 throw new IllegalStateException();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
58 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
59 return true;
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
60 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
61
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
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 * 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
64 * @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
65 */
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
66 public byte[] content(Nodeid nodeid) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
67 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
68 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
69
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
70 /**
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 * @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
72 */
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 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
74 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
75 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
76 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
77 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
78 }
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 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
81 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
82 }
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
83
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
84 /**
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
85 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query?
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
86 *
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
87 * @param revision - revision to query parents, or {@link HgRepository#TIP}
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
88 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1})
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
89 * @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
90 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
91 * @return
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
92 */
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
93 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
94 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
95 throw new IllegalArgumentException(String.valueOf(revision));
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
96 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
97 if (parentRevisions == null || parentRevisions.length < 2) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
98 throw new IllegalArgumentException(String.valueOf(parentRevisions));
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
99 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
100 if (parent1 != null && parent1.length < 20) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
101 throw new IllegalArgumentException(parent1.toString());
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
102 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
103 if (parent2 != null && parent2.length < 20) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
104 throw new IllegalArgumentException(parent2.toString());
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
105 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
106 class ParentCollector implements Revlog.Inspector {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
107 public int p1 = -1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
108 public int p2 = -1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
109 public byte[] nodeid;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
110
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
111 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
112 p1 = parent1Revision;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
113 p2 = parent2Revision;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
114 this.nodeid = new byte[20];
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
115 // 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
116 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
117 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
118 };
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
119 ParentCollector pc = new ParentCollector();
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
120 content.iterate(revision, revision, false, pc);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
121 parentRevisions[0] = pc.p1;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
122 parentRevisions[1] = pc.p2;
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
123 if (parent1 != null) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
124 if (parentRevisions[0] == -1) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
125 Arrays.fill(parent1, 0, 20, (byte) 0);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
126 } else {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
127 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
128 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
129 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
130 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
131 if (parent2 != null) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
132 if (parentRevisions[1] == -1) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
133 Arrays.fill(parent2, 0, 20, (byte) 0);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
134 } else {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
135 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
136 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
137 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
138 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
139 }
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
140
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 21
diff changeset
141 // 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
142 // 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
143 // 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
144 public interface Inspector {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
145 // 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
146 // 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
147 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
148 }
29
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 /*
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
151 * 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
152 * 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
153 * or
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
154 * 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
155 *
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
156 * 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
157 */
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
158 public final class ParentWalker {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
159 private Map<Nodeid, Nodeid> firstParent;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
160 private Map<Nodeid, Nodeid> secondParent;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
161 private Set<Nodeid> allNodes;
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 public ParentWalker() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
164 firstParent = secondParent = Collections.emptyMap();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
165 allNodes = Collections.emptySet();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
166 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
167
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
168 public void init() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
169 final RevlogStream stream = Revlog.this.content;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
170 final int revisionCount = stream.revisionCount();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
171 firstParent = new HashMap<Nodeid, Nodeid>(revisionCount);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
172 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
173 allNodes = new LinkedHashSet<Nodeid>();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
174
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
175 Inspector insp = new Inspector() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
176 final Nodeid[] sequentialRevisionNodeids = new Nodeid[revisionCount];
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
177 int ix = 0;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
178 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
179 if (ix != revisionNumber) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
180 // 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
181 throw new IllegalStateException();
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
182 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
183 if (parent1Revision >= revisionNumber || parent2Revision >= revisionNumber) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
184 throw new IllegalStateException(); // sanity, revisions are sequential
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
185 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
186 final Nodeid nid = new Nodeid(nodeid, true);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
187 sequentialRevisionNodeids[ix++] = nid;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
188 allNodes.add(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
189 if (parent1Revision != -1) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
190 firstParent.put(nid, sequentialRevisionNodeids[parent1Revision]);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
191 if (parent2Revision != -1) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
192 secondParent.put(nid, sequentialRevisionNodeids[parent2Revision]);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
193 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
194 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
195 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
196 };
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
197 stream.iterate(0, -1, false, insp);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
198 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
199
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
200 public Set<Nodeid> allNodes() {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
201 return Collections.unmodifiableSet(allNodes);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
202 }
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
203
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
204 // 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
205 public boolean knownNode(Nodeid nid) {
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
206 return allNodes.contains(nid);
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 29
diff changeset
207 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
208
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
209 // null if none
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
210 public Nodeid firstParent(Nodeid nid) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
211 return firstParent.get(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
212 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
213
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
214 // 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
215 public Nodeid safeFirstParent(Nodeid nid) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
216 Nodeid rv = firstParent(nid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
217 return rv == null ? Nodeid.NULL : rv;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
218 }
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
219
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
220 public Nodeid secondParent(Nodeid nid) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
221 return secondParent.get(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
222 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
223
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
224 public Nodeid safeSecondParent(Nodeid nid) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
225 Nodeid rv = secondParent(nid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
226 return rv == null ? Nodeid.NULL : rv;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
227 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 39
diff changeset
228
29
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
229 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
230 Nodeid p1 = firstParent(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
231 boolean modified = false;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
232 if (p1 != null) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
233 modified = c.add(p1);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
234 Nodeid p2 = secondParent(nid);
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
235 if (p2 != null) {
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
236 modified = c.add(p2) || modified;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
237 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
238 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
239 return modified;
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
240 }
6cce719bbb62 Collector for nodes and their parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 24
diff changeset
241 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 }