[vcs-log] VcsLog.getSelectedCommits returns list of CommitIds instead of Hashes

This commit is contained in:
Julia Beliaeva
2016-01-14 19:25:48 +03:00
parent 47e26ece65
commit 1ee5b29520
13 changed files with 42 additions and 42 deletions
@@ -32,7 +32,7 @@ public interface VcsLog {
* Returns commits currently selected in the log.
*/
@NotNull
List<Hash> getSelectedCommits();
List<CommitId> getSelectedCommits();
/**
* Returns details of the selected commits if all of them have been loaded.
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.NotNull;
public interface VcsLogDataProvider {
@NotNull
Hash getHash(int commitIndex);
CommitId getCommitId(int commitIndex);
int getCommitIndex(@NotNull Hash hash, @NotNull VirtualFile root);
@@ -28,7 +28,7 @@ public interface VcsLogHashMap {
int getCommitIndex(@NotNull Hash hash, @NotNull VirtualFile root);
@NotNull
Hash getHash(int commitIndex);
CommitId getCommitId(int commitIndex);
/**
* Iterates over known commid id to find the first one which satisfies given condition.
@@ -88,7 +88,7 @@ abstract class AbstractDataGetter<T extends VcsShortCommitDetails> implements Di
@Nullable
public T getCommitData(int row, @NotNull GraphTableModel tableModel) {
assert EventQueue.isDispatchThread();
Integer hash = tableModel.getCommitIdAtRow(row);
Integer hash = tableModel.getIdAtRow(row);
T details = getFromCache(hash);
if (details != null) {
return details;
@@ -140,7 +140,7 @@ abstract class AbstractDataGetter<T extends VcsShortCommitDetails> implements Di
@Override
public Hash compute() {
return myHashMap.getHash(commitId);
return myHashMap.getCommitId(commitId).getHash();
}
}, taskNumber, root));
}
@@ -158,7 +158,7 @@ abstract class AbstractDataGetter<T extends VcsShortCommitDetails> implements Di
int below) {
MultiMap<VirtualFile, Integer> commits = MultiMap.create();
for (int row = Math.max(0, selectedRow - above); row < selectedRow + below && row < model.getRowCount(); row++) {
Integer hash = model.getCommitIdAtRow(row);
Integer hash = model.getIdAtRow(row);
VirtualFile root = model.getRoot(row);
commits.putValue(root, hash);
}
@@ -170,7 +170,7 @@ abstract class AbstractDataGetter<T extends VcsShortCommitDetails> implements Di
List<String> hashStrings = ContainerUtil.map(entry.getValue(), new Function<Integer, String>() {
@Override
public String fun(Integer commitId) {
return myHashMap.getHash(commitId).asString();
return myHashMap.getCommitId(commitId).getHash().asString();
}
});
List<? extends T> details = readDetails(myLogProviders.get(entry.getKey()), entry.getKey(), hashStrings);
@@ -55,7 +55,7 @@ public class DataPack {
@NotNull
@Override
public Hash fun(Integer commitIndex) {
return hashMap.getHash(commitIndex);
return hashMap.getCommitId(commitIndex).getHash();
}
};
GraphColorManagerImpl colorManager = new GraphColorManagerImpl(refsModel, hashGetter, getRefManagerMap(providers));
@@ -126,8 +126,8 @@ public class VcsLogDataHolder implements Disposable, VcsLogDataProvider {
@Override
@NotNull
public Hash getHash(int commitIndex) {
return myHashMap.getHash(commitIndex);
public CommitId getCommitId(int commitIndex) {
return myHashMap.getCommitId(commitIndex);
}
@Override
@@ -61,7 +61,7 @@ public class VcsLogHashMapImpl implements Disposable, VcsLogHashMap {
@NotNull
@Override
public Hash getHash(int commitIndex) {
public CommitId getCommitId(int commitIndex) {
throw new UnsupportedOperationException("Illegal access to empty hash map by index " + commitIndex);
}
@@ -125,7 +125,7 @@ public class VcsLogHashMapImpl implements Disposable, VcsLogHashMap {
}
@Nullable
private CommitId doGetHash(int index) throws IOException {
private CommitId doGetCommitId(int index) throws IOException {
return myPersistentEnumerator.valueOf(index);
}
@@ -145,13 +145,13 @@ public class VcsLogHashMapImpl implements Disposable, VcsLogHashMap {
@Override
@NotNull
public Hash getHash(int commitIndex) {
public CommitId getCommitId(int commitIndex) {
try {
CommitId commitId = doGetHash(commitIndex);
CommitId commitId = doGetCommitId(commitIndex);
if (commitId == null) {
throw new RuntimeException("Unknown commit index: " + commitIndex); // TODO this shouldn't happen => need to recreate the map
}
return commitId.getHash();
return commitId;
}
catch (IOException e) {
throw new RuntimeException(e); // TODO map is corrupted => need to recreate it
@@ -45,16 +45,16 @@ public class VcsLogImpl implements VcsLog {
@Override
@NotNull
public List<Hash> getSelectedCommits() {
List<Hash> hashes = ContainerUtil.newArrayList();
public List<CommitId> getSelectedCommits() {
List<CommitId> commitIds = ContainerUtil.newArrayList();
JBTable table = myUi.getTable();
for (int row : table.getSelectedRows()) {
Hash hash = ((GraphTableModel)table.getModel()).getHashAtRow(row);
if (hash != null) {
hashes.add(hash);
CommitId commitId = ((GraphTableModel)table.getModel()).getCommitIdAtRow(row);
if (commitId != null) {
commitIds.add(commitId);
}
}
return hashes;
return commitIds;
}
@NotNull
@@ -326,11 +326,11 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider {
}));
}
else if (VcsDataKeys.VCS_REVISION_NUMBERS == key) {
List<Hash> hashes = myUI.getVcsLog().getSelectedCommits();
sink.put(key, ArrayUtil.toObjectArray(ContainerUtil.map(hashes, new Function<Hash, VcsRevisionNumber>() {
List<CommitId> hashes = myUI.getVcsLog().getSelectedCommits();
sink.put(key, ArrayUtil.toObjectArray(ContainerUtil.map(hashes, new Function<CommitId, VcsRevisionNumber>() {
@Override
public VcsRevisionNumber fun(Hash hash) {
return convertToRevisionNumber(hash);
public VcsRevisionNumber fun(CommitId commitId) {
return convertToRevisionNumber(commitId.getHash());
}
}), VcsRevisionNumber.class));
}
@@ -61,7 +61,7 @@ public class GraphTableModel extends AbstractTableModel {
int head = myDataPack.getVisibleGraph().getRowInfo(rowIndex).getOneOfHeads();
Collection<VcsRef> refs = myDataPack.getRefsModel().refsToCommit(head);
if (refs.isEmpty()) {
LOG.error("No references pointing to head " + myDataHolder.getHash(head) + " identified for commit at row " + rowIndex,
LOG.error("No references pointing to head " + myDataHolder.getCommitId(head) + " identified for commit at row " + rowIndex,
new Attachment("details.txt", getErrorDetails()));
// take the first root: it is the right choice in one-repo case, though it will likely fail in multi-repo case
return myDataPack.getLogProviders().keySet().iterator().next();
@@ -76,7 +76,7 @@ public class GraphTableModel extends AbstractTableModel {
List<GraphCommit<Integer>> commits = myDataPack.getPermanentGraph().getAllCommits();
for (int i = 0; i < 100 && i < commits.size(); i++) {
GraphCommit<Integer> commit = commits.get(i);
sb.append(String.format("%s -> %s\n", myDataHolder.getHash(commit.getId()).toShortString(), getParents(commit)));
sb.append(String.format("%s -> %s\n", myDataHolder.getCommitId(commit.getId()).getHash().toShortString(), getParents(commit)));
}
sb.append("\nALL REFS:\n");
printRefs(sb, myDataPack.getRefsModel().getAllRefsByRoot());
@@ -88,7 +88,7 @@ public class GraphTableModel extends AbstractTableModel {
return StringUtil.join(commit.getParents(), new Function<Integer, String>() {
@Override
public String fun(Integer integer) {
return myDataHolder.getHash(integer).toShortString();
return myDataHolder.getCommitId(integer).getHash().toShortString();
}
}, ", ");
}
@@ -117,13 +117,13 @@ public class GraphTableModel extends AbstractTableModel {
}
@NotNull
public Integer getCommitIdAtRow(int row) {
public Integer getIdAtRow(int row) {
return myDataPack.getVisibleGraph().getRowInfo(row).getCommit();
}
@Nullable
public Hash getHashAtRow(int row) {
return myDataHolder.getHash(getCommitIdAtRow(row));
public CommitId getCommitIdAtRow(int row) {
return myDataHolder.getCommitId(getIdAtRow(row));
}
public int getRowOfCommit(@NotNull final Hash hash, @NotNull VirtualFile root) {
@@ -236,7 +236,7 @@ public class VcsLogRefresherTest extends VcsLogPlatformTest {
@NotNull
@Override
public Hash fun(Integer integer) {
return myDataHolder.getHash(integer);
return myDataHolder.getCommitId(integer).getHash();
}
};
return new TimedVcsCommitImpl(convertor.fun(commit.getId()), ContainerUtil.map(commit.getParents(), convertor),
@@ -116,7 +116,7 @@ class VisiblePackBuilderTest {
assertDoesNotContain(visibleGraph, 1)
}
private fun GraphCommit<Int>.toVcsCommit(map: VcsLogHashMap) = TimedVcsCommitImpl(map.getHash(this.getId()), map.getHashes(this.getParents()), 1)
private fun GraphCommit<Int>.toVcsCommit(map: VcsLogHashMap) = TimedVcsCommitImpl(map.getCommitId(this.getId()).hash, map.getHashes(this.getParents()), 1)
fun assertDoesNotContain(graph: VisibleGraph<Int>, id: Int) {
assertTrue(null == (1..graph.getVisibleCommitCount()).firstOrNull { graph.getRowInfo(it - 1).getCommit() == id })
@@ -130,16 +130,16 @@ class VisiblePackBuilderTest {
val data: HashMap<GraphCommit<Int>, Data>) {
val root: VirtualFile = MockVirtualFile("root")
val providers: Map<VirtualFile, TestVcsLogProvider> = mapOf(root to TestVcsLogProvider(root))
val hashMap = generateHashMap(commits.maxBy { it.getId() }!!.getId())
val hashMap = generateHashMap(commits.maxBy { it.getId() }!!.getId(), root)
fun build(filters: VcsLogFilterCollection): VisiblePack {
val refs = refs.mapTo(HashSet<VcsRef>(), {
VcsRefImpl(hashMap.getHash(it.commit), it.name, BRANCH_TYPE, root)
VcsRefImpl(hashMap.getCommitId(it.commit).hash, it.name, BRANCH_TYPE, root)
})
val dataPack = DataPack.build(commits, mapOf(root to refs), providers, hashMap, true)
val detailsCache = data.entries.map {
val hash = hashMap.getHash(it.key.getId())
val hash = hashMap.getCommitId(it.key.getId()).hash
val metadata = if (it.value.user == null)
null
else VcsCommitMetadataImpl(hash, hashMap.getHashes(it.key.getParents()), 1L, root, it.value.subject,
@@ -161,17 +161,17 @@ class VisiblePackBuilderTest {
return builder.build(dataPack, PermanentGraph.SortType.Normal, filters, CommitCountStage.INITIAL).first
}
fun generateHashMap(num: Int): VcsLogHashMap {
fun generateHashMap(num: Int, root: VirtualFile): VcsLogHashMap {
val map = HashMap<Hash, Int>()
for (i in 1..num) {
map.put(HashImpl.build(i.toString()), i)
}
return ConstantVcsLogHashMap(map)
return ConstantVcsLogHashMap(map, root)
}
}
fun VcsLogHashMap.getHashes(ids: List<Int>) = ids.map { getHash(it) }
fun VcsLogHashMap.getHashes(ids: List<Int>) = ids.map { getCommitId(it).hash }
fun noFilters(): VcsLogFilterCollection = VcsLogFilterCollectionImpl(null, null, null, null, null, null, null)
@@ -225,12 +225,12 @@ class VisiblePackBuilderTest {
fun done() = Graph(commits, refs, data)
}
class ConstantVcsLogHashMap(val map: Map<Hash, Int>) : VcsLogHashMap {
val reverseMap = map.entries.map { Pair(it.value, it.key) }.toMap()
class ConstantVcsLogHashMap(val map: Map<Hash, Int>, val root: VirtualFile) : VcsLogHashMap {
val reverseMap = map.entrySet().map { Pair(it.value, it.key) }.toMap()
override fun getCommitIndex(hash: Hash, root: VirtualFile) = map.get(hash)!!
override fun getHash(commitIndex: Int) = reverseMap.get(commitIndex)!!
override fun getCommitId(commitIndex: Int) = CommitId(reverseMap.get(commitIndex)!!, root)
override fun findCommitId(condition: Condition<CommitId>): CommitId? = throw UnsupportedOperationException()
}