Search in sources :

Example 1 with HgNameWithHashInfo

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

the class HgCompareWithBranchAction method noBranchesToCompare.

@Override
protected boolean noBranchesToCompare(@NotNull HgRepository repository) {
    final Map<String, LinkedHashSet<Hash>> branches = repository.getBranches();
    if (branches.size() > 1)
        return false;
    final Hash currentRevisionHash = getCurrentHash(repository);
    final Collection<HgNameWithHashInfo> other_bookmarks = getOtherBookmarks(repository, currentRevisionHash);
    if (!other_bookmarks.isEmpty())
        return false;
    // if only one heavy branch and no other bookmarks -> check that current revision is not "main" branch head
    return currentRevisionHash.equals(getHeavyBranchMainHash(repository, repository.getCurrentBranch()));
}
Also used : Hash(com.intellij.vcs.log.Hash) HgNameWithHashInfo(org.zmlx.hg4idea.HgNameWithHashInfo)

Example 2 with HgNameWithHashInfo

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

the class HgQGotoFromLogAction method actionPerformed.

protected void actionPerformed(@NotNull final HgRepository repository, @NotNull final VcsFullCommitDetails commit) {
    final Project project = repository.getProject();
    List<Hash> parents = commit.getParents();
    final Hash parentHash = parents.isEmpty() ? null : parents.get(0);
    final HgNameWithHashInfo parentPatchName = ContainerUtil.find(repository.getMQAppliedPatches(), new Condition<HgNameWithHashInfo>() {

        @Override
        public boolean value(HgNameWithHashInfo info) {
            return info.getHash().equals(parentHash);
        }
    });
    new Task.Backgroundable(repository.getProject(), parentPatchName != null ? HgVcsMessages.message("hg4idea.mq.progress.goto", parentPatchName) : HgVcsMessages.message("hg4idea.mq.progress.pop")) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            if (parentPatchName != null) {
                new HgQGotoCommand(repository).executeInCurrentThread(parentPatchName.getName());
            } else {
                new HgQPopCommand(repository).executeInCurrentThread();
            }
        }

        @Override
        public void onSuccess() {
            HgShowUnAppliedPatchesAction.showUnAppliedPatches(project, repository);
        }
    }.queue();
}
Also used : HgQGotoCommand(org.zmlx.hg4idea.command.mq.HgQGotoCommand) Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Hash(com.intellij.vcs.log.Hash) HgNameWithHashInfo(org.zmlx.hg4idea.HgNameWithHashInfo) HgQPopCommand(org.zmlx.hg4idea.command.mq.HgQPopCommand)

Example 3 with HgNameWithHashInfo

use of org.zmlx.hg4idea.HgNameWithHashInfo 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 4 with HgNameWithHashInfo

use of org.zmlx.hg4idea.HgNameWithHashInfo 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 5 with HgNameWithHashInfo

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

the class HgQRenameCommand method execute.

public void execute(@NotNull final Hash patchHash) {
    final Project project = myRepository.getProject();
    HgNameWithHashInfo patchInfo = ContainerUtil.find(myRepository.getMQAppliedPatches(), new Condition<HgNameWithHashInfo>() {

        @Override
        public boolean value(HgNameWithHashInfo info) {
            return info.getHash().equals(patchHash);
        }
    });
    if (patchInfo == null) {
        LOG.error("Could not find patch " + patchHash.toString());
        return;
    }
    final String oldName = patchInfo.getName();
    final String newName = Messages.showInputDialog(project, String.format("Enter a new name for %s patch:", oldName), "Rename Patch", Messages.getQuestionIcon(), "", new HgPatchReferenceValidator(myRepository));
    if (newName != null) {
        performPatchRename(myRepository, oldName, newName);
    }
}
Also used : Project(com.intellij.openapi.project.Project) HgNameWithHashInfo(org.zmlx.hg4idea.HgNameWithHashInfo) HgPatchReferenceValidator(org.zmlx.hg4idea.util.HgPatchReferenceValidator)

Aggregations

HgNameWithHashInfo (org.zmlx.hg4idea.HgNameWithHashInfo)6 NotNull (org.jetbrains.annotations.NotNull)3 Project (com.intellij.openapi.project.Project)2 Hash (com.intellij.vcs.log.Hash)2 HgRepository (org.zmlx.hg4idea.repo.HgRepository)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HgQGotoCommand (org.zmlx.hg4idea.command.mq.HgQGotoCommand)1 HgQPopCommand (org.zmlx.hg4idea.command.mq.HgQPopCommand)1 HgPatchReferenceValidator (org.zmlx.hg4idea.util.HgPatchReferenceValidator)1