Search in sources :

Example 16 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgLogProvider method readAllRefs.

@NotNull
private Set<VcsRef> readAllRefs(@NotNull VirtualFile root) throws VcsException {
    if (myProject.isDisposed()) {
        return Collections.emptySet();
    }
    HgRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository not found for root " + root);
        return Collections.emptySet();
    }
    repository.update();
    Map<String, LinkedHashSet<Hash>> branches = repository.getBranches();
    Set<String> openedBranchNames = repository.getOpenedBranches();
    Collection<HgNameWithHashInfo> bookmarks = repository.getBookmarks();
    Collection<HgNameWithHashInfo> tags = repository.getTags();
    Collection<HgNameWithHashInfo> localTags = repository.getLocalTags();
    Collection<HgNameWithHashInfo> mqAppliedPatches = repository.getMQAppliedPatches();
    Set<VcsRef> refs = new HashSet<>(branches.size() + bookmarks.size());
    for (Map.Entry<String, LinkedHashSet<Hash>> entry : branches.entrySet()) {
        String branchName = entry.getKey();
        boolean opened = openedBranchNames.contains(branchName);
        for (Hash hash : entry.getValue()) {
            refs.add(myVcsObjectsFactory.createRef(hash, branchName, opened ? HgRefManager.BRANCH : HgRefManager.CLOSED_BRANCH, root));
        }
    }
    for (HgNameWithHashInfo bookmarkInfo : bookmarks) {
        refs.add(myVcsObjectsFactory.createRef(bookmarkInfo.getHash(), bookmarkInfo.getName(), HgRefManager.BOOKMARK, root));
    }
    String currentRevision = repository.getCurrentRevision();
    if (currentRevision != null) {
        // null => fresh repository
        refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(currentRevision), HEAD_REFERENCE, HgRefManager.HEAD, root));
    }
    String tipRevision = repository.getTipRevision();
    if (tipRevision != null) {
        // null => fresh repository
        refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(tipRevision), TIP_REFERENCE, HgRefManager.TIP, root));
    }
    for (HgNameWithHashInfo tagInfo : tags) {
        refs.add(myVcsObjectsFactory.createRef(tagInfo.getHash(), tagInfo.getName(), HgRefManager.TAG, root));
    }
    for (HgNameWithHashInfo localTagInfo : localTags) {
        refs.add(myVcsObjectsFactory.createRef(localTagInfo.getHash(), localTagInfo.getName(), HgRefManager.LOCAL_TAG, root));
    }
    for (HgNameWithHashInfo mqPatchRef : mqAppliedPatches) {
        refs.add(myVcsObjectsFactory.createRef(mqPatchRef.getHash(), mqPatchRef.getName(), HgRefManager.MQ_APPLIED_TAG, root));
    }
    return refs;
}
Also used : HgNameWithHashInfo(org.zmlx.hg4idea.HgNameWithHashInfo) HgRepository(org.zmlx.hg4idea.repo.HgRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgBranchUtil method getCommonBranches.

/**
   * Only common hg heavy branches
   */
@NotNull
public static List<String> getCommonBranches(@NotNull Collection<HgRepository> repositories) {
    Collection<String> commonBranches = null;
    for (HgRepository repository : repositories) {
        Collection<String> names = repository.getOpenedBranches();
        if (commonBranches == null) {
            commonBranches = names;
        } else {
            commonBranches = ContainerUtil.intersection(commonBranches, names);
        }
    }
    if (commonBranches != null) {
        ArrayList<String> common = new ArrayList<>(commonBranches);
        Collections.sort(common);
        return common;
    } else {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) HgRepository(org.zmlx.hg4idea.repo.HgRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgBranchUtil method getCommonBookmarks.

@NotNull
public static List<String> getCommonBookmarks(@NotNull Collection<HgRepository> repositories) {
    Collection<String> commonBookmarkNames = null;
    for (HgRepository repository : repositories) {
        Collection<HgNameWithHashInfo> bookmarksInfo = repository.getBookmarks();
        Collection<String> names = HgUtil.getSortedNamesWithoutHashes(bookmarksInfo);
        if (commonBookmarkNames == null) {
            commonBookmarkNames = names;
        } else {
            commonBookmarkNames = ContainerUtil.intersection(commonBookmarkNames, names);
        }
    }
    if (commonBookmarkNames != null) {
        ArrayList<String> common = new ArrayList<>(commonBookmarkNames);
        Collections.sort(common);
        return common;
    } else {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgNameWithHashInfo(org.zmlx.hg4idea.HgNameWithHashInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgChangeProvider method findChange.

@Nullable
private HgChange findChange(@NotNull HgRepository hgRepo, @NotNull HgNameWithHashInfo info) {
    File file = new File(hgRepo.getRoot().getPath(), info.getName());
    VirtualFile virtualSubrepoFile = VfsUtil.findFileByIoFile(file, false);
    HgRepository subrepo = HgUtil.getRepositoryForFile(myProject, virtualSubrepoFile);
    if (subrepo != null && !info.getHash().asString().equals(subrepo.getCurrentRevision())) {
        return new HgChange(new HgFile(hgRepo.getRoot(), VcsUtil.getFilePath(virtualSubrepoFile)), HgFileStatusEnum.MODIFIED);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgRepository(org.zmlx.hg4idea.repo.HgRepository) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgCheckinEnvironment method commit.

public List<VcsException> commit(List<Change> changes, String preparedComment, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
    List<VcsException> exceptions = new LinkedList<>();
    Map<HgRepository, Set<HgFile>> repositoriesMap = getFilesByRepository(changes);
    addRepositoriesWithoutChanges(repositoriesMap);
    for (Map.Entry<HgRepository, Set<HgFile>> entry : repositoriesMap.entrySet()) {
        HgRepository repo = entry.getKey();
        Set<HgFile> selectedFiles = entry.getValue();
        HgCommitTypeCommand command = myMqNewPatch ? new HgQNewCommand(myProject, repo, preparedComment, myNextCommitAmend) : new HgCommitCommand(myProject, repo, preparedComment, myNextCommitAmend, myCloseBranch, myShouldCommitSubrepos && !selectedFiles.isEmpty());
        if (isMergeCommit(repo.getRoot())) {
            //partial commits are not allowed during merges
            //verifyResult that all changed files in the repo are selected
            //If so, commit the entire repository
            //If not, abort
            Set<HgFile> changedFilesNotInCommit = getChangedFilesNotInCommit(repo.getRoot(), selectedFiles);
            boolean partial = !changedFilesNotInCommit.isEmpty();
            if (partial) {
                final StringBuilder filesNotIncludedString = new StringBuilder();
                for (HgFile hgFile : changedFilesNotInCommit) {
                    filesNotIncludedString.append("<li>");
                    filesNotIncludedString.append(hgFile.getRelativePath());
                    filesNotIncludedString.append("</li>");
                }
                if (!mayCommitEverything(filesNotIncludedString.toString())) {
                    //abort
                    return exceptions;
                }
                //firstly selected changes marked dirty in CommitHelper -> postRefresh, so we need to mark others
                VcsDirtyScopeManager dirtyManager = VcsDirtyScopeManager.getInstance(myProject);
                for (HgFile hgFile : changedFilesNotInCommit) {
                    dirtyManager.fileDirty(hgFile.toFilePath());
                }
            }
        // else : all was included, or it was OK to commit everything,
        // so no need to set the files on the command, because then mercurial will complain
        } else {
            command.setFiles(selectedFiles);
        }
        try {
            command.executeInCurrentThread();
        } catch (HgCommandException e) {
            exceptions.add(new VcsException(e));
        } catch (VcsException e) {
            exceptions.add(e);
        }
    }
    // push if needed
    if (myNextCommitIsPushed && exceptions.isEmpty()) {
        final List<HgRepository> preselectedRepositories = ContainerUtil.newArrayList(repositoriesMap.keySet());
        GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, HgUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
    }
    return exceptions;
}
Also used : HgQNewCommand(org.zmlx.hg4idea.command.mq.HgQNewCommand) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException) VcsPushDialog(com.intellij.dvcs.push.ui.VcsPushDialog) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Aggregations

HgRepository (org.zmlx.hg4idea.repo.HgRepository)36 NotNull (org.jetbrains.annotations.NotNull)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Project (com.intellij.openapi.project.Project)7 VcsException (com.intellij.openapi.vcs.VcsException)5 FilePath (com.intellij.openapi.vcs.FilePath)4 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 File (java.io.File)3 HgFile (org.zmlx.hg4idea.HgFile)3 HgCommandException (org.zmlx.hg4idea.execution.HgCommandException)3 Task (com.intellij.openapi.progress.Task)2 AbstractVcsVirtualFile (com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile)2 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)2 HgNameWithHashInfo (org.zmlx.hg4idea.HgNameWithHashInfo)2 HgLogCommand (org.zmlx.hg4idea.command.HgLogCommand)2