mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] introduce new api method to log provider and move current branch highlighter into vcs-log-impl
This commit is contained in:
@@ -38,7 +38,6 @@
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<projectService serviceImplementation="com.intellij.dvcs.push.PushSettings"/>
|
||||
<logHighlighterFactory implementation="com.intellij.dvcs.ui.CurrentBranchHighlighter$Factory"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
|
||||
@@ -106,6 +106,15 @@ public interface VcsLogProvider {
|
||||
@Nullable
|
||||
<T> T getPropertyValue(VcsLogProperties.VcsLogProperty<T> property);
|
||||
|
||||
/**
|
||||
* Returns currently checked out branch in given root, or null if not on any branch or provided root is not under version control.
|
||||
*
|
||||
* @param root root for which branch is requested.
|
||||
* @return branch that is currently checked out in the specified root.
|
||||
*/
|
||||
@Nullable
|
||||
String getCurrentBranch(@NotNull VirtualFile root);
|
||||
|
||||
interface Requirements {
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<statistics.usagesCollector implementation="com.intellij.vcs.log.statistics.VcsLogRepoSizeCollector" />
|
||||
|
||||
<logHighlighterFactory implementation="com.intellij.vcs.log.ui.MyCommitsHighlighter$Factory"/>
|
||||
<logHighlighterFactory implementation="com.intellij.vcs.log.ui.CurrentBranchHighlighter$Factory"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
|
||||
+8
-21
@@ -13,20 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.dvcs.ui;
|
||||
package com.intellij.vcs.log.ui;
|
||||
|
||||
import com.intellij.dvcs.repo.Repository;
|
||||
import com.intellij.dvcs.repo.VcsRepositoryManager;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsCommitStyleFactory;
|
||||
import com.intellij.vcs.log.VcsLogHighlighter;
|
||||
import com.intellij.vcs.log.VcsShortCommitDetails;
|
||||
import com.intellij.vcs.log.*;
|
||||
import com.intellij.vcs.log.data.LoadingDetails;
|
||||
import com.intellij.vcs.log.data.VcsLogDataHolder;
|
||||
import com.intellij.vcs.log.data.VcsLogUiProperties;
|
||||
import com.intellij.vcs.log.ui.VcsLogHighlighterFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -35,12 +29,10 @@ public class CurrentBranchHighlighter implements VcsLogHighlighter {
|
||||
private static final JBColor CURRENT_BRANCH_BG = new JBColor(new Color(228, 250, 255), new Color(63, 71, 73));
|
||||
@NotNull private final VcsLogUiProperties myUiProperties;
|
||||
@NotNull private final VcsLogDataHolder myDataHolder;
|
||||
@NotNull private final VcsRepositoryManager myRepositoryManager;
|
||||
|
||||
public CurrentBranchHighlighter(@NotNull VcsLogDataHolder logDataHolder, @NotNull VcsLogUiProperties uiProperties) {
|
||||
myDataHolder = logDataHolder;
|
||||
myUiProperties = uiProperties;
|
||||
myRepositoryManager = myDataHolder.getProject().getComponent(VcsRepositoryManager.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -49,17 +41,12 @@ public class CurrentBranchHighlighter implements VcsLogHighlighter {
|
||||
if (isSelected || !myUiProperties.isHighlightCurrentBranch()) return VcsCommitStyle.DEFAULT;
|
||||
VcsShortCommitDetails details = myDataHolder.getMiniDetailsGetter().getCommitDataIfAvailable(commitIndex);
|
||||
if (details != null && !(details instanceof LoadingDetails)) {
|
||||
Repository repo = myRepositoryManager.getRepositoryForRoot(details.getRoot());
|
||||
if (repo != null) {
|
||||
String currentBranch = repo.getCurrentBranchName();
|
||||
if (currentBranch == null) {
|
||||
if (repo.getCurrentRevision() != null) currentBranch = "HEAD"; // does this work for hg?
|
||||
}
|
||||
if (currentBranch != null) {
|
||||
Condition<Hash> condition = myDataHolder.getContainingBranchesGetter().getContainedInBranchCondition(currentBranch, details.getRoot());
|
||||
if (condition.value(details.getId())) {
|
||||
return VcsCommitStyleFactory.background(CURRENT_BRANCH_BG);
|
||||
}
|
||||
VcsLogProvider provider = myDataHolder.getLogProvider(details.getRoot());
|
||||
String currentBranch = provider.getCurrentBranch(details.getRoot());
|
||||
if (currentBranch != null) {
|
||||
Condition<Hash> condition = myDataHolder.getContainingBranchesGetter().getContainedInBranchCondition(currentBranch, details.getRoot());
|
||||
if (condition.value(details.getId())) {
|
||||
return VcsCommitStyleFactory.background(CURRENT_BRANCH_BG);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,6 +210,12 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getCurrentBranch(@NotNull VirtualFile root) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class MockRefManager implements VcsLogRefManager {
|
||||
|
||||
public static final Comparator<VcsRef> FAKE_COMPARATOR = new Comparator<VcsRef>() {
|
||||
|
||||
@@ -485,6 +485,18 @@ public class GitLogProvider implements VcsLogProvider {
|
||||
return GitBranchUtil.getBranches(myProject, root, true, true, commitHash.asString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getCurrentBranch(@NotNull VirtualFile root) {
|
||||
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
|
||||
if (repository == null) return null;
|
||||
String currentBranchName = repository.getCurrentBranchName();
|
||||
if (currentBranchName == null && repository.getCurrentRevision() != null) {
|
||||
return "HEAD";
|
||||
}
|
||||
return currentBranchName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getPropertyValue(VcsLogProperties.VcsLogProperty<T> property) {
|
||||
|
||||
@@ -274,6 +274,14 @@ public class HgLogProvider implements VcsLogProvider {
|
||||
return HgHistoryUtil.getDescendingHeadsOfBranches(myProject, root, commitHash);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getCurrentBranch(@NotNull VirtualFile root) {
|
||||
HgRepository repository = myRepositoryManager.getRepositoryForRoot(root);
|
||||
if (repository == null) return null;
|
||||
return repository.getCurrentBranchName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getPropertyValue(VcsLogProperties.VcsLogProperty<T> property) {
|
||||
|
||||
Reference in New Issue
Block a user