From 95a7c1238fe6d64217f520ef5e455f383d21c015 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sat, 8 Jun 2019 11:21:48 +0100 Subject: [PATCH] git: cleanup: convert GitBranchPair to a kotlin dataclass and rename properties to more clear names GitOrigin-RevId: 4433c399640b52f2637e6692d75ecd7c9c2d482b --- .../src/git4idea/branch/GitBranchPair.kt | 31 +++---------------- .../src/git4idea/update/GitMergeUpdater.java | 6 ++-- .../src/git4idea/update/GitRebaseUpdater.java | 4 +-- .../src/git4idea/update/GitUpdateProcess.java | 8 ++--- .../src/git4idea/update/GitUpdater.java | 2 +- 5 files changed, 14 insertions(+), 37 deletions(-) diff --git a/plugins/git4idea/src/git4idea/branch/GitBranchPair.kt b/plugins/git4idea/src/git4idea/branch/GitBranchPair.kt index 68a68b360120..5614546420e6 100644 --- a/plugins/git4idea/src/git4idea/branch/GitBranchPair.kt +++ b/plugins/git4idea/src/git4idea/branch/GitBranchPair.kt @@ -13,35 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.branch; +package git4idea.branch -import git4idea.GitLocalBranch; -import git4idea.GitRemoteBranch; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import git4idea.GitLocalBranch +import git4idea.GitRemoteBranch /** * Holder for Git branch and the branch it is "connected" with. It is tracked branch or so called "matched" branch. - * - * @author Kirill Likhodedov */ -public class GitBranchPair { - private @NotNull final GitLocalBranch myBranch; - private @Nullable final GitRemoteBranch myDestBranch; - - public GitBranchPair(@NotNull GitLocalBranch branch, @Nullable GitRemoteBranch destination) { - myBranch = branch; - myDestBranch = destination; - } - - @NotNull - public GitLocalBranch getBranch() { - return myBranch; - } - - @Nullable - public GitRemoteBranch getDest() { - return myDestBranch; - } - -} +data class GitBranchPair(val source: GitLocalBranch, val target: GitRemoteBranch?) diff --git a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java index 3fdcea85c17b..2bc848837dd1 100644 --- a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java +++ b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java @@ -68,7 +68,7 @@ public class GitMergeUpdater extends GitUpdater { String originalText = myProgressIndicator.getText(); myProgressIndicator.setText("Merging" + GitUtil.mention(myRepository) + "..."); try { - GitCommandResult result = myGit.merge(myRepository, assertNotNull(myBranchPair.getDest()).getName(), + GitCommandResult result = myGit.merge(myRepository, assertNotNull(myBranchPair.getTarget()).getName(), asList("--no-stat", "-v"), mergeLineListener, untrackedFilesDetector, GitStandardProgressAnalyzer.createListener(myProgressIndicator)); myProgressIndicator.setText(originalText); @@ -134,8 +134,8 @@ public class GitMergeUpdater extends GitUpdater { } // git log --name-status master..origin/master - String currentBranch = myBranchPair.getBranch().getName(); - String remoteBranch = myBranchPair.getDest().getName(); + String currentBranch = myBranchPair.getSource().getName(); + String remoteBranch = myBranchPair.getTarget().getName(); try { GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(myRoot); if (repository == null) { diff --git a/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java b/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java index db6dcbc38120..dbee1710fc8b 100644 --- a/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java +++ b/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java @@ -74,9 +74,9 @@ public class GitRebaseUpdater extends GitUpdater { @NotNull private String getRemoteBranchToMerge() { - GitBranch dest = myBranchPair.getDest(); + GitBranch dest = myBranchPair.getTarget(); LOG.assertTrue(dest != null, String.format("Destination branch is null for source branch %s in %s", - myBranchPair.getBranch().getName(), myRoot)); + myBranchPair.getSource().getName(), myRoot)); return dest.getName(); } diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java index 5a9922b6276b..0c7e0765be18 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java @@ -266,8 +266,8 @@ public class GitUpdateProcess { return ContainerUtil.mapNotNull(updaters.keySet(), repo -> { GitUpdater updater = updaters.get(repo); if (updater instanceof GitRebaseUpdater) { - String currentRef = ((GitRebaseUpdater)updater).getSourceAndTarget().getBranch().getFullName(); - String baseRef = assertNotNull(((GitRebaseUpdater)updater).getSourceAndTarget().getDest()).getFullName(); + String currentRef = ((GitRebaseUpdater)updater).getSourceAndTarget().getSource().getFullName(); + String baseRef = assertNotNull(((GitRebaseUpdater)updater).getSourceAndTarget().getTarget()).getFullName(); return GitRebaseOverMergeProblem.hasProblem(myProject, repo.getRoot(), baseRef, currentRef) ? repo : null; } return null; @@ -328,8 +328,8 @@ public class GitUpdateProcess { private Map calcPublishedTipPositions(@NotNull Map trackedBranches) { Map result = new LinkedHashMap<>(); for (GitRepository repository : trackedBranches.keySet()) { - GitLocalBranch localBranch = trackedBranches.get(repository).getBranch(); - GitRemoteBranch trackedBranch = trackedBranches.get(repository).getDest(); + GitLocalBranch localBranch = trackedBranches.get(repository).getSource(); + GitRemoteBranch trackedBranch = trackedBranches.get(repository).getTarget(); if (trackedBranch != null) { Hash mergeBase = getMergeBase(repository.getRoot(), localBranch.getFullName(), trackedBranch.getFullName()); if (mergeBase != null) { diff --git a/plugins/git4idea/src/git4idea/update/GitUpdater.java b/plugins/git4idea/src/git4idea/update/GitUpdater.java index 6b855bc5b949..f2dc542d64aa 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdater.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdater.java @@ -166,7 +166,7 @@ public abstract class GitUpdater { * @return true if update is needed, false otherwise. */ public boolean isUpdateNeeded(@NotNull GitBranchPair branchPair) throws VcsException { - GitBranch dest = branchPair.getDest(); + GitBranch dest = branchPair.getTarget(); assert dest != null; String remoteBranch = dest.getName(); if (!hasRemoteChanges(remoteBranch)) {