Skip to content

Commit

Permalink
Explicit dependency on git4idea has been removed. Support of SVN (an …
Browse files Browse the repository at this point in the history
…theoretically other VCS) has been added.
  • Loading branch information
peshrus committed Jun 10, 2020
1 parent ceec322 commit 1f31163
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 76 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,3 @@

# For developers
Setup IntelliJ plugin SDK (see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/using_dev_kit.html)

Add git4idea classpath to SDK:
1. Open File -> Project structure...
2. Platform Settings -> SDKs
3. *Your version of IntelliJ IDEA IU* -> Classpath
4. Add <idea installation dir>/plugins/git4idea/lib/git4idea.jar
35 changes: 17 additions & 18 deletions src/com/jetbrains/crucible/connection/CrucibleApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.intellij.openapi.vcs.changes.patch.MatchPatchPaths;
import com.intellij.openapi.vcs.changes.patch.TextFilePatchInProgress;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.crucible.model.*;
import org.apache.commons.httpclient.methods.RequestEntity;
Expand Down Expand Up @@ -49,7 +48,7 @@ private static Gson initGson() {

@NotNull
public static BasicReview parseReview(@NotNull JsonObject item, @NotNull Project project, @NotNull CrucibleSession crucibleSession)
throws IOException {
throws IOException {
ReviewRaw reviewRaw = gson.fromJson(item, ReviewRaw.class);

User moderator = (reviewRaw.moderator != null) ? reviewRaw.moderator.createUser() : null;
Expand Down Expand Up @@ -129,19 +128,20 @@ private static ReviewItem parsePatchReviewItem(ReviewItemRaw raw, Project projec
return null;
}

final VirtualFile repo = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(new LocalFilePath(base.getAbsolutePath(), base.isDirectory()));
final VirtualFile repo =
ProjectLevelVcsManager.getInstance(project).getVcsRootFor(new LocalFilePath(base.getAbsolutePath(), base.isDirectory()));
if (repo == null) {
LOG.error("Couldn't find repository for base " + base);
return null;
}

Map.Entry<String, VirtualFile> repoEntry = ContainerUtil.find(crucibleSession.getRepoHash().entrySet(),
new Condition<Map.Entry<String, VirtualFile>>() {
@Override
public boolean value(Map.Entry<String, VirtualFile> entry) {
return entry.getValue().equals(repo);
}
});
@Override
public boolean value(Map.Entry<String, VirtualFile> entry) {
return entry.getValue().equals(repo);
}
});

if (repoEntry == null) {
LOG.error("Couldn't find repository name for root " + repo);
Expand All @@ -155,7 +155,8 @@ public boolean value(Map.Entry<String, VirtualFile> entry) {

// temporary workaround until ReviewItem is rethinked
@NotNull
private static AbstractFilePatchInProgress findBestMatchingPatchByPath(@NotNull String toPath, @NotNull List<AbstractFilePatchInProgress> patches) {
private static AbstractFilePatchInProgress findBestMatchingPatchByPath(@NotNull String toPath,
@NotNull List<AbstractFilePatchInProgress> patches) {
int bestSimilarity = -1;
AbstractFilePatchInProgress bestCandidate = null;
for (AbstractFilePatchInProgress patch : patches) {
Expand Down Expand Up @@ -253,14 +254,13 @@ else if (raw instanceof GeneralComment) {
}

@NotNull
public static Collection<Repository> parseGitRepositories(@NotNull JsonObject object) {
Repositories repositories = gson.fromJson(object, Repositories.class);
return ContainerUtil.mapNotNull(repositories.repoData, new Function<RepoRaw, Repository>() {
@Override
public Repository fun(RepoRaw repository) {
return "git".equalsIgnoreCase(repository.type) ? new Repository(repository.name, repository.location) : null;
}
});
public static Collection<Repository> parseRepositories(@NotNull JsonObject object) {
final Repositories repositories = gson.fromJson(object, Repositories.class);

return ContainerUtil.mapNotNull(repositories.repoData,
repository -> repository.name != null && repository.location != null
? new Repository(repository.name, repository.location)
: null);
}

@NotNull
Expand Down Expand Up @@ -477,5 +477,4 @@ private static class Stat {
int leaveUnread;
int read;
}

}
23 changes: 6 additions & 17 deletions src/com/jetbrains/crucible/connection/CrucibleSessionImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jetbrains.crucible.connection;

import com.google.gson.*;
import com.intellij.dvcs.repo.VcsRepositoryManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
Expand All @@ -11,10 +12,6 @@
import com.jetbrains.crucible.connection.exceptions.CrucibleApiLoginException;
import com.jetbrains.crucible.model.*;
import com.jetbrains.crucible.ui.UiUtils;
import git4idea.GitUtil;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
Expand Down Expand Up @@ -267,7 +264,7 @@ public Comment postComment(@NotNull final Comment comment, boolean isGeneral,
public void fillRepoHash() throws IOException {
String url = getHostUrl() + REPOSITORIES;
final JsonObject jsonObject = buildJsonResponse(url);
Collection<Repository> repos = CrucibleApi.parseGitRepositories(jsonObject);
Collection<Repository> repos = CrucibleApi.parseRepositories(jsonObject);

for (Repository repo : repos) {
VirtualFile localPath = getLocalPath(repo);
Expand All @@ -278,18 +275,10 @@ public void fillRepoHash() throws IOException {

@Nullable
protected VirtualFile getLocalPath(@NotNull Repository repository) {
GitRepositoryManager manager = GitUtil.getRepositoryManager(myProject);
List<GitRepository> repositories = manager.getRepositories();
String location = repository.getUrl();
for (GitRepository repo : repositories) {
GitRemote origin = GitUtil.findRemoteByName(repo, GitRemote.ORIGIN);
if (origin != null) {
String originFirstUrl = origin.getFirstUrl();
if (originFirstUrl == null) continue;
if (location.equals(originFirstUrl)) {
return repo.getRoot();
}
}
final VcsRepositoryManager manager = VcsRepositoryManager.getInstance(myProject);
final Collection<com.intellij.dvcs.repo.Repository> repositories = manager.getRepositories();
for (com.intellij.dvcs.repo.Repository repo : repositories) {
return repo.getRoot();
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/jetbrains/crucible/model/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
public class Repository {

@NotNull private String myName;
@NotNull private String myUrl;
@NotNull private final String myName;
@NotNull private final String myUrl;

public Repository(@NotNull String name, @NotNull String url) {
myName = name;
Expand Down
2 changes: 1 addition & 1 deletion src/com/jetbrains/crucible/model/ReviewItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<CommittedChangeList> loadChangeLists(@NotNull Project project, @NotN
if (!loadedRevisions.contains(revision)) {
final VcsRevisionNumber revisionNumber = vcsFor.parseRevisionNumber(revision);
if (revisionNumber != null) {
final CommittedChangeList changeList = VcsUtils.loadRevisionsFromGit(project, revisionNumber, path);
final CommittedChangeList changeList = VcsUtils.loadRevisions(project, revisionNumber, path);
if (changeList != null) changeLists.add(changeList);
}
loadedRevisions.add(revision);
Expand Down
41 changes: 9 additions & 32 deletions src/com/jetbrains/crucible/vcs/VcsUtils.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,40 @@
package com.jetbrains.crucible.vcs;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ThrowableRunnable;
import com.intellij.util.ui.VcsSynchronousProgressWrapper;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.util.VcsUserUtil;
import com.intellij.vcsUtil.VcsUtil;
import git4idea.GitRevisionNumber;
import git4idea.GitVcs;
import git4idea.changes.GitCommittedChangeList;
import git4idea.history.GitHistoryUtils;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;

/**
* User: ktisha
*/
public class VcsUtils {

private VcsUtils() {
}

@Nullable
public static CommittedChangeList loadRevisionsFromGit(@NotNull final Project project,
final VcsRevisionNumber number, FilePath filePath) {
public static CommittedChangeList loadRevisions(@NotNull final Project project, final VcsRevisionNumber number, final FilePath filePath) {
final CommittedChangeList[] list = new CommittedChangeList[1];
final ThrowableRunnable<VcsException> runnable = () -> {
final AbstractVcs vcs = VcsUtil.getVcsFor(project, filePath);

FilePath lastCommitName = VcsUtil.getLastCommitPath(project, filePath);
GitRepository repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(lastCommitName);
if (repository == null) {
if (vcs == null) {
return;
}
VirtualFile root = repository.getRoot();

List<VcsFullCommitDetails> gitCommits = new ArrayList<>();
GitHistoryUtils.loadDetails(project, root, gitCommits::add,
GitHistoryUtils.formHashParameters(repository.getVcs(), Collections.singleton(number.asString())));
if (gitCommits.size() != 1) {
return;
}
VcsFullCommitDetails gitCommit = gitCommits.get(0);
CommittedChangeList commit = new GitCommittedChangeList(gitCommit.getFullMessage() + " (" + gitCommit.getId().toShortString() + ")",
gitCommit.getFullMessage(), VcsUserUtil.toExactString(gitCommit.getAuthor()),
(GitRevisionNumber)number,
new Date(gitCommit.getAuthorTime()), gitCommit.getChanges(),
Objects.requireNonNull(GitVcs.getInstance(project)), true);

list[0] = commit;
list[0] = vcs.loadRevisions(filePath.getVirtualFile(), number);
};
final boolean success = VcsSynchronousProgressWrapper.wrap(runnable, project, "Load revision contents");

final boolean success = VcsSynchronousProgressWrapper.wrap(runnable, project, "Load Revision Contents");

return success ? list[0] : null;
}
}

0 comments on commit 1f31163

Please sign in to comment.