Search in sources :

Example 1 with ItemLatestState

use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.

the class GitHistoryUtilsTest method testGetLastRevisionForExistingFile.

@Test(enabled = false)
public void testGetLastRevisionForExistingFile() throws Exception {
    final ItemLatestState state = GitHistoryUtils.getLastRevision(myProject, toFilePath(bfile));
    assertTrue(state.isItemExists());
    final GitRevisionNumber revisionNumber = (GitRevisionNumber) state.getNumber();
    assertEquals(revisionNumber.getRev(), myRevisions.get(0).myHash);
    assertEquals(revisionNumber.getTimestamp(), myRevisions.get(0).myDate);
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState) Test(org.testng.annotations.Test) GitSingleRepoTest(git4idea.test.GitSingleRepoTest)

Example 2 with ItemLatestState

use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.

the class VcsHistoryProviderBackgroundableProxy method getSessionFromCacheWithLastRevisionCheck.

@Nullable
private VcsAbstractHistorySession getSessionFromCacheWithLastRevisionCheck(final FilePath filePath, final VcsKey vcsKey) {
    final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
    if (pi != null) {
        pi.setText2("Checking last revision");
    }
    VcsAbstractHistorySession cached = getFullHistoryFromCache(vcsKey, filePath);
    if (cached == null)
        return null;
    final FilePath correctedFilePath = ((VcsCacheableHistorySessionFactory<Serializable, VcsAbstractHistorySession>) myDelegate).getUsedFilePath(cached);
    if (VcsType.distributed.equals(myType)) {
        final FilePath path = correctedFilePath != null ? correctedFilePath : filePath;
        VirtualFile virtualFile = path.getVirtualFile();
        if (virtualFile == null) {
            virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath());
        }
        if (virtualFile != null) {
            final VcsRevisionNumber currentRevision = myDiffProvider.getCurrentRevision(virtualFile);
            final List<VcsFileRevision> revisionList = cached.getRevisionList();
            if (!revisionList.isEmpty() && revisionList.get(0).getRevisionNumber().equals(currentRevision)) {
                return cached;
            }
        }
    } else {
        final ItemLatestState lastRevision = myDiffProvider.getLastRevision(correctedFilePath != null ? correctedFilePath : filePath);
        if (lastRevision != null && !lastRevision.isDefaultHead() && lastRevision.isItemExists()) {
            final List<VcsFileRevision> revisionList = cached.getRevisionList();
            if (!revisionList.isEmpty() && revisionList.get(0).getRevisionNumber().equals(lastRevision.getNumber())) {
                return cached;
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ItemLatestState

use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.

the class CvsDiffProvider method getLastState.

private ItemLatestState getLastState(final VirtualFile parent, final String name) {
    final Entry entry = CvsEntriesManager.getInstance().getEntryFor(parent, name);
    if (entry == null)
        return new ItemLatestState(new CvsRevisionNumber("HEAD"), true, true);
    final String stickyHead = new StickyHeadGetter.MyStickyBranchHeadGetter(entry.getRevision(), myProject).getHead(parent, name);
    if (stickyHead == null) {
        return new ItemLatestState(new CvsRevisionNumber("HEAD"), true, true);
    }
    return new ItemLatestState(new CvsRevisionNumber(stickyHead), (!entry.isRemoved()), false);
}
Also used : Entry(org.netbeans.lib.cvsclient.admin.Entry) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState) CvsRevisionNumber(com.intellij.cvsSupport2.history.CvsRevisionNumber)

Example 4 with ItemLatestState

use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.

the class GitHistoryUtilsTest method testGetLastRevisionForNonExistingFile.

public void testGetLastRevisionForNonExistingFile() throws Exception {
    git("remote add origin git://example.com/repo.git");
    git("config branch.master.remote origin");
    git("config branch.master.merge refs/heads/master");
    git("rm " + bfile.getPath());
    commit("removed bfile");
    String[] hashAndDate = log("--pretty=format:%H#%ct", "-n1").split("#");
    // to avoid pushing to this fake origin
    git("update-ref refs/remotes/origin/master HEAD");
    touch("dir/b.txt", "content");
    addCommit("recreated bfile");
    refresh();
    myRepo.update();
    final ItemLatestState state = GitHistoryUtils.getLastRevision(myProject, toFilePath(bfile));
    assertTrue(!state.isItemExists());
    final GitRevisionNumber revisionNumber = (GitRevisionNumber) state.getNumber();
    assertEquals(revisionNumber.getRev(), hashAndDate[0]);
    assertEquals(revisionNumber.getTimestamp(), GitTestRevision.gitTimeStampToDate(hashAndDate[1]));
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState)

Example 5 with ItemLatestState

use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.

the class GitHistoryUtils method getLastRevision.

/**
   * Get current revision for the file under git
   *
   * @param project  a project
   * @param filePath a file path
   * @return a revision number or null if the file is unversioned or new
   * @throws VcsException if there is problem with running git
   */
@Nullable
public static ItemLatestState getLastRevision(@NotNull Project project, @NotNull FilePath filePath) throws VcsException {
    VirtualFile root = GitUtil.getGitRoot(filePath);
    GitBranch c = GitBranchUtil.getCurrentBranch(project, root);
    GitBranch t = c == null ? null : GitBranchUtil.tracked(project, root, c.getName());
    if (t == null) {
        return new ItemLatestState(getCurrentRevision(project, filePath, null), true, false);
    }
    filePath = getLastCommitName(project, filePath);
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
    GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, COMMIT_TIME, PARENTS);
    h.setSilent(true);
    h.addParameters("-n1", parser.getPretty(), "--name-status", t.getFullName());
    h.endOptions();
    h.addRelativePaths(filePath);
    String result = h.run();
    if (result.length() == 0) {
        return null;
    }
    GitLogRecord record = parser.parseOneRecord(result);
    if (record == null) {
        return null;
    }
    final List<Change> changes = record.parseChanges(project, root);
    boolean exists = changes.isEmpty() || !FileStatus.DELETED.equals(changes.get(0).getFileStatus());
    record.setUsedHandler(h);
    return new ItemLatestState(new GitRevisionNumber(record.getHash(), record.getDate()), exists, false);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState) Change(com.intellij.openapi.vcs.changes.Change) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ItemLatestState (com.intellij.openapi.vcs.diff.ItemLatestState)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GitRevisionNumber (git4idea.GitRevisionNumber)2 Nullable (org.jetbrains.annotations.Nullable)2 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)2 CvsRevisionNumber (com.intellij.cvsSupport2.history.CvsRevisionNumber)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Change (com.intellij.openapi.vcs.changes.Change)1 GitSingleRepoTest (git4idea.test.GitSingleRepoTest)1 Entry (org.netbeans.lib.cvsclient.admin.Entry)1 Test (org.testng.annotations.Test)1 HgWorkingCopyRevisionsCommand (org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)1