private static void takeLine( final Project project, String line, StringBuilder sb, GitLogParser parser, SymbolicRefsI refs, VirtualFile root, VcsException[] exc, GitLineHandler h, AsynchConsumer<GitCommit> gitCommitConsumer) { final String text = sb.toString(); sb.setLength(0); sb.append(line); if (text.length() == 0) return; GitLogRecord record = parser.parseOneRecord(text); final GitCommit gitCommit; try { gitCommit = createCommit(project, refs, root, record); } catch (VcsException e) { exc[0] = e; h.cancel(); return; } gitCommitConsumer.consume(gitCommit); }
/** * Get current revision for the file under git * * @param project a project * @param filePath a file path * @return a revision number or null if the file is unversioned or new * @throws VcsException if there is problem with running git */ @Nullable public static ItemLatestState getLastRevision(final Project project, FilePath filePath) throws VcsException { VirtualFile root = GitUtil.getGitRoot(filePath); GitBranch c = GitBranch.current(project, root); GitBranch t = c == null ? null : c.tracked(project, root); if (t == null) { return new ItemLatestState(getCurrentRevision(project, filePath, null), true, false); } filePath = getLastCommitName(project, filePath); GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG); GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, COMMIT_TIME, SHORT_PARENTS); h.setNoSSH(true); h.setSilent(true); h.addParameters("-n1", parser.getPretty(), "--name-status", t.getFullName()); h.endOptions(); h.addRelativePaths(filePath); String result = h.run(); if (result.length() == 0) { return null; } GitLogRecord record = parser.parseOneRecord(result); if (record == null) { return null; } final List<Change> changes = record.parseChanges(project, root); boolean exists = !FileStatus.DELETED.equals(changes.get(0).getFileStatus()); record.setUsedHandler(h); return new ItemLatestState( new GitRevisionNumber(record.getHash(), record.getDate()), exists, false); }
@Nullable public static VcsRevisionNumber getCurrentRevision( final Project project, FilePath filePath, @Nullable String branch, final boolean shortHash) throws VcsException { filePath = getLastCommitName(project, filePath); GitSimpleHandler h = new GitSimpleHandler(project, GitUtil.getGitRoot(filePath), GitCommand.LOG); GitLogParser parser = shortHash ? new GitLogParser(project, SHORT_HASH, COMMIT_TIME) : new GitLogParser(project, HASH, COMMIT_TIME); h.setNoSSH(true); h.setSilent(true); h.addParameters("-n1", parser.getPretty()); if (branch != null && !branch.isEmpty()) { h.addParameters(branch); } else { h.addParameters("--all"); } h.endOptions(); h.addRelativePaths(filePath); String result = h.run(); if (result.length() == 0) { return null; } final GitLogRecord record = parser.parseOneRecord(result); if (record == null) { return null; } record.setUsedHandler(h); return shortHash ? new GitRevisionNumber(record.getShortHash(), record.getDate()) : new GitRevisionNumber(record.getHash(), record.getDate()); }
public static long getHeadTs(final Project project, FilePath filePath) throws VcsException { GitSimpleHandler h = new GitSimpleHandler(project, GitUtil.getGitRoot(filePath), GitCommand.LOG); GitLogParser parser = new GitLogParser(project, SHORT_HASH, COMMIT_TIME); h.setNoSSH(true); h.setSilent(true); h.addParameters("-n1", parser.getPretty()); h.addParameters("HEAD"); h.endOptions(); String result = h.run(); if (result.length() == 0) { return -1; } final GitLogRecord record = parser.parseOneRecord(result); if (record == null) { return -1; } record.setUsedHandler(h); return record.getDate().getTime(); }
@Nullable public static VcsRevisionDescription getCurrentRevisionDescription( final Project project, FilePath filePath, @Nullable String branch) throws VcsException { filePath = getLastCommitName(project, filePath); GitSimpleHandler h = new GitSimpleHandler(project, GitUtil.getGitRoot(filePath), GitCommand.LOG); GitLogParser parser = new GitLogParser( project, HASH, COMMIT_TIME, AUTHOR_NAME, COMMITTER_NAME, SUBJECT, BODY, RAW_BODY); h.setNoSSH(true); h.setSilent(true); h.addParameters("-n1", parser.getPretty()); if (branch != null && !branch.isEmpty()) { h.addParameters(branch); } else { h.addParameters("--all"); } h.endOptions(); h.addRelativePaths(filePath); String result = h.run(); if (result.length() == 0) { return null; } final GitLogRecord record = parser.parseOneRecord(result); if (record == null) { return null; } record.setUsedHandler(h); final String author = Comparing.equal(record.getAuthorName(), record.getCommitterName()) ? record.getAuthorName() : record.getAuthorName() + " (" + record.getCommitterName() + ")"; return new VcsRevisionDescriptionImpl( new GitRevisionNumber(record.getHash(), record.getDate()), record.getDate(), author, record.getFullMessage()); }
public static long getAuthorTime(Project project, FilePath path, final String commitsId) throws VcsException { // adjust path using change manager path = getLastCommitName(project, path); final VirtualFile root = GitUtil.getGitRoot(path); GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW); GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, AUTHOR_TIME); h.setNoSSH(true); h.setStdoutSuppressed(true); h.addParameters("--name-status", parser.getPretty(), "--encoding=UTF-8"); h.addParameters(commitsId); String output; try { output = h.run(); GitLogRecord logRecord = parser.parseOneRecord(output); return logRecord.getAuthorTimeStamp() * 1000; } catch (VcsException e) { throw e; } }
private GitLogRecord processResult(final String line) { return myParser.parseOneRecord(line); }