use of org.eclipse.egit.ui.internal.repository.tree.BranchHierarchyNode in project egit by eclipse.
the class AbstractBranchSelectionDialog method createRefNode.
private RefNode createRefNode(RepositoryTreeNode<?> root, Repository repository, Ref ref) {
IContentProvider cp = branchTree.getContentProvider();
if (cp instanceof RepositoriesViewContentProvider && ((RepositoriesViewContentProvider) cp).isHierarchical()) {
// Create intermediary BranchHierarchyNodes
String fullName = ref.getName();
int i = 0;
if (fullName.startsWith(Constants.R_HEADS)) {
i = Constants.R_HEADS.length();
} else if (fullName.startsWith(Constants.R_REMOTES)) {
i = Constants.R_REMOTES.length();
}
RepositoryTreeNode<?> top = root;
int l = fullName.length();
while (i < l) {
int j = fullName.indexOf('/', i);
if (j > i) {
top = new BranchHierarchyNode(top, repository, new Path(fullName.substring(0, j)));
i = j + 1;
} else {
break;
}
}
return new RefNode(top, repository, ref);
} else {
return new RefNode(root, repository, ref);
}
}
use of org.eclipse.egit.ui.internal.repository.tree.BranchHierarchyNode in project egit by eclipse.
the class RepositoriesViewContentProvider method getChildren.
@Override
public Object[] getChildren(Object parentElement) {
RepositoryTreeNode node = (RepositoryTreeNode) parentElement;
Repository repo = node.getRepository();
switch(node.getType()) {
case BRANCHES:
{
List<RepositoryTreeNode> nodes = new ArrayList<>();
nodes.add(new LocalNode(node, repo));
nodes.add(new RemoteTrackingNode(node, repo));
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 (Entry<String, Ref> refEntry : getRefs(repo, Constants.R_HEADS).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:
{
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 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();
}
case TAGS:
{
return getTagsChildren(node, repo);
}
case ADDITIONALREFS:
{
List<RepositoryTreeNode<Ref>> refs = new ArrayList<>();
try {
for (Entry<String, Ref> refEntry : getRefs(repo, RefDatabase.ALL).entrySet()) {
String name = refEntry.getKey();
if (!(name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_TAGS) || name.startsWith(Constants.R_REMOTES)))
refs.add(new AdditionalRefNode(node, repo, refEntry.getValue()));
}
for (Ref r : repo.getRefDatabase().getAdditionalRefs()) refs.add(new AdditionalRefNode(node, repo, r));
} catch (Exception e) {
return handleException(e, node);
}
return refs.toArray();
}
case REMOTES:
{
List<RepositoryTreeNode<String>> remotes = new ArrayList<>();
Repository rep = node.getRepository();
Set<String> configNames = rep.getConfig().getSubsections(RepositoriesView.REMOTE);
for (String configName : configNames) {
remotes.add(new RemoteNode(node, repo, configName));
}
return remotes.toArray();
}
case REPO:
{
List<RepositoryTreeNode<? extends Object>> nodeList = new ArrayList<>();
nodeList.add(new BranchesNode(node, repo));
nodeList.add(new TagsNode(node, repo));
nodeList.add(new AdditionalRefsNode(node, repo));
final boolean bare = repo.isBare();
if (!bare)
nodeList.add(new WorkingDirNode(node, repo));
nodeList.add(new RemotesNode(node, repo));
if (!bare && hasStashedCommits(repo))
nodeList.add(new StashNode(node, repo));
if (!bare && hasConfiguredSubmodules(repo))
nodeList.add(new SubmodulesNode(node, repo));
return nodeList.toArray();
}
case WORKINGDIR:
{
List<RepositoryTreeNode<File>> children = new ArrayList<>();
if (node.getRepository().isBare())
return children.toArray();
File workingDir = repo.getWorkTree();
if (!workingDir.exists())
return children.toArray();
File[] childFiles = workingDir.listFiles();
Arrays.sort(childFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
if (o1.isDirectory()) {
if (o2.isDirectory()) {
return o1.compareTo(o2);
}
return -1;
} else if (o2.isDirectory()) {
return 1;
}
return o1.compareTo(o2);
}
});
for (File file : childFiles) {
if (file.isDirectory()) {
children.add(new FolderNode(node, repo, file));
} else {
children.add(new FileNode(node, repo, file));
}
}
return children.toArray();
}
case FOLDER:
{
List<RepositoryTreeNode<File>> children = new ArrayList<>();
File parent = ((File) node.getObject());
File[] childFiles = parent.listFiles();
if (childFiles == null)
return children.toArray();
Arrays.sort(childFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
if (o1.isDirectory()) {
if (o2.isDirectory()) {
return o1.compareTo(o2);
}
return -1;
} else if (o2.isDirectory()) {
return 1;
}
return o1.compareTo(o2);
}
});
for (File file : childFiles) {
if (file.isDirectory()) {
children.add(new FolderNode(node, repo, file));
} else {
children.add(new FileNode(node, repo, file));
}
}
return children.toArray();
}
case REMOTE:
{
List<RepositoryTreeNode<String>> children = new ArrayList<>();
String remoteName = (String) node.getObject();
RemoteConfig rc;
try {
rc = new RemoteConfig(node.getRepository().getConfig(), remoteName);
} catch (URISyntaxException e) {
return handleException(e, node);
}
if (!rc.getURIs().isEmpty())
children.add(new FetchNode(node, node.getRepository(), rc.getURIs().get(0).toPrivateString()));
int uriCount = rc.getPushURIs().size();
if (uriCount == 0 && !rc.getURIs().isEmpty())
uriCount++;
// at least one push specification
if (uriCount > 0) {
URIish firstUri;
if (!rc.getPushURIs().isEmpty())
firstUri = rc.getPushURIs().get(0);
else
firstUri = rc.getURIs().get(0);
if (uriCount == 1)
children.add(new PushNode(node, node.getRepository(), firstUri.toPrivateString()));
else
children.add(new PushNode(node, node.getRepository(), // $NON-NLS-1$
firstUri.toPrivateString() + "..."));
}
return children.toArray();
}
case SUBMODULES:
List<RepositoryNode> children = new ArrayList<>();
try {
SubmoduleWalk walk = SubmoduleWalk.forIndex(node.getRepository());
while (walk.next()) {
Repository subRepo = walk.getRepository();
if (subRepo != null) {
Repository cachedRepo = null;
try {
cachedRepo = repositoryCache.lookupRepository(subRepo.getDirectory());
} finally {
subRepo.close();
}
if (cachedRepo != null)
children.add(new RepositoryNode(node, cachedRepo));
}
}
} catch (IOException e) {
handleException(e, node);
}
return children.toArray();
case STASH:
List<StashedCommitNode> stashNodes = new ArrayList<>();
int index = 0;
try {
for (RevCommit commit : Git.wrap(repo).stashList().call()) stashNodes.add(new StashedCommitNode(node, repo, index++, commit));
} catch (Exception e) {
handleException(e, node);
}
return stashNodes.toArray();
case FILE:
// fall through
case REF:
// fall through
case PUSH:
// fall through
case TAG:
// fall through
case FETCH:
// fall through
case ERROR:
// fall through
case STASHED_COMMIT:
// fall through
case ADDITIONALREF:
return null;
}
return null;
}
Aggregations