Skip to content
Draft
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
54 changes: 24 additions & 30 deletions ide/git/src/org/netbeans/modules/git/HistoryProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*/
public class HistoryProvider implements VCSHistoryProvider {

private final List<VCSHistoryProvider.HistoryChangeListener> listeners = new LinkedList<VCSHistoryProvider.HistoryChangeListener>();
private final List<VCSHistoryProvider.HistoryChangeListener> listeners = new LinkedList<>();
private static final Logger LOG = Logger.getLogger(HistoryProvider.class.getName());
private Action[] actions;

Expand All @@ -80,9 +80,9 @@ public synchronized HistoryEntry[] getHistory(File[] files, Date fromDate) {
return null;
}

List<HistoryEntry> ret = new LinkedList<HistoryEntry>();
Map<String, Set<File>> rev2FileMap = new HashMap<String, Set<File>>();
Map<String, GitRevisionInfo> rev2LMMap = new LinkedHashMap<String, GitRevisionInfo>();
List<HistoryEntry> ret = new LinkedList<>();
Map<String, Set<File>> rev2FileMap = new HashMap<>();
Map<String, GitRevisionInfo> rev2LMMap = new LinkedHashMap<>();

File repositoryRoot = repositories.iterator().next();
for (File file : files) {
Expand All @@ -96,12 +96,8 @@ public synchronized HistoryEntry[] getHistory(File[] files, Date fromDate) {
for (GitRevisionInfo h : history) {
String r = h.getRevision();
rev2LMMap.put(r, h);
Set<File> s = rev2FileMap.get(r);
if(s == null) {
s = new HashSet<File>();
rev2FileMap.put(r, s);
}
s.add(file);
rev2FileMap.computeIfAbsent(r, k -> new HashSet<File>())
.add(file);
}
} catch (GitException ex) {
LOG.log(Level.INFO, null, ex);
Expand All @@ -110,12 +106,12 @@ public synchronized HistoryEntry[] getHistory(File[] files, Date fromDate) {

for (GitRevisionInfo h : rev2LMMap.values()) {
Set<File> s = rev2FileMap.get(h.getRevision());
File[] involvedFiles = s.toArray(new File[0]);
File[] involvedFiles = s.toArray(File[]::new);

HistoryEntry e = createHistoryEntry(h, involvedFiles, repositoryRoot);
ret.add(e);
}
return ret.toArray(new HistoryEntry[0]);
return ret.toArray(HistoryEntry[]::new);
}

private HistoryEntry createHistoryEntry (GitRevisionInfo h, File[] involvedFiles, File repositoryRoot) {
Expand Down Expand Up @@ -150,20 +146,17 @@ public Action createShowHistoryAction(File[] files) {
public void fireHistoryChange (final File[] files) {
final HistoryChangeListener[] la;
synchronized(listeners) {
la = listeners.toArray(new HistoryChangeListener[0]);
la = listeners.toArray(HistoryChangeListener[]::new);
}
Git.getInstance().getRequestProcessor().post(new Runnable() {
@Override
public void run() {
for (HistoryChangeListener l : la) {
l.fireHistoryChanged(new HistoryEvent(HistoryProvider.this, files));
}
Git.getInstance().getRequestProcessor().post(() -> {
for (HistoryChangeListener l : la) {
l.fireHistoryChanged(new HistoryEvent(HistoryProvider.this, files));
}
});
}

private class RevisionProviderImpl implements RevisionProvider {
private String revision;
private final String revision;

public RevisionProviderImpl(String revision) {
this.revision = revision;
Expand Down Expand Up @@ -230,7 +223,7 @@ private void openHistory(File[] files) {
if(repositories == null || repositories.isEmpty()) {
return;
}
List<Node> nodes = new ArrayList<Node>(files.length);
List<Node> nodes = new ArrayList<>(files.length);
for (File f : files) {
nodes.add(new AbstractNode(Children.LEAF, Lookups.fixed(f)) {
@Override
Expand All @@ -239,7 +232,7 @@ public String getDisplayName() {
}
});
}
SearchHistoryAction.openSearch(repositories.iterator().next(), files, Utils.getContextDisplayName(VCSContext.forNodes(nodes.toArray(new Node[0]))));
SearchHistoryAction.openSearch(repositories.iterator().next(), files, Utils.getContextDisplayName(VCSContext.forNodes(nodes.toArray(Node[]::new))));
}

}
Expand Down Expand Up @@ -267,8 +260,9 @@ protected void perform(HistoryEntry entry, Set<File> files) {
@Override
protected void perform(final HistoryEntry entry, final Set<File> files) {
File root = Git.getInstance().getRepositoryRoot(files.iterator().next());
SystemAction.get(RevertChangesAction.class).revertFiles(root, files.toArray(new File[0]),
getRevisionShort(), Bundle.HistoryProvider_action_RevertTo_progress());
SystemAction.get(RevertChangesAction.class).revertFiles(
root, files.toArray(File[]::new), getRevisionShort(), Bundle.HistoryProvider_action_RevertTo_progress()
);
}
@Override
protected boolean isMultipleHistory() {
Expand Down Expand Up @@ -315,7 +309,7 @@ protected void perform () {
}

private static Set<File> getRepositoryRoots(File... files) {
Set<File> repositories = GitUtils.getRepositoryRoots(new HashSet<File>(Arrays.asList(files)));
Set<File> repositories = GitUtils.getRepositoryRoots(new HashSet<>(Arrays.asList(files)));
if (repositories.size() != 1) {
LOG.log(Level.WARNING, "History requested for {0} repositories", repositories.size()); // NOI18N
return null;
Expand All @@ -324,16 +318,16 @@ private static Set<File> getRepositoryRoots(File... files) {
}

private class ParentProviderImpl implements ParentProvider {
private GitRevisionInfo info;
private File[] files;
private File repository;
private Map<File, HistoryEntry> commonAncestors;
private final GitRevisionInfo info;
private final File[] files;
private final File repository;
private final Map<File, HistoryEntry> commonAncestors;

public ParentProviderImpl (GitRevisionInfo info, File[] files, File repository) {
this.info = info;
this.files = files;
this.repository = repository;
this.commonAncestors = new HashMap<File, HistoryEntry>(files.length);
this.commonAncestors = new HashMap<>((int) Math.ceil(files.length / 0.75));
}

@Override
Expand Down
13 changes: 2 additions & 11 deletions ide/libs.git/src/org/netbeans/libs/git/GitRevisionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
Expand All @@ -53,7 +51,6 @@ public final class GitRevisionInfo {
private final Repository repository;
private final Map<String, GitBranch> branches;
private GitFileInfo[] modifiedFiles;
private static final Logger LOG = Logger.getLogger(GitRevisionInfo.class.getName());
private String shortMessage;

GitRevisionInfo (RevCommit commit, Repository repository) {
Expand Down Expand Up @@ -146,7 +143,7 @@ public java.util.Map<java.io.File, GitFileInfo> getModifiedFiles () throws GitEx
listFiles();
}
}
Map<File, GitFileInfo> files = new HashMap<>(modifiedFiles.length);
Map<File, GitFileInfo> files = new HashMap<>((int) Math.ceil(modifiedFiles.length / 0.75));
for (GitFileInfo info : modifiedFiles) {
files.put(info.getFile(), info);
}
Expand Down Expand Up @@ -202,17 +199,11 @@ private void listFiles() throws GitException {
result.add(new GitFileInfo(new File(repository.getWorkTree(), walk.getPathString()), walk.getPathString(), GitFileInfo.Status.ADDED, null, null));
}
}
this.modifiedFiles = result.toArray(new GitFileInfo[0]);
this.modifiedFiles = result.toArray(GitFileInfo[]::new);
} catch (IOException ex) {
throw new GitException(ex);
}
}

private static Map<String, GitBranch> buildBranches (RevCommit commit, Map<String, GitBranch> branches) {
Map<String, GitBranch> retval = new LinkedHashMap<>(branches.size());

return retval;
}

/**
* Provides information about what happened to a file between two different commits.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ public interface VCSHistoryProvider {
* </table>
*/
public static final class HistoryEntry {
private Date dateTime;

private final Date dateTime;
private String message;
private VCSFileProxy[] files;
private String usernameShort;
private String username;
private String revisionShort;
private String revision;
private Action[] actions;
private RevisionProvider revisionProvider;
private MessageEditProvider mep;
private ParentProvider parentProvider;
private final VCSFileProxy[] files;
private final String usernameShort;
private final String username;
private final String revisionShort;
private final String revision;
private final Action[] actions;
private final RevisionProvider revisionProvider;
private final MessageEditProvider mep;
private final ParentProvider parentProvider;

/**
* Creates a new HistoryEntry instance.
Expand All @@ -107,8 +108,9 @@ public static final class HistoryEntry {
* @param revisionShort short description of the versioning revision
* @param actions actions which might be called in regard with this revision
* @param revisionProvider a RevisionProvider to get access to a files contents in this revision
*
* @since 1.26
* @param messageEditProvider a MessageEditProvider to change a revisions message
* @param parentProvider a ParentProvider to provide this entries parent entry. Not necessary for VCS
* where a revisions parent always is the time nearest previous revision.
*/
public HistoryEntry(
VCSFileProxy[] files,
Expand All @@ -119,7 +121,9 @@ public HistoryEntry(
String revision,
String revisionShort,
Action[] actions,
RevisionProvider revisionProvider)
RevisionProvider revisionProvider,
MessageEditProvider messageEditProvider,
ParentProvider parentProvider)
{
assert files != null && files.length > 0 : "a history entry must have at least one file"; // NOI18N
assert revision != null && revision != null : "a history entry must have a revision"; // NOI18N
Expand All @@ -135,6 +139,8 @@ public HistoryEntry(
this.revisionShort = revisionShort;
this.actions = actions;
this.revisionProvider = revisionProvider;
this.mep = messageEditProvider;
this.parentProvider = parentProvider;
}

/**
Expand Down Expand Up @@ -163,8 +169,7 @@ public HistoryEntry(
RevisionProvider revisionProvider,
MessageEditProvider messageEditProvider)
{
this(files, dateTime, message, username, usernameShort, revision, revisionShort, actions, revisionProvider);
this.mep = messageEditProvider;
this(files, dateTime, message, username, usernameShort, revision, revisionShort, actions, revisionProvider, messageEditProvider, null);
}

/**
Expand All @@ -179,10 +184,8 @@ public HistoryEntry(
* @param revisionShort short description of the versioning revision
* @param actions actions which might be called in regard with this revision
* @param revisionProvider a RevisionProvider to get access to a files contents in this revision
* @param messageEditProvider a MessageEditProvider to change a revisions message
* @param parentProvider a ParentProvider to provide this entries parent entry. Not necessary for VCS
* where a revisions parent always is the time nearest previous revision.
*
*
* @since 1.26
*/
public HistoryEntry(
VCSFileProxy[] files,
Expand All @@ -193,12 +196,9 @@ public HistoryEntry(
String revision,
String revisionShort,
Action[] actions,
RevisionProvider revisionProvider,
MessageEditProvider messageEditProvider,
ParentProvider parentProvider)
RevisionProvider revisionProvider)
{
this(files, dateTime, message, username, usernameShort, revision, revisionShort, actions, revisionProvider, messageEditProvider);
this.parentProvider = parentProvider;
this(files, dateTime, message, username, usernameShort, revision, revisionShort, actions, revisionProvider, null, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ public RequestProcessor getRequestProcessor() {
*/
public List<VCSHyperlinkProvider> getHyperlinkProviders() {
if (hpResult == null) {
hpResult = (Lookup.Result<? extends VCSHyperlinkProvider>) Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class);
hpResult = Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class);
}
if (hpResult == null) {
return Collections.emptyList();
}
Collection<? extends VCSHyperlinkProvider> providersCol = hpResult.allInstances();
List<VCSHyperlinkProvider> providersList = new ArrayList<VCSHyperlinkProvider>(providersCol.size());
providersList.addAll(providersCol);
return Collections.unmodifiableList(providersList);
return Collections.unmodifiableList(new ArrayList<>(providersCol));
}

VersioningSystem getLocalHistory(FileObject fo) {
Expand All @@ -94,14 +92,14 @@ static VCSFileProxy[] toProxies(FileObject[] files) {
if(files == null) {
return new VCSFileProxy[0];
}
List<VCSFileProxy> l = new ArrayList<VCSFileProxy>(files.length);
List<VCSFileProxy> l = new ArrayList<>(files.length);
for (FileObject f : files) {
VCSFileProxy proxy = VCSFileProxy.createFileProxy(f);
if(proxy != null) {
l.add(proxy);
}
}
return l.toArray(new VCSFileProxy[0]);
return l.toArray(VCSFileProxy[]::new);
}

}
Loading
Loading