comparison src/org/tmatesoft/hg/repo/HgDataFile.java @ 424:6437d261048a

Deprecated code removed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 28 Mar 2012 15:42:15 +0200
parents 9c9c442b5f2e
children 48f993aa2f41
comparison
equal deleted inserted replaced
423:9c9c442b5f2e 424:6437d261048a
26 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
27 import java.nio.channels.FileChannel; 27 import java.nio.channels.FileChannel;
28 import java.util.ArrayList; 28 import java.util.ArrayList;
29 import java.util.Arrays; 29 import java.util.Arrays;
30 import java.util.Collection; 30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.List;
33 31
34 import org.tmatesoft.hg.core.HgException; 32 import org.tmatesoft.hg.core.HgException;
35 import org.tmatesoft.hg.core.HgLogCommand;
36 import org.tmatesoft.hg.core.Nodeid; 33 import org.tmatesoft.hg.core.Nodeid;
37 import org.tmatesoft.hg.internal.DataAccess; 34 import org.tmatesoft.hg.internal.DataAccess;
38 import org.tmatesoft.hg.internal.FilterByteChannel; 35 import org.tmatesoft.hg.internal.FilterByteChannel;
39 import org.tmatesoft.hg.internal.FilterDataAccess; 36 import org.tmatesoft.hg.internal.FilterDataAccess;
40 import org.tmatesoft.hg.internal.IntMap; 37 import org.tmatesoft.hg.internal.IntMap;
103 throw ex.isRevisionSet() ? ex : ex.setRevision(nodeid); 100 throw ex.isRevisionSet() ? ex : ex.setRevision(nodeid);
104 } 101 }
105 } 102 }
106 103
107 /** 104 /**
108 * @deprecated Use {@link #getLength(Nodeid)} instead
109 */
110 @Deprecated
111 public int length(Nodeid nodeid) throws HgInvalidControlFileException, HgInvalidRevisionException {
112 return getLength(nodeid);
113 }
114
115 /**
116 * @param fileRevisionIndex - revision local index, non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense. 105 * @param fileRevisionIndex - revision local index, non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense.
117 * @return size of the file content at the revision identified by local revision number. 106 * @return size of the file content at the revision identified by local revision number.
118 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog (<em>runtime exception</em>) 107 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog (<em>runtime exception</em>)
119 * @throws HgInvalidControlFileException if access to revlog index/data entry failed 108 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
120 */ 109 */
144 return dataLen - metadata.dataOffset(fileRevisionIndex); 133 return dataLen - metadata.dataOffset(fileRevisionIndex);
145 } 134 }
146 return dataLen; 135 return dataLen;
147 } 136 }
148 137
149 /**
150 * @deprecated Use {@link #getLength(int)} instead
151 */
152 @Deprecated
153 public int length(int fileRevisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException {
154 return getLength(fileRevisionIndex);
155 }
156
157 /** 138 /**
158 * Reads content of the file from working directory. If file present in the working directory, its actual content without 139 * Reads content of the file from working directory. If file present in the working directory, its actual content without
159 * any filters is supplied through the sink. If file does not exist in the working dir, this method provides content of a file 140 * any filters is supplied through the sink. If file does not exist in the working dir, this method provides content of a file
160 * as if it would be refreshed in the working copy, i.e. its corresponding revision (according to dirstate) is read from the 141 * as if it would be refreshed in the working copy, i.e. its corresponding revision (according to dirstate) is read from the
161 * repository, and filters repo -> working copy get applied. 142 * repository, and filters repo -> working copy get applied.
324 HgInvalidControlFileException e = new HgInvalidControlFileException("Revision content access failed", ex, null); 305 HgInvalidControlFileException e = new HgInvalidControlFileException("Revision content access failed", ex, null);
325 throw content.initWithIndexFile(e).setFileName(getPath()).setRevisionIndex(fileRevisionIndex); 306 throw content.initWithIndexFile(e).setFileName(getPath()).setRevisionIndex(fileRevisionIndex);
326 } 307 }
327 } 308 }
328 309
329 private static class HistoryNode { 310 // FIXME is that still needed?
330 int changeset;
331 Nodeid cset;
332 HistoryNode parent1, parent2;
333 List<HistoryNode> children;
334
335 HistoryNode(int cs, HistoryNode p1, HistoryNode p2) {
336 changeset = cs;
337 parent1 = p1;
338 parent2 = p2;
339 if (p1 != null) {
340 p1.addChild(this);
341 }
342 if (p2 != null) {
343 p2.addChild(this);
344 }
345 }
346
347 Nodeid changesetRevision() {
348 assert cset != null : "we initialize all csets prior to use";
349 return cset;
350 }
351
352 void addChild(HistoryNode child) {
353 if (children == null) {
354 children = new ArrayList<HistoryNode>(2);
355 }
356 children.add(child);
357 }
358 }
359
360 /**
361 * @deprecated use {@link HgLogCommand#execute(org.tmatesoft.hg.core.HgChangesetTreeHandler)} instead
362 */
363 @Deprecated
364 public void history(HgChangelog.TreeInspector inspector) throws HgInvalidControlFileException{
365 final CancelSupport cancelSupport = CancelSupport.Factory.get(inspector);
366 try {
367 final boolean[] needsSorting = { false };
368 final HistoryNode[] completeHistory = new HistoryNode[getRevisionCount()];
369 final int[] commitRevisions = new int[completeHistory.length];
370 RevlogStream.Inspector insp = new RevlogStream.Inspector() {
371 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {
372 if (revisionNumber > 0) {
373 if (commitRevisions[revisionNumber-1] > linkRevision) {
374 needsSorting[0] = true;
375 }
376 }
377 commitRevisions[revisionNumber] = linkRevision;
378 HistoryNode p1 = null, p2 = null;
379 if (parent1Revision != -1) {
380 p1 = completeHistory[parent1Revision];
381 }
382 if (parent2Revision != -1) {
383 p2 = completeHistory[parent2Revision];
384 }
385 completeHistory[revisionNumber] = new HistoryNode(linkRevision, p1, p2);
386 }
387 };
388 content.iterate(0, getLastRevision(), false, insp);
389 cancelSupport.checkCancelled();
390 if (needsSorting[0]) {
391 Arrays.sort(commitRevisions);
392 }
393 // read changeset revisions at once (to avoid numerous changelog.getRevision reads)
394 // but just nodeids, not RawChangeset (changelog.iterate(data=false)
395 ArrayList<Nodeid> changesetRevisions = new ArrayList<Nodeid>(commitRevisions.length);
396 getRepo().getChangelog().getRevisionsInternal(changesetRevisions, commitRevisions);
397 cancelSupport.checkCancelled();
398 // assign them to corresponding HistoryNodes
399 for (int i = 0; i < completeHistory.length; i++ ) {
400 final HistoryNode n = completeHistory[i];
401 if (needsSorting[0]) {
402 int x = Arrays.binarySearch(commitRevisions, n.changeset);
403 assert x >= 0;
404 n.cset = changesetRevisions.get(x);
405 } else {
406 // commit revisions were not sorted, may use original index directly
407 n.cset = changesetRevisions.get(i);
408 }
409 }
410 cancelSupport.checkCancelled();
411 // XXX shall sort completeHistory according to changeset numbers?
412 for (int i = 0; i < completeHistory.length; i++ ) {
413 final HistoryNode n = completeHistory[i];
414 HistoryNode p;
415 Nodeid p1, p2;
416 if ((p = n.parent1) != null) {
417 p1 = p.changesetRevision();
418 } else {
419 p1 = Nodeid.NULL;
420 }
421 if ((p= n.parent2) != null) {
422 p2 = p.changesetRevision();
423 } else {
424 p2 = Nodeid.NULL;
425 }
426 final Pair<Nodeid, Nodeid> parentChangesets = new Pair<Nodeid, Nodeid>(p1, p2);
427 final List<Nodeid> childChangesets;
428 if (n.children == null) {
429 childChangesets = Collections.emptyList();
430 } else {
431 Nodeid[] revisions = new Nodeid[n.children.size()];
432 int j = 0;
433 for (HistoryNode hn : n.children) {
434 revisions[j++] = hn.changesetRevision();
435 }
436 childChangesets = Arrays.asList(revisions);
437 }
438 inspector.next(n.changesetRevision(), parentChangesets, childChangesets);
439 cancelSupport.checkCancelled();
440 }
441 } catch (CancelledException ex) {
442 return;
443 }
444 }
445
446 public void history(HgChangelog.Inspector inspector) throws HgInvalidControlFileException { 311 public void history(HgChangelog.Inspector inspector) throws HgInvalidControlFileException {
447 history(0, getLastRevision(), inspector); 312 history(0, getLastRevision(), inspector);
448 } 313 }
449 314
450 /** 315 /**
499 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog 364 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog
500 * @throws HgInvalidControlFileException if access to revlog index/data entry failed 365 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
501 */ 366 */
502 public int getChangesetRevisionIndex(int revision) throws HgInvalidControlFileException, HgInvalidRevisionException { 367 public int getChangesetRevisionIndex(int revision) throws HgInvalidControlFileException, HgInvalidRevisionException {
503 return content.linkRevision(revision); 368 return content.linkRevision(revision);
504 }
505 /**
506 * @deprecated use {@link #getChangesetRevisionIndex(int)} instead
507 */
508 @Deprecated
509 public int getChangesetLocalRevision(int revision) throws HgInvalidControlFileException, HgInvalidRevisionException {
510 return getChangesetRevisionIndex(revision);
511 } 369 }
512 370
513 /** 371 /**
514 * Complements {@link #getChangesetRevisionIndex(int)} to get changeset revision that corresponds to supplied file revision 372 * Complements {@link #getChangesetRevisionIndex(int)} to get changeset revision that corresponds to supplied file revision
515 * 373 *