Skip to content
Merged
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
8 changes: 3 additions & 5 deletions plugin/src/main/java/git4idea/GitBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
package git4idea;

import consulo.versionControlSystem.log.Hash;
import jakarta.annotation.Nonnull;
import org.jetbrains.annotations.NonNls;

import git4idea.branch.GitBranchUtil;
import git4idea.repo.GitRepository;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import org.jetbrains.annotations.NonNls;

/**
* <p>Represents a Git branch, local or remote.</p>
Expand All @@ -42,7 +40,6 @@
*/
public abstract class GitBranch extends GitReference
{

@NonNls
public static final String REFS_HEADS_PREFIX = "refs/heads/"; // Prefix for local branches ({@value})
@NonNls
Expand All @@ -66,6 +63,7 @@ protected GitBranch(@Nonnull String name)
public abstract boolean isRemote();

@Nonnull
@Override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @Override is indented with 4 spaces, but the rest of this file is tab-indented (the @Nonnull line just above uses a tab). The same tab/space mismatch recurs on several other reformatted lines in this PR (see notes on GitSSHXmlRpcClient and SSHMain). Suggest keeping each file consistent with its existing indentation.

Suggested change
@Override
@Override

public String getFullName()
{
return (isRemote() ? REFS_REMOTES_PREFIX : REFS_HEADS_PREFIX) + myName;
Expand Down
5 changes: 3 additions & 2 deletions plugin/src/main/java/git4idea/GitReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package git4idea;

import consulo.application.util.SystemInfo;
import consulo.platform.Platform;
import consulo.util.collection.HashingStrategy;
import consulo.util.lang.StringUtil;
import consulo.virtualFileSystem.util.FilePathHashingStrategy;
Expand Down Expand Up @@ -72,7 +72,8 @@ public int hashCode() {
return BRANCH_NAME_HASHING_STRATEGY.hashCode(myName);
}

@Override
public int compareTo(GitReference o) {
return o == null ? 1 : StringUtil.compare(getFullName(), o.getFullName(), SystemInfo.isFileSystemCaseSensitive);
return o == null ? 1 : StringUtil.compare(getFullName(), o.getFullName(), Platform.current().fs().isCaseSensitive());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good move off the deprecated SystemInfo. Worth one confirmation on semantics: SystemInfo.isFileSystemCaseSensitive reflected the case-sensitivity of the filesystem the IDE runs on, and Platform.current().fs().isCaseSensitive() should be its intended replacement. Since this value drives Git reference name comparison, a quick check that the two are truly equivalent is worthwhile.

}
}
3 changes: 2 additions & 1 deletion plugin/src/main/java/git4idea/GitRevisionSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package git4idea;

import consulo.versionControlSystem.history.VcsRevisionNumber;
import consulo.versionControlSystem.diff.RevisionSelector;
import consulo.versionControlSystem.history.VcsRevisionNumber;
import consulo.virtualFileSystem.VirtualFile;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
Expand All @@ -29,6 +29,7 @@ public class GitRevisionSelector implements RevisionSelector {
* {@inheritDoc}
*/
@Nullable
@Override
public VcsRevisionNumber selectNumber(@Nonnull VirtualFile file) {
//GitVirtualFile gitFile = (GitVirtualFile) file;
//TODO: implement selectNumber()
Expand Down
26 changes: 8 additions & 18 deletions plugin/src/main/java/git4idea/GitUserRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@
import consulo.annotation.component.ComponentScope;
import consulo.annotation.component.ServiceAPI;
import consulo.annotation.component.ServiceImpl;
import consulo.application.ApplicationManager;
import consulo.disposer.Disposable;
import consulo.application.Application;
import consulo.disposer.Disposable;
import consulo.logging.Logger;
import consulo.project.Project;
import consulo.util.collection.ContainerUtil;
import consulo.util.lang.StringUtil;
import consulo.util.lang.function.Condition;
import consulo.versionControlSystem.ProjectLevelVcsManager;
import consulo.versionControlSystem.VcsException;
import consulo.versionControlSystem.VcsListener;
import consulo.versionControlSystem.log.VcsLogObjectsFactory;
import consulo.versionControlSystem.log.VcsUser;
import consulo.virtualFileSystem.VirtualFile;
import git4idea.config.GitConfigUtil;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.util.Collection;
import java.util.Map;

Expand Down Expand Up @@ -113,22 +111,14 @@ public void directoryMappingChanged() {
if (vcs == null) {
return;
}
final VirtualFile[] roots = myVcsManager.getRootsUnderVcs(vcs);
final Collection<VirtualFile> rootsToCheck = ContainerUtil.filter(roots, new Condition<VirtualFile>() {
@Override
public boolean value(VirtualFile root) {
return getUser(root) == null;
}
});
VirtualFile[] roots = myVcsManager.getRootsUnderVcs(vcs);
Collection<VirtualFile> rootsToCheck = ContainerUtil.filter(roots, root -> getUser(root) == null);
if (!rootsToCheck.isEmpty()) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
for (VirtualFile root : rootsToCheck) {
getOrReadUser(root);
}
Application.get().executeOnPooledThread((Runnable) () -> {
for (VirtualFile root : rootsToCheck) {
getOrReadUser(root);
}
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import git4idea.GitUtil;
import git4idea.history.GitHistoryUtils;
import git4idea.history.browser.SHAHash;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import java.util.*;

public class GitOutgoingChangesProvider implements VcsOutgoingChangesProvider<CommittedChangeList> {
Expand All @@ -47,74 +47,79 @@ public GitOutgoingChangesProvider(Project project) {
myProject = project;
}

public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote)
@Override
public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(VirtualFile vcsRoot, boolean findRemote)
throws VcsException {
LOG.debug("getOutgoingChanges root: " + vcsRoot.getPath());
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, findRemote);
GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, findRemote);
if (searcher.getLocal() == null || searcher.getRemote() == null) {
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, Collections.<CommittedChangeList>emptyList());
return new Pair<>(null, Collections.<CommittedChangeList>emptyList());
}
final GitRevisionNumber base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
GitRevisionNumber base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
if (base == null) {
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, Collections.<CommittedChangeList>emptyList());
return new Pair<>(null, Collections.<CommittedChangeList>emptyList());
}
final List<GitCommittedChangeList> lists =
List<GitCommittedChangeList> lists =
GitUtil.getLocalCommittedChanges(myProject, vcsRoot, handler -> handler.addParameters(base.asString() + "..HEAD"));
return new Pair<>(base, ObjectsConvertor.convert(lists, o -> o));
}

@Nullable
public VcsRevisionNumber getMergeBaseNumber(final VirtualFile anyFileUnderRoot) throws VcsException {
@Override
public VcsRevisionNumber getMergeBaseNumber(VirtualFile anyFileUnderRoot) throws VcsException {
LOG.debug("getMergeBaseNumber parameter: " + anyFileUnderRoot.getPath());
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
final VirtualFile root = vcsManager.getVcsRootFor(anyFileUnderRoot);
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
VirtualFile root = vcsManager.getVcsRootFor(anyFileUnderRoot);
if (root == null) {
LOG.info("VCS root not found");
return null;
}

final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, root, true);
GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, root, true);
if (searcher.getLocal() == null || searcher.getRemote() == null) {
LOG.info("local or remote not found");
return null;
}
final GitRevisionNumber base = getMergeBase(myProject, root, searcher.getLocal(), searcher.getRemote());
GitRevisionNumber base = getMergeBase(myProject, root, searcher.getLocal(), searcher.getRemote());
LOG.debug("found base: " + ((base == null) ? null : base.asString()));
return base;
}

public Collection<Change> filterLocalChangesBasedOnLocalCommits(final Collection<Change> localChanges,
final VirtualFile vcsRoot) throws VcsException {
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, true);
@Override
public Collection<Change> filterLocalChangesBasedOnLocalCommits(Collection<Change> localChanges, VirtualFile vcsRoot)
throws VcsException {
GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, true);
if (searcher.getLocal() == null || searcher.getRemote() == null) {
return new ArrayList<Change>(localChanges); // no information, better strict approach (see getOutgoingChanges() code)
return new ArrayList<>(localChanges); // no information, better strict approach (see getOutgoingChanges() code)
}
final GitRevisionNumber base;
GitRevisionNumber base;
try {
base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
}
catch (VcsException e) {
LOG.info(e);
return new ArrayList<Change>(localChanges);
return new ArrayList<>(localChanges);
}
if (base == null) {
return new ArrayList<Change>(localChanges); // no information, better strict approach (see getOutgoingChanges() code)
return new ArrayList<>(localChanges); // no information, better strict approach (see getOutgoingChanges() code)
}
final List<Pair<SHAHash, Date>> hashes = GitHistoryUtils.onlyHashesHistory(myProject,
VcsContextFactory.getInstance().createFilePathOn(vcsRoot),
vcsRoot,
(base.asString() + "..HEAD"));
List<Pair<SHAHash, Date>> hashes = GitHistoryUtils.onlyHashesHistory(
myProject,
VcsContextFactory.getInstance().createFilePathOn(vcsRoot),
vcsRoot,
(base.asString() + "..HEAD")
);

if (hashes.isEmpty()) return Collections.emptyList(); // no local commits
final String first = hashes.get(0).getFirst().getValue(); // optimization
final Set<String> localHashes = new HashSet<String>();
String first = hashes.get(0).getFirst().getValue(); // optimization
Set<String> localHashes = new HashSet<>();
for (Pair<SHAHash, Date> hash : hashes) {
localHashes.add(hash.getFirst().getValue());
}
final Collection<Change> result = new ArrayList<Change>();
Collection<Change> result = new ArrayList<>();
for (Change change : localChanges) {
if (change.getBeforeRevision() != null) {
final String changeBeforeRevision = change.getBeforeRevision().getRevisionNumber().asString().trim();
String changeBeforeRevision = change.getBeforeRevision().getRevisionNumber().asString().trim();
if (first.equals(changeBeforeRevision) || localHashes.contains(changeBeforeRevision)) {
result.add(change);
}
Expand All @@ -124,6 +129,7 @@ public Collection<Change> filterLocalChangesBasedOnLocalCommits(final Collection
}

@Nullable
@Override
public Date getRevisionDate(VcsRevisionNumber revision, FilePath file) {
if (VcsRevisionNumber.NULL.equals(revision)) return null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package git4idea.changes;

import consulo.versionControlSystem.RepositoryLocation;
Expand All @@ -30,6 +29,7 @@ public GitRepositoryLocation(String url, File root) {
myRoot = root;
}

@Override
public String toPresentableString() {
return myUrl;
}
Expand All @@ -39,6 +39,7 @@ public String toString() {
return toPresentableString();
}

@Override
public String getKey() {
return myUrl;
}
Expand Down
16 changes: 9 additions & 7 deletions plugin/src/main/java/git4idea/commands/GitLineHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import consulo.util.lang.StringUtil;
import consulo.versionControlSystem.util.LineHandlerHelper;
import consulo.virtualFileSystem.VirtualFile;

import jakarta.annotation.Nonnull;

import java.io.File;
import java.util.Iterator;

Expand Down Expand Up @@ -63,14 +63,15 @@ public GitLineHandler(@Nonnull Project project, @Nonnull File directory, @Nonnul
* @param vcsRoot a process directory
* @param command a command to execute
*/
public GitLineHandler(@Nonnull final Project project, @Nonnull final VirtualFile vcsRoot, @Nonnull final GitCommand command) {
public GitLineHandler(@Nonnull Project project, @Nonnull VirtualFile vcsRoot, @Nonnull GitCommand command) {
super(project, vcsRoot, command);
}

/**
* {@inheritDoc}
*/
protected void processTerminated(final int exitCode) {
@Override
protected void processTerminated(int exitCode) {
// force newline
if (myStdoutLine.length() != 0) {
onTextAvailable("\n\r", ProcessOutputTypes.STDOUT);
Expand All @@ -94,7 +95,8 @@ public void addLineListener(GitLineHandlerListener listener) {
/**
* {@inheritDoc}
*/
protected void onTextAvailable(final String text, final Key outputType) {
@Override
protected void onTextAvailable(String text, Key outputType) {
Iterator<String> lines = LineHandlerHelper.splitText(text).iterator();
if (ProcessOutputTypes.STDOUT == outputType) {
notifyLines(outputType, lines, myStdoutLine);
Expand All @@ -111,13 +113,13 @@ else if (ProcessOutputTypes.STDERR == outputType) {
* @param lines line iterator
* @param lineBuilder a line builder
*/
private void notifyLines(final Key outputType, final Iterator<String> lines, final StringBuilder lineBuilder) {
private void notifyLines(Key outputType, Iterator<String> lines, StringBuilder lineBuilder) {
if (!lines.hasNext()) return;
if (lineBuilder.length() > 0) {
lineBuilder.append(lines.next());
if (lines.hasNext()) {
// line is complete
final String line = lineBuilder.toString();
String line = lineBuilder.toString();
notifyLine(line, outputType);
lineBuilder.setLength(0);
}
Expand Down Expand Up @@ -146,7 +148,7 @@ private void notifyLines(final Key outputType, final Iterator<String> lines, fin
* @param line a line to notify
* @param outputType output type
*/
private void notifyLine(final String line, final Key outputType) {
private void notifyLine(String line, Key outputType) {
String trimmed = LineHandlerHelper.trimLineSeparator(line);
// if line ends with return, then it is a progress line, ignore it
if (myVcs != null && !"\r".equals(line.substring(trimmed.length()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ public class GitLineHandlerAdapter implements GitLineHandlerListener {
/**
* {@inheritDoc}
*/
public void onLineAvailable(final String line, final Key outputType) {
@Override
public void onLineAvailable(String line, Key outputType) {
// do nothing
}

/**
* {@inheritDoc}
*/
public void processTerminated(final int exitCode) {
@Override
public void processTerminated(int exitCode) {
// do nothing
}

/**
* {@inheritDoc}
*/
public void startFailed(final Throwable exception) {
@Override
public void startFailed(Throwable exception) {
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface GitLineHandlerListener extends LineProcessEventListener
* @param line a line of the text
* @param outputType a type of output (one of constants from {@link ProcessOutputTypes})
*/
@Override
@SuppressWarnings({"UnusedParameters", "UnnecessaryFullyQualifiedName"})
void onLineAvailable(String line, Key outputType);
}
Loading
Loading