use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class RevertCommittedStuffAbstractAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
final VirtualFile baseDir = project.getBaseDir();
assert baseDir != null;
final Change[] changes = myForPerformConvertor.convert(e);
if (changes == null || changes.length == 0)
return;
final List<Change> changesList = new ArrayList<>();
Collections.addAll(changesList, changes);
FileDocumentManager.getInstance().saveAllDocuments();
String defaultName = null;
final ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
if (changeLists != null && changeLists.length > 0) {
defaultName = VcsBundle.message("revert.changes.default.name", changeLists[0].getName());
}
final ChangeListChooser chooser = new ChangeListChooser(project, ChangeListManager.getInstance(project).getChangeListsCopy(), null, "Select Target Changelist", defaultName);
if (!chooser.showAndGet()) {
return;
}
final List<FilePatch> patches = new ArrayList<>();
ProgressManager.getInstance().run(new Task.Backgroundable(project, VcsBundle.message("revert.changes.title"), true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
final List<Change> preprocessed = ChangesPreprocess.preprocessChangesRemoveDeletedForDuplicateMoved(changesList);
patches.addAll(IdeaTextPatchBuilder.buildPatch(project, preprocessed, baseDir.getPresentableUrl(), true));
} catch (final VcsException ex) {
WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog(project, "Failed to revert changes: " + ex.getMessage(), VcsBundle.message("revert.changes.title"));
}
}, null, myProject);
indicator.cancel();
}
}
@Override
public void onSuccess() {
new PatchApplier<BinaryFilePatch>(project, baseDir, patches, chooser.getSelectedList(), null, null).execute();
}
});
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class RollbackDeletionAction method processFiles.
protected List<VcsException> processFiles(final AbstractVcs vcs, final List<FilePath> files) {
RollbackEnvironment environment = vcs.getRollbackEnvironment();
if (environment == null)
return Collections.emptyList();
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
indicator.setText(vcs.getDisplayName() + ": performing rollback...");
}
final List<VcsException> result = new ArrayList<>(0);
try {
environment.rollbackMissingFileDeletion(files, result, new RollbackProgressModifier(files.size(), indicator));
} catch (ProcessCanceledException e) {
// for files refresh
}
LocalFileSystem.getInstance().refreshIoFiles(ChangesUtil.filePathsToFiles(files));
return result;
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class ChangeDiffRequestProducer method createRequest.
@NotNull
private DiffRequest createRequest(@Nullable Project project, @NotNull Change change, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
if (ChangesUtil.isTextConflictingChange(change)) {
// three side diff
// FIXME: This part is ugly as a VCS merge subsystem itself.
FilePath path = ChangesUtil.getFilePath(change);
VirtualFile file = path.getVirtualFile();
if (file == null) {
file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath());
}
if (file == null)
throw new DiffRequestProducerException("Can't show merge conflict - file not found");
if (project == null) {
throw new DiffRequestProducerException("Can't show merge conflict - project is unknown");
}
final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, project);
if (vcs == null || vcs.getMergeProvider() == null) {
throw new DiffRequestProducerException("Can't show merge conflict - operation nos supported");
}
try {
// FIXME: loadRevisions() can call runProcessWithProgressSynchronously() inside
final Ref<Throwable> exceptionRef = new Ref<>();
final Ref<MergeData> mergeDataRef = new Ref<>();
final VirtualFile finalFile = file;
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
mergeDataRef.set(vcs.getMergeProvider().loadRevisions(finalFile));
} catch (VcsException e) {
exceptionRef.set(e);
}
});
if (!exceptionRef.isNull()) {
Throwable e = exceptionRef.get();
if (e instanceof VcsException)
throw (VcsException) e;
if (e instanceof Error)
throw (Error) e;
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException(e);
}
MergeData mergeData = mergeDataRef.get();
ContentRevision bRev = change.getBeforeRevision();
ContentRevision aRev = change.getAfterRevision();
String beforeRevisionTitle = getRevisionTitle(bRev, "Your version");
String afterRevisionTitle = getRevisionTitle(aRev, "Server version");
String title = DiffRequestFactory.getInstance().getTitle(file);
List<String> titles = ContainerUtil.list(beforeRevisionTitle, "Base Version", afterRevisionTitle);
DiffContentFactory contentFactory = DiffContentFactory.getInstance();
List<DiffContent> contents = ContainerUtil.list(contentFactory.createFromBytes(project, mergeData.CURRENT, file), contentFactory.createFromBytes(project, mergeData.ORIGINAL, file), contentFactory.createFromBytes(project, mergeData.LAST, file));
SimpleDiffRequest request = new SimpleDiffRequest(title, contents, titles);
MergeUtil.putRevisionInfos(request, mergeData);
return request;
} catch (VcsException | IOException e) {
LOG.info(e);
throw new DiffRequestProducerException(e);
}
} else {
ContentRevision bRev = change.getBeforeRevision();
ContentRevision aRev = change.getAfterRevision();
if (bRev == null && aRev == null) {
LOG.warn("Both revision contents are empty");
throw new DiffRequestProducerException("Bad revisions contents");
}
if (bRev != null)
checkContentRevision(project, bRev, context, indicator);
if (aRev != null)
checkContentRevision(project, aRev, context, indicator);
String title = getRequestTitle(change);
indicator.setIndeterminate(true);
DiffContent content1 = createContent(project, bRev, context, indicator);
DiffContent content2 = createContent(project, aRev, context, indicator);
final String userLeftRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_LEFT_CONTENT_TITLE);
String beforeRevisionTitle = userLeftRevisionTitle != null ? userLeftRevisionTitle : getRevisionTitle(bRev, "Base version");
final String userRightRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_RIGHT_CONTENT_TITLE);
String afterRevisionTitle = userRightRevisionTitle != null ? userRightRevisionTitle : getRevisionTitle(aRev, "Your version");
SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, beforeRevisionTitle, afterRevisionTitle);
boolean bRevCurrent = bRev instanceof CurrentContentRevision;
boolean aRevCurrent = aRev instanceof CurrentContentRevision;
if (bRevCurrent && !aRevCurrent)
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.LEFT);
if (!bRevCurrent && aRevCurrent)
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.RIGHT);
return request;
}
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class GitAnnotationProvider method parseAnnotations.
@NotNull
private GitFileAnnotation parseAnnotations(@Nullable VcsRevisionNumber revision, @NotNull VirtualFile file, @NotNull VirtualFile root, @NotNull String output) throws VcsException {
Interner<FilePath> pathInterner = new Interner<>();
try {
List<LineInfo> lines = new ArrayList<>();
HashMap<String, LineInfo> commits = new HashMap<>();
for (StringScanner s = new StringScanner(output); s.hasMoreData(); ) {
// parse header line
String commitHash = s.spaceToken();
if (commitHash.equals(GitRevisionNumber.NOT_COMMITTED_HASH)) {
commitHash = null;
}
// skip revision line number
s.spaceToken();
String s1 = s.spaceToken();
int lineNum = Integer.parseInt(s1);
s.nextLine();
// parse commit information
LineInfo commit = commits.get(commitHash);
if (commit != null || commitHash == null) {
while (s.hasMoreData() && !s.startsWith('\t')) {
s.nextLine();
}
} else {
Date committerDate = null;
FilePath filePath = null;
String subject = null;
String authorName = null;
String authorEmail = null;
String previousRevision = null;
FilePath previousFilePath = null;
while (s.hasMoreData() && !s.startsWith('\t')) {
String key = s.spaceToken();
String value = s.line();
if (SUBJECT_KEY.equals(key)) {
subject = value;
} else if (AUTHOR_KEY.equals(key)) {
authorName = value;
} else if (COMMITTER_TIME_KEY.equals(key)) {
committerDate = GitUtil.parseTimestamp(value);
} else if (FILENAME_KEY.equals(key)) {
filePath = VcsUtil.getFilePath(root, value);
} else if (AUTHOR_EMAIL_KEY.equals(key)) {
authorEmail = value;
if (authorEmail.startsWith("<") && authorEmail.endsWith(">")) {
authorEmail = authorEmail.substring(1, authorEmail.length() - 1);
}
} else if (PREVIOUS_KEY.equals(key)) {
int index = value.indexOf(' ');
if (index != -1) {
previousRevision = value.substring(0, index);
previousFilePath = VcsUtil.getFilePath(root, value.substring(index + 1, value.length()));
}
}
}
if (committerDate == null || filePath == null || authorName == null || authorEmail == null || subject == null) {
throw new VcsException("Output for line " + lineNum + " lacks necessary data");
}
GitRevisionNumber revisionNumber = new GitRevisionNumber(commitHash, committerDate);
VcsUser author = myUserRegistry.createUser(authorName, authorEmail);
GitRevisionNumber previousRevisionNumber = previousRevision != null ? new GitRevisionNumber(previousRevision) : null;
filePath = pathInterner.intern(filePath);
if (previousFilePath != null)
previousFilePath = pathInterner.intern(previousFilePath);
commit = new LineInfo(myProject, revisionNumber, filePath, committerDate, author, subject, previousRevisionNumber, previousFilePath);
commits.put(commitHash, commit);
}
s.nextLine();
int expectedLineNum = lines.size() + 1;
if (lineNum != expectedLineNum) {
throw new VcsException("Adding for info for line " + lineNum + " but we are expecting it to be for " + expectedLineNum);
}
lines.add(commit);
}
return new GitFileAnnotation(myProject, file, revision, lines);
} catch (Exception e) {
LOG.error("Couldn't parse annotation: " + e, new Attachment("output.txt", output));
throw new VcsException(e);
}
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class GitAnnotationProvider method annotate.
@NotNull
public FileAnnotation annotate(@NotNull final VirtualFile file, @Nullable final VcsFileRevision revision) throws VcsException {
if (file.isDirectory()) {
throw new VcsException("Cannot annotate a directory");
}
final FilePath currentFilePath = VcsUtil.getFilePath(file.getPath());
final FilePath realFilePath;
if (revision == null) {
realFilePath = GitHistoryUtils.getLastCommitName(myProject, currentFilePath);
} else {
realFilePath = ((VcsFileRevisionEx) revision).getPath();
}
VcsRevisionNumber revisionNumber = revision != null ? revision.getRevisionNumber() : null;
return annotate(realFilePath, revisionNumber, file);
}
Aggregations