Search in sources :

Example 26 with FilePath

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

the class SingleCommittedListProvider method searchFromHead.

// return changed path, if any
private FilePath searchFromHead(@NotNull SVNURL url) throws VcsException {
    final SvnCopyPathTracker pathTracker = new SvnCopyPathTracker(repositoryUrl.toDecodedString(), repositoryRelativeUrl);
    SvnTarget target = SvnTarget.fromURL(url);
    myVcs.getFactory(target).createHistoryClient().doLog(target, SVNRevision.HEAD, revisionBefore, false, true, false, 0, null, logEntry -> {
        checkDisposed();
        if (logEntry.getDate() != null) {
            pathTracker.accept(logEntry);
            if (logEntry.getRevision() == revisionBefore.getNumber()) {
                changeList[0] = createChangeList(logEntry);
            }
        }
    });
    FilePath path = pathTracker.getFilePath(myVcs);
    return path == null ? filePath : path;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) SvnTarget(org.tmatesoft.svn.core.wc2.SvnTarget)

Example 27 with FilePath

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

the class SvnChangeList method createLists.

private void createLists() {
    myListsHolder = new ChangesListCreationHelper();
    // key: copied-from
    final Map<String, ExternallyRenamedChange> copiedAddedChanges = new HashMap<>();
    correctBeforePaths();
    final List<String> copyDeleted = new ArrayList<>(myDeletedPaths);
    for (String path : myAddedPaths) {
        final Change addedChange;
        if (myCopiedAddedPaths.containsKey(path)) {
            final String copyTarget = myCopiedAddedPaths.get(path);
            if (copyDeleted.contains(copyTarget)) {
                addedChange = new ExternallyRenamedChange(myListsHolder.createRevisionLazily(copyTarget, true), myListsHolder.createRevisionLazily(path, false), copyTarget);
                addedChange.getMoveRelativePath(myVcs.getProject());
                ((ExternallyRenamedChange) addedChange).setCopied(false);
                copyDeleted.remove(copyTarget);
            } else {
                addedChange = new ExternallyRenamedChange(null, myListsHolder.createRevisionLazily(path, false), copyTarget);
            }
            copiedAddedChanges.put(copyTarget, (ExternallyRenamedChange) addedChange);
        } else {
            addedChange = new Change(null, myListsHolder.createRevisionLazily(path, false));
        }
        myListsHolder.add(path, addedChange);
    }
    for (String path : copyDeleted) {
        final Change deletedChange;
        if (copiedAddedChanges.containsKey(path)) {
            // seems never occurs any more
            final ExternallyRenamedChange addedChange = copiedAddedChanges.get(path);
            final FilePath source = addedChange.getAfterRevision().getFile();
            deletedChange = new ExternallyRenamedChange(myListsHolder.createDeletedItemRevision(path, true), null, path);
            ((ExternallyRenamedChange) deletedChange).setCopied(false);
            //noinspection ConstantConditions
            //addedChange.setRenamedOrMovedTarget(deletedChange.getBeforeRevision().getFile());
            //noinspection ConstantConditions
            ((ExternallyRenamedChange) deletedChange).setRenamedOrMovedTarget(source);
        } else {
            deletedChange = new Change(myListsHolder.createDeletedItemRevision(path, true), null);
        }
        myListsHolder.add(path, deletedChange);
    }
    for (String path : myChangedPaths) {
        boolean moveAndChange = false;
        final boolean replaced = myReplacedPaths.contains(path);
        // this piece: for copied-from (or moved) and further modified
        for (String addedPath : myAddedPaths) {
            String copyFromPath = myCopiedAddedPaths.get(addedPath);
            if ((copyFromPath != null) && (SVNPathUtil.isAncestor(addedPath, path))) {
                if (addedPath.length() < path.length()) {
                    final String relative = SVNPathUtil.getRelativePath(addedPath, path);
                    copyFromPath = SVNPathUtil.append(copyFromPath, relative);
                }
                final ExternallyRenamedChange renamedChange = new ExternallyRenamedChange(myListsHolder.createRevisionLazily(copyFromPath, true), myListsHolder.createRevisionLazily(path, false), copyFromPath);
                moveAndChange = true;
                renamedChange.getMoveRelativePath(myVcs.getProject());
                renamedChange.setIsReplaced(replaced);
                final ExternallyRenamedChange addedChange = copiedAddedChanges.get(myCopiedAddedPaths.get(addedPath));
                renamedChange.setCopied(addedChange != null && addedChange.isCopied());
                myListsHolder.add(path, renamedChange);
                break;
            }
        }
        if (!moveAndChange) {
            final ExternallyRenamedChange renamedChange = new ExternallyRenamedChange(myListsHolder.createRevisionLazily(path, true), myListsHolder.createRevisionLazily(path, false), null);
            renamedChange.setIsReplaced(replaced);
            renamedChange.setCopied(false);
            myListsHolder.add(path, renamedChange);
        }
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath)

Example 28 with FilePath

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

the class SvnChangeList method patchChange.

private void patchChange(Change change, final String path) {
    final SVNURL becameUrl;
    SVNURL wasUrl;
    try {
        becameUrl = SVNURL.parseURIEncoded(SVNPathUtil.append(myRepositoryRoot, path));
        wasUrl = becameUrl;
        if (change instanceof ExternallyRenamedChange && change.getBeforeRevision() != null) {
            String originUrl = ((ExternallyRenamedChange) change).getOriginUrl();
            if (originUrl != null) {
                // use another url for origin
                wasUrl = SVNURL.parseURIEncoded(SVNPathUtil.append(myRepositoryRoot, originUrl));
            }
        }
    } catch (SVNException e) {
        // nothing to do
        LOG.info(e);
        return;
    }
    final FilePath filePath = ChangesUtil.getFilePath(change);
    final Change additional = new Change(createPropertyRevision(filePath, change.getBeforeRevision(), wasUrl), createPropertyRevision(filePath, change.getAfterRevision(), becameUrl));
    change.addAdditionalLayerElement(SvnChangeProvider.PROPERTY_LAYER, additional);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) SVNURL(org.tmatesoft.svn.core.SVNURL) SVNException(org.tmatesoft.svn.core.SVNException)

Example 29 with FilePath

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

the class ChangeListTodosTreeStructure method accept.

@Override
public boolean accept(final PsiFile psiFile) {
    if (!psiFile.isValid())
        return false;
    VirtualFile file = psiFile.getVirtualFile();
    ChangeListManager listManager = ChangeListManager.getInstance(myProject);
    FileStatus status = listManager.getStatus(file);
    if (status == FileStatus.NOT_CHANGED)
        return false;
    FilePath filePath = VcsUtil.getFilePath(file);
    final Collection<Change> changes = listManager.getDefaultChangeList().getChanges();
    for (Change change : changes) {
        ContentRevision afterRevision = change.getAfterRevision();
        if (afterRevision != null && afterRevision.getFile().equals(filePath)) {
            return (myTodoFilter != null && myTodoFilter.accept(mySearchHelper, psiFile) || (myTodoFilter == null && mySearchHelper.getTodoItemsCount(psiFile) > 0));
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) FileStatus(com.intellij.openapi.vcs.FileStatus) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 30 with FilePath

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

the class DiffRequestFactoryImpl method getTitle.

@NotNull
public static String getTitle(@NotNull FilePath path1, @NotNull FilePath path2, @NotNull String separator) {
    if ((path1.isDirectory() || path2.isDirectory()) && path1.getPath().equals(path2.getPath())) {
        return path1.getPresentableUrl();
    }
    String name1 = path1.getName();
    String name2 = path2.getName();
    if (path1.isDirectory() ^ path2.isDirectory()) {
        if (path1.isDirectory())
            name1 += File.separatorChar;
        if (path2.isDirectory())
            name2 += File.separatorChar;
    }
    FilePath parent1 = path1.getParentPath();
    FilePath parent2 = path2.getParentPath();
    return getRequestTitle(name1, path1.getPresentableUrl(), parent1 != null ? parent1.getPresentableUrl() : null, name2, path2.getPresentableUrl(), parent2 != null ? parent2.getPresentableUrl() : null, separator);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FilePath (com.intellij.openapi.vcs.FilePath)167 VirtualFile (com.intellij.openapi.vfs.VirtualFile)68 NotNull (org.jetbrains.annotations.NotNull)43 VcsException (com.intellij.openapi.vcs.VcsException)34 File (java.io.File)30 Change (com.intellij.openapi.vcs.changes.Change)26 Nullable (org.jetbrains.annotations.Nullable)22 Project (com.intellij.openapi.project.Project)20 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)15 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)13 FileStatus (com.intellij.openapi.vcs.FileStatus)10 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)8 GitRepository (git4idea.repo.GitRepository)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Test (org.junit.Test)6 StringUtil (com.intellij.openapi.util.text.StringUtil)5 Logger (com.intellij.openapi.diagnostic.Logger)4