com.intellij.openapi.vcs.history.VcsRevisionNumber Java Examples
The following examples show how to use
com.intellij.openapi.vcs.history.VcsRevisionNumber.
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: ContentRevisionCache.java From consulo with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: ResolveConflictHelperTest.java From azure-devops-intellij with MIT License | 6 votes |
public void bothTest(final String selectedName) throws Exception { helper = spy(new ResolveConflictHelper(mockProject, mockUpdatedFiles, updateRoots)); FilePath mockLocalPath = mock(FilePath.class); when(mockLocalPath.getPath()).thenReturn(CONFLICT_BOTH.getLocalPath()); FilePath mockServerPath = mock(FilePath.class); when(mockServerPath.getPath()).thenReturn(((RenameConflict) CONFLICT_BOTH).getServerPath()); VirtualFile mockVirtualFile = mock(VirtualFile.class); when(VcsUtil.getVirtualFileWithRefresh(any(File.class))).thenReturn(mockVirtualFile); when(mockNameMerger.mergeName(anyString(), anyString(), Matchers.eq(mockProject))).thenReturn(selectedName); when(VersionControlPath.getFilePath(eq(((RenameConflict) CONFLICT_BOTH).getServerPath()), anyBoolean())).thenReturn(mockServerPath); when(VersionControlPath.getFilePath(CONFLICT_BOTH.getLocalPath(), false)).thenReturn(mockLocalPath); when(mockContentMerger.mergeContent(any(ContentTriplet.class), eq(mockProject), eq(mockVirtualFile), isNull(VcsRevisionNumber.class))).thenReturn(true); helper.acceptMerge(CONFLICT_BOTH, mockResolveConflictsModel); verify(helper).populateThreeWayDiffWithProgress(CONFLICT_BOTH, new File(CONFLICT_BOTH.getLocalPath()), mockLocalPath, mockServerContext); verify(mockNameMerger).mergeName(anyString(), anyString(), eq(mockProject)); verify(mockContentMerger).mergeContent(any(ContentTriplet.class), eq(mockProject), eq(mockVirtualFile), isNull(VcsRevisionNumber.class)); verify(helper).resolveConflictWithProgress(eq(selectedName), eq(ResolveConflictsCommand.AutoResolveType.KeepYours), eq(mockServerContext), eq(mockResolveConflictsModel), eq(true), any(NameMergerResolution.class)); }
Example #3
Source File: HistoryIdColumn.java From consulo with Apache License 2.0 | 6 votes |
@Override public String getLineText(int line, Editor editor) { if (!isAvailable()) return ""; final VcsRevisionNumber revisionNumber = myAnnotation.getLineRevisionNumber(line); if (revisionNumber != null) { final Integer num = myHistoryIds.get(revisionNumber); if (num != null) { final String size = String.valueOf(myHistoryIds.size()); String value = num.toString(); while (value.length() < size.length()) { value = " " + value; } return value; } } return ""; }
Example #4
Source File: ChangesCacheFile.java From consulo with Apache License 2.0 | 6 votes |
private static boolean processFile(final FilePath path, final VcsRevisionNumber number, final List<IncomingChangeListData> incomingData, final ReceivedChangeListTracker tracker) { boolean foundRevision = false; debug("Processing updated file " + path + ", revision " + number); for(IncomingChangeListData data: incomingData) { for(Change change: data.changeList.getChanges()) { ContentRevision afterRevision = change.getAfterRevision(); if (afterRevision != null && afterRevision.getFile().equals(path)) { int rc = number.compareTo(afterRevision.getRevisionNumber()); if (rc == 0) { foundRevision = true; } if (rc >= 0) { tracker.addChange(data.changeList, change); data.accountedChanges.add(change); } } } } debug(foundRevision ? "All changes for file found" : "Some of changes for file not found"); return !foundRevision; }
Example #5
Source File: ShelvedChange.java From consulo with Apache License 2.0 | 6 votes |
public Change getChange(Project project) { if (myChange == null) { File baseDir = new File(project.getBaseDir().getPath()); File file = getAbsolutePath(baseDir, myBeforePath); final FilePathImpl beforePath = new FilePathImpl(file, false); beforePath.refresh(); ContentRevision beforeRevision = null; if (myFileStatus != FileStatus.ADDED) { beforeRevision = new CurrentContentRevision(beforePath) { @Override @Nonnull public VcsRevisionNumber getRevisionNumber() { return new TextRevisionNumber(VcsBundle.message("local.version.title")); } }; } ContentRevision afterRevision = null; if (myFileStatus != FileStatus.DELETED) { final FilePathImpl afterPath = new FilePathImpl(getAbsolutePath(baseDir, myAfterPath), false); afterRevision = new PatchedContentRevision(project, beforePath, afterPath); } myChange = new Change(beforeRevision, afterRevision, myFileStatus); } return myChange; }
Example #6
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 #7
Source File: TFSDiffProvider.java From azure-devops-intellij with MIT License | 6 votes |
@Override public Map<VirtualFile, VcsRevisionNumber> getCurrentRevisions(Iterable<VirtualFile> files) { final ServerContext context = TFSVcs.getInstance(project).getServerContext(true); final List<String> filePaths = ContainerUtil.newArrayList(); for (VirtualFile file : files) { String filePath = file.getPath(); filePaths.add(filePath); } TfvcClient client = TfvcClient.getInstance(project); final LocalFileSystem fs = LocalFileSystem.getInstance(); final Map<VirtualFile, VcsRevisionNumber> revisionMap = ContainerUtil.newHashMap(); client.getLocalItemsInfo(context, filePaths, info -> { final String itemPath = info.getLocalItem(); final VirtualFile virtualFile = fs.findFileByPath(itemPath); if (virtualFile == null) { logger.error("VirtualFile not found for item " + itemPath); return; } revisionMap.put(virtualFile, createRevision(info, itemPath)); }); return revisionMap; }
Example #8
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 #9
Source File: AnnotationAction.java From GitLink with MIT License | 6 votes |
@Override public void actionPerformed(final Project project, @NotNull final AnActionEvent event) { if (lineNumber < 0) { return; } VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE); VcsRevisionNumber revisionNumber = this.annotation.getLineRevisionNumber(lineNumber); if (file == null || project == null || revisionNumber == null) { return; } perform(project, new Commit(revisionNumber.asString()), file, new LineSelection(this.lineNumber + 1)); }
Example #10
Source File: ContentAnnotationCacheImpl.java From consulo with Apache License 2.0 | 6 votes |
@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); } }
Example #11
Source File: P4FileRevisionStore.java From p4ic4idea with Apache License 2.0 | 6 votes |
@NotNull public static P4FileRevision read(@NotNull State state) { return new P4FileRevisionImpl( P4RemoteFileStore.read(state.remoteFile), P4ChangelistIdStore.read(state.changelistId), new P4Revision(state.rev), state.action, P4FileType.convert(state.type), P4RemoteFileStore.readNullable(state.integratedFrom), state.revisionNumber < 0 ? null : new VcsRevisionNumber.Int(state.revisionNumber), state.date < 0 ? null : new Date(state.date), state.charset ); }
Example #12
Source File: VcsAnnotationLocalChangesListenerImpl.java From consulo with Apache License 2.0 | 6 votes |
private void processUnderFile(VirtualFile file) { final MultiMap<VirtualFile, FileAnnotation> annotations = new MultiMap<>(); synchronized (myLock) { for (VirtualFile virtualFile : myFileAnnotationMap.keySet()) { if (VfsUtilCore.isAncestor(file, virtualFile, true)) { final Collection<FileAnnotation> values = myFileAnnotationMap.get(virtualFile); for (FileAnnotation value : values) { annotations.putValue(virtualFile, value); } } } } if (! annotations.isEmpty()) { for (Map.Entry<VirtualFile, Collection<FileAnnotation>> entry : annotations.entrySet()) { final VirtualFile key = entry.getKey(); final VcsRevisionNumber number = fromDiffProvider(key); if (number == null) continue; final Collection<FileAnnotation> fileAnnotations = entry.getValue(); for (FileAnnotation annotation : fileAnnotations) { if (annotation.isBaseRevisionChanged(number)) { annotation.close(); } } } } }
Example #13
Source File: VcsAnnotationLocalChangesListenerImpl.java From consulo with Apache License 2.0 | 6 votes |
private void processFile(VcsRevisionNumber number, VirtualFile vf) { final Collection<FileAnnotation> annotations; synchronized (myLock) { annotations = myFileAnnotationMap.get(vf); } if (! annotations.isEmpty()) { if (number == null) { number = fromDiffProvider(vf); } if (number == null) return; for (FileAnnotation annotation : annotations) { if (annotation.isBaseRevisionChanged(number)) { annotation.close(); } } } }
Example #14
Source File: VcsCurrentRevisionProxy.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public VcsRevisionNumber getRevisionNumber() { try { return getVcsRevision().getRevisionNumber(); } catch(VcsException ex) { return VcsRevisionNumber.NULL; } }
Example #15
Source File: P4Vcs.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Override @Nullable public VcsRevisionNumber parseRevisionNumber(String revisionNumberString) throws VcsException { try { return new VcsRevisionNumber.Int(Integer.parseInt(revisionNumberString)); } catch (NumberFormatException e) { throw new VcsException(e); } }
Example #16
Source File: P4ChangelistNumber.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null || ! (obj instanceof VcsRevisionNumber)) { return false; } return compareTo((VcsRevisionNumber) obj) == 0; }
Example #17
Source File: TFSCommittedChangesProvider.java From azure-devops-intellij with MIT License | 5 votes |
@Override public Pair<TFSChangeList, FilePath> getOneList(final VirtualFile file, final VcsRevisionNumber number) throws VcsException { final ChangeBrowserSettings settings = createDefaultSettings(); settings.USE_CHANGE_AFTER_FILTER = true; settings.USE_CHANGE_BEFORE_FILTER = true; settings.CHANGE_BEFORE = settings.CHANGE_AFTER = String.valueOf(((TfsRevisionNumber) number).getValue()); final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file); final List<TFSChangeList> list = getCommittedChanges(settings, getLocationFor(filePath), 1); if (list.size() == 1) { return Pair.create(list.get(0), filePath); } return null; }
Example #18
Source File: IncrementalBlameCalculator.java From GitToolBox with Apache License 2.0 | 5 votes |
private GitLineHandler prepareLineHandler(@NotNull GitRepository repository, @NotNull VirtualFile file, @NotNull VcsRevisionNumber revisionNumber) { GitLineHandler handler = gateway.createLineHandler(repository); handler.setStdoutSuppressed(true); handler.addParameters("--incremental", "-l", "-t", "-w", "--encoding=UTF-8", revisionNumber.asString()); handler.endOptions(); handler.addRelativePaths(GtUtil.localFilePath(file)); return handler; }
Example #19
Source File: BlameCacheImpl.java From GitToolBox with Apache License 2.0 | 5 votes |
@NotNull private VcsRevisionNumber currentRepoRevision(@NotNull VirtualFile file) { GitRepository repo = gateway.getRepoForFile(file); if (repo != null) { return gateway.getCurrentRevision(repo); } return VcsRevisionNumber.NULL; }
Example #20
Source File: TFSDiffProvider.java From azure-devops-intellij with MIT License | 5 votes |
private String getModificationDate(final VcsRevisionNumber vcsRevisionNumber) { if (vcsRevisionNumber instanceof TfsRevisionNumber) { final TfsRevisionNumber revisionNumber = (TfsRevisionNumber) vcsRevisionNumber; return revisionNumber.getModificationDate(); } return StringUtils.EMPTY; }
Example #21
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 5 votes |
/** * Returns {@code true} if passed revision is up to date, comparing to latest repository revision. */ private boolean getRevisionState(final ContentRevision revision) { if (revision != null) { // TODO: Seems peg revision should also be tracked here. final VcsRevisionNumber local = revision.getRevisionNumber(); final String path = revision.getFile().getPath(); final VcsRevisionNumber remote = getNumber(path); return NOT_LOADED == remote || UNKNOWN == remote || local.compareTo(remote) >= 0; } return true; }
Example #22
Source File: ContentRevisionCache.java From consulo with Apache License 2.0 | 5 votes |
@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); } }
Example #23
Source File: P4RevisionSelector.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Nullable @Override public VcsRevisionNumber selectNumber(final VirtualFile file) { if (LOG.isDebugEnabled()) { LOG.debug("Selecting version for file " + file); } /* final P4FileRevision rev = RevisionDialog.requestRevision(vcs, file); if (rev == null) { return null; } return rev.getRevisionNumber(); */ throw new IllegalStateException("not implemented"); }
Example #24
Source File: AbstractP4FileContentRevision.java From p4ic4idea with Apache License 2.0 | 5 votes |
AbstractP4FileContentRevision( @NotNull FilePath filePath, @NotNull String serverFilePath, @NotNull VcsRevisionNumber.Int rev, @Nullable HistoryContentLoader loader, @Nullable Charset charset) { this.filePath = filePath; this.serverFilePath = serverFilePath; this.loader = loader; this.charset = ContentRevisionUtil.getNonNullCharset(charset); this.rev = rev; }
Example #25
Source File: P4RemoteFileContentRevision.java From p4ic4idea with Apache License 2.0 | 5 votes |
public static P4RemoteFileContentRevision create(@NotNull P4RemoteFile file, @NotNull FilePath path, @NotNull VcsRevisionNumber.Int rev, @NotNull ClientConfig clientConfig, @Nullable HistoryContentLoader loader, @Nullable Charset charset) { return new P4RemoteFileContentRevision(file, path, rev, loader, charset, () -> clientConfig); }
Example #26
Source File: PostReviewAction.java From reviewboard-plugin-for-idea with MIT License | 5 votes |
@Override public void update(AnActionEvent event) { final Project project = event.getData(PlatformDataKeys.PROJECT); final VirtualFile[] vFiles = event.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY); if (vFiles == null || vFiles.length == 0) { setActionEnable(event, false); return; } final ChangeListManager changeListManager = ChangeListManager.getInstance(project); int enableCount = 0; for (VirtualFile vf : vFiles) { if (vf != null) { vf.refresh(false, true); Change change = changeListManager.getChange(vf); if (change != null) { if (change.getType().equals(Change.Type.NEW)) { enableCount++; continue; } ContentRevision beforeRevision = change.getBeforeRevision(); if (beforeRevision != null) { VcsRevisionNumber revisionNumber = beforeRevision.getRevisionNumber(); if (!revisionNumber.equals(VcsRevisionNumber.NULL)) { enableCount++; } } } } } setActionEnable(event, enableCount == vFiles.length); }
Example #27
Source File: MockP4ChangelistId.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Override public int compareTo(@NotNull VcsRevisionNumber o) { if (o instanceof P4ChangelistId) { return id - ((P4ChangelistId) o).getChangelistId(); } return -1; }
Example #28
Source File: VcsContentAnnotationImpl.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable @Override public VcsRevisionNumber fileRecentlyChanged(VirtualFile vf) { final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject); final AbstractVcs vcs = vcsManager.getVcsFor(vf); if (vcs == null) return null; if (vcs.getDiffProvider() instanceof DiffMixin) { final VcsRevisionDescription description = ((DiffMixin)vcs.getDiffProvider()).getCurrentRevisionDescription(vf); final Date date = description.getRevisionDate(); return isRecent(date) ? description.getRevisionNumber() : null; } return null; }
Example #29
Source File: VcsCurrentRevisionProxy.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private Pair<VcsRevisionNumber, byte[]> loadContent() throws VcsException { VcsRevisionNumber currentRevision = getCurrentRevisionNumber(); ContentRevision contentRevision = myDiffProvider.createFileContent(currentRevision, myFile); if (contentRevision == null) { throw new VcsException("Failed to create content for current revision"); } return Pair.create(currentRevision, contentRevision.getContent().getBytes(myFile.getCharset())); }
Example #30
Source File: P4ChangelistIdImpl.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Override public int compareTo(@NotNull VcsRevisionNumber o) { if (o instanceof P4ChangelistId) { return id - ((P4ChangelistId) o).getChangelistId(); } return -1; }