use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class CvsCheckinEnvironment method commit.
public List<VcsException> commit(List<Change> changes, String preparedComment, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
final Collection<FilePath> filesList = ChangesUtil.getPaths(changes);
FilePath[] files = filesList.toArray(new FilePath[filesList.size()]);
final CvsOperationExecutor executor = new CvsOperationExecutor(myProject);
executor.setShowErrors(false);
final List<File> dirsToPrune = new ArrayList<>();
for (Change c : changes) {
if (c.getType() == Change.Type.DELETED) {
final ContentRevision contentRevision = c.getBeforeRevision();
assert contentRevision != null;
final FilePath path = contentRevision.getFile();
final FilePath parentPath = path.getParentPath();
if (parentPath != null) {
dirsToPrune.add(parentPath.getIOFile());
}
}
}
final CvsConfiguration cvsConfiguration = CvsConfiguration.getInstance(myProject);
CvsHandler handler = CommandCvsHandler.createCommitHandler(files, preparedComment, CvsBundle.message("operation.name.commit.file", files.length), cvsConfiguration.MAKE_NEW_FILES_READONLY, myProject, cvsConfiguration.TAG_AFTER_PROJECT_COMMIT, cvsConfiguration.TAG_AFTER_PROJECT_COMMIT_NAME, dirsToPrune);
executor.performActionSync(handler, CvsOperationExecutorCallback.EMPTY);
return executor.getResult().getErrorsAndWarnings();
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class GitResolveConflictsAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
Project project = ObjectUtils.assertNotNull(event.getProject());
GitVcs vcs = ObjectUtils.assertNotNull(GitVcs.getInstance(project));
final Set<VirtualFile> conflictedFiles = new TreeSet<>(new Comparator<VirtualFile>() {
@Override
public int compare(@NotNull VirtualFile f1, @NotNull VirtualFile f2) {
return f1.getPresentableUrl().compareTo(f2.getPresentableUrl());
}
});
for (Change change : ChangeListManager.getInstance(project).getAllChanges()) {
if (change.getFileStatus() != FileStatus.MERGED_WITH_CONFLICTS) {
continue;
}
ContentRevision before = change.getBeforeRevision();
ContentRevision after = change.getAfterRevision();
if (before != null) {
VirtualFile file = before.getFile().getVirtualFile();
if (file != null) {
conflictedFiles.add(file);
}
}
if (after != null) {
VirtualFile file = after.getFile().getVirtualFile();
if (file != null) {
conflictedFiles.add(file);
}
}
}
AbstractVcsHelper.getInstance(project).showMergeDialog(newArrayList(conflictedFiles), vcs.getMergeProvider());
for (GitRepository repository : GitUtil.getRepositoriesForFiles(project, conflictedFiles)) {
repository.update();
}
}
use of com.intellij.openapi.vcs.changes.ContentRevision 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 com.intellij.openapi.vcs.changes.ContentRevision 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 com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class GitRollbackEnvironment method rollbackChanges.
public void rollbackChanges(@NotNull List<Change> changes, final List<VcsException> exceptions, @NotNull final RollbackProgressListener listener) {
HashMap<VirtualFile, List<FilePath>> toUnindex = new HashMap<>();
HashMap<VirtualFile, List<FilePath>> toUnversion = new HashMap<>();
HashMap<VirtualFile, List<FilePath>> toRevert = new HashMap<>();
List<FilePath> toDelete = new ArrayList<>();
listener.determinate();
// collect changes to revert
for (Change c : changes) {
switch(c.getType()) {
case NEW:
// note that this the only change that could happen
// for HEAD-less working directories.
registerFile(toUnversion, c.getAfterRevision().getFile(), exceptions);
break;
case MOVED:
registerFile(toRevert, c.getBeforeRevision().getFile(), exceptions);
registerFile(toUnindex, c.getAfterRevision().getFile(), exceptions);
toDelete.add(c.getAfterRevision().getFile());
break;
case MODIFICATION:
// note that changes are also removed from index, if they got into index somehow
registerFile(toUnindex, c.getBeforeRevision().getFile(), exceptions);
registerFile(toRevert, c.getBeforeRevision().getFile(), exceptions);
break;
case DELETED:
registerFile(toRevert, c.getBeforeRevision().getFile(), exceptions);
break;
}
}
// unindex files
for (Map.Entry<VirtualFile, List<FilePath>> entry : toUnindex.entrySet()) {
listener.accept(entry.getValue());
try {
unindex(entry.getKey(), entry.getValue(), false);
} catch (VcsException e) {
exceptions.add(e);
}
}
// unversion files
for (Map.Entry<VirtualFile, List<FilePath>> entry : toUnversion.entrySet()) {
listener.accept(entry.getValue());
try {
unindex(entry.getKey(), entry.getValue(), true);
} catch (VcsException e) {
exceptions.add(e);
}
}
// delete files
for (FilePath file : toDelete) {
listener.accept(file);
try {
final File ioFile = file.getIOFile();
if (ioFile.exists()) {
if (!ioFile.delete()) {
//noinspection ThrowableInstanceNeverThrown
exceptions.add(new VcsException("Unable to delete file: " + file));
}
}
} catch (Exception e) {
//noinspection ThrowableInstanceNeverThrown
exceptions.add(new VcsException("Unable to delete file: " + file, e));
}
}
// revert files from HEAD
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
try {
for (Map.Entry<VirtualFile, List<FilePath>> entry : toRevert.entrySet()) {
listener.accept(entry.getValue());
try {
revert(entry.getKey(), entry.getValue());
} catch (VcsException e) {
exceptions.add(e);
}
}
} finally {
token.finish();
}
LocalFileSystem lfs = LocalFileSystem.getInstance();
HashSet<File> filesToRefresh = new HashSet<>();
for (Change c : changes) {
ContentRevision before = c.getBeforeRevision();
if (before != null) {
filesToRefresh.add(new File(before.getFile().getPath()));
}
ContentRevision after = c.getAfterRevision();
if (after != null) {
filesToRefresh.add(new File(after.getFile().getPath()));
}
}
lfs.refreshIoFiles(filesToRefresh);
for (GitRepository repo : GitUtil.getRepositoryManager(myProject).getRepositories()) {
repo.update();
}
}
Aggregations