use of com.intellij.vcs.log.CommitId in project intellij-community by JetBrains.
the class VcsCherryPickAction method groupByRoot.
@NotNull
private static Map<VirtualFile, List<Hash>> groupByRoot(@NotNull List<CommitId> details) {
Map<VirtualFile, List<Hash>> result = ContainerUtil.newHashMap();
for (CommitId commit : details) {
List<Hash> hashes = result.get(commit.getRoot());
if (hashes == null) {
hashes = ContainerUtil.newArrayList();
result.put(commit.getRoot(), hashes);
}
hashes.add(commit.getHash());
}
return result;
}
use of com.intellij.vcs.log.CommitId in project intellij-community by JetBrains.
the class VcsCherryPickAction method update.
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setVisible(true);
final VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG);
Project project = e.getProject();
if (project == null) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
VcsCherryPickManager cherryPickManager = VcsCherryPickManager.getInstance(project);
List<VcsCherryPicker> cherryPickers = getActiveCherryPickersForProject(project);
if (log == null || cherryPickers.isEmpty()) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
List<CommitId> commits = VcsLogUtil.collectFirstPack(log.getSelectedCommits(), VcsLogUtil.MAX_SELECTED_COMMITS);
if (commits.isEmpty() || cherryPickManager.isCherryPickAlreadyStartedFor(commits)) {
e.getPresentation().setEnabled(false);
return;
}
final Map<VirtualFile, List<Hash>> groupedByRoot = groupByRoot(commits);
VcsCherryPicker activeCherryPicker = getActiveCherryPicker(cherryPickers, groupedByRoot.keySet());
String description = activeCherryPicker != null ? activeCherryPicker.getInfo(log, groupedByRoot) : SEVERAL_VCS_DESCRIPTION;
e.getPresentation().setEnabled(description == null);
e.getPresentation().setText(activeCherryPicker == null ? concatActionNamesForAllAvailable(cherryPickers) : activeCherryPicker.getActionTitle());
e.getPresentation().setDescription(description == null ? "" : description);
}
use of com.intellij.vcs.log.CommitId in project intellij-community by JetBrains.
the class AbstractDataGetter method preLoadCommitData.
@NotNull
public TIntObjectHashMap<T> preLoadCommitData(@NotNull TIntHashSet commits) throws VcsException {
TIntObjectHashMap<T> result = new TIntObjectHashMap<>();
final MultiMap<VirtualFile, String> rootsAndHashes = MultiMap.create();
commits.forEach(commit -> {
CommitId commitId = myStorage.getCommitId(commit);
if (commitId != null) {
rootsAndHashes.putValue(commitId.getRoot(), commitId.getHash().asString());
}
return true;
});
for (Map.Entry<VirtualFile, Collection<String>> entry : rootsAndHashes.entrySet()) {
VcsLogProvider logProvider = myLogProviders.get(entry.getKey());
if (logProvider != null) {
List<? extends T> details = readDetails(logProvider, entry.getKey(), ContainerUtil.newArrayList(entry.getValue()));
for (T data : details) {
int index = myStorage.getCommitIndex(data.getId(), data.getRoot());
result.put(index, data);
}
saveInCache(result);
} else {
LOG.error("No log provider for root " + entry.getKey().getPath() + ". All known log providers " + myLogProviders);
}
}
return result;
}
use of com.intellij.vcs.log.CommitId in project intellij-community by JetBrains.
the class GraphTableController method getArrowTooltipText.
@NotNull
private String getArrowTooltipText(int commit, @Nullable Integer row) {
VcsShortCommitDetails details;
if (row != null && row >= 0) {
// preload rows around the commit
details = myTable.getModel().getShortDetails(row);
} else {
// preload just the commit
details = myLogData.getMiniDetailsGetter().getCommitData(commit, Collections.singleton(commit));
}
String balloonText = "";
if (details instanceof LoadingDetails) {
CommitId commitId = myLogData.getCommitId(commit);
if (commitId != null) {
balloonText = "Jump to commit" + " " + commitId.getHash().toShortString();
if (myUi.isMultipleRoots()) {
balloonText += " in " + commitId.getRoot().getName();
}
}
} else {
balloonText = "Jump to <b>\"" + StringUtil.shortenTextWithEllipsis(details.getSubject(), 50, 0, "...") + "\"</b> by " + VcsUserUtil.getShortPresentation(details.getAuthor()) + CommitPanel.formatDateTime(details.getAuthorTime());
}
return balloonText;
}
use of com.intellij.vcs.log.CommitId in project intellij-community by JetBrains.
the class CompareRevisionsFromHistoryAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
FileHistoryUi ui = e.getRequiredData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH);
if (e.getInputEvent() instanceof MouseEvent && ui.getTable().isResizingColumns()) {
// disable action during columns resize
return;
}
VcsLogUtil.triggerUsage(e);
List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
if (commits.size() != 1 && commits.size() != 2)
return;
List<Integer> commitIds = ContainerUtil.map(commits, c -> ui.getLogData().getCommitIndex(c.getHash(), c.getRoot()));
ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIds, details -> {
if (details.size() == 2) {
VcsFileRevision newestRevision = ui.createRevision(details.get(0));
VcsFileRevision olderRevision = ui.createRevision(details.get(1));
if (olderRevision != null && newestRevision != null) {
myDiffHandler.showDiffForTwo(project, filePath, olderRevision, newestRevision);
}
} else if (details.size() == 1) {
VcsFullCommitDetails detail = ObjectUtils.notNull(ContainerUtil.getFirstItem(details));
List<Change> changes = ui.collectRelevantChanges(detail);
if (filePath.isDirectory()) {
VcsDiffUtil.showChangesDialog(project, "Changes in " + detail.getId().toShortString() + " for " + filePath.getName(), ContainerUtil.newArrayList(changes));
} else {
ShowDiffAction.showDiffForChange(project, changes, 0, new ShowDiffContext());
}
}
}, null);
}
Aggregations