comparison src/org/tmatesoft/hg/repo/HgDataFile.java @ 625:b4948b159ab1

Refactor internals of blame support, tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 21 May 2013 17:24:22 +0200
parents 99ad1e3a4e4d
children 6526d8adbc0f
comparison
equal deleted inserted replaced
624:507602cb4fb3 625:b4948b159ab1
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew;
20 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex; 19 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex;
21 import static org.tmatesoft.hg.repo.HgRepository.*; 20 import static org.tmatesoft.hg.repo.HgRepository.*;
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Info; 21 import static org.tmatesoft.hg.util.LogFacility.Severity.Info;
23 22
24 import java.io.File; 23 import java.io.File;
428 427
429 /** 428 /**
430 * mimic 'hg diff -r clogRevIndex1 -r clogRevIndex2' 429 * mimic 'hg diff -r clogRevIndex1 -r clogRevIndex2'
431 */ 430 */
432 public void diff(int clogRevIndex1, int clogRevIndex2, HgBlameInspector insp) throws HgCallbackTargetException { 431 public void diff(int clogRevIndex1, int clogRevIndex2, HgBlameInspector insp) throws HgCallbackTargetException {
433 // FIXME clogRevIndex1 and clogRevIndex2 may point to different files, need to decide whether to throw an exception
434 // or to attempt to look up correct file node (tricky)
435 int fileRevIndex1 = fileRevIndex(this, clogRevIndex1); 432 int fileRevIndex1 = fileRevIndex(this, clogRevIndex1);
436 int fileRevIndex2 = fileRevIndex(this, clogRevIndex2); 433 int fileRevIndex2 = fileRevIndex(this, clogRevIndex2);
437 BlameHelper bh = new BlameHelper(insp, 5); 434 BlameHelper bh = new BlameHelper(insp);
438 bh.useFileUpTo(this, clogRevIndex2); 435 bh.prepare(this, clogRevIndex1, clogRevIndex2);
439 bh.diff(fileRevIndex1, clogRevIndex1, fileRevIndex2, clogRevIndex2); 436 bh.diff(fileRevIndex1, clogRevIndex1, fileRevIndex2, clogRevIndex2);
440 } 437 }
441 438
442 /** 439 /**
443 * Walk file history up/down to revision at given changeset and report changes for each revision 440 * Walk file history up/down to revision at given changeset and report changes for each revision
461 } 458 }
462 HgInternals.checkRevlogRange(changelogRevIndexStart, changelogRevIndexEnd, lastRevision); 459 HgInternals.checkRevlogRange(changelogRevIndexStart, changelogRevIndexEnd, lastRevision);
463 if (!exists()) { 460 if (!exists()) {
464 return; 461 return;
465 } 462 }
466 FileHistory fileHistory = new FileHistory(this, changelogRevIndexStart, changelogRevIndexEnd); 463 BlameHelper bh = new BlameHelper(insp);
467 fileHistory.build(); 464 FileHistory fileHistory = bh.prepare(this, changelogRevIndexStart, changelogRevIndexEnd);
468 BlameHelper bh = new BlameHelper(insp, 10); 465
469 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(OldToNew)) {
470 // iteration order is not important here
471 bh.useFileUpTo(fhc.getFile(), fhc.getEndChangeset());
472 }
473 int[] fileClogParentRevs = new int[2]; 466 int[] fileClogParentRevs = new int[2];
474 int[] fileParentRevs = new int[2]; 467 int[] fileParentRevs = new int[2];
475 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(iterateOrder)) { 468 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(iterateOrder)) {
476 for (int fri : fhc.fileRevisions(iterateOrder)) { 469 for (int fri : fhc.fileRevisions(iterateOrder)) {
477 int clogRevIndex = fhc.changeset(fri); 470 int clogRevIndex = fhc.changeset(fri);
496 int[] fileRevParents = new int[2]; 489 int[] fileRevParents = new int[2];
497 parents(fileRevIndex, fileRevParents, null, null); 490 parents(fileRevIndex, fileRevParents, null, null);
498 if (changelogRevisionIndex == TIP) { 491 if (changelogRevisionIndex == TIP) {
499 changelogRevisionIndex = getChangesetRevisionIndex(fileRevIndex); 492 changelogRevisionIndex = getChangesetRevisionIndex(fileRevIndex);
500 } 493 }
501 BlameHelper bh = new BlameHelper(insp, 5);
502 bh.useFileUpTo(this, changelogRevisionIndex);
503 int[] fileClogParentRevs = new int[2]; 494 int[] fileClogParentRevs = new int[2];
504 fileClogParentRevs[0] = fileRevParents[0] == NO_REVISION ? NO_REVISION : getChangesetRevisionIndex(fileRevParents[0]); 495 fileClogParentRevs[0] = fileRevParents[0] == NO_REVISION ? NO_REVISION : getChangesetRevisionIndex(fileRevParents[0]);
505 fileClogParentRevs[1] = fileRevParents[1] == NO_REVISION ? NO_REVISION : getChangesetRevisionIndex(fileRevParents[1]); 496 fileClogParentRevs[1] = fileRevParents[1] == NO_REVISION ? NO_REVISION : getChangesetRevisionIndex(fileRevParents[1]);
497 BlameHelper bh = new BlameHelper(insp);
498 int clogIndexStart = fileClogParentRevs[0] == NO_REVISION ? (fileClogParentRevs[1] == NO_REVISION ? 0 : fileClogParentRevs[1]) : fileClogParentRevs[0];
499 bh.prepare(this, clogIndexStart, changelogRevisionIndex);
506 bh.annotateChange(fileRevIndex, changelogRevisionIndex, fileRevParents, fileClogParentRevs); 500 bh.annotateChange(fileRevIndex, changelogRevisionIndex, fileRevParents, fileClogParentRevs);
507 } 501 }
508 502
509 @Override 503 @Override
510 public String toString() { 504 public String toString() {