com.intellij.openapi.vcs.changes.Change Java Examples
The following examples show how to use
com.intellij.openapi.vcs.changes.Change.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryChangesBrowser.java From consulo with Apache License 2.0 | 6 votes |
@Override public Object getData(@Nonnull Key<?> dataId) { if (CommittedChangesBrowserUseCase.DATA_KEY == dataId) { return myUseCase; } else if (VcsDataKeys.SELECTED_CHANGES == dataId) { final List<Change> list = myViewer.getSelectedChanges(); return list.toArray(new Change[list.size()]); } else if (VcsDataKeys.CHANGE_LEAD_SELECTION == dataId) { final Change highestSelection = myViewer.getHighestLeadSelection(); return (highestSelection == null) ? new Change[]{} : new Change[]{highestSelection}; } else { final TypeSafeDataProviderAdapter adapter = new TypeSafeDataProviderAdapter(this); return adapter.getData(dataId); } }
Example #2
Source File: GitDiffProvider.java From review-board-idea-plugin with Apache License 2.0 | 6 votes |
@Override public String generateDiff(Project project, AnActionEvent action) throws VcsException { String diffContent; VcsRevisionNumber[] data = action.getData(VcsDataKeys.VCS_REVISION_NUMBERS); if (data != null) { diffContent = fromRevisions(project, project.getBaseDir(), data[data.length - 1], data[0]); } else { final Change[] changes = action.getData(VcsDataKeys.CHANGES); // if (changes == null) { // return null; // } List<VirtualFile> virtualFiles = new ArrayList<>(); // for (Change change : changes) { // if (change.getVirtualFile() != null) { // virtualFiles.add(change.getVirtualFile()); // } // } diffContent = fromHead(project, project.getBaseDir(), virtualFiles); } return diffContent; }
Example #3
Source File: L2GitUtil.java From azure-devops-intellij with MIT License | 6 votes |
/** * Adds a new line of text to a file and adds/commits it * * @param file * @param repository * @param project * @throws IOException * @throws IOException */ public static void editAndCommitFile(final File file, final git4idea.repo.GitRepository repository, final Project project) throws IOException { // edits file final VirtualFile readmeVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(file); Assert.assertNotNull("Git repository should have a " + file.getName() + " file", readmeVirtualFile); FileUtil.writeToFile(file, "\nnew line", true); // adds and commits the change final LocalChangeListImpl localChangeList = LocalChangeListImpl.createEmptyChangeListImpl(project, "TestCommit", "12345"); final ChangeListManagerImpl changeListManager = ChangeListManagerImpl.getInstanceImpl(project); VcsDirtyScopeManager.getInstance(project).markEverythingDirty(); changeListManager.ensureUpToDate(false); changeListManager.addUnversionedFiles(localChangeList, ImmutableList.of(readmeVirtualFile)); final Change change = changeListManager.getChange(LocalFileSystem.getInstance().findFileByIoFile(file)); repository.getVcs().getCheckinEnvironment().commit(ImmutableList.of(change), COMMIT_MESSAGE); }
Example #4
Source File: TFSRollbackEnvironmentTest.java From azure-devops-intellij with MIT License | 6 votes |
private void setupRollbackChanges() { Change change1 = mock(Change.class); Change change2 = mock(Change.class); Change change3 = mock(Change.class); changes = ImmutableList.of(change1, change2, change3); ContentRevision contentRevision1 = mock(ContentRevision.class); ContentRevision contentRevision2 = mock(ContentRevision.class); ContentRevision contentRevision3 = mock(ContentRevision.class); when(change1.getType()).thenReturn(Change.Type.DELETED); when(change2.getType()).thenReturn(Change.Type.MODIFICATION); when(change3.getType()).thenReturn(Change.Type.NEW); when(contentRevision1.getFile()).thenReturn(filePath1); when(contentRevision2.getFile()).thenReturn(filePath2); when(contentRevision3.getFile()).thenReturn(filePath3); when(change1.getBeforeRevision()).thenReturn(contentRevision1); when(change2.getAfterRevision()).thenReturn(contentRevision2); when(change3.getAfterRevision()).thenReturn(contentRevision3); }
Example #5
Source File: ChangeGoToChangePopupAction.java From consulo with Apache License 2.0 | 6 votes |
@SuppressWarnings("AbstractMethodCallInConstructor") public Fake(@Nonnull Chain chain, int selection, @Nonnull Consumer<Integer> onSelected) { super(chain, onSelected); mySelection = selection; // we want to show ChangeBrowser-based popup, so have to create some fake changes List<? extends DiffRequestProducer> requests = chain.getRequests(); myChanges = new ArrayList<Change>(requests.size()); for (int i = 0; i < requests.size(); i++) { FilePath path = getFilePath(i); FileStatus status = getFileStatus(i); FakeContentRevision revision = new FakeContentRevision(path); myChanges.add(new Change(revision, revision, status)); } }
Example #6
Source File: ChangesTreeList.java From consulo with Apache License 2.0 | 6 votes |
@Override public Color getFileColorFor(Object object) { VirtualFile file; if (object instanceof FilePath) { file = ((FilePath)object).getVirtualFile(); } else if (object instanceof Change) { file = ((Change)object).getVirtualFile(); } else { file = ObjectUtils.tryCast(object, VirtualFile.class); } if (file != null) { return FileColorManager.getInstance(myProject).getFileColor(file); } return super.getFileColorFor(object); }
Example #7
Source File: VcsCommittedListsZipperAdapter.java From consulo with Apache License 2.0 | 6 votes |
public CommittedChangeList zip(final RepositoryLocationGroup group, final List<CommittedChangeList> lists) { if (lists.size() == 1) { return lists.get(0); } final CommittedChangeList result = lists.get(0); for (int i = 1; i < lists.size(); i++) { final CommittedChangeList list = lists.get(i); for (Change change : list.getChanges()) { final Collection<Change> resultChanges = result.getChanges(); if (! resultChanges.contains(change)) { resultChanges.add(change); } } } return result; }
Example #8
Source File: CommittedChangesCache.java From consulo with Apache License 2.0 | 6 votes |
@Override public CommittedChangeList zip(final RepositoryLocationGroup group, final List<CommittedChangeList> lists) { if (lists.size() == 1) { return lists.get(0); } final CommittedChangeList victim = ReceivedChangeList.unwrap(lists.get(0)); final ReceivedChangeList result = new ReceivedChangeList(victim); result.setForcePartial(false); final Set<Change> baseChanges = new HashSet<Change>(); for (CommittedChangeList list : lists) { baseChanges.addAll(ReceivedChangeList.unwrap(list).getChanges()); final Collection<Change> changes = list.getChanges(); for (Change change : changes) { if (!result.getChanges().contains(change)) { result.addChange(change); } } } result.setForcePartial(baseChanges.size() != result.getChanges().size()); return result; }
Example #9
Source File: DiffCompareInfoProvider.java From azure-devops-intellij with MIT License | 5 votes |
private GitCommitCompareInfo getCompareInfo(final Project project, final GitRepository gitRepository, final String source, final String target) throws VcsException { final VirtualFile root = gitRepository.getRoot(); final List<GitCommit> commits1 = getUtilWrapper().history(project, root, ".." + target); final List<GitCommit> commits2 = getUtilWrapper().history(project, root, target + ".."); final Collection<Change> diff = getUtilWrapper().getDiff(project, root, target, source); final GitCommitCompareInfo info = new GitCommitCompareInfo(GitCommitCompareInfo.InfoType.BRANCH_TO_HEAD); info.put(gitRepository, diff); info.put(gitRepository, new Pair<List<GitCommit>, List<GitCommit>>(commits1, commits2)); return info; }
Example #10
Source File: ChangeInfoCalculator.java From consulo with Apache License 2.0 | 5 votes |
public void update(@Nonnull List<Change> displayedChanges, @Nonnull List<Change> includedChanges, int unversionedFilesCount, int includedUnversionedFilesCount) { myDisplayedChanges = displayedChanges; myIncludedChanges = includedChanges; myUnversionedFilesCount = unversionedFilesCount; myIncludedUnversionedFilesCount = includedUnversionedFilesCount; }
Example #11
Source File: IdeaDiffProvider.java From review-board-idea-plugin with Apache License 2.0 | 5 votes |
@Override public String generateDiff(Project project, AnActionEvent action) throws VcsException { try { Change[] data = action.getData(VcsDataKeys.CHANGES); File tempFile = File.createTempFile("diff", "patch"); PatchCreator.create(project, Arrays.asList(data), tempFile.getPath(), false, null); byte[] encoded = Files.readAllBytes(Paths.get(tempFile.getPath())); String contents = new String(encoded, StandardCharsets.UTF_8); return contents; } catch (IOException e) { e.printStackTrace(); } return null; }
Example #12
Source File: ChangelistBuilderStatusVisitor.java From azure-devops-intellij with MIT License | 5 votes |
public void renamed(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus) { if (localItemExists) { final ContentRevision before = getPreviousRenamedRevision(localPath, serverStatus.localVer); final ContentRevision after = CurrentContentRevision.create(localPath); changelistBuilder.processChange(new Change(before, after), TFSVcs.getKey()); } else { changelistBuilder.processLocallyDeletedFile(localPath); } }
Example #13
Source File: ChangelistBuilderStatusVisitor.java From azure-devops-intellij with MIT License | 5 votes |
public void renamedCheckedOut(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus) { if (localItemExists) { final ContentRevision before = getPreviousRenamedRevision(localPath, serverStatus.localVer); final ContentRevision after = CurrentContentRevision.create(localPath); changelistBuilder.processChange(new Change(before, after), TFSVcs.getKey()); } else { changelistBuilder.processLocallyDeletedFile(localPath); } }
Example #14
Source File: ChangesBrowserFilePathNode.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable public static FilePath safeCastToFilePath(Object o) { if (o instanceof FilePath) return (FilePath)o; if (o instanceof Change) { return ChangesUtil.getAfterPath((Change)o); } return null; }
Example #15
Source File: ChangelistBuilderStatusVisitor.java From azure-devops-intellij with MIT License | 5 votes |
public void checkedOutForEdit(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus) { if (localItemExists) { TFSContentRevision baseRevision = TFSContentRevision.create(project, localPath, serverStatus.localVer, serverStatus.modicationDate); changelistBuilder.processChange(new Change(baseRevision, CurrentContentRevision.create(localPath)), TFSVcs.getKey()); } else { changelistBuilder.processLocallyDeletedFile(localPath); } }
Example #16
Source File: PatchReviewItem.java From Crucible4IDEA with MIT License | 5 votes |
@NotNull private List<Change> getChanges(@NotNull List<AbstractFilePatchInProgress> patches) { return ContainerUtil.map(patches, new Function<AbstractFilePatchInProgress, Change>() { @Override public Change fun(AbstractFilePatchInProgress patch) { return patch.getChange(); } }); }
Example #17
Source File: MockChangelistBuilder.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Override public void processChangeInList(Change change, String changeListName, VcsKey vcsKey) { assertEquals(expectedKey, vcsKey); // ensure the changelist exists. gate.getExisting(changeListName); addChange(changeListName, change); }
Example #18
Source File: FormatChangedTextUtil.java From consulo with Apache License 2.0 | 5 votes |
/** * Allows to answer if given file or any file below the given directory (any level of nesting) has changes in comparison with VCS. * * @param file target directory to check * @param project target project * @return <code>true</code> if given file or any file below the given directory has changes in comparison with VCS; * <code>false</code> otherwise */ public static boolean hasChanges(@Nonnull VirtualFile file, @Nonnull Project project) { final Collection<Change> changes = ChangeListManager.getInstance(project).getChangesIn(file); for (Change change : changes) { if (change.getType() == Change.Type.NEW || change.getType() == Change.Type.MODIFICATION) { return true; } } return false; }
Example #19
Source File: PatchDiffRequestFactory.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static DiffRequest createDiffRequest(@javax.annotation.Nullable Project project, @Nonnull Change change, @Nonnull String name, @Nonnull UserDataHolder context, @Nonnull ProgressIndicator indicator) throws DiffRequestProducerException { ChangeDiffRequestProducer proxyProducer = ChangeDiffRequestProducer.create(project, change); if (proxyProducer == null) throw new DiffRequestProducerException("Can't show diff for '" + name + "'"); return proxyProducer.process(context, indicator); }
Example #20
Source File: SessionDialog.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static JComponent createConfigurationUI(final CommitSession session, final List<Change> changes, final String commitMessage) { try { return session.getAdditionalConfigurationUI(changes, commitMessage); } catch(AbstractMethodError e) { return session.getAdditionalConfigurationUI(); } }
Example #21
Source File: VcsUtil.java From consulo with Apache License 2.0 | 5 votes |
/** * @param change "Change" description. * @return Return true if the "Change" object is created for "Rename" operation: * in this case name of files for "before" and "after" revisions must not * coniside. */ public static boolean isRenameChange(Change change) { boolean isRenamed = false; ContentRevision before = change.getBeforeRevision(); ContentRevision after = change.getAfterRevision(); if (before != null && after != null) { String prevFile = getCanonicalLocalPath(before.getFile().getPath()); String newFile = getCanonicalLocalPath(after.getFile().getPath()); isRenamed = !prevFile.equals(newFile); } return isRenamed; }
Example #22
Source File: PatchCreator.java From consulo with Apache License 2.0 | 5 votes |
public static void create(Project p, @Nonnull String basePath, List<Change> changes, String filePath, boolean isReverse, CommitContext commitContext, Charset charset) throws IOException, VcsException { List<FilePatch> patches = IdeaTextPatchBuilder.buildPatch(p, changes, basePath, isReverse); PatchWriter.writePatches(p, filePath, basePath, patches, commitContext, charset); }
Example #23
Source File: VcsDiffUtil.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess public static void showDiffFor(@Nonnull Project project, @Nonnull final Collection<Change> changes, @Nonnull final String revNumTitle1, @Nonnull final String revNumTitle2, @Nonnull final FilePath filePath) { if (filePath.isDirectory()) { showChangesDialog(project, getDialogTitle(filePath, revNumTitle1, revNumTitle2), ContainerUtil.newArrayList(changes)); } else { if (changes.isEmpty()) { DiffManager.getInstance().showDiff(project, new MessageDiffRequest("No Changes Found")); } else { final HashMap<Key, Object> revTitlesMap = new HashMap<>(2); revTitlesMap.put(VCS_DIFF_LEFT_CONTENT_TITLE, revNumTitle1); revTitlesMap.put(VCS_DIFF_RIGHT_CONTENT_TITLE, revNumTitle2); ShowDiffContext showDiffContext = new ShowDiffContext() { @Nonnull @Override public Map<Key, Object> getChangeContext(@Nonnull Change change) { return revTitlesMap; } }; ShowDiffAction.showDiffForChange(project, changes, 0, showDiffContext); } } }
Example #24
Source File: TodoCheckinHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) { if (! myConfiguration.CHECK_NEW_TODO) return ReturnResult.COMMIT; if (DumbService.getInstance(myProject).isDumb()) { String todoName = VcsBundle.message("before.checkin.new.todo.check.title"); if (Messages.showOkCancelDialog(myProject, todoName + " can't be performed while " + ApplicationNamesInfo.getInstance().getFullProductName() + " updates the indices in background.\n" + "You can commit the changes without running checks, or you can wait until indices are built.", todoName + " is not possible right now", "&Wait", "&Commit", null) == Messages.OK) { return ReturnResult.CANCEL; } return ReturnResult.COMMIT; } Collection<Change> changes = myCheckinProjectPanel.getSelectedChanges(); TodoCheckinHandlerWorker worker = new TodoCheckinHandlerWorker(myProject, changes, myTodoFilter, true); Ref<Boolean> completed = Ref.create(Boolean.FALSE); ProgressManager.getInstance().run(new Task.Modal(myProject, "Looking for New and Edited TODO Items...", true) { @Override public void run(@Nonnull ProgressIndicator indicator) { indicator.setIndeterminate(true); worker.execute(); } @Override public void onSuccess() { completed.set(Boolean.TRUE); } }); if (completed.get() && (worker.getAddedOrEditedTodos().isEmpty() && worker.getInChangedTodos().isEmpty() && worker.getSkipped().isEmpty())) return ReturnResult.COMMIT; if (!completed.get()) return ReturnResult.CANCEL; return showResults(worker, executor); }
Example #25
Source File: MoveChangesDialog.java From consulo with Apache License 2.0 | 5 votes |
private void setSelected(boolean selected) { myTreeList.excludeChanges(myChanges); if (selected) { Change selection = myTreeList.getLeadSelection(); if (selection != null) { myTreeList.includeChange(selection); } } else { myTreeList.includeChanges(mySelected); } PropertiesComponent.getInstance().setValue(MOVE_CHANGES_CURRENT_ONLY, selected); }
Example #26
Source File: ChangeListTodosTreeStructure.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean accept(final PsiFile psiFile) { if (!psiFile.isValid()) return false; boolean isAffected = false; final Collection<Change> changes = ChangeListManager.getInstance(myProject).getDefaultChangeList().getChanges(); for (Change change : changes) { if (change.affectsFile(VfsUtil.virtualToIoFile(psiFile.getVirtualFile()))) { isAffected = true; break; } } return isAffected && (myTodoFilter != null && myTodoFilter.accept(mySearchHelper, psiFile) || (myTodoFilter == null && mySearchHelper.getTodoItemsCount(psiFile) > 0)); }
Example #27
Source File: ReviewChangesTreeList.java From review-board-idea-plugin with Apache License 2.0 | 5 votes |
@Nullable @Override protected Change getLeadSelectedObject(ChangesBrowserNode node) { final Object o = node.getUserObject(); if (o instanceof Change) { return (Change) o; } return null; }
Example #28
Source File: P4ChangelistListener.java From p4ic4idea with Apache License 2.0 | 5 votes |
private Collection<FilePath> getAffectedFiles(ClientConfigRoot clientConfigRoot, Collection<Change> changes) { Set<FilePath> ret = new HashSet<>(); for (Change change : changes) { for (ContentRevision cr : Arrays.asList(change.getBeforeRevision(), change.getAfterRevision())) { if (cr != null) { FilePath file = cr.getFile(); if (!ret.contains(file) && FileTreeUtil.isSameOrUnder(clientConfigRoot.getClientRootDir(), file)) { ret.add(cr.getFile()); } } } } return ret; }
Example #29
Source File: PushLog.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static List<Change> collectChanges(@Nonnull List<CommitNode> commitNodes) { List<Change> changes = ContainerUtil.newArrayList(); for (CommitNode node : commitNodes) { changes.addAll(node.getUserObject().getChanges()); } return changes; }
Example #30
Source File: P4CheckinEnvironment.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Nullable @Override public List<VcsException> commit(List<Change> changes, final String preparedComment, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) { return CommitUtil.commit(project, changes, preparedComment, SubmitModel.getJobs(parametersHolder), SubmitModel.getSubmitStatus(parametersHolder)); }