Mercurial > hg4j
comparison src/org/tmatesoft/hg/core/HgLogCommand.java @ 596:43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Thu, 02 May 2013 19:23:53 +0200 |
| parents | e4ee4bf4c7d0 |
| children | 6526d8adbc0f |
comparison
equal
deleted
inserted
replaced
| 595:92c3ad9c2a51 | 596:43cfa08ff3fd |
|---|---|
| 28 import java.util.Comparator; | 28 import java.util.Comparator; |
| 29 import java.util.ConcurrentModificationException; | 29 import java.util.ConcurrentModificationException; |
| 30 import java.util.Iterator; | 30 import java.util.Iterator; |
| 31 import java.util.LinkedList; | 31 import java.util.LinkedList; |
| 32 import java.util.List; | 32 import java.util.List; |
| 33 import java.util.ListIterator; | |
| 34 import java.util.Set; | 33 import java.util.Set; |
| 35 import java.util.TreeSet; | 34 import java.util.TreeSet; |
| 36 | 35 |
| 37 import org.tmatesoft.hg.internal.AdapterPlug; | 36 import org.tmatesoft.hg.internal.AdapterPlug; |
| 38 import org.tmatesoft.hg.internal.BatchRangeHelper; | 37 import org.tmatesoft.hg.internal.BatchRangeHelper; |
| 40 import org.tmatesoft.hg.internal.IntMap; | 39 import org.tmatesoft.hg.internal.IntMap; |
| 41 import org.tmatesoft.hg.internal.IntVector; | 40 import org.tmatesoft.hg.internal.IntVector; |
| 42 import org.tmatesoft.hg.internal.Internals; | 41 import org.tmatesoft.hg.internal.Internals; |
| 43 import org.tmatesoft.hg.internal.Lifecycle; | 42 import org.tmatesoft.hg.internal.Lifecycle; |
| 44 import org.tmatesoft.hg.internal.LifecycleProxy; | 43 import org.tmatesoft.hg.internal.LifecycleProxy; |
| 44 import org.tmatesoft.hg.internal.ReverseIterator; | |
| 45 import org.tmatesoft.hg.repo.HgChangelog; | 45 import org.tmatesoft.hg.repo.HgChangelog; |
| 46 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 46 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
| 47 import org.tmatesoft.hg.repo.HgDataFile; | 47 import org.tmatesoft.hg.repo.HgDataFile; |
| 48 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | 48 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
| 49 import org.tmatesoft.hg.repo.HgInvalidStateException; | 49 import org.tmatesoft.hg.repo.HgInvalidStateException; |
| 444 public void next(int revisionIndex, Nodeid nodeid, RawChangeset cset) { | 444 public void next(int revisionIndex, Nodeid nodeid, RawChangeset cset) { |
| 445 batch.add(new BatchRecord(revisionIndex, nodeid, cset.clone())); | 445 batch.add(new BatchRecord(revisionIndex, nodeid, cset.clone())); |
| 446 } | 446 } |
| 447 | 447 |
| 448 public Iterable<BatchRecord> iterate(final boolean reverse) { | 448 public Iterable<BatchRecord> iterate(final boolean reverse) { |
| 449 return new Iterable<BatchRecord>() { | 449 return reverse ? ReverseIterator.reversed(batch) : batch; |
| 450 | |
| 451 public Iterator<BatchRecord> iterator() { | |
| 452 return reverse ? new ReverseIterator<BatchRecord>(batch) : batch.iterator(); | |
| 453 } | |
| 454 }; | |
| 455 } | 450 } |
| 456 | 451 |
| 457 // alternative would be dispatch(HgChangelog.Inspector) and dispatchReverse() | 452 // alternative would be dispatch(HgChangelog.Inspector) and dispatchReverse() |
| 458 // methods, but progress and cancellation might get messy then | 453 // methods, but progress and cancellation might get messy then |
| 459 } | 454 } |
| 561 } // for fileRenamesQueue; | 556 } // for fileRenamesQueue; |
| 562 frqBuilder.reportRenameIfNotInQueue(fileRenamesQueue, renameHandler); | 557 frqBuilder.reportRenameIfNotInQueue(fileRenamesQueue, renameHandler); |
| 563 progressHelper.done(); | 558 progressHelper.done(); |
| 564 } | 559 } |
| 565 | 560 |
| 566 private static class ReverseIterator<E> implements Iterator<E> { | |
| 567 private final ListIterator<E> listIterator; | |
| 568 | |
| 569 public ReverseIterator(List<E> list) { | |
| 570 listIterator = list.listIterator(list.size()); | |
| 571 } | |
| 572 | |
| 573 public boolean hasNext() { | |
| 574 return listIterator.hasPrevious(); | |
| 575 } | |
| 576 public E next() { | |
| 577 return listIterator.previous(); | |
| 578 } | |
| 579 public void remove() { | |
| 580 listIterator.remove(); | |
| 581 } | |
| 582 } | |
| 583 | |
| 584 /** | 561 /** |
| 585 * Utility to build sequence of file renames | 562 * Utility to build sequence of file renames |
| 586 */ | 563 */ |
| 587 private class FileRenameQueueBuilder { | 564 private class FileRenameQueueBuilder { |
| 588 | 565 |
