Search in sources :

Example 1 with SHAHash

use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.

the class GitOutgoingChangesProvider method filterLocalChangesBasedOnLocalCommits.

public Collection<Change> filterLocalChangesBasedOnLocalCommits(final Collection<Change> localChanges, final VirtualFile vcsRoot) throws VcsException {
    final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, true);
    if (searcher.getLocal() == null || searcher.getRemote() == null) {
        // no information, better strict approach (see getOutgoingChanges() code)
        return new ArrayList<>(localChanges);
    }
    final GitRevisionNumber base;
    try {
        base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
    } catch (VcsException e) {
        LOG.info(e);
        return new ArrayList<>(localChanges);
    }
    if (base == null) {
        // no information, better strict approach (see getOutgoingChanges() code)
        return new ArrayList<>(localChanges);
    }
    final List<Pair<SHAHash, Date>> hashes = GitHistoryUtils.onlyHashesHistory(myProject, VcsUtil.getFilePath(vcsRoot), vcsRoot, (base.asString() + "..HEAD"));
    // no local commits
    if (hashes.isEmpty())
        return Collections.emptyList();
    // optimization
    final String first = hashes.get(0).getFirst().getValue();
    final Set<String> localHashes = new HashSet<>();
    for (Pair<SHAHash, Date> hash : hashes) {
        localHashes.add(hash.getFirst().getValue());
    }
    final Collection<Change> result = new ArrayList<>();
    for (Change change : localChanges) {
        if (change.getBeforeRevision() != null) {
            final String changeBeforeRevision = change.getBeforeRevision().getRevisionNumber().asString().trim();
            if (first.equals(changeBeforeRevision) || localHashes.contains(changeBeforeRevision)) {
                result.add(change);
            }
        }
    }
    return result;
}
Also used : SHAHash(git4idea.history.browser.SHAHash) Change(com.intellij.openapi.vcs.changes.Change) GitBranchesSearcher(git4idea.GitBranchesSearcher) GitRevisionNumber(git4idea.GitRevisionNumber) Pair(com.intellij.openapi.util.Pair)

Example 2 with SHAHash

use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.

the class GitHistoryProvider method getBaseVersionContent.

@Override
public boolean getBaseVersionContent(FilePath filePath, Processor<CharSequence> processor, final String beforeVersionId, List<String> warnings) throws VcsException {
    if (StringUtil.isEmptyOrSpaces(beforeVersionId) || filePath.getVirtualFile() == null)
        return false;
    // apply if base revision id matches revision
    final VirtualFile root = GitUtil.getGitRoot(filePath);
    if (root == null)
        return false;
    final SHAHash shaHash = GitChangeUtils.commitExists(myProject, root, beforeVersionId, null, "HEAD");
    if (shaHash == null) {
        throw new VcsException("Can not apply patch to " + filePath.getPath() + ".\nCan not find revision '" + beforeVersionId + "'.");
    }
    final ContentRevision content = GitVcs.getInstance(myProject).getDiffProvider().createFileContent(new GitRevisionNumber(shaHash.getValue()), filePath.getVirtualFile());
    if (content == null) {
        throw new VcsException("Can not load content of '" + filePath.getPath() + "' for revision '" + shaHash.getValue() + "'");
    }
    return !processor.process(content.getContent());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SHAHash(git4idea.history.browser.SHAHash) GitRevisionNumber(git4idea.GitRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision)

Example 3 with SHAHash

use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.

the class GitChangeUtils method commitExists.

@Nullable
public static SHAHash commitExists(final Project project, final VirtualFile root, final String anyReference, List<VirtualFile> paths, final String... parameters) {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
    h.setSilent(true);
    h.addParameters(parameters);
    h.addParameters("--max-count=1", "--pretty=%H", "--encoding=UTF-8", anyReference, "--");
    if (paths != null && !paths.isEmpty()) {
        h.addRelativeFiles(paths);
    }
    try {
        final String output = h.run().trim();
        if (StringUtil.isEmptyOrSpaces(output))
            return null;
        return new SHAHash(output);
    } catch (VcsException e) {
        return null;
    }
}
Also used : SHAHash(git4idea.history.browser.SHAHash) GitSimpleHandler(git4idea.commands.GitSimpleHandler) VcsException(com.intellij.openapi.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with SHAHash

use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.

the class GitHistoryUtils method createCommit.

@NotNull
private static GitHeavyCommit createCommit(@NotNull Project project, @Nullable SymbolicRefsI refs, @NotNull VirtualFile root, @NotNull GitLogRecord record) throws VcsException {
    final Collection<String> currentRefs = record.getRefs();
    List<String> locals = new ArrayList<>();
    List<String> remotes = new ArrayList<>();
    List<String> tags = new ArrayList<>();
    final String s = parseRefs(refs, currentRefs, locals, remotes, tags);
    GitHeavyCommit gitCommit = new GitHeavyCommit(root, AbstractHash.create(record.getHash()), new SHAHash(record.getHash()), record.getAuthorName(), record.getCommitterName(), record.getDate(), record.getSubject(), record.getFullMessage(), new HashSet<>(Arrays.asList(record.getParentsHashes())), record.getFilePaths(root), record.getAuthorEmail(), record.getCommitterEmail(), tags, locals, remotes, record.parseChanges(project, root), record.getAuthorTimeStamp());
    gitCommit.setCurrentBranch(s);
    return gitCommit;
}
Also used : SHAHash(git4idea.history.browser.SHAHash) GitHeavyCommit(git4idea.history.browser.GitHeavyCommit) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SHAHash (git4idea.history.browser.SHAHash)4 VcsException (com.intellij.openapi.vcs.VcsException)2 GitRevisionNumber (git4idea.GitRevisionNumber)2 Pair (com.intellij.openapi.util.Pair)1 Change (com.intellij.openapi.vcs.changes.Change)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GitBranchesSearcher (git4idea.GitBranchesSearcher)1 GitSimpleHandler (git4idea.commands.GitSimpleHandler)1 GitHeavyCommit (git4idea.history.browser.GitHeavyCommit)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1