use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.
the class GitOutgoingChangesProvider method filterLocalChangesBasedOnLocalCommits.
public Collection<Change> filterLocalChangesBasedOnLocalCommits(final Collection<Change> localChanges, final VirtualFile vcsRoot) throws VcsException {
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, true);
if (searcher.getLocal() == null || searcher.getRemote() == null) {
// no information, better strict approach (see getOutgoingChanges() code)
return new ArrayList<>(localChanges);
}
final GitRevisionNumber base;
try {
base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
} catch (VcsException e) {
LOG.info(e);
return new ArrayList<>(localChanges);
}
if (base == null) {
// no information, better strict approach (see getOutgoingChanges() code)
return new ArrayList<>(localChanges);
}
final List<Pair<SHAHash, Date>> hashes = GitHistoryUtils.onlyHashesHistory(myProject, VcsUtil.getFilePath(vcsRoot), vcsRoot, (base.asString() + "..HEAD"));
// no local commits
if (hashes.isEmpty())
return Collections.emptyList();
// optimization
final String first = hashes.get(0).getFirst().getValue();
final Set<String> localHashes = new HashSet<>();
for (Pair<SHAHash, Date> hash : hashes) {
localHashes.add(hash.getFirst().getValue());
}
final Collection<Change> result = new ArrayList<>();
for (Change change : localChanges) {
if (change.getBeforeRevision() != null) {
final String changeBeforeRevision = change.getBeforeRevision().getRevisionNumber().asString().trim();
if (first.equals(changeBeforeRevision) || localHashes.contains(changeBeforeRevision)) {
result.add(change);
}
}
}
return result;
}
use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.
the class GitHistoryProvider method getBaseVersionContent.
@Override
public boolean getBaseVersionContent(FilePath filePath, Processor<CharSequence> processor, final String beforeVersionId, List<String> warnings) throws VcsException {
if (StringUtil.isEmptyOrSpaces(beforeVersionId) || filePath.getVirtualFile() == null)
return false;
// apply if base revision id matches revision
final VirtualFile root = GitUtil.getGitRoot(filePath);
if (root == null)
return false;
final SHAHash shaHash = GitChangeUtils.commitExists(myProject, root, beforeVersionId, null, "HEAD");
if (shaHash == null) {
throw new VcsException("Can not apply patch to " + filePath.getPath() + ".\nCan not find revision '" + beforeVersionId + "'.");
}
final ContentRevision content = GitVcs.getInstance(myProject).getDiffProvider().createFileContent(new GitRevisionNumber(shaHash.getValue()), filePath.getVirtualFile());
if (content == null) {
throw new VcsException("Can not load content of '" + filePath.getPath() + "' for revision '" + shaHash.getValue() + "'");
}
return !processor.process(content.getContent());
}
use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.
the class GitChangeUtils method commitExists.
@Nullable
public static SHAHash commitExists(final Project project, final VirtualFile root, final String anyReference, List<VirtualFile> paths, final String... parameters) {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
h.setSilent(true);
h.addParameters(parameters);
h.addParameters("--max-count=1", "--pretty=%H", "--encoding=UTF-8", anyReference, "--");
if (paths != null && !paths.isEmpty()) {
h.addRelativeFiles(paths);
}
try {
final String output = h.run().trim();
if (StringUtil.isEmptyOrSpaces(output))
return null;
return new SHAHash(output);
} catch (VcsException e) {
return null;
}
}
use of git4idea.history.browser.SHAHash in project intellij-community by JetBrains.
the class GitHistoryUtils method createCommit.
@NotNull
private static GitHeavyCommit createCommit(@NotNull Project project, @Nullable SymbolicRefsI refs, @NotNull VirtualFile root, @NotNull GitLogRecord record) throws VcsException {
final Collection<String> currentRefs = record.getRefs();
List<String> locals = new ArrayList<>();
List<String> remotes = new ArrayList<>();
List<String> tags = new ArrayList<>();
final String s = parseRefs(refs, currentRefs, locals, remotes, tags);
GitHeavyCommit gitCommit = new GitHeavyCommit(root, AbstractHash.create(record.getHash()), new SHAHash(record.getHash()), record.getAuthorName(), record.getCommitterName(), record.getDate(), record.getSubject(), record.getFullMessage(), new HashSet<>(Arrays.asList(record.getParentsHashes())), record.getFilePaths(root), record.getAuthorEmail(), record.getCommitterEmail(), tags, locals, remotes, record.parseChanges(project, root), record.getAuthorTimeStamp());
gitCommit.setCurrentBranch(s);
return gitCommit;
}
Aggregations