Search in sources :

Example 16 with Info

use of org.jetbrains.idea.svn.info.Info in project intellij-community by JetBrains.

the class BranchInfo method checkAlive.

@NotNull
private SvnMergeInfoCache.MergeCheckResult checkAlive(@NotNull SvnChangeList list, @NotNull String branchPath) {
    final Info info = myVcs.getInfo(new File(branchPath));
    if (info == null || info.getURL() == null || !SVNPathUtil.isAncestor(myBranch.getUrl(), info.getURL().toString())) {
        return SvnMergeInfoCache.MergeCheckResult.NOT_MERGED;
    }
    final String subPathUnderBranch = SVNPathUtil.getRelativePath(myBranch.getUrl(), info.getURL().toString());
    MultiMap<SvnMergeInfoCache.MergeCheckResult, String> result = checkPaths(list, branchPath, subPathUnderBranch);
    if (result.containsKey(SvnMergeInfoCache.MergeCheckResult.NOT_EXISTS)) {
        return SvnMergeInfoCache.MergeCheckResult.NOT_EXISTS;
    }
    if (result.containsKey(SvnMergeInfoCache.MergeCheckResult.NOT_MERGED)) {
        myPartlyMerged.put(list.getNumber(), result.get(SvnMergeInfoCache.MergeCheckResult.NOT_MERGED));
        return SvnMergeInfoCache.MergeCheckResult.NOT_MERGED;
    }
    return SvnMergeInfoCache.MergeCheckResult.MERGED;
}
Also used : Info(org.jetbrains.idea.svn.info.Info) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with Info

use of org.jetbrains.idea.svn.info.Info in project intellij-community by JetBrains.

the class BranchInfo method goUp.

@NotNull
private SvnMergeInfoCache.MergeCheckResult goUp(final long revisionAsked, final long targetRevision, final String branchRootPath, final String path, @NotNull String trunkUrl) throws SVNException, VcsException {
    SvnMergeInfoCache.MergeCheckResult result;
    String newTrunkUrl = SVNPathUtil.removeTail(trunkUrl).trim();
    if (newTrunkUrl.length() == 0 || "/".equals(newTrunkUrl)) {
        result = SvnMergeInfoCache.MergeCheckResult.NOT_MERGED;
    } else {
        String newPath = new File(path).getParent();
        if (newPath.length() < branchRootPath.length()) {
            // we are higher than WC root -> go into repo only
            if (targetRevision == -1) {
                // no paths in local copy
                result = SvnMergeInfoCache.MergeCheckResult.NOT_EXISTS;
            } else {
                Info svnInfo = myVcs.getInfo(new File(branchRootPath));
                result = svnInfo == null || svnInfo.getURL() == null ? SvnMergeInfoCache.MergeCheckResult.NOT_MERGED : goUpInRepo(revisionAsked, targetRevision, svnInfo.getURL().removePathTail(), newTrunkUrl);
            }
        } else {
            result = checkPathGoingUp(revisionAsked, targetRevision, branchRootPath, newPath, newTrunkUrl, false);
        }
    }
    return result;
}
Also used : Info(org.jetbrains.idea.svn.info.Info) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with Info

use of org.jetbrains.idea.svn.info.Info in project intellij-community by JetBrains.

the class SvnAnnotationProvider method annotate.

private FileAnnotation annotate(final VirtualFile file, final VcsFileRevision revision, final VcsRevisionNumber lastChangedRevision, final boolean loadExternally) throws VcsException {
    if (file.isDirectory()) {
        throw new VcsException(SvnBundle.message("exception.text.cannot.annotate.directory"));
    }
    final FileAnnotation[] annotation = new FileAnnotation[1];
    final VcsException[] exception = new VcsException[1];
    Runnable command = () -> {
        final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
        final File ioFile = virtualToIoFile(file).getAbsoluteFile();
        Info info = null;
        try {
            final String contents;
            if (loadExternally) {
                byte[] data = SvnUtil.getFileContents(myVcs, SvnTarget.fromFile(ioFile), SVNRevision.BASE, SVNRevision.UNDEFINED);
                contents = LoadTextUtil.getTextByBinaryPresentation(data, file, false, false).toString();
            } else {
                final byte[] bytes = VcsHistoryUtil.loadRevisionContent(revision);
                contents = LoadTextUtil.getTextByBinaryPresentation(bytes, file, false, false).toString();
            }
            final SvnFileAnnotation result = new SvnFileAnnotation(myVcs, file, contents, lastChangedRevision);
            info = myVcs.getInfo(ioFile);
            if (info == null) {
                exception[0] = new VcsException(new SVNException(SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "File ''{0}'' is not under version control", ioFile)));
                return;
            }
            final String url = info.getURL() == null ? null : info.getURL().toString();
            SVNRevision endRevision = ((SvnFileRevision) revision).getRevision();
            if (SVNRevision.WORKING.equals(endRevision)) {
                endRevision = info.getRevision();
            }
            if (progress != null) {
                progress.setText(SvnBundle.message("progress.text.computing.annotation", file.getName()));
            }
            // ignore mime type=true : IDEA-19562
            final AnnotationConsumer annotateHandler = createAnnotationHandler(progress, result);
            boolean calculateMergeinfo = myVcs.getSvnConfiguration().isShowMergeSourcesInAnnotate() && SvnUtil.checkRepositoryVersion15(myVcs, url);
            final MySteppedLogGetter logGetter = new MySteppedLogGetter(myVcs, ioFile, progress, myVcs.getFactory(ioFile).createHistoryClient(), endRevision, result, url, calculateMergeinfo, file.getCharset());
            logGetter.go();
            final LinkedList<SVNRevision> rp = logGetter.getRevisionPoints();
            // TODO: only 2 elements will be in rp and for loop will be executed only once - probably rewrite with Pair
            AnnotateClient annotateClient = myVcs.getFactory(ioFile).createAnnotateClient();
            for (int i = 0; i < rp.size() - 1; i++) {
                annotateClient.annotate(SvnTarget.fromFile(ioFile), rp.get(i + 1), rp.get(i), calculateMergeinfo, getLogClientOptions(myVcs), annotateHandler);
            }
            if (rp.get(1).getNumber() > 0) {
                result.setFirstRevision(rp.get(1));
            }
            annotation[0] = result;
        } catch (IOException e) {
            exception[0] = new VcsException(e);
        } catch (VcsException e) {
            if (e.getCause() instanceof SVNException) {
                handleSvnException(ioFile, info, (SVNException) e.getCause(), file, revision, annotation, exception);
            } else {
                exception[0] = e;
            }
        }
    };
    if (ApplicationManager.getApplication().isDispatchThread()) {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(command, SvnBundle.message("action.text.annotate"), false, myVcs.getProject());
    } else {
        command.run();
    }
    if (exception[0] != null) {
        throw new VcsException(exception[0]);
    }
    return annotation[0];
}
Also used : SVNException(org.tmatesoft.svn.core.SVNException) IOException(java.io.IOException) Info(org.jetbrains.idea.svn.info.Info) LinkedList(java.util.LinkedList) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 19 with Info

use of org.jetbrains.idea.svn.info.Info in project intellij-community by JetBrains.

the class RelocateAction method perform.

@Override
protected void perform(@NotNull SvnVcs vcs, @NotNull VirtualFile file, @NotNull DataContext context) throws VcsException {
    Info info = vcs.getInfo(file);
    assert info != null;
    RelocateDialog dlg = new RelocateDialog(vcs.getProject(), info.getURL());
    if (!dlg.showAndGet()) {
        return;
    }
    String beforeURL = dlg.getBeforeURL();
    String afterURL = dlg.getAfterURL();
    if (beforeURL.equals(afterURL))
        return;
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null) {
            indicator.setIndeterminate(true);
        }
        try {
            File path = VfsUtilCore.virtualToIoFile(file);
            vcs.getFactory(path).createRelocateClient().relocate(path, beforeURL, afterURL);
            VcsDirtyScopeManager.getInstance(vcs.getProject()).markEverythingDirty();
        } catch (VcsException e) {
            runOrInvokeLaterAboveProgress(() -> Messages.showErrorDialog(vcs.getProject(), "Error relocating working copy: " + e.getMessage(), "Relocate Working Copy"), null, vcs.getProject());
        }
    }, "Relocating Working Copy", false, vcs.getProject());
}
Also used : RelocateDialog(org.jetbrains.idea.svn.dialogs.RelocateDialog) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) Info(org.jetbrains.idea.svn.info.Info) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 20 with Info

use of org.jetbrains.idea.svn.info.Info in project intellij-community by JetBrains.

the class SvnResolveTreeAcceptVariantsTest method testTheirsFull.

@Test
public void testTheirsFull() throws Exception {
    int cnt = 0;
    myWorkingCopyDir = createDirInCommand(myWorkingCopyDir, "test--");
    myTheirs = createDirInCommand(myTheirs, "theirs--");
    //final TreeConflictData.Data data = TreeConflictData.FileToFile.MINE_MOVE_THEIRS_ADD;
    for (final TreeConflictData.Data data : TreeConflictData.ourAll) {
        if (myTraceClient) {
            System.out.println("========= TEST " + getTestName(data) + " =========");
        }
        myWorkingCopyDir = createDirInCommand(myWorkingCopyDir.getParent(), "test" + cnt);
        myTheirs = createDirInCommand(myTheirs.getParent(), "theirs" + cnt);
        mySvnClientRunner.checkout(myRepoUrl, myTheirs);
        mySvnClientRunner.checkout(myRepoUrl, myWorkingCopyDir);
        createSubTree(data);
        final ConflictCreator creator = new ConflictCreator(myProject, myTheirs, myWorkingCopyDir, data, mySvnClientRunner);
        creator.create();
        myDirtyScopeManager.markEverythingDirty();
        myChangeListManager.ensureUpToDate(false);
        myDirtyScopeManager.markEverythingDirty();
        myChangeListManager.ensureUpToDate(false);
        final String conflictFile = data.getConflictFile();
        final File conflictIoFile = new File(myWorkingCopyDir.getPath(), conflictFile);
        final FilePath filePath = VcsUtil.getFilePath(conflictIoFile);
        final Change change = myChangeListManager.getChange(filePath);
        Assert.assertNotNull(change);
        Assert.assertTrue(change instanceof ConflictedSvnChange);
        final SvnRevisionNumber committedRevision = change.getBeforeRevision() != null ? (SvnRevisionNumber) change.getBeforeRevision().getRevisionNumber() : null;
        FilePath beforePath = null;
        if (change.isMoved() || change.isRenamed()) {
            beforePath = change.getBeforeRevision().getFile();
        }
        //SvnRevisionNumber committedRevision = new SvnRevisionNumber(SVNRevision.create(cnt * 2 + 1));
        final SvnTreeConflictResolver resolver = new SvnTreeConflictResolver(myVcs, filePath, beforePath);
        resolver.resolveSelectTheirsFull();
        myTheirs.refresh(false, true);
        myWorkingCopyDir.refresh(false, true);
        VfsUtil.processFileRecursivelyWithoutIgnored(myTheirs, file -> {
            final String relative = VfsUtil.getRelativePath(file, myTheirs, File.separatorChar);
            File workingFile = new File(myWorkingCopyDir.getPath(), relative);
            boolean exists = workingFile.exists();
            if (!exists) {
                String[] excluded = data.getExcludeFromToTheirsCheck();
                if (excluded != null && Arrays.asList(excluded).contains(relative)) {
                    return true;
                }
                Assert.assertTrue("Check failed for test: " + getTestName(data) + " and file: " + relative + " in: " + myWorkingCopyDir.getPath(), exists);
            }
            final File theirsFile = virtualToIoFile(file);
            Info theirsInfo = myVcs.getInfo(theirsFile);
            Info thisInfo = myVcs.getInfo(workingFile);
            if (theirsInfo != null) {
                Assert.assertEquals("Check failed for test: " + getTestName(data) + " and file: " + relative + " in: " + myWorkingCopyDir.getPath() + ", theirs: " + theirsInfo.getRevision().getNumber() + ", mine: " + thisInfo.getRevision().getNumber(), theirsInfo.getRevision().getNumber(), thisInfo.getRevision().getNumber());
                if (!theirsFile.isDirectory()) {
                    try {
                        final String workText = FileUtil.loadFile(workingFile);
                        final String theirsText = FileUtil.loadFile(theirsFile);
                        Assert.assertEquals(theirsText, workText);
                    } catch (IOException e) {
                        Assert.assertTrue(e.getMessage(), false);
                    }
                }
            }
            return true;
        });
        ++cnt;
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Change(com.intellij.openapi.vcs.changes.Change) IOException(java.io.IOException) Info(org.jetbrains.idea.svn.info.Info) SvnTreeConflictResolver(org.jetbrains.idea.svn.treeConflict.SvnTreeConflictResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Info (org.jetbrains.idea.svn.info.Info)32 File (java.io.File)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 VcsException (com.intellij.openapi.vcs.VcsException)6 NotNull (org.jetbrains.annotations.NotNull)6 SVNURL (org.tmatesoft.svn.core.SVNURL)6 SVNRevision (org.tmatesoft.svn.core.wc.SVNRevision)6 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)5 RootUrlInfo (org.jetbrains.idea.svn.RootUrlInfo)5 IOException (java.io.IOException)3 Nullable (org.jetbrains.annotations.Nullable)3 Test (org.junit.Test)3 SVNException (org.tmatesoft.svn.core.SVNException)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 FilePath (com.intellij.openapi.vcs.FilePath)2 ArrayList (java.util.ArrayList)2 SvnVcs (org.jetbrains.idea.svn.SvnVcs)2 SvnBindException (org.jetbrains.idea.svn.commandLine.SvnBindException)2 WCInfo (org.jetbrains.idea.svn.dialogs.WCInfo)2 SvnChangeList (org.jetbrains.idea.svn.history.SvnChangeList)2