diff options
author | Thomas Wolf | 2018-05-26 07:54:50 +0000 |
---|---|---|
committer | Thomas Wolf | 2018-05-28 13:00:46 +0000 |
commit | 636918dd9989392d7e7a287d30c387fc03069bcc (patch) | |
tree | 2da2a0b328c3d1e140b26d00ca13bc7b4508deb3 /org.eclipse.egit.ui/src | |
parent | c53d24f0aaf1589ae83a68c9d52fe7b727d7641f (diff) | |
download | egit-636918dd9989392d7e7a287d30c387fc03069bcc.tar.gz egit-636918dd9989392d7e7a287d30c387fc03069bcc.tar.xz egit-636918dd9989392d7e7a287d30c387fc03069bcc.zip |
Remove duplicate code in RepositoriesViewContentProvider
Change-Id: I0bf64bafe0569125cc3f5a47dc0ecf44d9230d65
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui/src')
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java | 130 |
1 files changed, 44 insertions, 86 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java index 287aaea423..e7d40e1516 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java @@ -26,7 +26,6 @@ import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -139,13 +138,12 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider, .getRepositoryUtil(); if (inputElement instanceof Collection) { - for (Iterator it = ((Collection) inputElement).iterator(); it - .hasNext();) { - Object next = it.next(); - if (next instanceof RepositoryTreeNode) + for (Object next : ((Collection) inputElement)) { + if (next instanceof RepositoryTreeNode) { nodes.add((RepositoryTreeNode) next); - else if (next instanceof String) + } else if (next instanceof String) { directories.add((String) next); + } } } else if (inputElement instanceof IWorkspaceRoot) { directories.addAll(repositoryUtil.getConfiguredRepositories()); @@ -197,87 +195,15 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider, return nodes.toArray(); } - case LOCAL: { - if (branchHierarchyMode) { - BranchHierarchyNode hierNode = new BranchHierarchyNode(node, - repo, new Path(Constants.R_HEADS)); - List<RepositoryTreeNode> children = new ArrayList<>(); - try { - for (IPath path : hierNode.getChildPaths()) { - children.add(new BranchHierarchyNode(node, node - .getRepository(), path)); - } - for (Ref ref : hierNode.getChildRefs()) { - children.add(new RefNode(node, node.getRepository(), - ref)); - } - } catch (Exception e) { - return handleException(e, node); - } - return children.toArray(); - } else { - List<RepositoryTreeNode<Ref>> refs = new ArrayList<>(); - try { - for (Ref ref : getRefs(repo, Constants.R_HEADS).values()) { - if (!ref.isSymbolic()) - refs.add(new RefNode(node, repo, ref)); - } - } catch (Exception e) { - return handleException(e, node); - } - return refs.toArray(); - } - } + case LOCAL: + return getBranchChildren(node, repo, Constants.R_HEADS); - case REMOTETRACKING: { - if (branchHierarchyMode) { - BranchHierarchyNode hierNode = new BranchHierarchyNode(node, - repo, new Path(Constants.R_REMOTES)); - List<RepositoryTreeNode> children = new ArrayList<>(); - try { - for (IPath path : hierNode.getChildPaths()) { - children.add(new BranchHierarchyNode(node, node - .getRepository(), path)); - } - for (Ref ref : hierNode.getChildRefs()) { - children.add(new RefNode(node, node.getRepository(), - ref)); - } - } catch (Exception e) { - return handleException(e, node); - } - return children.toArray(); - } else { - List<RepositoryTreeNode<Ref>> refs = new ArrayList<>(); - try { - for (Entry<String, Ref> refEntry : getRefs(repo, Constants.R_REMOTES).entrySet()) { - if (!refEntry.getValue().isSymbolic()) - refs.add(new RefNode(node, repo, refEntry - .getValue())); - } - } catch (Exception e) { - return handleException(e, node); - } - - return refs.toArray(); - } - } + case REMOTETRACKING: + return getBranchChildren(node, repo, Constants.R_REMOTES); case BRANCHHIERARCHY: { - BranchHierarchyNode hierNode = (BranchHierarchyNode) node; - List<RepositoryTreeNode> children = new ArrayList<>(); - try { - for (IPath path : hierNode.getChildPaths()) { - children.add(new BranchHierarchyNode(node, node - .getRepository(), path)); - } - for (Ref ref : hierNode.getChildRefs()) { - children.add(new RefNode(node, node.getRepository(), ref)); - } - } catch (IOException e) { - return handleException(e, node); - } - return children.toArray(); + return getBranchHierarchyChildren((BranchHierarchyNode) node, repo, + node); } case TAGS: @@ -438,6 +364,39 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider, } + private Object[] getBranchChildren(RepositoryTreeNode node, Repository repo, + String prefix) { + if (branchHierarchyMode) { + return getBranchHierarchyChildren( + new BranchHierarchyNode(node, repo, new Path(prefix)), repo, + node); + } else { + try { + return getRefs(repo, prefix).values().stream() + .filter(ref -> !ref.isSymbolic()) + .map(ref -> new RefNode(node, repo, ref)).toArray(); + } catch (IOException e) { + return handleException(e, node); + } + } + } + + private Object[] getBranchHierarchyChildren(BranchHierarchyNode hierNode, + Repository repo, RepositoryTreeNode parentNode) { + try { + List<RepositoryTreeNode> children = new ArrayList<>(); + for (IPath path : hierNode.getChildPaths()) { + children.add(new BranchHierarchyNode(parentNode, repo, path)); + } + for (Ref ref : hierNode.getChildRefs()) { + children.add(new RefNode(parentNode, repo, ref)); + } + return children.toArray(); + } catch (IOException e) { + return handleException(e, parentNode); + } + } + private Object[] getDirectoryChildren(RepositoryTreeNode parentNode, File parent) { Repository repo = parentNode.getRepository(); @@ -482,8 +441,7 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider, try (RevWalk walk = new RevWalk(repo)) { walk.setRetainBody(true); - Map<String, Ref> tagRefs = getRefs(repo, Constants.R_TAGS); - for (Ref tagRef : tagRefs.values()) { + for (Ref tagRef : getRefs(repo, Constants.R_TAGS).values()) { ObjectId objectId = tagRef.getLeaf().getObjectId(); RevObject revObject = walk.parseAny(objectId); RevObject peeledObject = walk.peel(revObject); |