Search in sources :

Example 1 with CvsChangeList

use of com.intellij.cvsSupport2.changeBrowser.CvsChangeList in project intellij-community by JetBrains.

the class CvsCommittedChangesProvider method getOneList.

@Nullable
@Override
public Pair<CvsChangeList, FilePath> getOneList(VirtualFile file, final VcsRevisionNumber number) throws VcsException {
    final File ioFile = new File(file.getPath());
    final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(ioFile);
    final VirtualFile vcsRoot = ProjectLevelVcsManager.getInstance(myProject).getVcsRootFor(filePath);
    final CvsRepositoryLocation cvsLocation = getLocationFor(filePath);
    if (cvsLocation == null)
        return null;
    final String module = CvsUtil.getModuleName(vcsRoot);
    final CvsEnvironment connectionSettings = cvsLocation.getEnvironment();
    if (connectionSettings.isOffline()) {
        return null;
    }
    final CvsChangeListsBuilder builder = new CvsChangeListsBuilder(module, connectionSettings, myProject, vcsRoot);
    final Ref<CvsChangeList> result = new Ref<>();
    final LoadHistoryOperation operation = new LoadHistoryOperation(connectionSettings, wrapper -> {
        final List<Revision> revisions = wrapper.getRevisions();
        if (revisions.isEmpty())
            return;
        final RevisionWrapper revision = new RevisionWrapper(wrapper.getFile(), revisions.get(0), null);
        result.set(builder.addRevision(revision));
    }, cvsLocation.getModuleName(), number.asString());
    final CvsResult executionResult = operation.run(myProject);
    if (executionResult.isCanceled()) {
        throw new ProcessCanceledException();
    } else if (executionResult.hasErrors()) {
        throw executionResult.composeError();
    }
    if (result.isNull()) {
        return null;
    }
    final Date commitDate = result.get().getCommitDate();
    final CvsEnvironment rootConnectionSettings = CvsEntriesManager.getInstance().getCvsConnectionSettingsFor(vcsRoot);
    final long t = commitDate.getTime();
    final Date dateFrom = new Date(t - CvsChangeList.SUITABLE_DIFF);
    final Date dateTo = new Date(t + CvsChangeList.SUITABLE_DIFF);
    final LoadHistoryOperation operation2 = new LoadHistoryOperation(rootConnectionSettings, module, dateFrom, dateTo, wrapper -> {
        final List<RevisionWrapper> wrappers = builder.revisionWrappersFromLog(wrapper);
        if (wrappers != null) {
            for (RevisionWrapper revisionWrapper : wrappers) {
                if (result.get().containsFileRevision(revisionWrapper)) {
                    continue;
                }
                builder.addRevision(revisionWrapper);
            }
        }
    });
    final CvsResult cvsResult = operation2.run(myProject);
    if (cvsResult.hasErrors()) {
        throw cvsResult.composeError();
    }
    return Pair.create(result.get(), filePath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CvsResult(com.intellij.openapi.cvsIntegration.CvsResult) Ref(com.intellij.openapi.util.Ref) Revision(org.netbeans.lib.cvsclient.command.log.Revision) CvsEnvironment(com.intellij.cvsSupport2.connections.CvsEnvironment) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CvsChangeList

use of com.intellij.cvsSupport2.changeBrowser.CvsChangeList in project intellij-community by JetBrains.

the class CvsCommittedChangesProvider method isDifferentBranch.

private static boolean isDifferentBranch(final FilePath filePath, final CvsChangeList changeList) {
    final String localTag;
    final CvsEntriesManager cvsEntriesManager = CvsEntriesManager.getInstance();
    final VirtualFile parent = filePath.getVirtualFileParent();
    if (parent != null) {
        final Entry entry = cvsEntriesManager.getEntryFor(parent, filePath.getName());
        if (entry != null) {
            localTag = entry.getStickyTag();
        } else {
            localTag = getDirectoryTag(parent);
        }
    } else {
        final VirtualFile validParent = ChangesUtil.findValidParentAccurately(filePath);
        if (validParent == null)
            return false;
        localTag = getDirectoryTag(validParent);
    }
    final String remoteTag = changeList.getBranch();
    if (!Comparing.equal(localTag, remoteTag)) {
        if (LOG.isDebugEnabled())
            LOG.info(filePath + ": local tag " + localTag + ", remote tag " + remoteTag);
        return true;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Entry(org.netbeans.lib.cvsclient.admin.Entry) CvsEntriesManager(com.intellij.cvsSupport2.application.CvsEntriesManager)

Example 3 with CvsChangeList

use of com.intellij.cvsSupport2.changeBrowser.CvsChangeList in project intellij-community by JetBrains.

the class CvsCommittedChangesProvider method isChangeLocallyAvailable.

public boolean isChangeLocallyAvailable(final FilePath filePath, @Nullable VcsRevisionNumber localRevision, VcsRevisionNumber changeRevision, final CvsChangeList changeList) {
    if (localRevision instanceof CvsRevisionNumber && changeRevision instanceof CvsRevisionNumber) {
        final CvsRevisionNumber cvsLocalRevision = (CvsRevisionNumber) localRevision;
        final CvsRevisionNumber cvsChangeRevision = (CvsRevisionNumber) changeRevision;
        final int[] localSubRevisions = cvsLocalRevision.getSubRevisions();
        final int[] changeSubRevisions = cvsChangeRevision.getSubRevisions();
        if (localSubRevisions != null && changeSubRevisions != null) {
            if (localSubRevisions.length != changeSubRevisions.length) {
                // local is trunk, change is branch / vice versa
                return true;
            }
            for (int i = 2; i < localSubRevisions.length; i += 2) {
                if (localSubRevisions[i] != changeSubRevisions[i]) {
                    // local is one branch, change is a different branch
                    return true;
                }
            }
        }
    }
    return isDifferentBranch(filePath, changeList) || (localRevision != null && localRevision.compareTo(changeRevision) >= 0);
}
Also used : CvsRevisionNumber(com.intellij.cvsSupport2.history.CvsRevisionNumber)

Example 4 with CvsChangeList

use of com.intellij.cvsSupport2.changeBrowser.CvsChangeList in project intellij-community by JetBrains.

the class CvsCommittedChangesProvider method loadCommittedChanges.

public void loadCommittedChanges(ChangeBrowserSettings settings, RepositoryLocation location, int maxCount, final AsynchConsumer<CommittedChangeList> consumer) throws VcsException {
    try {
        final CvsRepositoryLocation cvsLocation = (CvsRepositoryLocation) location;
        final String module = cvsLocation.getModuleName();
        final CvsEnvironment connectionSettings = cvsLocation.getEnvironment();
        if (connectionSettings.isOffline()) {
            return;
        }
        final CvsChangeListsBuilder builder = new CvsChangeListsBuilder(module, connectionSettings, myProject, cvsLocation.getRootFile());
        final Date dateTo = settings.getDateBeforeFilter();
        Date dateFrom = settings.getDateAfterFilter();
        if (dateFrom == null) {
            final Calendar calendar = Calendar.getInstance();
            calendar.set(1970, Calendar.MARCH, 2);
            dateFrom = calendar.getTime();
        }
        final ChangeBrowserSettings.Filter filter = settings.createFilter();
        final Set<CvsChangeList> controlSet = new HashSet<>();
        final LoadHistoryOperation operation = new LoadHistoryOperation(connectionSettings, module, dateFrom, dateTo, wrapper -> {
            final List<RevisionWrapper> wrappers = builder.revisionWrappersFromLog(wrapper);
            if (wrappers != null) {
                for (RevisionWrapper revisionWrapper : wrappers) {
                    final CvsChangeList changeList = builder.addRevision(revisionWrapper);
                    if (controlSet.contains(changeList))
                        continue;
                    controlSet.add(changeList);
                    if (filter.accepts(changeList)) {
                        consumer.consume(changeList);
                    }
                }
            }
        });
        final CvsResult executionResult = operation.run(myProject);
        if (executionResult.isCanceled()) {
            throw new ProcessCanceledException();
        } else if (executionResult.hasErrors()) {
            throw executionResult.composeError();
        }
    } finally {
        consumer.finished();
    }
}
Also used : CvsResult(com.intellij.openapi.cvsIntegration.CvsResult) ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) CvsEnvironment(com.intellij.cvsSupport2.connections.CvsEnvironment) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

CvsEnvironment (com.intellij.cvsSupport2.connections.CvsEnvironment)2 CvsResult (com.intellij.openapi.cvsIntegration.CvsResult)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CvsEntriesManager (com.intellij.cvsSupport2.application.CvsEntriesManager)1 CvsRevisionNumber (com.intellij.cvsSupport2.history.CvsRevisionNumber)1 Ref (com.intellij.openapi.util.Ref)1 ChangeBrowserSettings (com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1 Entry (org.netbeans.lib.cvsclient.admin.Entry)1 Revision (org.netbeans.lib.cvsclient.command.log.Revision)1