[vcs] IJPL-72638 refactoring: extract method.

GitOrigin-RevId: c6c7fd88c5cc2d663e3673ce00c8c5df0ef494a1
This commit is contained in:
Denis Zaichenko
2024-05-10 10:24:54 +03:00
committed by intellij-monorepo-bot
parent af10d1b315
commit 56d136bb42

View File

@@ -167,16 +167,8 @@ public final class GitBranchUtil {
public static @Nls @NotNull String getDisplayableBranchText(@NotNull GitRepository repository,
@NotNull Function<@NotNull @NlsSafe String, @NotNull @NlsSafe String> branchNameTruncator) {
GitRepository.State state = repository.getState();
if (state == GitRepository.State.DETACHED) {
String currentRevision = repository.getCurrentRevision();
if (currentRevision != null) {
return DvcsUtil.getShortHash(currentRevision);
}
else {
LOG.warn(String.format("Current revision is null in DETACHED state. isFresh: %s", repository.isFresh()));
return GitBundle.message("git.status.bar.widget.text.unknown");
}
}
String currentRevision = getDetachedPresentableText(repository, state);
if (currentRevision != null) return currentRevision;
GitBranch branch = repository.getCurrentBranch();
String branchName = (branch == null ? "" : branchNameTruncator.apply(branch.getName()));
@@ -198,6 +190,21 @@ public final class GitBranchUtil {
}
}
@Nls
private static @Nullable String getDetachedPresentableText(@NotNull GitRepository repository, GitRepository.State state) {
if (state == GitRepository.State.DETACHED) {
String currentRevision = repository.getCurrentRevision();
if (currentRevision != null) {
return DvcsUtil.getShortHash(currentRevision);
}
else {
LOG.warn(String.format("Current revision is null in DETACHED state. isFresh: %s", repository.isFresh()));
return GitBundle.message("git.status.bar.widget.text.unknown");
}
}
return null;
}
/**
* @deprecated Prefer {@link #guessWidgetRepository(Project)} or {@link #guessRepositoryForOperation(Project, DataContext)}.
*/