@Override protected void render(ColoredTreeCellRenderer renderer) { renderer.append( revision.asString().substring(0, HASH_PREFIX_SIZE), SimpleTextAttributes.GRAYED_ATTRIBUTES); renderer.append(": "); renderer.append(message); if (isMerge) { renderer.append( " " + GitBundle.getString("push.active.commit.node.merge"), SimpleTextAttributes.GRAYED_ATTRIBUTES); } }
private static void showDiffWithBranch( @NotNull Project project, @NotNull VirtualFile file, @NotNull String head, @NotNull String branchToCompare) throws VcsException { final FilePath filePath = new FilePathImpl(file); // we could use something like GitRepository#getCurrentRevision here, // but this way we can easily identify if the file is available in the branch final GitRevisionNumber currentRevisionNumber = (GitRevisionNumber) GitHistoryUtils.getCurrentRevision(project, filePath, head); final GitRevisionNumber compareRevisionNumber = (GitRevisionNumber) GitHistoryUtils.getCurrentRevision(project, filePath, branchToCompare); if (compareRevisionNumber == null) { fileDoesntExistInBranchError(project, file, branchToCompare); return; } LOG.assertTrue( currentRevisionNumber != null, String.format( "Current revision number is null for file [%s] and branch [%s]", filePath, head)); // constructing the revision with human readable name (will work for files comparison // however). final VcsFileRevision compareRevision = new GitFileRevision( project, filePath, new GitRevisionNumber(branchToCompare, compareRevisionNumber.getTimestamp())); CurrentRevision currentRevision = new CurrentRevision( file, new GitRevisionNumber(head, currentRevisionNumber.getTimestamp())); new GitDiffFromHistoryHandler(project) .showDiffForTwo(new FilePathImpl(file), compareRevision, currentRevision); }
@Nullable public static GitRevisionNumber getMergeBase( final Project project, final VirtualFile root, @NotNull final String first, @NotNull final String second) throws VcsException { GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.MERGE_BASE); h.setNoSSH(true); h.setSilent(true); h.addParameters(first, second); String output = h.run().trim(); if (output.length() == 0) { return null; } else { return GitRevisionNumber.resolve(project, root, output); } }
@Override @Nullable public VcsRevisionNumber parseRevisionNumber(@Nullable String revision, @Nullable FilePath path) throws VcsException { if (revision == null || revision.length() == 0) return null; if (revision.length() > 40) { // date & revision-id encoded string String dateString = revision.substring(0, revision.indexOf("[")); String rev = revision.substring(revision.indexOf("[") + 1, 40); Date d = new Date(Date.parse(dateString)); return new GitRevisionNumber(rev, d); } if (path != null) { try { VirtualFile root = GitUtil.getGitRoot(path); return GitRevisionNumber.resolve(myProject, root, revision); } catch (VcsException e) { log.info("Unexpected problem with resolving the git revision number: ", e); throw e; } } return new GitRevisionNumber(revision); }
protected void markStart(VirtualFile root) throws VcsException { // remember the current position myBefore = GitRevisionNumber.resolve(myProject, root, "HEAD"); }
@NotNull public String getHash() { return revision.getRev(); }
@Override public String toString() { return path.getName() + ":" + revision.getShortRev(); }
public int compareTo(VcsFileRevision rev) { if (rev instanceof GitFileRevision) return revision.compareTo(((GitFileRevision) rev).revision); return getRevisionDate().compareTo(rev.getRevisionDate()); }
public synchronized byte[] loadContent() throws IOException, VcsException { final VirtualFile root = GitUtil.getGitRoot(path); return GitFileUtils.getFileContent( project, root, revision.getRev(), VcsFileUtil.relativePath(root, path)); }
public Date getRevisionDate() { return revision.getTimestamp(); }
@Override public String toString() { String mergeCommitStr = isMerge ? " " + GitBundle.getString("push.active.commit.node.merge") : ""; return revision.toShortString() + " " + message + mergeCommitStr; }