FilePath path = VcsUtil.getFilePath(file); return P4ServerComponent .perform(project, entity.first, new AddEditAction(path, null, p4cl, path.getCharset(project))) .whenCompleted((r) -> VcsDirtyScopeManager.getInstance(project).filesDirty(Collections.singleton(file), null)) .whenServerError((err) -> exceptions.add(new VcsException(err)))
private AddEditResult addEditFile(IClient client, ClientConfig config, AddEditAction action) throws P4JavaException { if (LOG.isDebugEnabled()) { LOG.debug("Running add/edit against the server for " + action.getFile()); LOG.debug("Working directory: " + ((Server)client.getServer()).getUsageOptions().getWorkingDirectory()); List<IFileSpec> srcFiles = FileSpecBuildUtil.escapedForFilePaths(action.getFile()); OpenFileStatus status = new OpenFileStatus(cmd.getFileDetailsForOpenedSpecs(client.getServer(), srcFiles, 1000)); status.throwIfError(); LOG.info("Already opened for add/edit: " + action.getFile()); return new AddEditResult(config, action.getFile(), false, action.getFileType(), action.getChangelistId() == null ? P4ChangelistIdImpl.createDefaultChangelistId(config.getClientServerRef()) : action.getChangelistId(), new P4RemoteFileImpl(status.getOpen().get(0))); LOG.info("File added, but server says it's deleted. Reverted " + action.getFile() + ": " + MessageStatusUtil.getMessages(reverted, "\n")); MessageStatusUtil.throwIfError(reverted); srcFiles = FileSpecBuildUtil.forFilePaths(action.getFile()); if (LOG.isDebugEnabled()) { LOG.debug("Opening " + action.getFile() + " for add as " + srcFiles); ret = cmd.addFiles(client, srcFiles, null, action.getChangelistId(), action.getCharset()); } else { if (LOG.isDebugEnabled()) { LOG.debug("Opening " + action.getFile() + " for edit as " + srcFiles);
@NotNull @Override public String[] getDisplayParameters() { if (changelistId != null) { return new String[] { changeId(changelistId) }; } return EMPTY; }
case ADD_EDIT_FILE: { AddEditAction fileAction = (AddEditAction) action; return performFileAction(config, action, fileAction.getFile(), fileAction.getFileType(), P4FileAction.ADD_EDIT);
P4LocalFileImpl.Builder builder = files.get(a.getFile()); if (builder == null) { builder = new P4LocalFileImpl.Builder() .withLocal(a.getFile()) .withHave(new P4Revision(-1)); files.put(a.getFile(), builder); .withChangelist(a.getChangelistId()); break;
LOG.debug("Remove existing action `add/edit " + existing.getFile() + "` because of a later move for the same file.");
public AddEditAction(@NotNull FilePath file, @Nullable P4FileType type, @NotNull P4ChangelistId changelistId, @Nullable String charset) { this(createActionId(AddEditAction.class), file, type, changelistId, charset); }
return ((MoveFileAction) action).getChangelistId(); case ADD_EDIT_FILE: return ((AddEditAction) action).getChangelistId(); case DELETE_FILE: return ((DeleteFileAction) action).getChangelistId();
(ClientActionRunner<AddEditResult>) (config, action) -> new ActionAnswerImpl<>(connectionManager.withConnection(config, ((AddEditAction) action).getFile().getIOFile().getParentFile(), (client) -> addEditFile(client, config, (AddEditAction) action))));
@Test void curateFile_add_delete() { Map<String, MockVirtualFile> fs = MockVirtualFileSystem.createTree( "a.txt", "abc" ); MockVirtualFile f1 = fs.get("a.txt"); PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); List<ActionStore.PendingAction> actions = new ArrayList<>(); P4ChangelistIdImpl cl = new P4ChangelistIdImpl(100, REF_A1); ActionStore.PendingAction addFile = ActionStore.createPendingAction(REF_A1, new AddEditAction( f1.asFilePath(), null, cl, (String) null)); actions.add(addFile); ActionStore.PendingAction deleteFile = ActionStore.createPendingAction(REF_A1, new DeleteFileAction(f1.asFilePath(), cl)); curator.curateActionList(deleteFile, actions); // Delete file cannot tell if the file was open for add or edit, so it must be left alone. assertContainsExactly(actions, addFile, deleteFile); }
AddEditAction a = (AddEditAction) action; ret.data .putFilePath("file", a.getFile()) .putString("type", a.getFileType() == null ? null : a.getFileType().toString()) .putChangelistId("cl-id", a.getChangelistId()) .putString("charset", a.getCharset()); break;
new AddEditAction(fp, getFileType(fp), id, (String) null)) .whenAnyState(() -> { if (LOG.isDebugEnabled()) {
@Test void curateFile_delete_add_delete() { 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 addFile = ActionStore.createPendingAction(REF_A1, new AddEditAction(file.asFilePath(), null, cl, (String) null)); actions.add(addFile); // Reuse the delete request curator.curateActionList(deleteFile, actions); // Because we stop looking with the delete -> add, the list should be maintained as expected. assertContainsExactly(actions, deleteFile, addFile, deleteFile); }
.perform(project, root.getClientConfig(), new AddEditAction(fp, getFileType(fp), id, (String) null)) .whenCompleted((res) -> ChangeListManager.getInstance(project).scheduleUpdate(true))
@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); }
@Test void curateFile_addTgt_moveSrc_deleteSrc() { SimplePendingActionFactory actionFactory = new SimplePendingActionFactory(REF_A1); PendingActionCurator curator = new PendingActionCurator(actionFactory); Map<String, MockVirtualFile> fs = MockVirtualFileSystem.createTree( "a.txt", "abc", "b.txt", "def" ); MockVirtualFile src = fs.get("a.txt"); MockVirtualFile tgt = fs.get("b.txt"); List<ActionStore.PendingAction> actions = new ArrayList<>(); P4ChangelistIdImpl cl1 = new P4ChangelistIdImpl(100, REF_A1); P4ChangelistIdImpl cl2 = new P4ChangelistIdImpl(100, REF_A1); ActionStore.PendingAction addFile = ActionStore.createPendingAction(REF_A1, new AddEditAction(tgt.asFilePath(), null, cl1, (String) null)); actions.add(addFile); ActionStore.PendingAction moveFile = ActionStore.createPendingAction(REF_A1, new MoveFileAction(src.asFilePath(), tgt.asFilePath(), cl1)); actions.add(moveFile); ActionStore.PendingAction deleteFile = ActionStore.createPendingAction(REF_A1, new DeleteFileAction(src.asFilePath(), cl2)); curator.curateActionList(deleteFile, actions); assertSize(0, actionFactory.created); assertContainsExactly(actions, addFile, moveFile); }
state.data.getChangelistIdNotNull("cl-id")); case ADD_EDIT_FILE: return new AddEditAction(state.actionId, state.data.getFilePathNotNull("file"), P4FileType.convertNullable(state.data.getStringNullable("type", null)),
new AddEditAction(tgt.asFilePath(), null, cl1, (String) null)); actions.add(addFile); ActionStore.PendingAction moveFile = ActionStore.createPendingAction(REF_A1,
new AddEditAction(tgt, null, id, (String) null)));
.perform(root.getClientConfig(), new AddEditAction(addedFile, null, defaultChangeId, (String) null)); assertSize(0, errors); assertSize(1, vcs.cacheComponent.getState().pendingActions);