Search in sources :

Example 6 with GitRevisionNumber

use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.

the class GitOutgoingChangesProvider method getMergeBaseNumber.

@Nullable
public VcsRevisionNumber getMergeBaseNumber(final VirtualFile anyFileUnderRoot) throws VcsException {
    LOG.debug("getMergeBaseNumber parameter: " + anyFileUnderRoot.getPath());
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
    final VirtualFile root = vcsManager.getVcsRootFor(anyFileUnderRoot);
    if (root == null) {
        LOG.info("VCS root not found");
        return null;
    }
    final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, root, true);
    if (searcher.getLocal() == null || searcher.getRemote() == null) {
        LOG.info("local or remote not found");
        return null;
    }
    final GitRevisionNumber base = getMergeBase(myProject, root, searcher.getLocal(), searcher.getRemote());
    LOG.debug("found base: " + ((base == null) ? null : base.asString()));
    return base;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRevisionNumber(git4idea.GitRevisionNumber) GitBranchesSearcher(git4idea.GitBranchesSearcher) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GitRevisionNumber

use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.

the class GitChangesParser method parseChange.

private static Change parseChange(final Project project, final VirtualFile vcsRoot, final List<GitRevisionNumber> parentRevisions, final GitLogStatusInfo statusInfo, final VcsRevisionNumber thisRevision) throws VcsException {
    final ContentRevision before;
    final ContentRevision after;
    FileStatus status = null;
    final String path = statusInfo.getFirstPath();
    @Nullable GitRevisionNumber firstParent = parentRevisions.isEmpty() ? null : parentRevisions.get(0);
    switch(statusInfo.getType()) {
        case ADDED:
            before = null;
            status = FileStatus.ADDED;
            after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false, true);
            break;
        case UNRESOLVED:
            status = FileStatus.MERGED_WITH_CONFLICTS;
        case MODIFIED:
            if (status == null) {
                status = FileStatus.MODIFIED;
            }
            final FilePath filePath = GitContentRevision.createPath(vcsRoot, path, false, true, true);
            before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, false, false, true);
            after = GitContentRevision.createRevision(filePath, thisRevision, project, null);
            break;
        case DELETED:
            status = FileStatus.DELETED;
            final FilePath filePathDeleted = GitContentRevision.createPath(vcsRoot, path, true, true, true);
            before = GitContentRevision.createRevision(filePathDeleted, firstParent, project, null);
            after = null;
            break;
        case COPIED:
        case RENAMED:
            status = FileStatus.MODIFIED;
            String secondPath = statusInfo.getSecondPath();
            final FilePath filePathAfterRename = GitContentRevision.createPath(vcsRoot, secondPath == null ? path : secondPath, false, false, true);
            before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, true, true, true);
            after = GitContentRevision.createRevision(filePathAfterRename, thisRevision, project, null);
            break;
        case TYPE_CHANGED:
            status = FileStatus.MODIFIED;
            final FilePath filePath2 = GitContentRevision.createPath(vcsRoot, path, false, true, true);
            before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, false, false, true);
            after = GitContentRevision.createRevision(filePath2, thisRevision, project, null);
            break;
        default:
            throw new AssertionError("Unknown file status: " + statusInfo);
    }
    return new Change(before, after, status);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) FileStatus(com.intellij.openapi.vcs.FileStatus) GitRevisionNumber(git4idea.GitRevisionNumber) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) GitContentRevision(git4idea.GitContentRevision) Change(com.intellij.openapi.vcs.changes.Change) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with GitRevisionNumber

use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.

the class GitChangesParser method parse.

@NotNull
public static List<Change> parse(@NotNull Project project, @NotNull VirtualFile root, @NotNull List<GitLogStatusInfo> statusInfos, @NotNull String hash, @NotNull Date date, @NotNull List<String> parentsHashes) throws VcsException {
    GitRevisionNumber thisRevision = new GitRevisionNumber(hash, date);
    List<GitRevisionNumber> parentRevisions = prepareParentRevisions(parentsHashes);
    List<Change> result = new ArrayList<>();
    for (GitLogStatusInfo statusInfo : statusInfos) {
        result.add(parseChange(project, root, parentRevisions, statusInfo, thisRevision));
    }
    return result;
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) ArrayList(java.util.ArrayList) Change(com.intellij.openapi.vcs.changes.Change) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GitRevisionNumber

use of git4idea.GitRevisionNumber 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 10 with GitRevisionNumber

use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.

the class GitChangeUtils method getDiffWithWorkingDir.

@NotNull
public static Collection<Change> getDiffWithWorkingDir(@NotNull Project project, @NotNull VirtualFile root, @NotNull String oldRevision, @Nullable Collection<FilePath> dirtyPaths, boolean reverse) throws VcsException {
    String output = getDiffOutput(project, root, oldRevision, dirtyPaths, reverse);
    Collection<Change> changes = new ArrayList<>();
    final GitRevisionNumber revisionNumber = resolveReference(project, root, oldRevision);
    parseChanges(project, root, reverse ? revisionNumber : null, reverse ? null : revisionNumber, output, changes, Collections.<String>emptySet());
    return changes;
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) Change(com.intellij.openapi.vcs.changes.Change) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitRevisionNumber (git4idea.GitRevisionNumber)29 VcsException (com.intellij.openapi.vcs.VcsException)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Change (com.intellij.openapi.vcs.changes.Change)8 NotNull (org.jetbrains.annotations.NotNull)8 Nullable (org.jetbrains.annotations.Nullable)8 FilePath (com.intellij.openapi.vcs.FilePath)4 GitSingleRepoTest (git4idea.test.GitSingleRepoTest)4 Test (org.testng.annotations.Test)4 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)3 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)3 GitBranchesSearcher (git4idea.GitBranchesSearcher)3 GitSimpleHandler (git4idea.commands.GitSimpleHandler)3 GitRepository (git4idea.repo.GitRepository)3 StringScanner (git4idea.util.StringScanner)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Pair (com.intellij.openapi.util.Pair)2