private RevertFileResult revertFile(IClient client, ClientConfig config, RevertFileAction action) throws P4JavaException { // Explicit request to revert the file. So the file contents will be changed in the operation. List<IFileSpec> srcFiles = FileSpecBuildUtil.escapedForFilePaths(action.getFile()); SpecialFileEventMessage.send(project).fileReverted(new SpecialFileEventMessage.SpecialFileEvent( srcFiles.stream().map(IFileSpec::toString).collect(Collectors.toList()), "User request to revert files; on-disk contents changed.")); List<IFileSpec> reverted = cmd.revertFiles(client, srcFiles, false); LOG.info("Explicit revert " + action.getFile() + ": " + MessageStatusUtil.getMessages(reverted, "\n")); MessageStatusUtil.throwIfError(reverted); return new RevertFileResult(config, action.getFile(), reverted); }
@NotNull @Override public String[] getDisplayParameters() { if (isRevertOnlyIfUnchanged()) { // TODO message catalog // TODO make this static return new String[] { "unchanged" }; } return EMPTY; }
public RevertFileAction(@NotNull FilePath file, boolean ifUnchanged) { this(createActionId(RevertFileAction.class), file, ifUnchanged); }
.filter((p) -> p.first != null) .map((p) -> P4ServerComponent .perform(project, p.first.getClientConfig(), new RevertFileAction(p.second, false)) .whenCompleted((r) -> { LOG.info("Reverted " + p.second);
RevertFileAction a = (RevertFileAction) action; ret.data .putFilePath("file", a.getFile()) .putBoolean("unchanged", a.isRevertOnlyIfUnchanged()); break;
@Test void curateFile_delete_revert_add() { SimplePendingActionFactory actionFactory = new SimplePendingActionFactory(REF_A1); PendingActionCurator curator = new PendingActionCurator(actionFactory); Map<String, MockVirtualFile> fs = MockVirtualFileSystem.createTree( "a.txt", "abc" ); MockVirtualFile file = fs.get("a.txt"); List<ActionStore.PendingAction> actions = new ArrayList<>(); P4ChangelistIdImpl cl = new P4ChangelistIdImpl(100, REF_A1); ActionStore.PendingAction deleteFile = ActionStore.createPendingAction(REF_A1, new DeleteFileAction(file.asFilePath(), cl)); actions.add(deleteFile); ActionStore.PendingAction revertFile = ActionStore.createPendingAction(REF_A1, new RevertFileAction(file.asFilePath(), false)); actions.add(revertFile); ActionStore.PendingAction addFile = ActionStore.createPendingAction(REF_A1, new AddEditAction(file.asFilePath(), null, cl, (String) null)); curator.curateActionList(addFile, actions); // Because offline revert isn't implemented, the revert then add maintains the integrity. assertContainsExactly(actions, deleteFile, revertFile, addFile); }
@Override public void rollbackIfUnchanged(VirtualFile file) { if (file == null || project.isDisposed()) { return; } ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (registry == null || registry.isDisposed()) { LOG.info("Skipping revert for " + file + ": plugin not in a valid state"); return; } FilePath fp = VcsUtil.getFilePath(file); if (fp == null) { LOG.info("Skipping revert for " + file + ": no FilePath found"); return; } ClientConfigRoot root = registry.getClientFor(file); if (root == null) { LOG.info("SKipping revert for " + file + ": no P4 root found"); return; } P4ServerComponent .perform(project, root.getClientConfig(), new RevertFileAction(fp, true)) .whenCompleted((r) -> ChangeListManager.getInstance(project).scheduleUpdate(true)); }
return performFileAction(config, action, fileAction.getFile(), null, P4FileAction.REVERTED);
state.data.getChangelistIdNullable("cl-id")); case REVERT_FILE: return new RevertFileAction(state.actionId, state.data.getFilePathNotNull("file"), state.data.getBooleanNullable("unchanged", false));
files.remove(a.getFile()); break;
.map((cm) -> new ConnectCommandRunner(idea.getMockProject(), cm)) .futureMap((runner, sink) -> runner.perform(clientConfig, new RevertFileAction(newFile, false)) .whenCompleted(sink::resolve) .whenServerError(sink::reject)
(ClientActionRunner<RevertFileResult>) (config, action) -> new ActionAnswerImpl<>(connectionManager.withConnection(config, ((RevertFileAction) action).getFile().getIOFile().getParentFile(), (client) -> revertFile(client, config, (RevertFileAction) action))));