Skip to content

Commit

Permalink
Port away from deprecated git4idea API
Browse files Browse the repository at this point in the history
  • Loading branch information
uwolfer committed Jun 13, 2021
1 parent 6d83069 commit cfa491b
Showing 1 changed file with 14 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.FetchInfo;
import com.google.inject.Inject;
import com.intellij.dvcs.util.CommitCompareInfo;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
Expand Down Expand Up @@ -60,14 +60,13 @@
import git4idea.commands.GitLineHandlerListener;
import git4idea.commands.GitSimpleEventDetector;
import git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector;
import git4idea.fetch.GitFetchResult;
import git4idea.fetch.GitFetchSupport;
import git4idea.history.GitHistoryUtils;
import git4idea.merge.GitConflictResolver;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.update.GitFetchResult;
import git4idea.update.GitFetcher;
import git4idea.util.GitCommitCompareInfo;
import git4idea.util.GitUntrackedFilesHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -159,10 +158,8 @@ public void run(@NotNull ProgressIndicator indicator) {
}
fetch = fetchInfo.ref;
}
GitFetchResult result = fetchNatively(gitRepository, remote, fetch);
if (!result.isSuccess()) {
GitFetcher.displayFetchResult(project, result, null, result.getErrors());
}
GitFetchResult result = GitFetchSupport.fetchSupport(project).fetch(gitRepository, remote, fetch);
result.showNotificationIfFailed();

try {
if (fetchCallback != null) {
Expand Down Expand Up @@ -220,12 +217,12 @@ private boolean cherryPick(@NotNull GitRepository repository, @NotNull VcsShortC
GitSimpleEventDetector localChangesOverwrittenDetector = new GitSimpleEventDetector(LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK);
GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector =
new GitUntrackedFilesOverwrittenByOperationDetector(repository.getRoot());
GitCommandResult result = git.cherryPick(repository, commit.getId().asString(), false,
GitCommandResult result = git.cherryPick(repository, commit.getId().asString(), false, true,
conflictDetector, localChangesOverwrittenDetector, untrackedFilesDetector);
if (result.success()) {
return true;
} else if (conflictDetector.hasHappened()) {
return new CherryPickConflictResolver(project, git, repository.getRoot(),
return new CherryPickConflictResolver(project, repository.getRoot(),
commit.getId().toShortString(), commit.getAuthor().getName(),
commit.getSubject()).merge();
} else if (untrackedFilesDetector.wasMessageDetected()) {
Expand Down Expand Up @@ -253,9 +250,9 @@ private boolean cherryPick(@NotNull GitRepository repository, @NotNull VcsShortC
*/
private static class CherryPickConflictResolver extends GitConflictResolver {

public CherryPickConflictResolver(@NotNull Project project, @NotNull Git git, @NotNull VirtualFile root,
public CherryPickConflictResolver(@NotNull Project project, @NotNull VirtualFile root,
@NotNull String commitHash, @NotNull String commitAuthor, @NotNull String commitMessage) {
super(project, git, Collections.singleton(root), makeParams(commitHash, commitAuthor, commitMessage));
super(project, Collections.singleton(root), makeParams(commitHash, commitAuthor, commitMessage));
}

private static Params makeParams(String commitHash, String commitAuthor, String commitMessage) {
Expand Down Expand Up @@ -304,29 +301,6 @@ public String getRightPanelTitle(VirtualFile file, VcsRevisionNumber lastRevisio
}
}

/**
* Almost a copy of git4idea.update.GitFetcher#fetchNatively().
* Modifications:
* * removal of GitFetchPruneDetector
* * do not prepend "refs/heads/..." (with getFetchSpecForBranch).
*/
@NotNull
private static GitFetchResult fetchNatively(@NotNull GitRepository repository, @NotNull GitRemote remote, @Nullable String branch) {
Git git = ServiceManager.getService(Git.class);
GitCommandResult result = git.fetch(repository, remote,
Collections.<GitLineHandlerListener>emptyList(), new String[]{branch});

GitFetchResult fetchResult;
if (result.success()) {
fetchResult = GitFetchResult.success();
} else if (result.cancelled()) {
fetchResult = GitFetchResult.cancel();
} else {
fetchResult = GitFetchResult.error(result.getErrorOutputAsJoinedString());
}
return fetchResult;
}

public boolean checkIfCommitIsFetched(GitRepository repository, String commitHash) {
FormattedGitLineHandlerListener listener = new FormattedGitLineHandlerListener();
final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.SHOW);
Expand All @@ -349,7 +323,7 @@ public GitLineHandler compute() {
}

@NotNull
public Pair<List<GitCommit>, List<GitCommit>> loadCommitsToCompare(@NotNull GitRepository repository, @NotNull final String branchName, @NotNull final Project project) {
private Pair<List<GitCommit>, List<GitCommit>> loadCommitsToCompare(@NotNull GitRepository repository, @NotNull final String branchName, @NotNull final Project project) {
final List<GitCommit> headToBranch;
final List<GitCommit> branchToHead;
try {
Expand All @@ -363,11 +337,11 @@ public Pair<List<GitCommit>, List<GitCommit>> loadCommitsToCompare(@NotNull GitR
}

@NotNull
public GitCommitCompareInfo loadCommitsToCompare(Collection<GitRepository> repositories, String branchName, @NotNull final Project project) {
GitCommitCompareInfo compareInfo = new GitCommitCompareInfo();
public CommitCompareInfo loadCommitsToCompare(Collection<GitRepository> repositories, String branchName, @NotNull final Project project) {
CommitCompareInfo compareInfo = new CommitCompareInfo();
for (GitRepository repository : repositories) {
compareInfo.put(repository, loadCommitsToCompare(repository, branchName, project));
// compareInfo.put(repository, loadTotalDiff(repository, branchName));
Pair<List<GitCommit>, List<GitCommit>> listListPair = loadCommitsToCompare(repository, branchName, project);
compareInfo.put(repository, listListPair.first, listListPair.second);
}
return compareInfo;
}
Expand Down

0 comments on commit cfa491b

Please sign in to comment.