Mercurial > jhg
comparison src/com/tmate/hgkit/ll/Revlog.java @ 56:576d6e8a09f6
Analog of 'hg status --change' command
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 17 Jan 2011 05:15:13 +0100 |
parents | 26e3eeaa3962 |
children |
comparison
equal
deleted
inserted
replaced
55:05829a70b30b | 56:576d6e8a09f6 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010, 2011 Artem Tikhomirov | 2 * Copyright (c) 2010, 2011 Artem Tikhomirov |
3 */ | 3 */ |
4 package com.tmate.hgkit.ll; | 4 package com.tmate.hgkit.ll; |
5 | 5 |
6 import static com.tmate.hgkit.ll.HgRepository.TIP; | |
7 | |
8 import java.util.Arrays; | |
6 import java.util.Collection; | 9 import java.util.Collection; |
7 import java.util.Collections; | 10 import java.util.Collections; |
8 import java.util.HashMap; | 11 import java.util.HashMap; |
9 import java.util.LinkedHashSet; | 12 import java.util.LinkedHashSet; |
10 import java.util.Map; | 13 import java.util.Map; |
74 dataPtr[0] = data; | 77 dataPtr[0] = data; |
75 } | 78 } |
76 }; | 79 }; |
77 content.iterate(revision, revision, true, insp); | 80 content.iterate(revision, revision, true, insp); |
78 return dataPtr[0]; | 81 return dataPtr[0]; |
82 } | |
83 | |
84 /** | |
85 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? | |
86 * | |
87 * @param revision - revision to query parents, or {@link HgRepository#TIP} | |
88 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1}) | |
89 * @param parent1 - byte[20] or null, if parent's nodeid is not needed | |
90 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed | |
91 * @return | |
92 */ | |
93 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) { | |
94 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) { | |
95 throw new IllegalArgumentException(String.valueOf(revision)); | |
96 } | |
97 if (parentRevisions == null || parentRevisions.length < 2) { | |
98 throw new IllegalArgumentException(String.valueOf(parentRevisions)); | |
99 } | |
100 if (parent1 != null && parent1.length < 20) { | |
101 throw new IllegalArgumentException(parent1.toString()); | |
102 } | |
103 if (parent2 != null && parent2.length < 20) { | |
104 throw new IllegalArgumentException(parent2.toString()); | |
105 } | |
106 class ParentCollector implements Revlog.Inspector { | |
107 public int p1 = -1; | |
108 public int p2 = -1; | |
109 public byte[] nodeid; | |
110 | |
111 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | |
112 p1 = parent1Revision; | |
113 p2 = parent2Revision; | |
114 this.nodeid = new byte[20]; | |
115 // nodeid arg now comes in 32 byte from (as in file format description), however upper 12 bytes are zeros. | |
116 System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20); | |
117 } | |
118 }; | |
119 ParentCollector pc = new ParentCollector(); | |
120 content.iterate(revision, revision, false, pc); | |
121 parentRevisions[0] = pc.p1; | |
122 parentRevisions[1] = pc.p2; | |
123 if (parent1 != null) { | |
124 if (parentRevisions[0] == -1) { | |
125 Arrays.fill(parent1, 0, 20, (byte) 0); | |
126 } else { | |
127 content.iterate(parentRevisions[0], parentRevisions[0], false, pc); | |
128 System.arraycopy(pc.nodeid, 0, parent1, 0, 20); | |
129 } | |
130 } | |
131 if (parent2 != null) { | |
132 if (parentRevisions[1] == -1) { | |
133 Arrays.fill(parent2, 0, 20, (byte) 0); | |
134 } else { | |
135 content.iterate(parentRevisions[1], parentRevisions[1], false, pc); | |
136 System.arraycopy(pc.nodeid, 0, parent2, 0, 20); | |
137 } | |
138 } | |
79 } | 139 } |
80 | 140 |
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 | 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 |
82 // instantly - e.g. calculate hash, or comparing two revisions | 142 // instantly - e.g. calculate hash, or comparing two revisions |
83 // XXX seems that RevlogStream is better place for this class. | 143 // XXX seems that RevlogStream is better place for this class. |