Search in sources :

Example 46 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class GitHistoryUtils method history.

public static void history(@NotNull Project project, @NotNull FilePath path, @Nullable VirtualFile root, @NotNull VcsRevisionNumber startingRevision, @NotNull Consumer<GitFileRevision> consumer, @NotNull Consumer<VcsException> exceptionConsumer, String... parameters) {
    // adjust path using change manager
    final FilePath filePath = getLastCommitName(project, path);
    final VirtualFile finalRoot;
    try {
        finalRoot = (root == null ? GitUtil.getGitRoot(filePath) : root);
    } catch (VcsException e) {
        exceptionConsumer.consume(e);
        return;
    }
    final GitLogParser logParser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, COMMIT_TIME, AUTHOR_NAME, AUTHOR_EMAIL, COMMITTER_NAME, COMMITTER_EMAIL, PARENTS, SUBJECT, BODY, RAW_BODY, AUTHOR_TIME);
    final AtomicReference<String> firstCommit = new AtomicReference<>(startingRevision.asString());
    final AtomicReference<String> firstCommitParent = new AtomicReference<>(firstCommit.get());
    final AtomicReference<FilePath> currentPath = new AtomicReference<>(filePath);
    final AtomicReference<GitLineHandler> logHandler = new AtomicReference<>();
    final AtomicBoolean skipFurtherOutput = new AtomicBoolean();
    final Consumer<GitLogRecord> resultAdapter = record -> {
        if (skipFurtherOutput.get()) {
            return;
        }
        if (record == null) {
            exceptionConsumer.consume(new VcsException("revision details are null."));
            return;
        }
        record.setUsedHandler(logHandler.get());
        final GitRevisionNumber revision = new GitRevisionNumber(record.getHash(), record.getDate());
        firstCommit.set(record.getHash());
        final String[] parentHashes = record.getParentsHashes();
        if (parentHashes.length < 1) {
            firstCommitParent.set(null);
        } else {
            firstCommitParent.set(parentHashes[0]);
        }
        final String message = record.getFullMessage();
        FilePath revisionPath;
        try {
            final List<FilePath> paths = record.getFilePaths(finalRoot);
            if (paths.size() > 0) {
                revisionPath = paths.get(0);
            } else {
                revisionPath = currentPath.get();
            }
            Couple<String> authorPair = Couple.of(record.getAuthorName(), record.getAuthorEmail());
            Couple<String> committerPair = Couple.of(record.getCommitterName(), record.getCommitterEmail());
            Collection<String> parents = Arrays.asList(parentHashes);
            consumer.consume(new GitFileRevision(project, finalRoot, revisionPath, revision, Couple.of(authorPair, committerPair), message, null, new Date(record.getAuthorTimeStamp()), parents));
            List<GitLogStatusInfo> statusInfos = record.getStatusInfos();
            if (statusInfos.isEmpty()) {
                return;
            }
            if (statusInfos.get(0).getType() == GitChangeType.ADDED && !filePath.isDirectory()) {
                skipFurtherOutput.set(true);
            }
        } catch (VcsException e) {
            exceptionConsumer.consume(e);
        }
    };
    GitVcs vcs = GitVcs.getInstance(project);
    GitVersion version = vcs != null ? vcs.getVersion() : GitVersion.NULL;
    final AtomicBoolean criticalFailure = new AtomicBoolean();
    while (currentPath.get() != null && firstCommitParent.get() != null) {
        logHandler.set(getLogHandler(project, version, finalRoot, logParser, currentPath.get(), firstCommitParent.get(), parameters));
        final MyTokenAccumulator accumulator = new MyTokenAccumulator(logParser);
        final Semaphore semaphore = new Semaphore();
        logHandler.get().addLineListener(new GitLineHandlerAdapter() {

            @Override
            public void onLineAvailable(String line, Key outputType) {
                final GitLogRecord record = accumulator.acceptLine(line);
                if (record != null) {
                    resultAdapter.consume(record);
                }
            }

            @Override
            public void startFailed(Throwable exception) {
                //noinspection ThrowableInstanceNeverThrown
                try {
                    exceptionConsumer.consume(new VcsException(exception));
                } finally {
                    criticalFailure.set(true);
                    semaphore.up();
                }
            }

            @Override
            public void processTerminated(int exitCode) {
                try {
                    super.processTerminated(exitCode);
                    final GitLogRecord record = accumulator.processLast();
                    if (record != null) {
                        resultAdapter.consume(record);
                    }
                } catch (ProcessCanceledException ignored) {
                } catch (Throwable t) {
                    LOG.error(t);
                    exceptionConsumer.consume(new VcsException("Internal error " + t.getMessage(), t));
                    criticalFailure.set(true);
                } finally {
                    semaphore.up();
                }
            }
        });
        semaphore.down();
        logHandler.get().start();
        semaphore.waitFor();
        if (criticalFailure.get()) {
            return;
        }
        try {
            Pair<String, FilePath> firstCommitParentAndPath = getFirstCommitParentAndPathIfRename(project, finalRoot, firstCommit.get(), currentPath.get(), version);
            currentPath.set(firstCommitParentAndPath == null ? null : firstCommitParentAndPath.second);
            firstCommitParent.set(firstCommitParentAndPath == null ? null : firstCommitParentAndPath.first);
            skipFurtherOutput.set(false);
        } catch (VcsException e) {
            LOG.warn("Tried to get first commit rename path", e);
            exceptionConsumer.consume(e);
            return;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.openapi.util(com.intellij.openapi.util) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Change(com.intellij.openapi.vcs.changes.Change) git4idea.commands(git4idea.commands) ObjectUtils.notNull(com.intellij.util.ObjectUtils.notNull) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitLogProvider(git4idea.log.GitLogProvider) GitVersionSpecialty(git4idea.config.GitVersionSpecialty) ReadAction(com.intellij.openapi.application.ReadAction) VcsRevisionDescriptionImpl(com.intellij.openapi.vcs.history.VcsRevisionDescriptionImpl) SmartList(com.intellij.util.SmartList) Semaphore(com.intellij.util.concurrency.Semaphore) GitVersion(git4idea.config.GitVersion) GitHeavyCommit(git4idea.history.browser.GitHeavyCommit) Logger(com.intellij.openapi.diagnostic.Logger) VcsException(com.intellij.openapi.vcs.VcsException) FilePath(com.intellij.openapi.vcs.FilePath) git4idea(git4idea) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) GitBundle(git4idea.i18n.GitBundle) NullableFunction(com.intellij.util.NullableFunction) com.intellij.vcs.log(com.intellij.vcs.log) AbstractHash(git4idea.history.wholeTree.AbstractHash) Nullable(org.jetbrains.annotations.Nullable) ServiceManager(com.intellij.openapi.components.ServiceManager) HashImpl(com.intellij.vcs.log.impl.HashImpl) StopWatch(com.intellij.vcs.log.util.StopWatch) Registry(com.intellij.openapi.util.registry.Registry) GitLogOption(git4idea.history.GitLogParser.GitLogOption) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) SHAHash(git4idea.history.browser.SHAHash) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState) FileStatus(com.intellij.openapi.vcs.FileStatus) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) VcsRevisionDescription(com.intellij.openapi.vcs.history.VcsRevisionDescription) SymbolicRefsI(git4idea.history.browser.SymbolicRefsI) LogDataImpl(com.intellij.vcs.log.impl.LogDataImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContainerUtil(com.intellij.util.containers.ContainerUtil) GitBranchUtil(git4idea.branch.GitBranchUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Project(com.intellij.openapi.project.Project) SymbolicRefs(git4idea.history.browser.SymbolicRefs) ProcessOutputTypes(com.intellij.execution.process.ProcessOutputTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) OpenTHashSet(com.intellij.util.containers.OpenTHashSet) GitRefManager(git4idea.log.GitRefManager) Semaphore(com.intellij.util.concurrency.Semaphore) SmartList(com.intellij.util.SmartList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FilePath(com.intellij.openapi.vcs.FilePath) GitVersion(git4idea.config.GitVersion) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VcsException(com.intellij.openapi.vcs.VcsException)

Example 47 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class GithubOpenCommitInBrowserFromAnnotateAction method getData.

@Nullable
@Override
protected CommitData getData(AnActionEvent e) {
    if (myLineNumber < 0)
        return null;
    Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    if (project == null || virtualFile == null)
        return null;
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    if (document == null)
        return null;
    GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForFileQuick(virtualFile);
    if (repository == null || !GithubUtil.isRepositoryOnGitHub(repository))
        return null;
    VcsRevisionNumber revisionNumber = myAnnotation.getLineRevisionNumber(myLineNumber);
    return new CommitData(project, repository, revisionNumber != null ? revisionNumber.asString() : null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class GitPreservingProcess method configureSaver.

/**
   * Configures the saver: i.e. notifications and texts for the GitConflictResolver used inside.
   */
@NotNull
private GitChangesSaver configureSaver(@NotNull GitVcsSettings.UpdateChangesPolicy saveMethod) {
    GitChangesSaver saver = GitChangesSaver.getSaver(myProject, myGit, myProgressIndicator, myStashMessage, saveMethod);
    MergeDialogCustomizer mergeDialogCustomizer = new MergeDialogCustomizer() {

        @Override
        public String getMultipleFileMergeDescription(@NotNull Collection<VirtualFile> files) {
            return String.format("<html>Uncommitted changes that were saved before %s have conflicts with files from <code>%s</code></html>", myOperationTitle, myDestinationName);
        }

        @Override
        public String getLeftPanelTitle(@NotNull VirtualFile file) {
            return "Uncommitted changes from stash";
        }

        @Override
        public String getRightPanelTitle(@NotNull VirtualFile file, VcsRevisionNumber revisionNumber) {
            return String.format("<html>Changes from <b><code>%s</code></b></html>", myDestinationName);
        }
    };
    GitConflictResolver.Params params = new GitConflictResolver.Params().setReverse(true).setMergeDialogCustomizer(mergeDialogCustomizer).setErrorNotificationTitle("Local changes were not restored");
    saver.setConflictResolverParams(params);
    return saver;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MergeDialogCustomizer(com.intellij.openapi.vcs.merge.MergeDialogCustomizer) GitConflictResolver(git4idea.merge.GitConflictResolver) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Collection(java.util.Collection) GitChangesSaver(git4idea.stash.GitChangesSaver) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)48 VirtualFile (com.intellij.openapi.vfs.VirtualFile)14 Nullable (org.jetbrains.annotations.Nullable)12 NotNull (org.jetbrains.annotations.NotNull)11 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)7 FilePath (com.intellij.openapi.vcs.FilePath)6 Project (com.intellij.openapi.project.Project)5 VcsException (com.intellij.openapi.vcs.VcsException)4 File (java.io.File)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Pair (com.intellij.openapi.util.Pair)3 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 VcsRoot (com.intellij.openapi.vcs.VcsRoot)3 Change (com.intellij.openapi.vcs.changes.Change)3 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)3 HashMap (com.intellij.util.containers.HashMap)3 DiffContent (com.intellij.diff.contents.DiffContent)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2