Search in sources :

Example 6 with StringScanner

use of git4idea.util.StringScanner in project intellij-community by JetBrains.

the class GitOldChangesCollector method parseFiles.

private void parseFiles(String list) throws VcsException {
    for (StringScanner sc = new StringScanner(list); sc.hasMoreData(); ) {
        if (sc.isEol()) {
            sc.nextLine();
            continue;
        }
        char status = sc.peek();
        sc.skipChars(2);
        if ('?' == status) {
            VirtualFile file = myVcsRoot.findFileByRelativePath(GitUtil.unescapePath(sc.line()));
            if (Comparing.equal(GitUtil.gitRootOrNull(file), myVcsRoot)) {
                myUnversioned.add(file);
            }
        } else {
            //noinspection HardCodedStringLiteral
            if ('M' == status) {
                sc.boundedToken('\t');
                String file = GitUtil.unescapePath(sc.line());
                VirtualFile vFile = myVcsRoot.findFileByRelativePath(file);
                if (!Comparing.equal(GitUtil.gitRootOrNull(vFile), myVcsRoot)) {
                    continue;
                }
                if (!myUnmergedNames.add(file)) {
                    continue;
                }
                // assume modify-modify conflict
                ContentRevision before = GitContentRevision.createRevision(myVcsRoot, file, new GitRevisionNumber("orig_head"), myProject, false, true, true);
                ContentRevision after = GitContentRevision.createRevision(myVcsRoot, file, null, myProject, false, false, true);
                myChanges.add(new Change(before, after, FileStatus.MERGED_WITH_CONFLICTS));
            } else {
                throw new VcsException("Unsupported type of the merge conflict detected: " + status);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRevisionNumber(git4idea.GitRevisionNumber) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) GitContentRevision(git4idea.GitContentRevision) Change(com.intellij.openapi.vcs.changes.Change) StringScanner(git4idea.util.StringScanner)

Example 7 with StringScanner

use of git4idea.util.StringScanner in project intellij-community by JetBrains.

the class GitTagDialog method fetchTags.

/**
   * Fetch tags
   */
private void fetchTags() {
    myExistingTags.clear();
    GitSimpleHandler h = new GitSimpleHandler(myProject, getGitRoot(), GitCommand.TAG);
    h.setSilent(true);
    String output = GitHandlerUtil.doSynchronously(h, GitBundle.getString("tag.getting.existing.tags"), h.printableCommandLine());
    for (StringScanner s = new StringScanner(output); s.hasMoreData(); ) {
        String line = s.line();
        if (line.length() == 0) {
            continue;
        }
        myExistingTags.add(line);
    }
}
Also used : StringScanner(git4idea.util.StringScanner)

Example 8 with StringScanner

use of git4idea.util.StringScanner in project intellij-community by JetBrains.

the class GitChangeUtils method getRevisionChanges.

/**
   * Get list of changes. Because native Git non-linear revision tree structure is not
   * supported by the current IDEA interfaces some simplifications are made in the case
   * of the merge, so changes are reported as difference with the first revision
   * listed on the the merge that has at least some changes.
   *
   *
   *
   * @param project      the project file
   * @param root         the git root
   * @param revisionName the name of revision (might be tag)
   * @param skipDiffsForMerge
   * @param local
   * @param revertable
   * @return change list for the respective revision
   * @throws VcsException in case of problem with running git
   */
public static GitCommittedChangeList getRevisionChanges(Project project, VirtualFile root, String revisionName, boolean skipDiffsForMerge, boolean local, boolean revertable) throws VcsException {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW);
    h.setSilent(true);
    h.addParameters("--name-status", "--first-parent", "--no-abbrev", "-M", "--pretty=format:" + COMMITTED_CHANGELIST_FORMAT, "--encoding=UTF-8", revisionName, "--");
    String output = h.run();
    StringScanner s = new StringScanner(output);
    return parseChangeList(project, root, s, skipDiffsForMerge, h, local, revertable);
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) StringScanner(git4idea.util.StringScanner)

Example 9 with StringScanner

use of git4idea.util.StringScanner in project intellij-community by JetBrains.

the class GitChangeUtils method parseChanges.

/**
   * Parse changes from lines
   *
   * @param project        the context project
   * @param vcsRoot        the git root
   * @param thisRevision   the current revision
   * @param parentRevision the parent revision for this change list
   * @param s              the lines to parse
   * @param changes        a list of changes to update
   * @param ignoreNames    a set of names ignored during collection of the changes
   * @throws VcsException if the input format does not matches expected format
   */
public static void parseChanges(Project project, VirtualFile vcsRoot, @Nullable GitRevisionNumber thisRevision, GitRevisionNumber parentRevision, String s, Collection<Change> changes, final Set<String> ignoreNames) throws VcsException {
    StringScanner sc = new StringScanner(s);
    parseChanges(project, vcsRoot, thisRevision, parentRevision, sc, changes, ignoreNames);
    if (sc.hasMoreData()) {
        throw new IllegalStateException("Unknown file status: " + sc.line());
    }
}
Also used : StringScanner(git4idea.util.StringScanner)

Example 10 with StringScanner

use of git4idea.util.StringScanner in project intellij-community by JetBrains.

the class GitUtil method getLocalCommittedChanges.

public static void getLocalCommittedChanges(final Project project, final VirtualFile root, final Consumer<GitSimpleHandler> parametersSpecifier, final Consumer<GitCommittedChangeList> consumer, boolean skipDiffsForMerge) throws VcsException {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
    h.setSilent(true);
    h.addParameters("--pretty=format:%x04%x01" + GitChangeUtils.COMMITTED_CHANGELIST_FORMAT, "--name-status");
    parametersSpecifier.consume(h);
    String output = h.run();
    LOG.debug("getLocalCommittedChanges output: '" + output + "'");
    StringScanner s = new StringScanner(output);
    final StringBuilder sb = new StringBuilder();
    boolean firstStep = true;
    while (s.hasMoreData()) {
        final String line = s.line();
        final boolean lineIsAStart = line.startsWith("");
        if ((!firstStep) && lineIsAStart) {
            final StringScanner innerScanner = new StringScanner(sb.toString());
            sb.setLength(0);
            consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false, false));
        }
        sb.append(lineIsAStart ? line.substring(2) : line).append('\n');
        firstStep = false;
    }
    if (sb.length() > 0) {
        final StringScanner innerScanner = new StringScanner(sb.toString());
        sb.setLength(0);
        consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false, false));
    }
    if (s.hasMoreData()) {
        throw new IllegalStateException("More input is avaialble: " + s.line());
    }
}
Also used : StringScanner(git4idea.util.StringScanner)

Aggregations

StringScanner (git4idea.util.StringScanner)15 VcsException (com.intellij.openapi.vcs.VcsException)6 GitSimpleHandler (git4idea.commands.GitSimpleHandler)5 NotNull (org.jetbrains.annotations.NotNull)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GitRevisionNumber (git4idea.GitRevisionNumber)3 FilePath (com.intellij.openapi.vcs.FilePath)2 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)2 File (java.io.File)2 Nullable (org.jetbrains.annotations.Nullable)2 Attachment (com.intellij.openapi.diagnostic.Attachment)1 Key (com.intellij.openapi.util.Key)1 Change (com.intellij.openapi.vcs.changes.Change)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 Interner (com.intellij.util.containers.Interner)1 OpenTHashSet (com.intellij.util.containers.OpenTHashSet)1 VcsUser (com.intellij.vcs.log.VcsUser)1 GitContentRevision (git4idea.GitContentRevision)1 LineInfo (git4idea.annotate.GitFileAnnotation.LineInfo)1 GitCommandResult (git4idea.commands.GitCommandResult)1