use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class GitMergeProvider method loadRevisions.
@Override
@NotNull
public MergeData loadRevisions(@NotNull final VirtualFile file) throws VcsException {
final MergeData mergeData = new MergeData();
final VirtualFile root = GitUtil.getGitRoot(file);
final FilePath path = VcsUtil.getFilePath(file.getPath());
VcsRunnable runnable = new VcsRunnable() {
@Override
@SuppressWarnings({ "ConstantConditions" })
public void run() throws VcsException {
GitFileRevision original = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + ORIGINAL_REVISION_NUM));
GitFileRevision current = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + yoursRevision(root)));
GitFileRevision last = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + theirsRevision(root)));
try {
try {
mergeData.ORIGINAL = original.getContent();
} catch (Exception ex) {
/// This could happen in case if rebasing.
try {
mergeData.ORIGINAL = file.contentsToByteArray();
} catch (IOException e) {
LOG.error(e);
mergeData.ORIGINAL = ArrayUtil.EMPTY_BYTE_ARRAY;
}
}
mergeData.CURRENT = loadRevisionCatchingErrors(current);
mergeData.LAST = loadRevisionCatchingErrors(last);
// TODO: can be done once for a root
mergeData.CURRENT_REVISION_NUMBER = findCurrentRevisionNumber(root);
mergeData.LAST_REVISION_NUMBER = findLastRevisionNumber(root);
mergeData.ORIGINAL_REVISION_NUMBER = findOriginalRevisionNumber(root, mergeData.CURRENT_REVISION_NUMBER, mergeData.LAST_REVISION_NUMBER);
Trinity<String, String, String> blobs = getAffectedBlobs(root, file);
mergeData.CURRENT_FILE_PATH = getBlobPathInRevision(root, file, blobs.getFirst(), mergeData.CURRENT_REVISION_NUMBER);
mergeData.ORIGINAL_FILE_PATH = getBlobPathInRevision(root, file, blobs.getSecond(), mergeData.ORIGINAL_REVISION_NUMBER);
mergeData.LAST_FILE_PATH = getBlobPathInRevision(root, file, blobs.getThird(), mergeData.LAST_REVISION_NUMBER);
} catch (IOException e) {
throw new IllegalStateException("Failed to load file content", e);
}
}
};
VcsUtil.runVcsProcessWithProgress(runnable, GitBundle.message("merge.load.files"), false, myProject);
return mergeData;
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class GitMergeUpdater method getFilesOverwrittenByMerge.
// parses the output of merge conflict returning files which would be overwritten by merge. These files will be stashed.
private List<FilePath> getFilesOverwrittenByMerge(@NotNull List<String> mergeOutput) {
final List<FilePath> paths = new ArrayList<>();
for (String line : mergeOutput) {
if (StringUtil.isEmptyOrSpaces(line)) {
continue;
}
if (line.contains("Please, commit your changes or stash them before you can merge")) {
break;
}
line = line.trim();
final String path;
try {
path = myRoot.getPath() + "/" + GitUtil.unescapePath(line);
final File file = new File(path);
if (file.exists()) {
paths.add(VcsUtil.getFilePath(file, false));
}
} catch (VcsException e) {
// just continue
}
}
return paths;
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class GitSimplePathsBrowser method createBrowser.
@NotNull
private static FilePathChangesTreeList createBrowser(@NotNull Project project, @NotNull Collection<String> absolutePaths) {
List<FilePath> filePaths = toFilePaths(absolutePaths);
FilePathChangesTreeList browser = new FilePathChangesTreeList(project, filePaths, false, false, null, null);
browser.setChangesToDisplay(filePaths);
return browser;
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class GitVFSListener method performForceMove.
private void performForceMove(@NotNull List<MovedFileInfo> files) {
Map<FilePath, MovedFileInfo> filesToMove = map2Map(files, (info) -> Pair.create(VcsUtil.getFilePath(info.myNewPath), info));
Set<File> toRefresh = newHashSet();
performBackgroundOperation(filesToMove.keySet(), "Moving Files...", new LongOperationPerRootExecutor() {
@Override
public void execute(@NotNull VirtualFile root, @NotNull List<FilePath> files) throws VcsException {
for (FilePath file : files) {
GitHandler h = new GitSimpleHandler(myProject, root, GitCommand.MV);
MovedFileInfo info = filesToMove.get(file);
h.addParameters("-f", info.myOldPath, info.myNewPath);
h.runInCurrentThread(null);
toRefresh.add(new File(info.myOldPath));
toRefresh.add(new File(info.myNewPath));
}
}
@Override
public Collection<File> getFilesToRefresh() {
return toRefresh;
}
});
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class GithubOpenInBrowserAction method getDataFromHistory.
@Nullable
private static CommitData getDataFromHistory(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
if (project == null || filePath == null || fileRevision == null)
return null;
if (!(fileRevision instanceof GitFileRevision))
return null;
GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForFile(filePath);
if (repository == null || !GithubUtil.isRepositoryOnGitHub(repository))
return null;
return new CommitData(project, repository, fileRevision.getRevisionNumber().asString());
}
Aggregations