Search in sources :

Example 1 with GitVersion

use of git4idea.config.GitVersion in project intellij-community by JetBrains.

the class GitVersionTest method testParse.

/**
   * Tests that parsing the 'git version' command output returns the correct GitVersion object.
   * Tests on UNIX and on Windows - both CYGWIN and MSYS.
   */
@Test
public void testParse() throws Exception {
    if (SystemInfo.isUnix) {
        for (TestGitVersion test : commonTests) {
            GitVersion version = GitVersion.parse(test.output);
            assertEqualVersions(version, test, Type.UNIX);
        }
    } else if (SystemInfo.isWindows) {
        for (TestGitVersion test : commonTests) {
            GitVersion version = GitVersion.parse(test.output);
            assertEqualVersions(version, test, Type.CYGWIN);
        }
        for (TestGitVersion test : msysTests) {
            GitVersion version = GitVersion.parse(test.output);
            assertEqualVersions(version, test, Type.MSYS);
        }
    }
}
Also used : GitVersion(git4idea.config.GitVersion) Test(org.junit.Test)

Example 2 with GitVersion

use of git4idea.config.GitVersion in project intellij-community by JetBrains.

the class GitVersionTest method assertEqualVersions.

// Compares the parsed output and what we've expected.
// Uses reflection to get private fields of GitVersion: we don't need them in code, so no need to trash the class with unused accessors.
private static void assertEqualVersions(GitVersion actual, TestGitVersion expected, Type expectedType) throws Exception {
    Field field = GitVersion.class.getDeclaredField("myMajor");
    field.setAccessible(true);
    final int major = field.getInt(actual);
    field = GitVersion.class.getDeclaredField("myMinor");
    field.setAccessible(true);
    final int minor = field.getInt(actual);
    field = GitVersion.class.getDeclaredField("myRevision");
    field.setAccessible(true);
    final int rev = field.getInt(actual);
    field = GitVersion.class.getDeclaredField("myPatchLevel");
    field.setAccessible(true);
    final int patch = field.getInt(actual);
    field = GitVersion.class.getDeclaredField("myType");
    field.setAccessible(true);
    final Type type = (Type) field.get(actual);
    assertEquals(major, expected.major);
    assertEquals(minor, expected.minor);
    assertEquals(rev, expected.rev);
    assertEquals(patch, expected.patch);
    assertEquals(type, expectedType);
}
Also used : Field(java.lang.reflect.Field) Type(git4idea.config.GitVersion.Type) GitVersion(git4idea.config.GitVersion)

Example 3 with GitVersion

use of git4idea.config.GitVersion in project intellij-community by JetBrains.

the class GitVersionTest method testEqualsAndCompare.

@Test
public void testEqualsAndCompare() throws Exception {
    GitVersion v1 = GitVersion.parse("git version 1.6.3");
    GitVersion v2 = GitVersion.parse("git version 1.7.3");
    GitVersion v3 = GitVersion.parse("git version 1.7.3");
    GitVersion v4 = GitVersion.parse("git version 1.7.3.msysgit.0");
    assertFalse(v1.equals(v2));
    assertFalse(v1.equals(v3));
    assertTrue(v2.equals(v3));
    if (SystemInfo.isWindows) {
        assertFalse(v1.equals(v4));
        assertFalse(v2.equals(v4));
        assertFalse(v3.equals(v4));
    }
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v1.compareTo(v3), -1);
    assertEquals(v1.compareTo(v4), -1);
    assertEquals(v2.compareTo(v3), 0);
    assertEquals(v2.compareTo(v4), 0);
    assertEquals(v3.compareTo(v4), 0);
}
Also used : GitVersion(git4idea.config.GitVersion) Test(org.junit.Test)

Example 4 with GitVersion

use of git4idea.config.GitVersion in project intellij-community by JetBrains.

the class GitChangeProvider method isNewGitChangeProviderAvailable.

private boolean isNewGitChangeProviderAvailable() {
    GitVcs vcs = GitVcs.getInstance(myProject);
    if (vcs == null) {
        return false;
    }
    final GitVersion version = vcs.getVersion();
    return GitVersionSpecialty.KNOWS_STATUS_PORCELAIN.existsIn(version);
}
Also used : GitVcs(git4idea.GitVcs) GitVersion(git4idea.config.GitVersion)

Example 5 with GitVersion

use of git4idea.config.GitVersion 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)

Aggregations

GitVersion (git4idea.config.GitVersion)6 VcsException (com.intellij.openapi.vcs.VcsException)2 Test (org.junit.Test)2 ProcessOutputTypes (com.intellij.execution.process.ProcessOutputTypes)1 ReadAction (com.intellij.openapi.application.ReadAction)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 com.intellij.openapi.util (com.intellij.openapi.util)1 Registry (com.intellij.openapi.util.registry.Registry)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 FilePath (com.intellij.openapi.vcs.FilePath)1 FileStatus (com.intellij.openapi.vcs.FileStatus)1 Change (com.intellij.openapi.vcs.changes.Change)1 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)1 ItemLatestState (com.intellij.openapi.vcs.diff.ItemLatestState)1 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)1 VcsRevisionDescription (com.intellij.openapi.vcs.history.VcsRevisionDescription)1 VcsRevisionDescriptionImpl (com.intellij.openapi.vcs.history.VcsRevisionDescriptionImpl)1