comparison src/com/tmate/hgkit/ll/HgDataFile.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
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; 6 import static com.tmate.hgkit.ll.HgRepository.TIP;
7 7
8 import java.util.Arrays;
9 8
10 /** 9 /**
11 * Extends Revlog/uses RevlogStream?
12 * ? name:HgFileNode? 10 * ? name:HgFileNode?
13 * @author artem 11 * @author artem
14 */ 12 */
15 public class HgDataFile extends Revlog { 13 public class HgDataFile extends Revlog {
16 14
57 } 55 }
58 }; 56 };
59 content.iterate(start, end, false, insp); 57 content.iterate(start, end, false, insp);
60 getRepo().getChangelog().range(inspector, commitRevisions); 58 getRepo().getChangelog().range(inspector, commitRevisions);
61 } 59 }
62
63 /**
64 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query?
65 *
66 * @param revision - revision to query parents, or {@link HgRepository#TIP}
67 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1})
68 * @param parent1 - byte[20] or null, if parent's nodeid is not needed
69 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed
70 * @return
71 */
72 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) {
73 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) {
74 throw new IllegalArgumentException(String.valueOf(revision));
75 }
76 if (parentRevisions == null || parentRevisions.length < 2) {
77 throw new IllegalArgumentException(String.valueOf(parentRevisions));
78 }
79 if (parent1 != null && parent1.length < 20) {
80 throw new IllegalArgumentException(parent1.toString());
81 }
82 if (parent2 != null && parent2.length < 20) {
83 throw new IllegalArgumentException(parent2.toString());
84 }
85 class ParentCollector implements Revlog.Inspector {
86 public int p1 = -1;
87 public int p2 = -1;
88 public byte[] nodeid;
89
90 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
91 p1 = parent1Revision;
92 p2 = parent2Revision;
93 this.nodeid = new byte[20];
94 // nodeid arg now comes in 32 byte from (as in file format description), however upper 12 bytes are zeros.
95 System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20);
96 }
97 };
98 ParentCollector pc = new ParentCollector();
99 content.iterate(revision, revision, false, pc);
100 parentRevisions[0] = pc.p1;
101 parentRevisions[1] = pc.p2;
102 if (parent1 != null) {
103 if (parentRevisions[0] == -1) {
104 Arrays.fill(parent1, 0, 20, (byte) 0);
105 } else {
106 content.iterate(parentRevisions[0], parentRevisions[0], false, pc);
107 System.arraycopy(pc.nodeid, 0, parent1, 0, 20);
108 }
109 }
110 if (parent2 != null) {
111 if (parentRevisions[1] == -1) {
112 Arrays.fill(parent2, 0, 20, (byte) 0);
113 } else {
114 content.iterate(parentRevisions[1], parentRevisions[1], false, pc);
115 System.arraycopy(pc.nodeid, 0, parent2, 0, 20);
116 }
117 }
118 }
119 } 60 }