コード例 #1
0
  @Nullable
  public static Pair<AbstractHash, AbstractHash> getStashTop(
      @NotNull Project project, @NotNull VirtualFile root) throws VcsException {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
    GitLogParser parser = new GitLogParser(project, SHORT_HASH, SHORT_PARENTS);
    h.setSilent(true);
    h.setNoSSH(true);
    h.addParameters("list");
    h.addParameters("-n1");
    h.addParameters(parser.getPretty());

    String out;
    h.setCharset(Charset.forName(GitConfigUtil.getLogEncoding(project, root)));
    out = h.run();
    final List<GitLogRecord> gitLogRecords = parser.parse(out);
    for (GitLogRecord gitLogRecord : gitLogRecords) {
      ProgressManager.checkCanceled();

      GitSimpleHandler h1 = new GitSimpleHandler(project, root, GitCommand.LOG);
      GitLogParser parser1 = new GitLogParser(project, SHORT_HASH, SHORT_PARENTS, SUBJECT);
      h1.setSilent(true);
      h1.setNoSSH(true);
      h1.addParameters("-n1");
      h1.addParameters(parser1.getPretty());
      // h1.endOptions();
      h1.addParameters(gitLogRecord.getShortHash());

      String out1;
      out1 = h1.run();
      final List<GitLogRecord> gitLogRecords1 = parser1.parse(out1);
      assert gitLogRecords1.size() == 1;
      final GitLogRecord logRecord = gitLogRecords1.get(0);
      final String[] parentsShortHashes = logRecord.getParentsShortHashes();
      String indexCommit = null;
      // heuristics
      if (parentsShortHashes.length == 2) {
        if (logRecord.getSubject().contains(parentsShortHashes[0])) {
          indexCommit = parentsShortHashes[1];
        }
        if (logRecord.getSubject().contains(parentsShortHashes[1])) {
          indexCommit = parentsShortHashes[0];
        }
      }
      return new Pair<AbstractHash, AbstractHash>(
          AbstractHash.create(gitLogRecord.getShortHash()),
          indexCommit == null ? null : AbstractHash.create(indexCommit));
    }
    return null;
  }
コード例 #2
0
 private static GitCommit createCommit(
     Project project, SymbolicRefsI refs, VirtualFile root, GitLogRecord record)
     throws VcsException {
   GitCommit gitCommit;
   final Collection<String> currentRefs = record.getRefs();
   List<String> locals = new ArrayList<String>();
   List<String> remotes = new ArrayList<String>();
   List<String> tags = new ArrayList<String>();
   final String s = parseRefs(refs, currentRefs, locals, remotes, tags);
   gitCommit =
       new GitCommit(
           root,
           AbstractHash.create(record.getShortHash()),
           new SHAHash(record.getHash()),
           record.getAuthorName(),
           record.getCommitterName(),
           record.getDate(),
           record.getSubject(),
           record.getFullMessage(),
           new HashSet<String>(Arrays.asList(record.getParentsShortHashes())),
           record.getFilePaths(root),
           record.getAuthorEmail(),
           record.getCommitterEmail(),
           tags,
           locals,
           remotes,
           record.parseChanges(project, root),
           record.getAuthorTimeStamp() * 1000);
   gitCommit.setCurrentBranch(s);
   /*final String current = refs.getCurrent().getName();
   gitCommit.setOnLocal((current != null) && (! current.startsWith(GitBranch.REFS_REMOTES_PREFIX)) &&
                        (! current.startsWith("remotes/")) && branches.contains(current));
   String remoteName = refs.getTrackedRemoteName();
   if (".".equals(remoteName)) {
     gitCommit.setOnTracked(gitCommit.isOnLocal());
   } else {
     remoteName = remoteName.startsWith("refs/") ? remoteName.substring("refs/".length()) : remoteName;
     gitCommit.setOnTracked(remoteName != null && branches.contains(remoteName));
   }*/
   return gitCommit;
 }