Mercurial > hg4j
comparison src/com/tmate/hgkit/ll/HgDataFile.java @ 17:571e1b2cc3f7
Query file for its parents. Demo of recently added ignore and digest support from within cat cmd
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 27 Dec 2010 01:43:08 +0100 |
parents | fc265ddeab26 |
children | e929cecae4e1 |
comparison
equal
deleted
inserted
replaced
16:254078595653 | 17:571e1b2cc3f7 |
---|---|
1 /** | 1 /* |
2 * Copyright (c) 2010 Artem Tikhomirov | 2 * Copyright (c) 2010 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; | 6 import static com.tmate.hgkit.ll.HgRepository.TIP; |
7 | |
8 import java.util.Arrays; | |
7 | 9 |
8 /** | 10 /** |
9 * Extends Revlog/uses RevlogStream? | 11 * Extends Revlog/uses RevlogStream? |
10 * ? name:HgFileNode? | 12 * ? name:HgFileNode? |
11 * @author artem | 13 * @author artem |
69 } | 71 } |
70 | 72 |
71 public void history(int start, int end, Changeset.Inspector i) { | 73 public void history(int start, int end, Changeset.Inspector i) { |
72 throw HgRepository.notImplemented(); | 74 throw HgRepository.notImplemented(); |
73 } | 75 } |
76 | |
77 /** | |
78 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? | |
79 * | |
80 * @param revision - revision to query parents, or {@link HgRepository#TIP} | |
81 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1}) | |
82 * @param parent1 - byte[20] or null, if parent's nodeid is not needed | |
83 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed | |
84 * @return | |
85 */ | |
86 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) { | |
87 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) { | |
88 throw new IllegalArgumentException(String.valueOf(revision)); | |
89 } | |
90 if (parentRevisions == null || parentRevisions.length < 2) { | |
91 throw new IllegalArgumentException(String.valueOf(parentRevisions)); | |
92 } | |
93 if (parent1 != null && parent1.length < 20) { | |
94 throw new IllegalArgumentException(parent1.toString()); | |
95 } | |
96 if (parent2 != null && parent2.length < 20) { | |
97 throw new IllegalArgumentException(parent2.toString()); | |
98 } | |
99 class ParentCollector implements Revlog.Inspector { | |
100 public int p1 = -1; | |
101 public int p2 = -1; | |
102 public byte[] nodeid; | |
103 | |
104 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | |
105 p1 = parent1Revision; | |
106 p2 = parent2Revision; | |
107 this.nodeid = new byte[20]; | |
108 // nodeid arg now comes in 32 byte from (as in file format description), however upper 12 bytes are zeros. | |
109 System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20); | |
110 } | |
111 }; | |
112 ParentCollector pc = new ParentCollector(); | |
113 content.iterate(revision, revision, false, pc); | |
114 parentRevisions[0] = pc.p1; | |
115 parentRevisions[1] = pc.p2; | |
116 if (parent1 != null) { | |
117 if (parentRevisions[0] == -1) { | |
118 Arrays.fill(parent1, 0, 20, (byte) 0); | |
119 } else { | |
120 content.iterate(parentRevisions[0], parentRevisions[0], false, pc); | |
121 System.arraycopy(pc.nodeid, 0, parent1, 0, 20); | |
122 } | |
123 } | |
124 if (parent2 != null) { | |
125 if (parentRevisions[1] == -1) { | |
126 Arrays.fill(parent2, 0, 20, (byte) 0); | |
127 } else { | |
128 content.iterate(parentRevisions[1], parentRevisions[1], false, pc); | |
129 System.arraycopy(pc.nodeid, 0, parent2, 0, 20); | |
130 } | |
131 } | |
132 } | |
74 } | 133 } |