Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions plugin/src/main/java/consulo/git/util/LazyDebug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package consulo.git.util;

import jakarta.annotation.Nonnull;

import java.util.function.Supplier;

/**
* @author UNV
* @since 2025-11-21
*/
public final record LazyDebug(@Nonnull Supplier<String> stringSupplier) {
@Override
public String toString() {
return stringSupplier.get();
}
}
145 changes: 83 additions & 62 deletions plugin/src/main/java/git4idea/DialogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import consulo.annotation.component.ServiceImpl;
import consulo.ide.ServiceManager;
import consulo.project.Project;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.awt.DialogWrapper;
import consulo.ui.ex.awt.Messages;
import consulo.ui.image.Image;
import jakarta.inject.Singleton;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import jakarta.inject.Singleton;

/**
* Use {@link DialogManager#show(DialogWrapper) DialogManager.show(DialogWrapper)} instead of {@link DialogWrapper#show()}
Expand All @@ -25,71 +25,92 @@
@ServiceAPI(ComponentScope.APPLICATION)
@ServiceImpl
public class DialogManager {
public static void show(@Nonnull DialogWrapper dialog) {
dialogManager().showDialog(dialog);
}
@RequiredUIAccess
public static void show(@Nonnull DialogWrapper dialog) {
dialogManager().showDialog(dialog);
}

public static int showMessage(@Nonnull final String description,
@Nonnull final String title,
@Nonnull final String[] options,
final int defaultButtonIndex,
final int focusedButtonIndex,
@Nullable final Image icon,
@Nullable final DialogWrapper.DoNotAskOption dontAskOption) {
return dialogManager().showMessageDialog(description, title, options, defaultButtonIndex, focusedButtonIndex, icon, dontAskOption);
}
@RequiredUIAccess
public static int showMessage(
@Nonnull String description,
@Nonnull String title,
@Nonnull String[] options,
int defaultButtonIndex,
int focusedButtonIndex,
@Nullable Image icon,
@Nullable DialogWrapper.DoNotAskOption dontAskOption
) {
return dialogManager().showMessageDialog(description, title, options, defaultButtonIndex, focusedButtonIndex, icon, dontAskOption);
}

public static int showOkCancelDialog(@Nonnull Project project,
@Nonnull String message,
@Nonnull String title,
@Nonnull String okButtonText,
@Nonnull String cancelButtonText,
@Nullable Image icon) {
return dialogManager().showMessageDialog(project, message, title, new String[]{
okButtonText,
cancelButtonText
}, 0, icon);
}
public static int showOkCancelDialog(
@Nonnull Project project,
@Nonnull String message,
@Nonnull String title,
@Nonnull String okButtonText,
@Nonnull String cancelButtonText,
@Nullable Image icon
) {
return dialogManager().showMessageDialog(project, message, title, new String[]{
okButtonText,
cancelButtonText
}, 0, icon);
}

public static int showYesNoCancelDialog(@Nonnull Project project,
@Nonnull String message,
@Nonnull String title,
@Nonnull String yesButtonText,
@Nonnull String noButtonText,
@Nonnull String cancelButtonText,
@Nullable Image icon) {
return dialogManager().showMessageDialog(project, message, title, new String[]{
yesButtonText,
noButtonText,
cancelButtonText
}, 0, icon);
}
public static int showYesNoCancelDialog(
@Nonnull Project project,
@Nonnull String message,
@Nonnull String title,
@Nonnull String yesButtonText,
@Nonnull String noButtonText,
@Nonnull String cancelButtonText,
@Nullable Image icon
) {
return dialogManager().showMessageDialog(
project,
message,
title,
new String[]{
yesButtonText,
noButtonText,
cancelButtonText
},
0,
icon
);
}

protected void showDialog(@Nonnull DialogWrapper dialog) {
dialog.show();
}
@RequiredUIAccess
protected void showDialog(@Nonnull DialogWrapper dialog) {
dialog.show();
}

protected int showMessageDialog(@Nonnull Project project,
@Nonnull String message,
@Nonnull String title,
@Nonnull String[] options,
int defaultButtonIndex,
@Nullable Image icon) {
return Messages.showDialog(project, message, title, options, defaultButtonIndex, icon);
}
protected int showMessageDialog(
@Nonnull Project project,
@Nonnull String message,
@Nonnull String title,
@Nonnull String[] options,
int defaultButtonIndex,
@Nullable Image icon
) {
return Messages.showDialog(project, message, title, options, defaultButtonIndex, icon);
}

protected int showMessageDialog(@Nonnull String description,
@Nonnull String title,
@Nonnull String[] options,
int defaultButtonIndex,
int focusedButtonIndex,
@Nullable Image icon,
@Nullable DialogWrapper.DoNotAskOption dontAskOption) {
return Messages.showDialog(description, title, options, defaultButtonIndex, focusedButtonIndex, icon, dontAskOption);
}
@RequiredUIAccess
protected int showMessageDialog(
@Nonnull String description,
@Nonnull String title,
@Nonnull String[] options,
int defaultButtonIndex,
int focusedButtonIndex,
@Nullable Image icon,
@Nullable DialogWrapper.DoNotAskOption dontAskOption
) {
return Messages.showDialog(description, title, options, defaultButtonIndex, focusedButtonIndex, icon, dontAskOption);
}

@Nonnull
private static DialogManager dialogManager() {
return ServiceManager.getService(DialogManager.class);
}
@Nonnull
private static DialogManager dialogManager() {
return ServiceManager.getService(DialogManager.class);
}
}
73 changes: 38 additions & 35 deletions plugin/src/main/java/git4idea/GitBranchesSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,58 @@

package git4idea;

import consulo.logging.Logger;
import consulo.project.Project;
import consulo.versionControlSystem.VcsException;
import consulo.virtualFileSystem.VirtualFile;
import git4idea.branch.GitBranchUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;

public class GitBranchesSearcher {
private final static Logger LOG = Logger.getInstance(GitBranchesSearcher.class);
private final GitBranch myLocal;
private GitBranch myRemote;
private final static Logger LOG = LoggerFactory.getLogger(GitBranchesSearcher.class);
private final GitBranch myLocal;
private GitBranch myRemote;

public GitBranchesSearcher(final Project project, final VirtualFile root, final boolean findRemote) throws VcsException {
LOG.debug("constructing, root: " + root.getPath() + " findRemote = " + findRemote);
final Set<GitBranch> usedBranches = new HashSet<GitBranch>();
myLocal = GitBranchUtil.getCurrentBranch(project, root);
LOG.debug("local: " + myLocal);
if (myLocal == null) return;
usedBranches.add(myLocal);
public GitBranchesSearcher(Project project, VirtualFile root, boolean findRemote) throws VcsException {
LOG.debug("constructing, root: {} findRemote = {}", root.getPath(), findRemote);
Set<GitBranch> usedBranches = new HashSet<>();
myLocal = GitBranchUtil.getCurrentBranch(project, root);
LOG.debug("local: {}", myLocal);
if (myLocal == null) {
return;
}
usedBranches.add(myLocal);

GitBranch remote = myLocal;
while (true) {
remote = GitBranchUtil.tracked(project, root, remote.getName());
if (remote == null) {
LOG.debug("remote == null, exiting");
return;
}
GitBranch remote = myLocal;
while (true) {
remote = GitBranchUtil.tracked(project, root, remote.getName());
if (remote == null) {
LOG.debug("remote == null, exiting");
return;
}

if ((! findRemote) || remote.isRemote()) {
LOG.debug("remote found, isRemote: " + remote.isRemote() + " remoteName: " + remote.getFullName());
myRemote = remote;
return;
}
if (!findRemote || remote.isRemote()) {
LOG.debug("remote found, isRemote: {} remoteName: {}", remote.isRemote(), remote.getFullName());
myRemote = remote;
return;
}

if (usedBranches.contains(remote)) {
LOG.debug("loop found for: " + remote.getFullName() + ", exiting");
return;
}
usedBranches.add(remote);
if (usedBranches.contains(remote)) {
LOG.debug("loop found for: {}, exiting", remote.getFullName());
return;
}
usedBranches.add(remote);
}
}
}

public GitBranch getLocal() {
return myLocal;
}
public GitBranch getLocal() {
return myLocal;
}

public GitBranch getRemote() {
return myRemote;
}
public GitBranch getRemote() {
return myRemote;
}
}
Loading
Loading