use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitOutgoingChangesProvider method getMergeBaseNumber.
@Nullable
public VcsRevisionNumber getMergeBaseNumber(final VirtualFile anyFileUnderRoot) throws VcsException {
LOG.debug("getMergeBaseNumber parameter: " + anyFileUnderRoot.getPath());
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
final VirtualFile root = vcsManager.getVcsRootFor(anyFileUnderRoot);
if (root == null) {
LOG.info("VCS root not found");
return null;
}
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, root, true);
if (searcher.getLocal() == null || searcher.getRemote() == null) {
LOG.info("local or remote not found");
return null;
}
final GitRevisionNumber base = getMergeBase(myProject, root, searcher.getLocal(), searcher.getRemote());
LOG.debug("found base: " + ((base == null) ? null : base.asString()));
return base;
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitChangesParser method parseChange.
private static Change parseChange(final Project project, final VirtualFile vcsRoot, final List<GitRevisionNumber> parentRevisions, final GitLogStatusInfo statusInfo, final VcsRevisionNumber thisRevision) throws VcsException {
final ContentRevision before;
final ContentRevision after;
FileStatus status = null;
final String path = statusInfo.getFirstPath();
@Nullable GitRevisionNumber firstParent = parentRevisions.isEmpty() ? null : parentRevisions.get(0);
switch(statusInfo.getType()) {
case ADDED:
before = null;
status = FileStatus.ADDED;
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false, true);
break;
case UNRESOLVED:
status = FileStatus.MERGED_WITH_CONFLICTS;
case MODIFIED:
if (status == null) {
status = FileStatus.MODIFIED;
}
final FilePath filePath = GitContentRevision.createPath(vcsRoot, path, false, true, true);
before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, false, false, true);
after = GitContentRevision.createRevision(filePath, thisRevision, project, null);
break;
case DELETED:
status = FileStatus.DELETED;
final FilePath filePathDeleted = GitContentRevision.createPath(vcsRoot, path, true, true, true);
before = GitContentRevision.createRevision(filePathDeleted, firstParent, project, null);
after = null;
break;
case COPIED:
case RENAMED:
status = FileStatus.MODIFIED;
String secondPath = statusInfo.getSecondPath();
final FilePath filePathAfterRename = GitContentRevision.createPath(vcsRoot, secondPath == null ? path : secondPath, false, false, true);
before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, true, true, true);
after = GitContentRevision.createRevision(filePathAfterRename, thisRevision, project, null);
break;
case TYPE_CHANGED:
status = FileStatus.MODIFIED;
final FilePath filePath2 = GitContentRevision.createPath(vcsRoot, path, false, true, true);
before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, false, false, true);
after = GitContentRevision.createRevision(filePath2, thisRevision, project, null);
break;
default:
throw new AssertionError("Unknown file status: " + statusInfo);
}
return new Change(before, after, status);
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitChangesParser method parse.
@NotNull
public static List<Change> parse(@NotNull Project project, @NotNull VirtualFile root, @NotNull List<GitLogStatusInfo> statusInfos, @NotNull String hash, @NotNull Date date, @NotNull List<String> parentsHashes) throws VcsException {
GitRevisionNumber thisRevision = new GitRevisionNumber(hash, date);
List<GitRevisionNumber> parentRevisions = prepareParentRevisions(parentsHashes);
List<Change> result = new ArrayList<>();
for (GitLogStatusInfo statusInfo : statusInfos) {
result.add(parseChange(project, root, parentRevisions, statusInfo, thisRevision));
}
return result;
}
use of git4idea.GitRevisionNumber 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.GitRevisionNumber in project intellij-community by JetBrains.
the class GitChangeUtils method getDiffWithWorkingDir.
@NotNull
public static Collection<Change> getDiffWithWorkingDir(@NotNull Project project, @NotNull VirtualFile root, @NotNull String oldRevision, @Nullable Collection<FilePath> dirtyPaths, boolean reverse) throws VcsException {
String output = getDiffOutput(project, root, oldRevision, dirtyPaths, reverse);
Collection<Change> changes = new ArrayList<>();
final GitRevisionNumber revisionNumber = resolveReference(project, root, oldRevision);
parseChanges(project, root, reverse ? revisionNumber : null, reverse ? null : revisionNumber, output, changes, Collections.<String>emptySet());
return changes;
}
Aggregations