Search in sources :

Example 11 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 12 with FilePath

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

the class HgCheckinEnvironment method addFile.

private void addFile(Map<HgRepository, Set<HgFile>> result, ContentRevision contentRevision) {
    FilePath filePath = contentRevision.getFile();
    // try to find repository from hgFile from change: to be able commit sub repositories as expected
    HgRepository repo = HgUtil.getRepositoryForFile(myProject, contentRevision instanceof HgCurrentBinaryContentRevision ? ((HgCurrentBinaryContentRevision) contentRevision).getRepositoryRoot() : ChangesUtil.findValidParentAccurately(filePath));
    if (repo == null) {
        return;
    }
    Set<HgFile> hgFiles = result.get(repo);
    if (hgFiles == null) {
        hgFiles = new HashSet<>();
        result.put(repo, hgFiles);
    }
    hgFiles.add(new HgFile(repo.getRoot(), filePath));
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgCurrentBinaryContentRevision(org.zmlx.hg4idea.provider.HgCurrentBinaryContentRevision)

Example 13 with FilePath

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

the class HgLogProvider method getCommitsMatchingFilter.

@NotNull
@Override
public List<TimedVcsCommit> getCommitsMatchingFilter(@NotNull final VirtualFile root, @NotNull VcsLogFilterCollection filterCollection, int maxCount) throws VcsException {
    List<String> filterParameters = ContainerUtil.newArrayList();
    // branch filter and user filter may be used several times without delimiter
    VcsLogBranchFilter branchFilter = filterCollection.getBranchFilter();
    if (branchFilter != null) {
        HgRepository repository = myRepositoryManager.getRepositoryForRoot(root);
        if (repository == null) {
            LOG.error("Repository not found for root " + root);
            return Collections.emptyList();
        }
        Collection<String> branchNames = repository.getBranches().keySet();
        Collection<String> bookmarkNames = HgUtil.getNamesWithoutHashes(repository.getBookmarks());
        Collection<String> predefinedNames = ContainerUtil.list(TIP_REFERENCE);
        boolean atLeastOneBranchExists = false;
        for (String branchName : ContainerUtil.concat(branchNames, bookmarkNames, predefinedNames)) {
            if (branchFilter.matches(branchName)) {
                filterParameters.add(HgHistoryUtil.prepareParameter("branch", branchName));
                atLeastOneBranchExists = true;
            }
        }
        if (branchFilter.matches(HEAD_REFERENCE)) {
            filterParameters.add(HgHistoryUtil.prepareParameter("branch", "."));
            filterParameters.add("-r");
            //all ancestors for current revision;
            filterParameters.add("::.");
            atLeastOneBranchExists = true;
        }
        if (!atLeastOneBranchExists) {
            // no such branches => filter matches nothing
            return Collections.emptyList();
        }
    }
    if (filterCollection.getUserFilter() != null) {
        filterParameters.add("-r");
        String authorFilter = StringUtil.join(ContainerUtil.map(ContainerUtil.map(filterCollection.getUserFilter().getUsers(root), VcsUserUtil::toExactString), UserNameRegex.EXTENDED_INSTANCE), "|");
        filterParameters.add("user('re:" + authorFilter + "')");
    }
    if (filterCollection.getDateFilter() != null) {
        StringBuilder args = new StringBuilder();
        final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        filterParameters.add("-d");
        VcsLogDateFilter filter = filterCollection.getDateFilter();
        if (filter.getAfter() != null) {
            if (filter.getBefore() != null) {
                args.append(dateFormatter.format(filter.getAfter())).append(" to ").append(dateFormatter.format(filter.getBefore()));
            } else {
                args.append('>').append(dateFormatter.format(filter.getAfter()));
            }
        } else if (filter.getBefore() != null) {
            args.append('<').append(dateFormatter.format(filter.getBefore()));
        }
        filterParameters.add(args.toString());
    }
    if (filterCollection.getTextFilter() != null) {
        String textFilter = filterCollection.getTextFilter().getText();
        if (filterCollection.getTextFilter().isRegex()) {
            filterParameters.add("-r");
            filterParameters.add("grep(r'" + textFilter + "')");
        } else if (filterCollection.getTextFilter().matchesCase()) {
            filterParameters.add("-r");
            filterParameters.add("grep(r'" + StringUtil.escapeChars(textFilter, UserNameRegex.EXTENDED_REGEX_CHARS) + "')");
        } else {
            filterParameters.add(HgHistoryUtil.prepareParameter("keyword", textFilter));
        }
    }
    if (filterCollection.getStructureFilter() != null) {
        for (FilePath file : filterCollection.getStructureFilter().getFiles()) {
            filterParameters.add(file.getPath());
        }
    }
    return HgHistoryUtil.readAllHashes(myProject, root, Consumer.EMPTY_CONSUMER, filterParameters);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsUserUtil(com.intellij.vcs.log.util.VcsUserUtil) HgRepository(org.zmlx.hg4idea.repo.HgRepository) SimpleDateFormat(java.text.SimpleDateFormat) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with FilePath

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

the class HgHistoryUtil method getOriginalHgFile.

public static HgFile getOriginalHgFile(Project project, VirtualFile root) {
    HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
    if (project.isDisposed()) {
        return hgFile;
    }
    FilePath originalFileName = HgUtil.getOriginalFileName(hgFile.toFilePath(), ChangeListManager.getInstance(project));
    return new HgFile(hgFile.getRepo(), originalFileName);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath)

Example 15 with FilePath

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

the class HgHistoryProvider method getHistory.

public static List<HgFileRevision> getHistory(@NotNull FilePath filePath, @NotNull VirtualFile vcsRoot, @NotNull Project project, @Nullable HgRevisionNumber revisionNumber, int limit) {
    /*  The standard way to get history following renames is to call hg log --follow. However:
  1. It is broken in case of uncommitted rename (i.e. if the file is currently renamed in the working dir):
    in this case we use a special python template "follow(path)" which handles this case.
  2. We don't use this python "follow(path)" function for all cases, because it is fully supported only since hg 2.6,
   and it is a bit slower and possibly less reliable than plain --follow parameter.
  3. It doesn't work with "-r": in this case --follow is simply ignored (hg commit 24208:8b4b9ee6001a).
   As a workaround we could use the same follow(path) python, but this function requires current name of the file,
    which is unknown in case of "-r", and identifying it would be very slow.

    As a result we don't follow renames in annotate called from diff or from an old revision, which we can survive.
*/
    FilePath originalFilePath = HgUtil.getOriginalFileName(filePath, ChangeListManager.getInstance(project));
    if (revisionNumber == null && !filePath.isDirectory() && !filePath.equals(originalFilePath)) {
        // uncommitted renames detected
        return getHistoryForUncommittedRenamed(originalFilePath, vcsRoot, project, limit);
    }
    final HgLogCommand logCommand = new HgLogCommand(project);
    logCommand.setFollowCopies(!filePath.isDirectory());
    logCommand.setIncludeRemoved(true);
    List<String> args = new ArrayList<>();
    if (revisionNumber != null) {
        args.add("--rev");
        args.add("reverse(0::" + revisionNumber.getChangeset() + ")");
    }
    return logCommand.execute(new HgFile(vcsRoot, filePath), limit, false, args);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HgFile(org.zmlx.hg4idea.HgFile) ArrayList(java.util.ArrayList) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

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