use of org.eclipse.egit.core.RepositoryCache in project egit by eclipse.
the class ResourceUtil method splitPathsByRepository.
/**
* The method splits the given paths by their repository. For each occurring
* repository a list is built containing the repository relative paths of
* the related resources.
* <p>
* When one of the passed paths corresponds to the working directory,
* <code>""</code> will be returned as part of the collection.
*
* @param paths
* @return a map containing a list of repository relative paths for each
* occurring repository
*/
public static Map<Repository, Collection<String>> splitPathsByRepository(Collection<IPath> paths) {
RepositoryCache repositoryCache = Activator.getDefault().getRepositoryCache();
Map<Repository, Collection<String>> result = new HashMap<Repository, Collection<String>>();
for (IPath path : paths) {
Repository repository = repositoryCache.getRepository(path);
if (repository != null) {
IPath repoPath = new Path(repository.getWorkTree().getAbsolutePath());
IPath repoRelativePath = path.makeRelativeTo(repoPath);
addPathToMap(repository, repoRelativePath.toString(), result);
}
}
return result;
}
use of org.eclipse.egit.core.RepositoryCache in project egit by eclipse.
the class RepositoryJobResultAction method run.
@Override
public final void run() {
Repository repo = null;
if (!repositoryGone) {
RepositoryCache repoCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
repo = repoCache.getRepository(repositoryDir);
if (repo == null && FileKey.isGitRepository(repositoryDir, FS.DETECTED)) {
// No longer in the Egit cache but still on disk
try {
repo = repoCache.lookupRepository(repositoryDir);
} catch (IOException e) {
// Ignore, repo remains null
}
}
repositoryGone = repo == null;
}
if (repositoryGone || repo == null) {
Activator.showError(MessageFormat.format(UIText.RepositoryJobResultAction_RepositoryGone, repositoryDir), null);
return;
}
showResult(repo);
}
use of org.eclipse.egit.core.RepositoryCache in project egit by eclipse.
the class RepositoryMenuUtil method getRepositoryActions.
/**
* Creates for each configured repository an {@link IAction} that will
* perform the given {@code action} when invoked.
*
* @param includeBare
* {@code true} if bare repositories should be included in the
* list, {@code false} otherwise
* @param currentRepoDir
* git directory of a repository that is to be marked as
* "current"; may be {@code null}.
* @param action
* to perform on the chosen repository
* @return the (possibly empty) list of actions
*/
public static Collection<IAction> getRepositoryActions(boolean includeBare, @Nullable File currentRepoDir, @NonNull Consumer<Repository> action) {
RepositoryUtil util = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
RepositoryCache cache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
Set<String> repositories = util.getRepositories();
Map<String, Set<File>> repos = new HashMap<>();
for (String repo : repositories) {
File gitDir = new File(repo);
String name = null;
try {
Repository r = cache.lookupRepository(gitDir);
if (!includeBare && r.isBare()) {
continue;
}
name = util.getRepositoryName(r);
} catch (IOException e) {
continue;
}
Set<File> files = repos.get(name);
if (files == null) {
files = new HashSet<>();
files.add(gitDir);
repos.put(name, files);
} else {
files.add(gitDir);
}
}
String[] repoNames = repos.keySet().toArray(new String[repos.size()]);
Arrays.sort(repoNames, CommonUtils.STRING_ASCENDING_COMPARATOR);
List<IAction> result = new ArrayList<>();
for (String repoName : repoNames) {
Set<File> files = repos.get(repoName);
File[] gitDirs = files.toArray(new File[files.size()]);
Arrays.sort(gitDirs);
for (File f : gitDirs) {
IAction menuItem = new Action(repoName, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
try {
Repository r = cache.lookupRepository(f);
action.accept(r);
} catch (IOException e) {
Activator.showError(e.getLocalizedMessage(), e);
}
}
};
menuItem.setToolTipText(f.getPath());
if (f.equals(currentRepoDir)) {
menuItem.setChecked(true);
}
result.add(menuItem);
}
}
return result;
}
use of org.eclipse.egit.core.RepositoryCache in project egit by eclipse.
the class GlobalConfigurationPreferencePage method init.
@Override
public void init(IWorkbench workbench) {
if (sysConfig == null)
sysConfig = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
if (userConfig == null)
// no inherit here!
userConfig = SystemReader.getInstance().openUserConfig(null, FS.DETECTED);
if (repositories == null) {
repositories = new ArrayList<>();
List<String> repoPaths = Activator.getDefault().getRepositoryUtil().getConfiguredRepositories();
RepositoryCache repositoryCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
for (String repoPath : repoPaths) {
File gitDir = new File(repoPath);
if (!gitDir.exists())
continue;
try {
repositories.add(repositoryCache.lookupRepository(gitDir));
} catch (IOException e) {
continue;
}
}
sortRepositoriesByName();
}
}
use of org.eclipse.egit.core.RepositoryCache in project jbosstools-openshift by jbosstools.
the class TestRepository method cloneRepository.
public TestRepository cloneRepository(File path) throws URISyntaxException, InvocationTargetException, InterruptedException, IOException {
URIish uri = new URIish("file:///" + repository.getDirectory().toString());
CloneOperation clop = new CloneOperation(uri, true, null, path, Constants.R_HEADS + Constants.MASTER, Constants.DEFAULT_REMOTE_NAME, 0);
clop.run(null);
RepositoryCache repositoryCache = Activator.getDefault().getRepositoryCache();
Repository clonedRepository = repositoryCache.lookupRepository(new File(path, Constants.DOT_GIT));
return new TestRepository(clonedRepository);
}
Aggregations