Search in sources :

Example 1 with AbstractVcs

use of com.intellij.openapi.vcs.AbstractVcs in project intellij-community by JetBrains.

the class VcsCherryPickManager method getCherryPickerForCommit.

@Nullable
private VcsCherryPicker getCherryPickerForCommit(@NotNull VcsFullCommitDetails commitDetails) {
    AbstractVcs vcs = myProjectLevelVcsManager.getVcsFor(commitDetails.getRoot());
    if (vcs == null)
        return null;
    VcsKey key = vcs.getKeyInstanceMethod();
    return getCherryPickerFor(key);
}
Also used : VcsKey(com.intellij.openapi.vcs.VcsKey) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AbstractVcs

use of com.intellij.openapi.vcs.AbstractVcs in project intellij-community by JetBrains.

the class VcsRepositoryManager method findNewRoots.

@NotNull
private Map<VirtualFile, Repository> findNewRoots(@NotNull Set<VirtualFile> knownRoots) {
    Map<VirtualFile, Repository> newRootsMap = ContainerUtil.newHashMap();
    for (VcsRoot root : myVcsManager.getAllVcsRoots()) {
        VirtualFile rootPath = root.getPath();
        if (rootPath != null && !knownRoots.contains(rootPath)) {
            AbstractVcs vcs = root.getVcs();
            VcsRepositoryCreator repositoryCreator = getRepositoryCreator(vcs);
            if (repositoryCreator == null)
                continue;
            Repository repository = repositoryCreator.createRepositoryIfValid(rootPath);
            if (repository != null) {
                newRootsMap.put(rootPath, repository);
            }
        }
    }
    return newRootsMap;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsRoot(com.intellij.openapi.vcs.VcsRoot) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AbstractVcs

use of com.intellij.openapi.vcs.AbstractVcs in project intellij-community by JetBrains.

the class CommittedChangeListRenderer method renderChangeList.

public void renderChangeList(JComponent tree, CommittedChangeList changeList) {
    final Container parent = tree.getParent();
    final int rowX = getRowX(myTree, 2);
    int availableWidth = parent == null ? 100 : parent.getWidth() - rowX;
    final FontMetrics fontMetrics = tree.getFontMetrics(tree.getFont());
    final FontMetrics boldMetrics = tree.getFontMetrics(tree.getFont().deriveFont(Font.BOLD));
    final FontMetrics italicMetrics = tree.getFontMetrics(tree.getFont().deriveFont(Font.ITALIC));
    if (myDateWidth <= 0 || (fontMetrics.getFont().getSize() != myFontSize)) {
        myDateWidth = Math.max(fontMetrics.stringWidth(", Yesterday 00:00 PM "), fontMetrics.stringWidth(", 00/00/00 00:00 PM "));
        myDateWidth = Math.max(myDateWidth, fontMetrics.stringWidth(getDateOfChangeList(new Date(2000, 11, 31))));
        myFontSize = fontMetrics.getFont().getSize();
    }
    int dateCommitterSize = myDateWidth + boldMetrics.stringWidth(changeList.getCommitterName());
    final Pair<String, Boolean> descriptionInfo = getDescriptionOfChangeList(changeList.getName().trim());
    boolean truncated = descriptionInfo.getSecond().booleanValue();
    String description = descriptionInfo.getFirst();
    for (CommittedChangeListDecorator decorator : myDecorators) {
        final Icon icon = decorator.decorate(changeList);
        if (icon != null) {
            setIcon(icon);
        }
    }
    int descMaxWidth = availableWidth - dateCommitterSize - 8;
    boolean partial = (changeList instanceof ReceivedChangeList) && ((ReceivedChangeList) changeList).isPartial();
    int descWidth = 0;
    int partialMarkerWidth = 0;
    if (partial) {
        final String partialMarker = VcsBundle.message("committed.changes.partial.list") + " ";
        append(partialMarker, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        partialMarkerWidth = boldMetrics.stringWidth(partialMarker);
        descWidth += partialMarkerWidth;
    }
    descWidth += fontMetrics.stringWidth(description);
    int numberWidth = 0;
    final AbstractVcs vcs = changeList.getVcs();
    if (vcs != null) {
        final CachingCommittedChangesProvider provider = vcs.getCachingCommittedChangesProvider();
        if (provider != null && provider.getChangelistTitle() != null) {
            String number = "#" + changeList.getNumber() + "  ";
            numberWidth = fontMetrics.stringWidth(number);
            descWidth += numberWidth;
            append(number, SimpleTextAttributes.GRAY_ATTRIBUTES);
        }
    }
    int branchWidth = 0;
    String branch = changeList.getBranch();
    if (branch != null) {
        branch += " ";
        branchWidth = italicMetrics.stringWidth(branch);
        descWidth += branchWidth;
        append(branch, SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES);
    }
    if (description.isEmpty() && !truncated) {
        append(VcsBundle.message("committed.changes.empty.comment"), SimpleTextAttributes.GRAYED_ATTRIBUTES);
        appendTextPadding(descMaxWidth);
    } else if (descMaxWidth < 0) {
        myRenderer.appendTextWithLinks(description);
    } else if (descWidth < descMaxWidth && !truncated) {
        myRenderer.appendTextWithLinks(description);
        appendTextPadding(descMaxWidth);
    } else {
        final String moreMarker = VcsBundle.message("changes.browser.details.marker");
        int moreWidth = fontMetrics.stringWidth(moreMarker);
        int remainingWidth = descMaxWidth - moreWidth - numberWidth - branchWidth - partialMarkerWidth;
        description = truncateDescription(description, fontMetrics, remainingWidth);
        myRenderer.appendTextWithLinks(description);
        if (!StringUtil.isEmpty(description)) {
            append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
            append(moreMarker, SimpleTextAttributes.LINK_ATTRIBUTES, new CommittedChangesTreeBrowser.MoreLauncher(myProject, changeList));
        } else if (remainingWidth > 0) {
            append(moreMarker, SimpleTextAttributes.LINK_ATTRIBUTES, new CommittedChangesTreeBrowser.MoreLauncher(myProject, changeList));
        }
        // align value is for the latest added piece
        appendTextPadding(descMaxWidth);
    }
    append(changeList.getCommitterName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    if (changeList.getCommitDate() != null) {
        String date = ", " + getDateOfChangeList(changeList.getCommitDate());
        append(date, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
}
Also used : CachingCommittedChangesProvider(com.intellij.openapi.vcs.CachingCommittedChangesProvider) Date(java.util.Date) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 4 with AbstractVcs

use of com.intellij.openapi.vcs.AbstractVcs in project intellij-community by JetBrains.

the class ChangeDiffRequestProducer method createRequest.

@NotNull
private DiffRequest createRequest(@Nullable Project project, @NotNull Change change, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
    if (ChangesUtil.isTextConflictingChange(change)) {
        // three side diff
        // FIXME: This part is ugly as a VCS merge subsystem itself.
        FilePath path = ChangesUtil.getFilePath(change);
        VirtualFile file = path.getVirtualFile();
        if (file == null) {
            file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath());
        }
        if (file == null)
            throw new DiffRequestProducerException("Can't show merge conflict - file not found");
        if (project == null) {
            throw new DiffRequestProducerException("Can't show merge conflict - project is unknown");
        }
        final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, project);
        if (vcs == null || vcs.getMergeProvider() == null) {
            throw new DiffRequestProducerException("Can't show merge conflict - operation nos supported");
        }
        try {
            // FIXME: loadRevisions() can call runProcessWithProgressSynchronously() inside
            final Ref<Throwable> exceptionRef = new Ref<>();
            final Ref<MergeData> mergeDataRef = new Ref<>();
            final VirtualFile finalFile = file;
            ApplicationManager.getApplication().invokeAndWait(() -> {
                try {
                    mergeDataRef.set(vcs.getMergeProvider().loadRevisions(finalFile));
                } catch (VcsException e) {
                    exceptionRef.set(e);
                }
            });
            if (!exceptionRef.isNull()) {
                Throwable e = exceptionRef.get();
                if (e instanceof VcsException)
                    throw (VcsException) e;
                if (e instanceof Error)
                    throw (Error) e;
                if (e instanceof RuntimeException)
                    throw (RuntimeException) e;
                throw new RuntimeException(e);
            }
            MergeData mergeData = mergeDataRef.get();
            ContentRevision bRev = change.getBeforeRevision();
            ContentRevision aRev = change.getAfterRevision();
            String beforeRevisionTitle = getRevisionTitle(bRev, "Your version");
            String afterRevisionTitle = getRevisionTitle(aRev, "Server version");
            String title = DiffRequestFactory.getInstance().getTitle(file);
            List<String> titles = ContainerUtil.list(beforeRevisionTitle, "Base Version", afterRevisionTitle);
            DiffContentFactory contentFactory = DiffContentFactory.getInstance();
            List<DiffContent> contents = ContainerUtil.list(contentFactory.createFromBytes(project, mergeData.CURRENT, file), contentFactory.createFromBytes(project, mergeData.ORIGINAL, file), contentFactory.createFromBytes(project, mergeData.LAST, file));
            SimpleDiffRequest request = new SimpleDiffRequest(title, contents, titles);
            MergeUtil.putRevisionInfos(request, mergeData);
            return request;
        } catch (VcsException | IOException e) {
            LOG.info(e);
            throw new DiffRequestProducerException(e);
        }
    } else {
        ContentRevision bRev = change.getBeforeRevision();
        ContentRevision aRev = change.getAfterRevision();
        if (bRev == null && aRev == null) {
            LOG.warn("Both revision contents are empty");
            throw new DiffRequestProducerException("Bad revisions contents");
        }
        if (bRev != null)
            checkContentRevision(project, bRev, context, indicator);
        if (aRev != null)
            checkContentRevision(project, aRev, context, indicator);
        String title = getRequestTitle(change);
        indicator.setIndeterminate(true);
        DiffContent content1 = createContent(project, bRev, context, indicator);
        DiffContent content2 = createContent(project, aRev, context, indicator);
        final String userLeftRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_LEFT_CONTENT_TITLE);
        String beforeRevisionTitle = userLeftRevisionTitle != null ? userLeftRevisionTitle : getRevisionTitle(bRev, "Base version");
        final String userRightRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_RIGHT_CONTENT_TITLE);
        String afterRevisionTitle = userRightRevisionTitle != null ? userRightRevisionTitle : getRevisionTitle(aRev, "Your version");
        SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, beforeRevisionTitle, afterRevisionTitle);
        boolean bRevCurrent = bRev instanceof CurrentContentRevision;
        boolean aRevCurrent = aRev instanceof CurrentContentRevision;
        if (bRevCurrent && !aRevCurrent)
            request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.LEFT);
        if (!bRevCurrent && aRevCurrent)
            request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.RIGHT);
        return request;
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) DiffContentFactory(com.intellij.diff.DiffContentFactory) MergeData(com.intellij.openapi.vcs.merge.MergeData) IOException(java.io.IOException) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) Ref(com.intellij.openapi.util.Ref) VcsException(com.intellij.openapi.vcs.VcsException) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with AbstractVcs

use of com.intellij.openapi.vcs.AbstractVcs in project intellij-community by JetBrains.

the class BrowseChangesAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE);
    AbstractVcs vcs = notNull(getVcsForFile(file, project));
    CommittedChangesProvider provider = notNull(vcs.getCommittedChangesProvider());
    ChangeBrowserSettings settings = vcs.getConfiguration().CHANGE_BROWSER_SETTINGS.computeIfAbsent(vcs.getName(), key -> provider.createDefaultSettings());
    CommittedChangesFilterDialog dialog = new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
    if (dialog.showAndGet()) {
        showChanges(vcs, file, settings);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) CommittedChangesFilterDialog(com.intellij.openapi.vcs.changes.committed.CommittedChangesFilterDialog) CommittedChangesProvider(com.intellij.openapi.vcs.CommittedChangesProvider) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Aggregations

AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 NotNull (org.jetbrains.annotations.NotNull)12 Project (com.intellij.openapi.project.Project)9 FilePath (com.intellij.openapi.vcs.FilePath)7 VcsRoot (com.intellij.openapi.vcs.VcsRoot)7 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)6 Nullable (org.jetbrains.annotations.Nullable)5 Module (com.intellij.openapi.module.Module)3 VcsDirectoryMapping (com.intellij.openapi.vcs.VcsDirectoryMapping)3 VcsKey (com.intellij.openapi.vcs.VcsKey)3 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)3 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)3 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)3 Date (java.util.Date)3 Pair (com.intellij.openapi.util.Pair)2 VcsException (com.intellij.openapi.vcs.VcsException)2 DiffProvider (com.intellij.openapi.vcs.diff.DiffProvider)2 VcsHistorySession (com.intellij.openapi.vcs.history.VcsHistorySession)2 VcsLogProvider (com.intellij.vcs.log.VcsLogProvider)2