diff options
author | Andre Bossert | 2016-02-24 11:31:59 +0000 |
---|---|---|
committer | Thomas Wolf | 2016-03-21 18:45:38 +0000 |
commit | 1010e77ce569f3689f1fec89c2b0df4551982124 (patch) | |
tree | bad5112bfc760c15d1ba9ab2daafcdf2ad6346de | |
parent | 3705869f0523ac4b1861116159749b4dbd1b879b (diff) | |
download | egit-1010e77ce569f3689f1fec89c2b0df4551982124.tar.gz egit-1010e77ce569f3689f1fec89c2b0df4551982124.tar.xz egit-1010e77ce569f3689f1fec89c2b0df4551982124.zip |
Extended support for nested repositories in project.
Refactoring of RepositoryMapping.getMapping(IPath) to make it support
submodules and inner repositories.
* RepositoryMapping
* changed getMapping(IPath): searches in all project mappings
* added getMappings(IProject): returns all mappings for a project
* introduced getProjectData(): because needed in other methods
multiple times
Change-Id: Ie9aa6bd9df812c515e9f4967e1fb06c17e7cf636
Signed-off-by: Andre Bossert <anb0s@anbos.de>
-rw-r--r-- | org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java | 14 | ||||
-rw-r--r-- | org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java | 93 |
2 files changed, 73 insertions, 34 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java index 5485f91d6b..37ff200b62 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java @@ -3,14 +3,13 @@ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2008, Google Inc. * Copyright (C) 2015, IBM Corporation (Dani Megert <daniel_megert@ch.ibm.com>) + * Copyright (C) 2016, Thomas Wolf <thomas.wolf@paranor.ch> + * Copyright (C) 2016, Andre Bossert <anb0s@anbos.de> * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andre Bossert <anb0s@anbos.de> - Cleaning up the DecoratableResourceAdapter *******************************************************************************/ package org.eclipse.egit.core.project; @@ -456,6 +455,15 @@ public class GitProjectData { } /** + * Get repository mappings + * + * @return the repository mappings for a project + */ + public final Map<IPath, RepositoryMapping> getRepositoryMappings() { + return mappings; + } + + /** * Hide our private parts from the navigators other browsers. * * @throws CoreException diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java index 57f9a2a2eb..15501e211f 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java @@ -13,12 +13,17 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andre Bossert <anb0s@anbos.de> - Extended support for nested repositories in project. *******************************************************************************/ package org.eclipse.egit.core.project; import static org.eclipse.egit.core.internal.util.ResourceUtil.isNonWorkspace; import java.io.File; +import java.util.Collections; +import java.util.Map; import java.util.Properties; import org.eclipse.core.resources.IContainer; @@ -69,8 +74,8 @@ public class RepositoryMapping { * @param initialKey * property key to use to read the git directory */ - public RepositoryMapping(@NonNull final Properties p, - @NonNull final String initialKey) { + public RepositoryMapping(final @NonNull Properties p, + final @NonNull String initialKey) { final int dot = initialKey.lastIndexOf('.'); containerPathString = initialKey.substring(0, dot); @@ -248,7 +253,7 @@ public class RepositoryMapping { * determined. */ @Nullable - public String getRepoRelativePath(@NonNull final IResource rsrc) { + public String getRepoRelativePath(final @NonNull IResource rsrc) { IPath location = rsrc.getLocation(); if (location == null) return null; @@ -295,7 +300,8 @@ public class RepositoryMapping { * GitProvider. */ @Nullable - public static RepositoryMapping getMapping(@NonNull final IResource resource) { + public static RepositoryMapping getMapping( + final @NonNull IResource resource) { if (isNonWorkspace(resource)) { return null; } @@ -318,7 +324,8 @@ public class RepositoryMapping { * GitProvider. */ @Nullable - public static RepositoryMapping getMapping(@Nullable final IProject project) { + public static RepositoryMapping getMapping( + final @Nullable IProject project) { if (project == null) { return null; } @@ -326,17 +333,16 @@ public class RepositoryMapping { } /** - * Get the repository mapping for a project. + * Get the git project data for a project. * - * @param resource - * to find the mapping for - * @return the RepositoryMapping for this project, or null for non + * @param project + * to find the data for + * @return the git project data for this project, or null for non * GitProvider. */ @Nullable - private static RepositoryMapping findMapping(@NonNull - final IResource resource) { - final IProject project = resource.getProject(); + private static GitProjectData getProjectData( + final @Nullable IProject project) { if (project == null || isNonWorkspace(project)) { return null; } @@ -352,6 +358,21 @@ public class RepositoryMapping { } else { data = rp.getData(); } + return data; + } + + /** + * Get the repository mapping for a resource. + * + * @param resource + * to find the mapping for + * @return the RepositoryMapping for this resource, or null if resource is + * not associated with Git managed project. + */ + @Nullable + private static RepositoryMapping findMapping( + final @NonNull IResource resource) { + GitProjectData data = getProjectData(resource.getProject()); if (data == null) { return null; } @@ -359,6 +380,23 @@ public class RepositoryMapping { } /** + * Get all repository mappings for a project. + * + * @param project + * @return all RepositoryMappings for this project, can be empty list for + * non GitProvider. + */ + @NonNull + private static Map<IPath, RepositoryMapping> getMappings( + final @Nullable IProject project) { + GitProjectData data = getProjectData(project); + if (data == null) { + return Collections.emptyMap(); + } + return data.getRepositoryMappings(); + } + + /** * Get the repository mapping for a path if it exists. * * @param path @@ -368,34 +406,27 @@ public class RepositoryMapping { public static RepositoryMapping getMapping(@NonNull IPath path) { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot() .getProjects(); - IPath bestWorkingTree = null; RepositoryMapping bestMapping = null; - for (IProject project : projects) { if (isNonWorkspace(project)) { continue; } - RepositoryMapping mapping = getMapping(project); - if (mapping == null) { - continue; - } - - File workTree = mapping.getWorkTree(); - if (workTree == null) { - continue; - } - IPath workingTree = new Path(workTree.toString()); - if (workingTree.isPrefixOf(path)) { - if (bestWorkingTree == null - || workingTree.segmentCount() > bestWorkingTree - .segmentCount()) { - bestWorkingTree = workingTree; - bestMapping = mapping; + for (RepositoryMapping mapping : getMappings(project).values()) { + File workTree = mapping.getWorkTree(); + if (workTree == null) { + continue; + } + IPath workingTree = new Path(workTree.toString()); + if (workingTree.isPrefixOf(path)) { + if (bestWorkingTree == null || workingTree + .segmentCount() > bestWorkingTree.segmentCount()) { + bestWorkingTree = workingTree; + bestMapping = mapping; + } } } } - return bestMapping; } |