Search in sources :

Example 1 with Hash

use of com.intellij.vcs.log.Hash in project intellij-community by JetBrains.

the class HgRepositoryReader method readBranches.

@NotNull
public Map<String, LinkedHashSet<Hash>> readBranches() {
    Map<String, LinkedHashSet<Hash>> branchesWithHashes = new HashMap<>();
    // Set<String> branchNames = new HashSet<String>();
    if (isBranchInfoAvailable()) {
        Pattern activeBranchPattern = myStatusInBranchFile ? HASH_STATUS_NAME : HASH_NAME;
        String[] branchesWithHeads = DvcsUtil.tryLoadFileOrReturn(myBranchHeadsFile, "").split("\n");
        // first one - is a head revision: head hash + head number;
        for (int i = 1; i < branchesWithHeads.length; ++i) {
            Matcher matcher = activeBranchPattern.matcher(branchesWithHeads[i]);
            if (matcher.matches()) {
                String name = matcher.group(2);
                if (branchesWithHashes.containsKey(name)) {
                    branchesWithHashes.get(name).add(myVcsObjectsFactory.createHash(matcher.group(1)));
                } else {
                    LinkedHashSet<Hash> hashes = new LinkedHashSet<>();
                    hashes.add(myVcsObjectsFactory.createHash(matcher.group(1)));
                    branchesWithHashes.put(name, hashes);
                }
            }
        }
    }
    return branchesWithHashes;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Hash

use of com.intellij.vcs.log.Hash in project intellij-community by JetBrains.

the class HgCompareWithBranchAction method getDiffChanges.

@Override
@NotNull
protected Collection<Change> getDiffChanges(@NotNull Project project, @NotNull VirtualFile file, @NotNull String branchToCompare) throws VcsException {
    HgRepository repository = getRepositoryManager(project).getRepositoryForFile(file);
    if (repository == null) {
        throw new VcsException("Couldn't find repository for " + file.getName());
    }
    final FilePath filePath = VcsUtil.getFilePath(file);
    final VirtualFile repositoryRoot = repository.getRoot();
    final HgFile hgFile = new HgFile(repositoryRoot, filePath);
    Hash refHashToCompare = detectActiveHashByName(repository, branchToCompare);
    if (refHashToCompare == null) {
        throw new VcsException(String.format("Couldn't detect commit related to %s name for %s.", branchToCompare, file));
    }
    final HgRevisionNumber compareWithRevisionNumber = HgRevisionNumber.getInstance(branchToCompare, refHashToCompare.toString());
    List<Change> changes = HgUtil.getDiff(project, repositoryRoot, filePath, compareWithRevisionNumber, null);
    if (changes.isEmpty() && !existInBranch(repository, filePath, compareWithRevisionNumber)) {
        throw new VcsException(fileDoesntExistInBranchError(file, branchToCompare));
    }
    return changes.isEmpty() && !filePath.isDirectory() ? createChangesWithCurrentContentForFile(filePath, HgContentRevision.create(project, hgFile, compareWithRevisionNumber)) : changes;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository) Change(com.intellij.openapi.vcs.changes.Change) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Hash

use of com.intellij.vcs.log.Hash 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 4 with Hash

use of com.intellij.vcs.log.Hash 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 5 with Hash

use of com.intellij.vcs.log.Hash in project intellij-community by JetBrains.

the class HashBuildTest method doTest.

private static void doTest(String strHash) {
    Hash hash = HashImpl.build(strHash);
    assertEquals(strHash, hash.asString());
}
Also used : Hash(com.intellij.vcs.log.Hash)

Aggregations

Hash (com.intellij.vcs.log.Hash)21 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Test (org.junit.Test)4 VcsRef (com.intellij.vcs.log.VcsRef)2 GitRepository (git4idea.repo.GitRepository)2 HgNameWithHashInfo (org.zmlx.hg4idea.HgNameWithHashInfo)2 RepoStateException (com.intellij.dvcs.repo.RepoStateException)1 AccessToken (com.intellij.openapi.application.AccessToken)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Change (com.intellij.openapi.vcs.changes.Change)1 MultiMap (com.intellij.util.containers.MultiMap)1 CommitId (com.intellij.vcs.log.CommitId)1 GraphColorManagerImpl (com.intellij.vcs.log.graph.GraphColorManagerImpl)1 StopWatch (com.intellij.vcs.log.util.StopWatch)1 GitLocalBranch (git4idea.GitLocalBranch)1