Java源码示例:com.intellij.openapi.vcs.VcsKey
示例1
@Test
public void testUpdateDirectories_FilesStale() {
SyncResults syncResults = new SyncResults(false, ImmutableList.of("/path/to/file1", "/path/to/directory"), ImmutableList.of("/path/to/newFile"),
ImmutableList.of("/path/to/file2"), ImmutableList.of(new SyncException("test exception")));
FilePath[] filePaths = setupUpdate(syncResults);
UpdateSession session = updateEnvironment.updateDirectories(filePaths, mockUpdatedFiles, mockProgressIndicator, mockUpdatesContext);
verify(mockFileGroupRemove).add(eq("/path/to/file2"), any(VcsKey.class), isNull(VcsRevisionNumber.class));
verify(mockFileGroupCreate).add(eq("/path/to/newFile"), any(VcsKey.class), isNull(VcsRevisionNumber.class));
verify(mockFileGroupUpdate).add(eq("/path/to/file1"), any(VcsKey.class), isNull(VcsRevisionNumber.class));
verify(mockFileGroupUpdate).add(eq("/path/to/directory"), any(VcsKey.class), isNull(VcsRevisionNumber.class));
verifyNoMoreInteractions(mockFileGroupRemove, mockFileGroupCreate, mockFileGroupUpdate, mockConflictsHandler);
verifyNoMoreInteractions(mockConflictsHandler);
assertEquals(1, session.getExceptions().size());
verifyStatic(times(1));
TfsFileUtil.refreshAndInvalidate(mockProject, filePaths, false);
}
示例2
@Nonnull
@Override
public Set<UsageDescriptor> getProjectUsages(@Nonnull Project project) throws CollectUsagesException {
VcsProjectLog projectLog = VcsProjectLog.getInstance(project);
VcsLogData logData = projectLog.getDataManager();
if (logData != null) {
DataPack dataPack = logData.getDataPack();
if (dataPack.isFull()) {
PermanentGraph<Integer> permanentGraph = dataPack.getPermanentGraph();
MultiMap<VcsKey, VirtualFile> groupedRoots = groupRootsByVcs(dataPack.getLogProviders());
Set<UsageDescriptor> usages = ContainerUtil.newHashSet();
usages.add(StatisticsUtilKt.getCountingUsage("data.commit.count", permanentGraph.getAllCommits().size(),
asList(0, 1, 100, 1000, 10 * 1000, 100 * 1000, 500 * 1000)));
for (VcsKey vcs : groupedRoots.keySet()) {
usages.add(StatisticsUtilKt.getCountingUsage("data." + vcs.getName().toLowerCase() + ".root.count", groupedRoots.get(vcs).size(),
asList(0, 1, 2, 5, 8, 15, 30, 50, 100, 500, 1000)));
}
return usages;
}
}
return Collections.emptySet();
}
示例3
@Override
@Nullable
public ThreeState isRecent(final VirtualFile vf,
final VcsKey vcsKey,
final VcsRevisionNumber number,
final TextRange range,
final long boundTime) {
TreeMap<Integer, Long> treeMap;
synchronized (myLock) {
treeMap = myCache.get(new HistoryCacheWithRevisionKey(VcsContextFactory.SERVICE.getInstance().createFilePathOn(vf), vcsKey, number));
}
if (treeMap != null) {
Map.Entry<Integer, Long> last = treeMap.floorEntry(range.getEndOffset());
if (last == null || last.getKey() < range.getStartOffset()) return ThreeState.NO;
Map.Entry<Integer, Long> first = treeMap.ceilingEntry(range.getStartOffset());
assert first != null;
final SortedMap<Integer,Long> interval = treeMap.subMap(first.getKey(), last.getKey());
for (Map.Entry<Integer, Long> entry : interval.entrySet()) {
if (entry.getValue() >= boundTime) return ThreeState.YES;
}
return ThreeState.NO;
}
return ThreeState.UNSURE;
}
示例4
@Override
public void register(final VirtualFile vf, final VcsKey vcsKey, final VcsRevisionNumber number, final FileAnnotation fa) {
final HistoryCacheWithRevisionKey key = new HistoryCacheWithRevisionKey(VcsContextFactory.SERVICE.getInstance().createFilePathOn(vf), vcsKey, number);
synchronized (myLock) {
if (myCache.get(key) != null) return;
}
final long absoluteLimit = System.currentTimeMillis() - VcsContentAnnotationSettings.ourAbsoluteLimit;
final TreeMap<Integer, Long> map = new TreeMap<Integer, Long>();
final int lineCount = fa.getLineCount();
for (int i = 0; i < lineCount; i++) {
Date lineDate = fa.getLineDate(i);
if (lineDate == null) return;
if (lineDate.getTime() >= absoluteLimit) map.put(i, lineDate.getTime());
}
synchronized (myLock) {
myCache.put(key, map);
}
}
示例5
private static VcsRevisionNumber putIntoCurrentCache(final ContentRevisionCache cache,
FilePath path,
@Nonnull VcsKey vcsKey,
final CurrentRevisionProvider loader) throws VcsException, IOException {
VcsRevisionNumber loadedRevisionNumber;
Pair<VcsRevisionNumber, Long> currentRevision;
while (true) {
loadedRevisionNumber = loader.getCurrentRevision();
currentRevision = cache.getCurrent(path, vcsKey);
if (loadedRevisionNumber.equals(currentRevision.getFirst())) return loadedRevisionNumber;
if (cache.putCurrent(path, loadedRevisionNumber, vcsKey, currentRevision.getSecond())) {
return loadedRevisionNumber;
}
}
}
示例6
public static Pair<VcsRevisionNumber, byte[]> getOrLoadCurrentAsBytes(final Project project, FilePath path, @Nonnull VcsKey vcsKey,
final CurrentRevisionProvider loader) throws VcsException, IOException {
ContentRevisionCache cache = ProjectLevelVcsManager.getInstance(project).getContentRevisionCache();
VcsRevisionNumber currentRevision;
Pair<VcsRevisionNumber, byte[]> loaded;
while (true) {
currentRevision = putIntoCurrentCache(cache, path, vcsKey, loader);
final byte[] cachedCurrent = cache.getBytes(path, currentRevision, vcsKey, UniqueType.REPOSITORY_CONTENT);
if (cachedCurrent != null) {
return Pair.create(currentRevision, cachedCurrent);
}
checkLocalFileSize(path);
loaded = loader.get();
if (loaded.getFirst().equals(currentRevision)) break;
}
cache.put(path, currentRevision, vcsKey, UniqueType.REPOSITORY_CONTENT, loaded.getSecond());
return loaded;
}
示例7
@Override
public void processChangeInList(final Change change, @Nullable final ChangeList changeList, final VcsKey vcsKey) {
checkIfDisposed();
LOG.debug("[processChangeInList-1] entering, cl name: " + ((changeList == null) ? null : changeList.getName()) +
" change: " + ChangesUtil.getFilePath(change).getPath());
final String fileName = ChangesUtil.getFilePath(change).getName();
if (FileTypeManager.getInstance().isFileIgnored(fileName)) {
LOG.debug("[processChangeInList-1] file type ignored");
return;
}
if (ChangeListManagerImpl.isUnder(change, myScope)) {
if (changeList != null) {
LOG.debug("[processChangeInList-1] to add change to cl");
myChangeListWorker.addChangeToList(changeList.getName(), change, vcsKey);
}
else {
LOG.debug("[processChangeInList-1] to add to corresponding list");
myChangeListWorker.addChangeToCorrespondingList(change, vcsKey);
}
}
else {
LOG.debug("[processChangeInList-1] not under scope");
}
}
示例8
private Runnable createUpdateStuff() {
return new Runnable() {
@Override
public void run() {
final Set<String> paths = new HashSet<>();
final Map<String, VcsRevisionNumber> changes = new HashMap<>();
final Set<VirtualFile> files = new HashSet<>();
Set<VcsKey> vcsToRefresh;
synchronized (myLock) {
vcsToRefresh = new HashSet<>(myVcsKeySet);
paths.addAll(myDirtyPaths);
changes.putAll(myDirtyChanges);
files.addAll(myDirtyFiles);
myDirtyPaths.clear();
myDirtyChanges.clear();
myVcsKeySet.clear();
myDirtyFiles.clear();
}
closeForVcs(vcsToRefresh);
checkByDirtyScope(paths, changes, files);
}
};
}
示例9
private void addChangeToIdx(final Change change, final VcsKey key) {
final ContentRevision afterRevision = change.getAfterRevision();
final ContentRevision beforeRevision = change.getBeforeRevision();
if (afterRevision != null) {
add(afterRevision.getFile(), change.getFileStatus(), key, beforeRevision == null ? VcsRevisionNumber.NULL : beforeRevision.getRevisionNumber());
}
if (beforeRevision != null) {
if (afterRevision != null) {
if (! Comparing.equal(beforeRevision.getFile(), afterRevision.getFile())) {
add(beforeRevision.getFile(), FileStatus.DELETED, key, beforeRevision.getRevisionNumber());
}
} else {
add(beforeRevision.getFile(), change.getFileStatus(), key, beforeRevision.getRevisionNumber());
}
}
}
示例10
/**
* @param canUseLastRevision
*/
@Override
public void run(boolean isRefresh, boolean canUseLastRevision) {
myIsRefresh = isRefresh;
mySessionPartner.beforeRefresh();
VcsHistoryProviderBackgroundableProxy proxy = new VcsHistoryProviderBackgroundableProxy(myVcs, myVcsHistoryProvider,
myVcs.getDiffProvider());
VcsKey key = myVcs.getKeyInstanceMethod();
if (myVcsHistoryProvider instanceof VcsHistoryProviderEx && myStartingRevisionNumber != null) {
proxy.executeAppendableSession(key, myPath, myStartingRevisionNumber, mySessionPartner, null);
}
else {
proxy.executeAppendableSession(key, myPath, mySessionPartner, null, myCanUseCache, canUseLastRevision);
}
myCanUseCache = false;
}
示例11
@Override
public void directoryCheckedOut(final File directory, final VcsKey vcs) {
myVcsKey = vcs;
if (!myFoundProject && directory.isDirectory()) {
if (myFirstDirectory == null) {
myFirstDirectory = directory;
}
notifyCheckoutListeners(directory, false);
}
}
示例12
@Override
public void processChangeInList(Change change, @Nullable ChangeList changeList, VcsKey vcsKey) {
assertEquals(expectedKey, vcsKey);
if (changeList == null) {
addChange(null, change);
} else {
// ensure the changelist exists in the gate.
gate.getExisting(changeList.getName());
addChange(changeList.getName(), change);
}
}
示例13
@Override
public void processChangeInList(Change change, String changeListName, VcsKey vcsKey) {
assertEquals(expectedKey, vcsKey);
// ensure the changelist exists.
gate.getExisting(changeListName);
addChange(changeListName, change);
}
示例14
@Nonnull
private static MultiMap<VcsKey, VirtualFile> groupRootsByVcs(@Nonnull Map<VirtualFile, VcsLogProvider> providers) {
MultiMap<VcsKey, VirtualFile> result = MultiMap.create();
for (Map.Entry<VirtualFile, VcsLogProvider> entry : providers.entrySet()) {
VirtualFile root = entry.getKey();
VcsKey vcs = entry.getValue().getSupportedVcs();
result.putValue(vcs, root);
}
return result;
}
示例15
@Nullable
private VcsCherryPicker getCherryPickerForCommit(@Nonnull VcsFullCommitDetails commitDetails) {
AbstractVcs vcs = myProjectLevelVcsManager.getVcsFor(commitDetails.getRoot());
if (vcs == null) return null;
VcsKey key = vcs.getKeyInstanceMethod();
return getCherryPickerFor(key);
}
示例16
@Nullable
public VcsCherryPicker getCherryPickerFor(@Nonnull final VcsKey key) {
return ContainerUtil.find(Extensions.getExtensions(VcsCherryPicker.EXTENSION_POINT_NAME, myProject), new Condition<VcsCherryPicker>() {
@Override
public boolean value(VcsCherryPicker picker) {
return picker.getSupportedVcs().equals(key);
}
});
}
示例17
@Nullable
public String get(FilePath path, VcsRevisionNumber number, @Nonnull VcsKey vcsKey, @Nonnull UniqueType type) {
synchronized (myLock) {
final byte[] bytes = getBytes(path, number, vcsKey, type);
if (bytes == null) return null;
return bytesToString(path, bytes);
}
}
示例18
@javax.annotation.Nullable
public static String getOrLoadAsString(@Nonnull Project project,
@Nonnull FilePath file,
VcsRevisionNumber number,
@Nonnull VcsKey key,
@Nonnull UniqueType type,
@Nonnull Throwable2Computable<byte[], VcsException, IOException> loader,
@Nullable Charset charset)
throws VcsException, IOException {
final byte[] bytes = getOrLoadAsBytes(project, file, number, key, type, loader);
if (bytes == null) return null;
return getAsString(bytes, file, charset);
}
示例19
@javax.annotation.Nullable
public byte[] getBytes(FilePath path, VcsRevisionNumber number, @Nonnull VcsKey vcsKey, @Nonnull UniqueType type) {
synchronized (myLock) {
final SoftReference<byte[]> reference = myCache.get(new Key(path, number, vcsKey, type));
return SoftReference.dereference(reference);
}
}
示例20
private boolean putCurrent(FilePath path, VcsRevisionNumber number, @Nonnull VcsKey vcsKey, final long counter) {
synchronized (myLock) {
if (myCounter != counter) return false;
++ myCounter;
myCurrentRevisionsCache.put(new CurrentKey(path, vcsKey), number);
}
return true;
}
示例21
public static byte[] getOrLoadAsBytes(final Project project, FilePath path, VcsRevisionNumber number, @Nonnull VcsKey vcsKey,
@Nonnull UniqueType type, final Throwable2Computable<byte[], VcsException, IOException> loader)
throws VcsException, IOException {
ContentRevisionCache cache = ProjectLevelVcsManager.getInstance(project).getContentRevisionCache();
byte[] bytes = cache.getBytes(path, number, vcsKey, type);
if (bytes != null) return bytes;
checkLocalFileSize(path);
bytes = loader.compute();
cache.put(path, number, vcsKey, type, bytes);
return bytes;
}
示例22
public <C extends Serializable, T extends VcsAbstractHistorySession> void put(final FilePath filePath,
@javax.annotation.Nullable final FilePath correctedPath,
final VcsKey vcsKey,
final T session,
@Nonnull final VcsCacheableHistorySessionFactory<C, T> factory,
boolean isFull) {
synchronized (myLock) {
myHistoryCache.put(new HistoryCacheBaseKey(filePath, vcsKey),
new CachedHistory(correctedPath != null ? correctedPath : filePath, session.getRevisionList(),
session.getCurrentRevisionNumber(), factory.getAddinionallyCachedData(session), isFull));
}
}
示例23
public void editCached(final FilePath filePath, final VcsKey vcsKey, final Consumer<List<VcsFileRevision>> consumer) {
synchronized (myLock) {
final CachedHistory cachedHistory = myHistoryCache.get(new HistoryCacheBaseKey(filePath, vcsKey));
if (cachedHistory != null) {
consumer.consume(cachedHistory.getRevisions());
}
}
}
示例24
@javax.annotation.Nullable
public <C extends Serializable, T extends VcsAbstractHistorySession> T getFull(final FilePath filePath, final VcsKey vcsKey,
@Nonnull final VcsCacheableHistorySessionFactory<C, T> factory) {
synchronized (myLock) {
final CachedHistory cachedHistory = myHistoryCache.get(new HistoryCacheBaseKey(filePath, vcsKey));
if (cachedHistory == null || ! cachedHistory.isIsFull()) {
return null;
}
return factory.createFromCachedData((C) cachedHistory.getCustomData(), cachedHistory.getRevisions(), cachedHistory.getPath(),
cachedHistory.getCurrentRevision());
}
}
示例25
@javax.annotation.Nullable
public <C extends Serializable, T extends VcsAbstractHistorySession> T getMaybePartial(final FilePath filePath, final VcsKey vcsKey,
@Nonnull final VcsCacheableHistorySessionFactory<C, T> factory) {
synchronized (myLock) {
final CachedHistory cachedHistory = myHistoryCache.get(new HistoryCacheBaseKey(filePath, vcsKey));
if (cachedHistory == null) {
return null;
}
return factory.createFromCachedData((C) cachedHistory.getCustomData(), cachedHistory.getRevisions(), cachedHistory.getPath(),
cachedHistory.getCurrentRevision());
}
}
示例26
@Override
public boolean processCheckedOutDirectory(Project currentProject, File directory, VcsKey vcsKey) {
Project project = CompositeCheckoutListener.findProjectByBaseDirLocation(directory);
if (project != null) {
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
if (!vcsManager.hasAnyMappings()) {
vcsManager.setDirectoryMappings(Collections.singletonList(VcsDirectoryMapping.createDefault(vcsKey.getName())));
}
return true;
}
return false;
}
示例27
@Override
public void directoryCheckedOut(final File directory, VcsKey vcs) {
myVcsKey = vcs;
if (!myFoundProject) {
final VirtualFile virtualFile = refreshVFS(directory);
if (virtualFile != null) {
if (myFirstDirectory == null) {
myFirstDirectory = directory;
}
notifyCheckoutListeners(directory, CheckoutListener.EP_NAME);
}
}
}
示例28
@Override
public void processChangeInList(final Change change, final String changeListName, VcsKey vcsKey) {
checkIfDisposed();
LocalChangeList list = null;
if (changeListName != null) {
list = myChangeListWorker.getCopyByName(changeListName);
if (list == null) {
list = myGate.addChangeList(changeListName, null);
}
}
processChangeInList(change, list, vcsKey);
}
示例29
private VcsAnnotationRefresher createHandler() {
return new VcsAnnotationRefresher() {
@Override
public void dirtyUnder(VirtualFile file) {
if (file == null) return;
synchronized (myLock) {
myDirtyFiles.add(file);
}
myUpdater.queue(myUpdateStuff);
}
@Override
public void dirty(BaseRevision currentRevision) {
synchronized (myLock) {
myDirtyChanges.put(currentRevision.getPath().getPath(), currentRevision.getRevision());
}
myUpdater.queue(myUpdateStuff);
}
@Override
public void dirty(String path) {
synchronized (myLock) {
myDirtyPaths.add(path);
}
myUpdater.queue(myUpdateStuff);
}
@Override
public void configurationChanged(VcsKey vcsKey) {
synchronized (myLock) {
myVcsKeySet.add(vcsKey);
}
myUpdater.queue(myUpdateStuff);
}
};
}
示例30
void add(final FilePath file, final FileStatus status, final VcsKey key, VcsRevisionNumber number) {
myFileToStatus.put(file, status);
myFileToVcs.put(file, Pair.create(key, number));
if (LOG.isDebugEnabled()) {
LOG.debug("Set status " + status + " for " + file);
}
}