com.intellij.openapi.vcs.VcsRoot Java Examples
The following examples show how to use
com.intellij.openapi.vcs.VcsRoot.
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: VcsLogManager.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static Map<VirtualFile, VcsLogProvider> findLogProviders(@Nonnull Collection<VcsRoot> roots, @Nonnull Project project) { Map<VirtualFile, VcsLogProvider> logProviders = ContainerUtil.newHashMap(); VcsLogProvider[] allLogProviders = Extensions.getExtensions(LOG_PROVIDER_EP, project); for (VcsRoot root : roots) { AbstractVcs vcs = root.getVcs(); VirtualFile path = root.getPath(); if (vcs == null || path == null) { LOG.error("Skipping invalid VCS root: " + root); continue; } for (VcsLogProvider provider : allLogProviders) { if (provider.getSupportedVcs().equals(vcs.getKeyInstanceMethod())) { logProviders.put(path, provider); break; } } } return logProviders; }
Example #2
Source File: VcsRootDetectorImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public Collection<VcsRoot> detect(@javax.annotation.Nullable VirtualFile startDir) { if (startDir == null || myCheckers.isEmpty()) { return Collections.emptyList(); } final Set<VcsRoot> roots = scanForRootsInsideDir(startDir); roots.addAll(scanForRootsInContentRoots()); for (VcsRoot root : roots) { if (startDir.equals(root.getPath())) { return roots; } } List<VcsRoot> rootsAbove = scanForSingleRootAboveDir(startDir); roots.addAll(rootsAbove); return roots; }
Example #3
Source File: VcsRootDetectorImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private Set<VcsRoot> scanForRootsInContentRoots() { Set<VcsRoot> vcsRoots = new HashSet<VcsRoot>(); VirtualFile[] roots = myProjectManager.getContentRoots(); for (VirtualFile contentRoot : roots) { Set<VcsRoot> rootsInsideRoot = scanForRootsInsideDir(contentRoot); boolean shouldScanAbove = true; for (VcsRoot root : rootsInsideRoot) { if (contentRoot.equals(root.getPath())) { shouldScanAbove = false; } } if (shouldScanAbove) { List<VcsRoot> rootsAbove = scanForSingleRootAboveDir(contentRoot); rootsInsideRoot.addAll(rootsAbove); } vcsRoots.addAll(rootsInsideRoot); } return vcsRoots; }
Example #4
Source File: VcsRootDetectorImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private Set<VcsRoot> scanForRootsInsideDir(@Nonnull final VirtualFile dir, final int depth) { final Set<VcsRoot> roots = new HashSet<VcsRoot>(); if (depth > MAXIMUM_SCAN_DEPTH) { // performance optimization via limitation: don't scan deep though the whole VFS, 2 levels under a content root is enough return roots; } if (myProject.isDisposed() || !dir.isDirectory()) { return roots; } List<AbstractVcs> vcsList = getVcsListFor(dir); for (AbstractVcs vcs : vcsList) { roots.add(new VcsRoot(vcs, dir)); } for (VirtualFile child : dir.getChildren()) { roots.addAll(scanForRootsInsideDir(child, depth + 1)); } return roots; }
Example #5
Source File: VcsRootDetectorImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private List<VcsRoot> scanForSingleRootAboveDir(@Nonnull final VirtualFile dir) { List<VcsRoot> roots = new ArrayList<VcsRoot>(); if (myProject.isDisposed()) { return roots; } VirtualFile par = dir.getParent(); while (par != null) { List<AbstractVcs> vcsList = getVcsListFor(par); for (AbstractVcs vcs : vcsList) { roots.add(new VcsRoot(vcs, par)); } if (!roots.isEmpty()) { return roots; } par = par.getParent(); } return roots; }
Example #6
Source File: LocalChangesUnderRoots.java From consulo with Apache License 2.0 | 6 votes |
@javax.annotation.Nullable private VirtualFile getRootForPath(@Nonnull FilePath file, @Nonnull Collection<VirtualFile> rootsToSave) { final VirtualFile vf = ChangesUtil.findValidParentUnderReadAction(file); if (vf == null) { return null; } VirtualFile rootCandidate = null; for (VcsRoot root : myRoots) { if (VfsUtilCore.isAncestor(root.getPath(), vf, false)) { if (rootCandidate == null || VfsUtil.isAncestor(rootCandidate, root.getPath(), true)) { // in the case of nested roots choose the closest root rootCandidate = root.getPath(); } } } if (! rootsToSave.contains(rootCandidate)) return null; return rootCandidate; }
Example #7
Source File: VcsRepositoryManager.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private Map<VirtualFile, Repository> findNewRoots(@Nonnull Set<VirtualFile> knownRoots) { Map<VirtualFile, Repository> newRootsMap = ContainerUtil.newHashMap(); for (VcsRoot root : myVcsManager.getAllVcsRoots()) { VirtualFile rootPath = root.getPath(); if (rootPath != null && !knownRoots.contains(rootPath)) { AbstractVcs vcs = root.getVcs(); VcsRepositoryCreator repositoryCreator = getRepositoryCreator(vcs); if (repositoryCreator == null) continue; Repository repository = repositoryCreator.createRepositoryIfValid(rootPath); if (repository != null) { newRootsMap.put(rootPath, repository); } } } return newRootsMap; }
Example #8
Source File: VcsLogManager.java From consulo with Apache License 2.0 | 6 votes |
public VcsLogManager(@Nonnull Project project, @Nonnull VcsLogTabsProperties uiProperties, @Nonnull Collection<VcsRoot> roots, boolean scheduleRefreshImmediately, @Nullable Runnable recreateHandler) { myProject = project; myUiProperties = uiProperties; myRecreateMainLogHandler = recreateHandler; Map<VirtualFile, VcsLogProvider> logProviders = findLogProviders(roots, myProject); myLogData = new VcsLogData(myProject, logProviders, new MyFatalErrorsHandler()); myPostponableRefresher = new PostponableLogRefresher(myLogData); myTabsLogRefresher = new VcsLogTabsWatcher(myProject, myPostponableRefresher, myLogData); refreshLogOnVcsEvents(logProviders, myPostponableRefresher, myLogData); myColorManager = new VcsLogColorManagerImpl(logProviders.keySet()); if (scheduleRefreshImmediately) { scheduleInitialization(); } Disposer.register(project, this); }
Example #9
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 6 votes |
public boolean updateStep() { mySomethingChanged = false; // copy under lock final HashMap<VcsRoot, LazyRefreshingSelfQueue> copyMap; synchronized (myLock) { copyMap = new HashMap<>(myRefreshingQueues); } // filter only items for vcs roots that support background operations for (Iterator<Map.Entry<VcsRoot, LazyRefreshingSelfQueue>> iterator = copyMap.entrySet().iterator(); iterator.hasNext();) { final Map.Entry<VcsRoot, LazyRefreshingSelfQueue> entry = iterator.next(); final VcsRoot key = entry.getKey(); final boolean backgroundOperationsAllowed = key.getVcs().isVcsBackgroundOperationsAllowed(key.getPath()); LOG.debug("backgroundOperationsAllowed: " + backgroundOperationsAllowed + " for " + key.getVcs().getName() + ", " + key.getPath().getPath()); if (! backgroundOperationsAllowed) { iterator.remove(); } } LOG.debug("queues refresh started, queues: " + copyMap.size()); // refresh "up to date" info for (LazyRefreshingSelfQueue queue : copyMap.values()) { if (myProject.isDisposed()) throw new ProcessCanceledException(); queue.updateStep(); } return mySomethingChanged; }
Example #10
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 6 votes |
public void plus(final Pair<String, AbstractVcs> pair) { // does not support if (pair.getSecond().getDiffProvider() == null) return; final String key = pair.getFirst(); final AbstractVcs newVcs = pair.getSecond(); final VirtualFile root = getRootForPath(key); if (root == null) return; final VcsRoot vcsRoot = new VcsRoot(newVcs, root); synchronized (myLock) { final Pair<VcsRoot, VcsRevisionNumber> value = myData.get(key); if (value == null) { final LazyRefreshingSelfQueue<String> queue = getQueue(vcsRoot); myData.put(key, Pair.create(vcsRoot, NOT_LOADED)); queue.addRequest(key); } else if (! value.getFirst().equals(vcsRoot)) { switchVcs(value.getFirst(), vcsRoot, key); } } }
Example #11
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private LazyRefreshingSelfQueue<String> getQueue(final VcsRoot vcsRoot) { synchronized (myLock) { LazyRefreshingSelfQueue<String> queue = myRefreshingQueues.get(vcsRoot); if (queue != null) return queue; queue = new LazyRefreshingSelfQueue<>(new Getter<Long>() { public Long get() { return myVcsConfiguration.CHANGED_ON_SERVER_INTERVAL > 0 ? myVcsConfiguration.CHANGED_ON_SERVER_INTERVAL * 60000 : ourRottenPeriod; } }, new MyShouldUpdateChecker(vcsRoot), new MyUpdater(vcsRoot)); myRefreshingQueues.put(vcsRoot, queue); return queue; } }
Example #12
Source File: PersistentRootConfigComponent.java From p4ic4idea with Apache License 2.0 | 6 votes |
private boolean isValidRoot(final VirtualFile file) { if (project.isDisposed()) { // Err on the side of caution return true; } ProjectLevelVcsManager mgr = ProjectLevelVcsManager.getInstance(project); if (mgr == null) { // Err on the side of caution return true; } for (VcsRoot root : mgr.getAllVcsRoots()) { if (root == null || root.getVcs() == null || root.getPath() == null) { continue; } if (!P4VcsKey.VCS_NAME.equals(root.getVcs().getKeyInstanceMethod().getName())) { continue; } if (file.equals(root.getPath())) { return true; } } // This can happen if the passed-in file is not yet registered in // the VCS root path. return false; }
Example #13
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 5 votes |
private void switchVcs(final VcsRoot oldVcsRoot, final VcsRoot newVcsRoot, final String key) { synchronized (myLock) { final LazyRefreshingSelfQueue<String> oldQueue = getQueue(oldVcsRoot); final LazyRefreshingSelfQueue<String> newQueue = getQueue(newVcsRoot); myData.put(key, Pair.create(newVcsRoot, NOT_LOADED)); oldQueue.forceRemove(key); newQueue.addRequest(key); } }
Example #14
Source File: TFSVcs.java From azure-devops-intellij with MIT License | 5 votes |
@Override public void enableIntegration() { BackgroundTaskUtil.executeOnPooledThread(myProject, () -> { Collection<VcsRoot> roots = ServiceManager.getService(myProject, VcsRootDetector.class).detect(); new TfvcIntegrationEnabler(this).enable(roots); }); }
Example #15
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 5 votes |
RemoteRevisionsNumbersCache(final Project project) { myProject = project; myLock = new Object(); myData = new HashMap<>(); myRefreshingQueues = Collections.synchronizedMap(new HashMap<VcsRoot, LazyRefreshingSelfQueue<String>>()); myLatestRevisionsMap = new HashMap<>(); myLfs = LocalFileSystem.getInstance(); myVcsManager = ProjectLevelVcsManager.getInstance(project); myVcsConfiguration = VcsConfiguration.getInstance(project); }
Example #16
Source File: VcsAnnotationLocalChangesListenerImpl.java From consulo with Apache License 2.0 | 5 votes |
private VcsRevisionNumber fromDiffProvider(final VirtualFile vf) { final VcsRoot vcsRoot = myVcsManager.getVcsRootObjectFor(vf); DiffProvider diffProvider; if (vcsRoot != null && vcsRoot.getVcs() != null && (diffProvider = vcsRoot.getVcs().getDiffProvider()) != null) { return diffProvider.getCurrentRevision(vf); } return null; }
Example #17
Source File: VcsDirtyScopeImpl.java From consulo with Apache License 2.0 | 5 votes |
private boolean isInDirtyFiles(final FilePath path) { final VcsRoot rootObject = myVcsManager.getVcsRootObjectFor(path); if (rootObject != null && myVcs.equals(rootObject.getVcs())) { final THashSet<FilePath> files = myDirtyFiles.get(rootObject.getPath()); if (files != null && files.contains(path)) return true; } return false; }
Example #18
Source File: VcsDirtyScopeImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean belongsTo(final FilePath path, final Consumer<AbstractVcs> vcsConsumer) { if (myProject.isDisposed()) return false; final VcsRoot rootObject = myVcsManager.getVcsRootObjectFor(path); if (vcsConsumer != null && rootObject != null) { vcsConsumer.consume(rootObject.getVcs()); } if (rootObject == null || rootObject.getVcs() != myVcs) { return false; } final VirtualFile vcsRoot = rootObject.getPath(); if (vcsRoot != null) { for (VirtualFile contentRoot : myAffectedContentRoots) { // since we don't know exact dirty mechanics, maybe we have 3 nested mappings like: // /root -> vcs1, /root/child -> vcs2, /root/child/inner -> vcs1, and we have file /root/child/inner/file, // mapping is detected as vcs1 with root /root/child/inner, but we could possibly have in scope // "affected root" -> /root with scope = /root recursively if (VfsUtilCore.isAncestor(contentRoot, vcsRoot, false)) { THashSet<FilePath> dirsByRoot = myDirtyDirectoriesRecursively.get(contentRoot); if (dirsByRoot != null) { for (FilePath filePath : dirsByRoot) { if (path.isUnder(filePath, false)) return true; } } } } } if (!myDirtyFiles.isEmpty()) { FilePath parent = path.getParentPath(); return isInDirtyFiles(path) || isInDirtyFiles(parent); } return false; }
Example #19
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 5 votes |
public void invalidate(final Collection<String> paths) { synchronized (myLock) { for (String path : paths) { final Pair<VcsRoot, VcsRevisionNumber> pair = myData.remove(path); if (pair != null) { // vcs [root] seems to not change final VcsRoot vcsRoot = pair.getFirst(); final LazyRefreshingSelfQueue<String> queue = getQueue(vcsRoot); queue.forceRemove(path); queue.addRequest(path); myData.put(path, Pair.create(vcsRoot, NOT_LOADED)); } } } }
Example #20
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 5 votes |
public void minus(Pair<String, AbstractVcs> pair) { // does not support if (pair.getSecond().getDiffProvider() == null) return; final VirtualFile root = getRootForPath(pair.getFirst()); if (root == null) return; final LazyRefreshingSelfQueue<String> queue; final String key = pair.getFirst(); synchronized (myLock) { queue = getQueue(new VcsRoot(pair.getSecond(), root)); myData.remove(key); } queue.forceRemove(key); }
Example #21
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 5 votes |
public void consume(String s) { LOG.debug("update for: " + s); //todo check canceled - check VCS's ready for asynchronous queries // get last remote revision for file final VirtualFile vf = myLfs.refreshAndFindFileByIoFile(new File(s)); final ItemLatestState state; final DiffProvider diffProvider = myVcsRoot.getVcs().getDiffProvider(); if (vf == null) { // doesnt matter if directory or not state = diffProvider.getLastRevision(VcsUtil.getFilePath(s, false)); } else { state = diffProvider.getLastRevision(vf); } final VcsRevisionNumber newNumber = (state == null) || state.isDefaultHead() ? UNKNOWN : state.getNumber(); final Pair<VcsRoot, VcsRevisionNumber> oldPair; // update value in cache synchronized (myLock) { oldPair = myData.get(s); myData.put(s, Pair.create(myVcsRoot, newNumber)); } if (oldPair == null || oldPair.getSecond().compareTo(newNumber) != 0) { LOG.debug("refresh triggered by " + s); mySomethingChanged = true; } }
Example #22
Source File: TfvcIntegrationEnabler.java From azure-devops-intellij with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public void enable(@NotNull Collection vcsRoots) { // This override does the same as base method, but tries to determine a workspace directory instead of using // project.getBaseDir(). Collection<VcsRoot> typedRoots = (Collection<VcsRoot>)vcsRoots; Collection<VirtualFile> existingRoots = typedRoots.stream().filter(root -> { AbstractVcs vcs = root.getVcs(); return vcs != null && vcs.getName().equals(myVcs.getName()); }).map(VcsRoot::getPath).collect(toList()); if (!existingRoots.isEmpty()) { super.enable(vcsRoots); return; } String basePath = myProject.getBasePath(); if (basePath == null) { ourLogger.warn("Project base path is null"); return; } Path workspacePath = determineWorkspaceDirectory(Paths.get(basePath)); VirtualFile workspaceFile = ObjectUtils.notNull( LocalFileSystem.getInstance().findFileByIoFile(workspacePath.toFile())); if (initOrNotifyError(workspaceFile)) addVcsRoot(workspaceFile); }
Example #23
Source File: IdeaTextPatchBuilder.java From consulo with Apache License 2.0 | 5 votes |
public static List<BeforeAfter<AirContentRevision>> revisionsConvertor(final Project project, final List<Change> changes) throws VcsException { final List<BeforeAfter<AirContentRevision>> result = new ArrayList<BeforeAfter<AirContentRevision>>(changes.size()); final Convertor<Change, FilePath> beforePrefferingConvertor = new Convertor<Change, FilePath>() { @Override public FilePath convert(Change o) { final FilePath before = ChangesUtil.getBeforePath(o); return before == null ? ChangesUtil.getAfterPath(o) : before; } }; final MultiMap<VcsRoot,Change> byRoots = new SortByVcsRoots<Change>(project, beforePrefferingConvertor).sort(changes); for (VcsRoot root : byRoots.keySet()) { final Collection<Change> rootChanges = byRoots.get(root); if (root.getVcs() == null || root.getVcs().getOutgoingChangesProvider() == null) { addConvertChanges(rootChanges, result); continue; } final VcsOutgoingChangesProvider<?> provider = root.getVcs().getOutgoingChangesProvider(); final Collection<Change> basedOnLocal = provider.filterLocalChangesBasedOnLocalCommits(rootChanges, root.getPath()); rootChanges.removeAll(basedOnLocal); addConvertChanges(rootChanges, result); for (Change change : basedOnLocal) { // dates are here instead of numbers result.add(new BeforeAfter<AirContentRevision>(convertRevision(change.getBeforeRevision(), provider), convertRevision(change.getAfterRevision(), provider))); } } return result; }
Example #24
Source File: SortByVcsRoots.java From consulo with Apache License 2.0 | 5 votes |
public MultiMap<VcsRoot, T> sort(final Collection<T> in) { final MultiMap<VcsRoot, T> result = new MultiMap<VcsRoot,T>(); for (T t : in) { final VcsRoot root = myVcsManager.getVcsRootObjectFor(myConvertor.convert(t)); if (root != null) { result.putValue(root, t); } else { result.putValue(ourFictiveValue, t); } } return result; }
Example #25
Source File: ExternalExec.java From idea-gitignore with MIT License | 5 votes |
/** * Returns list of ignored files for the given repository. * * @param vcsRoot repository to check * @return unignored files list */ @NotNull public static List<String> getIgnoredFiles(@NotNull VcsRoot vcsRoot) { ArrayList<String> result = run( GitLanguage.INSTANCE, GIT_IGNORED_FILES, vcsRoot.getPath(), new SimpleOutputParser() ); return ContainerUtil.notNullize(result); }
Example #26
Source File: IgnoreManager.java From idea-gitignore with MIT License | 5 votes |
/** * Finds {@link VirtualFile} directory of {@link VcsRoot} that contains passed file. * * @param file to check * @return VCS Root for given file */ @Nullable private VirtualFile getVcsRootFor(@NotNull final VirtualFile file) { final VcsRoot vcsRoot = ContainerUtil.find( ContainerUtil.reverse(vcsRoots), root -> Utils.isUnder(file, root.getPath()) ); return vcsRoot != null ? vcsRoot.getPath() : null; }
Example #27
Source File: IgnoreManager.java From idea-gitignore with MIT License | 5 votes |
/** * Rebuilds {@link #confirmedIgnoredFiles} map. * * @param silent propagate {@link IgnoreManager.TrackedIgnoredListener#TRACKED_IGNORED} event */ public void run(boolean silent) { final ConcurrentMap<VirtualFile, VcsRoot> result = ContainerUtil.newConcurrentMap(); for (VcsRoot vcsRoot : vcsRoots) { if (!Utils.isGitPluginEnabled() || !(vcsRoot.getVcs() instanceof GitVcs)) { continue; } final VirtualFile root = vcsRoot.getPath(); for (String path : ExternalExec.getIgnoredFiles(vcsRoot)) { final VirtualFile file = root.findFileByRelativePath(path); if (file != null) { result.put(file, vcsRoot); } } } if (!silent && !result.isEmpty()) { project.getMessageBus().syncPublisher(TRACKED_IGNORED).handleFiles(result); } confirmedIgnoredFiles.clear(); confirmedIgnoredFiles.putAll(result); notConfirmedIgnoredFiles.clear(); debouncedStatusesChanged.run(); for (AbstractProjectViewPane pane : AbstractProjectViewPane.EP_NAME.getExtensions()) { if (pane.getTreeBuilder() != null) { pane.getTreeBuilder().queueUpdate(); } } }
Example #28
Source File: VcsLogManager.java From consulo with Apache License 2.0 | 4 votes |
public VcsLogManager(@Nonnull Project project, @Nonnull VcsLogTabsProperties uiProperties, @Nonnull Collection<VcsRoot> roots) { this(project, uiProperties, roots, true, null); }
Example #29
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 4 votes |
private VcsRevisionNumber getNumber(final String path) { synchronized (myLock) { final Pair<VcsRoot, VcsRevisionNumber> pair = myData.get(path); return pair == null ? NOT_LOADED : pair.getSecond(); } }
Example #30
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 4 votes |
public MyShouldUpdateChecker(final VcsRoot vcsRoot) { myVcsRoot = vcsRoot; }