Search in sources :

Example 1 with CommitId

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommitId(com.intellij.vcs.log.CommitId) List(java.util.List) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CommitId

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CommitId(com.intellij.vcs.log.CommitId) VcsLog(com.intellij.vcs.log.VcsLog) List(java.util.List)

Example 3 with CommitId

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommitId(com.intellij.vcs.log.CommitId) VcsLogProvider(com.intellij.vcs.log.VcsLogProvider) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Collection(java.util.Collection) Map(java.util.Map) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) MultiMap(com.intellij.util.containers.MultiMap) TIntIntHashMap(gnu.trove.TIntIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CommitId

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;
}
Also used : VcsShortCommitDetails(com.intellij.vcs.log.VcsShortCommitDetails) CommitId(com.intellij.vcs.log.CommitId) LoadingDetails(com.intellij.vcs.log.data.LoadingDetails) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CommitId

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);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) MouseEvent(java.awt.event.MouseEvent) CommitId(com.intellij.vcs.log.CommitId) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) List(java.util.List) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails)

Aggregations

CommitId (com.intellij.vcs.log.CommitId)11 Project (com.intellij.openapi.project.Project)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 VcsLog (com.intellij.vcs.log.VcsLog)4 FileHistoryUi (com.intellij.vcs.log.history.FileHistoryUi)3 List (java.util.List)3 NotNull (org.jetbrains.annotations.NotNull)3 FilePath (com.intellij.openapi.vcs.FilePath)1 ShowDiffContext (com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext)1 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)1 MultiMap (com.intellij.util.containers.MultiMap)1 Hash (com.intellij.vcs.log.Hash)1 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)1 VcsLogProvider (com.intellij.vcs.log.VcsLogProvider)1 VcsShortCommitDetails (com.intellij.vcs.log.VcsShortCommitDetails)1 LoadingDetails (com.intellij.vcs.log.data.LoadingDetails)1 GitRepository (git4idea.repo.GitRepository)1 TIntIntHashMap (gnu.trove.TIntIntHashMap)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1 MouseEvent (java.awt.event.MouseEvent)1