mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
vcs: when building a patch from changes, don't search for the date and don't save it for Git
Looking at the date of the tip commit of a file takes time in case of many files. At the same time it is not necessary for DVCS at all, since these VCSs save the base revision by default (which is far more reliable). GitOrigin-RevId: 44eb147b6732b7c56824b2f6c86f1cad4d8a3b06
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c3d4629513
commit
b9cc2e27fa
@@ -16,21 +16,15 @@
|
||||
package com.intellij.openapi.vcs;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface VcsOutgoingChangesProvider <T extends CommittedChangeList> extends VcsProviderMarker {
|
||||
Pair<VcsRevisionNumber, List<T>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote) throws VcsException;
|
||||
@Nullable
|
||||
VcsRevisionNumber getMergeBaseNumber(final VirtualFile anyFileUnderRoot) throws VcsException;
|
||||
Collection<Change> filterLocalChangesBasedOnLocalCommits(final Collection<? extends Change> localChanges, final VirtualFile vcsRoot) throws VcsException;
|
||||
@Nullable
|
||||
Date getRevisionDate(final VcsRevisionNumber revision, FilePath file);
|
||||
}
|
||||
|
||||
+17
-55
@@ -5,7 +5,8 @@ import com.intellij.diff.util.Side;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vcs.*;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vcs.ex.PartialCommitHelper;
|
||||
import com.intellij.openapi.vcs.impl.PartialChangesUtil;
|
||||
@@ -16,12 +17,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.openapi.vcs.changes.ChangesUtil.getAfterPath;
|
||||
import static com.intellij.openapi.vcs.changes.ChangesUtil.getBeforePath;
|
||||
import static com.intellij.util.ObjectUtils.chooseNotNull;
|
||||
import static com.intellij.vcsUtil.VcsUtil.groupByRoots;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class IdeaTextPatchBuilder {
|
||||
private IdeaTextPatchBuilder() {
|
||||
@@ -29,34 +27,15 @@ public class IdeaTextPatchBuilder {
|
||||
|
||||
private static List<BeforeAfter<AirContentRevision>> revisionsConvertor(@NotNull Project project,
|
||||
@NotNull List<? extends Change> changes,
|
||||
boolean honorExcludedFromCommit) throws VcsException {
|
||||
boolean honorExcludedFromCommit) {
|
||||
final List<BeforeAfter<AirContentRevision>> result = new ArrayList<>(changes.size());
|
||||
Map<VcsRoot, List<Change>> byRoots =
|
||||
groupByRoots(project, changes, true, change -> chooseNotNull(getBeforePath(change), getAfterPath(change)));
|
||||
|
||||
for (VcsRoot root : byRoots.keySet()) {
|
||||
final Collection<Change> rootChanges = byRoots.get(root);
|
||||
|
||||
AbstractVcs vcs = root != null ? root.getVcs() : null;
|
||||
if (vcs == null || vcs.getOutgoingChangesProvider() == null) {
|
||||
addConvertChanges(project, rootChanges, result, null, honorExcludedFromCommit);
|
||||
}
|
||||
else {
|
||||
final VcsOutgoingChangesProvider<?> provider = vcs.getOutgoingChangesProvider();
|
||||
final Collection<Change> basedOnLocal = provider.filterLocalChangesBasedOnLocalCommits(rootChanges, root.getPath());
|
||||
rootChanges.removeAll(basedOnLocal);
|
||||
|
||||
addConvertChanges(project, rootChanges, result, null, honorExcludedFromCommit);
|
||||
addConvertChanges(project, basedOnLocal, result, provider, honorExcludedFromCommit);
|
||||
}
|
||||
}
|
||||
addConvertChanges(project, changes, result, honorExcludedFromCommit);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void addConvertChanges(@NotNull Project project,
|
||||
@NotNull Collection<? extends Change> changes,
|
||||
@NotNull List<? super BeforeAfter<AirContentRevision>> result,
|
||||
@Nullable VcsOutgoingChangesProvider<?> provider,
|
||||
boolean honorExcludedFromCommit) {
|
||||
Collection<Change> otherChanges = PartialChangesUtil.processPartialChanges(project, changes, false, (partialChanges, tracker) -> {
|
||||
if (!tracker.hasPartialChangesToCommit()) return false;
|
||||
@@ -67,14 +46,14 @@ public class IdeaTextPatchBuilder {
|
||||
PartialCommitHelper helper = tracker.handlePartialCommit(Side.LEFT, changelistIds, honorExcludedFromCommit);
|
||||
String actualText = helper.getContent();
|
||||
|
||||
result.add(new BeforeAfter<>(convertRevision(change.getBeforeRevision(), null, provider),
|
||||
convertRevision(change.getAfterRevision(), actualText, provider)));
|
||||
result.add(new BeforeAfter<>(convertRevision(change.getBeforeRevision(), null),
|
||||
convertRevision(change.getAfterRevision(), actualText)));
|
||||
return true;
|
||||
});
|
||||
|
||||
for (Change change : otherChanges) {
|
||||
result.add(new BeforeAfter<>(convertRevision(change.getBeforeRevision(), null, provider),
|
||||
convertRevision(change.getAfterRevision(), null, provider)));
|
||||
result.add(new BeforeAfter<>(convertRevision(change.getBeforeRevision(), null),
|
||||
convertRevision(change.getAfterRevision(), null)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,40 +88,23 @@ public class IdeaTextPatchBuilder {
|
||||
|
||||
@Nullable
|
||||
private static AirContentRevision convertRevision(@Nullable ContentRevision cr) {
|
||||
return convertRevision(cr, null, null);
|
||||
return convertRevision(cr, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AirContentRevision convertRevision(@Nullable ContentRevision cr,
|
||||
@Nullable String actualTextContent,
|
||||
@Nullable VcsOutgoingChangesProvider provider) {
|
||||
private static AirContentRevision convertRevision(@Nullable ContentRevision cr, @Nullable String actualTextContent) {
|
||||
if (cr == null) return null;
|
||||
if (provider != null) {
|
||||
final Date date = provider.getRevisionDate(cr.getRevisionNumber(), cr.getFile());
|
||||
final Long ts = date == null ? null : date.getTime();
|
||||
return convertRevisionToAir(cr, actualTextContent, ts);
|
||||
}
|
||||
else {
|
||||
return convertRevisionToAir(cr, actualTextContent, null);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static AirContentRevision convertRevisionToAir(@NotNull ContentRevision cr,
|
||||
@Nullable String actualTextContent,
|
||||
@Nullable Long ts) {
|
||||
final FilePath fp = cr.getFile();
|
||||
final StaticPathDescription description = new StaticPathDescription(fp.isDirectory(),
|
||||
ts == null ? fp.getIOFile().lastModified() : ts, fp.getPath());
|
||||
final StaticPathDescription description = new StaticPathDescription(fp.isDirectory(), fp.getIOFile().lastModified(), fp.getPath());
|
||||
|
||||
if (actualTextContent != null) {
|
||||
return new PartialTextAirContentRevision(actualTextContent, cr, description, ts);
|
||||
return new PartialTextAirContentRevision(actualTextContent, cr, description, null);
|
||||
}
|
||||
else if (cr instanceof BinaryContentRevision) {
|
||||
return new BinaryAirContentRevision((BinaryContentRevision)cr, description, ts);
|
||||
return new BinaryAirContentRevision((BinaryContentRevision)cr, description, null);
|
||||
}
|
||||
else {
|
||||
return new TextAirContentRevision(cr, description, ts);
|
||||
return new TextAirContentRevision(cr, description, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,11 @@ package git4idea.changes;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.VcsOutgoingChangesProvider;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.vcsUtil.VcsUtil;
|
||||
import git4idea.GitBranch;
|
||||
import git4idea.GitBranchesSearcher;
|
||||
import git4idea.GitRevisionNumber;
|
||||
@@ -22,7 +19,8 @@ import git4idea.repo.GitRepositoryManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.util.Functions.identity;
|
||||
import static com.intellij.util.containers.ContainerUtil.map;
|
||||
@@ -72,54 +70,6 @@ public class GitOutgoingChangesProvider implements VcsOutgoingChangesProvider<Co
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Change> filterLocalChangesBasedOnLocalCommits(final Collection<? extends Change> localChanges, final VirtualFile vcsRoot)
|
||||
throws VcsException {
|
||||
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, true);
|
||||
if (searcher.getLocal() == null || searcher.getRemote() == null) {
|
||||
return new ArrayList<>(localChanges); // no information, better strict approach (see getOutgoingChanges() code)
|
||||
}
|
||||
final GitRevisionNumber base;
|
||||
try {
|
||||
base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
|
||||
}
|
||||
catch (VcsException e) {
|
||||
LOG.info(e);
|
||||
return new ArrayList<>(localChanges);
|
||||
}
|
||||
if (base == null) {
|
||||
return new ArrayList<>(localChanges); // no information, better strict approach (see getOutgoingChanges() code)
|
||||
}
|
||||
|
||||
Set<String> localHashes = new HashSet<>();
|
||||
GitHistoryUtils.loadTimedCommits(myProject, vcsRoot, commit -> localHashes.add(commit.getId().asString()), base.asString() + "..HEAD");
|
||||
if (localHashes.isEmpty()) return Collections.emptyList();
|
||||
|
||||
Collection<Change> result = new ArrayList<>();
|
||||
for (Change change : localChanges) {
|
||||
if (change.getBeforeRevision() != null) {
|
||||
if (localHashes.contains(change.getBeforeRevision().getRevisionNumber().asString().trim())) {
|
||||
result.add(change);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Date getRevisionDate(VcsRevisionNumber revision, FilePath file) {
|
||||
if (VcsRevisionNumber.NULL.equals(revision)) return null;
|
||||
try {
|
||||
file = VcsUtil.getLastCommitPath(myProject, file);
|
||||
VirtualFile root = GitUtil.getRepositoryForFile(myProject, file).getRoot();
|
||||
return new Date(GitHistoryUtils.getAuthorTime(myProject, root, revision.asString()));
|
||||
}
|
||||
catch (VcsException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a merge base between the current branch and specified branch.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user