use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class SubmoduleFolderTest method testChildProjectMapsToSubRepo.
@Test
public void testChildProjectMapsToSubRepo() {
RepositoryMapping mapping = RepositoryMapping.getMapping(childProject);
assertNotNull("Child project should have a mapping", mapping);
assertEquals(subRepository, mapping.getRepository());
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class SubmoduleFolderTest method testParentFolderMapsToParentRepo.
@Test
public void testParentFolderMapsToParentRepo() {
RepositoryMapping mapping = RepositoryMapping.getMapping(childFolder.getParent());
assertNotNull("Child folder's parent should have a mapping", mapping);
assertEquals(parentRepository, mapping.getRepository());
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitDocument method populate.
void populate() throws IOException {
if (GitTraceLocation.QUICKDIFF.isActive())
GitTraceLocation.getTrace().traceEntry(GitTraceLocation.QUICKDIFF.getLocation(), resource);
// Do not populate if already disposed
if (disposed)
return;
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
if (mapping == null) {
// $NON-NLS-1$
setResolved(null, null, null, "");
return;
}
final String gitPath = mapping.getRepoRelativePath(resource);
if (gitPath == null) {
// $NON-NLS-1$
setResolved(null, null, null, "");
return;
}
final Repository repository = mapping.getRepository();
String baseline = GitQuickDiffProvider.baseline.get(repository);
if (baseline == null)
baseline = Constants.HEAD;
ObjectId commitId = repository.resolve(baseline);
if (commitId != null) {
if (commitId.equals(lastCommit)) {
if (GitTraceLocation.QUICKDIFF.isActive())
GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), // $NON-NLS-1$
"(GitDocument) already resolved");
return;
}
} else {
if (repository.exactRef(Constants.HEAD) == null) {
// Complain only if not an unborn branch
String msg = NLS.bind(UIText.GitDocument_errorResolveQuickdiff, new Object[] { baseline, resource, repository });
Activator.logError(msg, new Throwable());
}
// $NON-NLS-1$
setResolved(null, null, null, "");
return;
}
RevCommit baselineCommit;
String oldPath = gitPath;
try (RevWalk rw = new RevWalk(repository);
ObjectReader reader = repository.newObjectReader()) {
baselineCommit = rw.parseCommit(commitId);
DiffConfig diffConfig = repository.getConfig().get(DiffConfig.KEY);
if (diffConfig.getRenameDetectionType() != RenameDetectionType.FALSE) {
TreeWalk walk = new TreeWalk(repository);
CanonicalTreeParser baseLineIterator = new CanonicalTreeParser();
baseLineIterator.reset(reader, baselineCommit.getTree());
walk.addTree(baseLineIterator);
walk.addTree(new DirCacheIterator(repository.readDirCache()));
List<DiffEntry> diffs = DiffEntry.scan(walk, true);
RenameDetector renameDetector = new RenameDetector(repository);
renameDetector.addAll(diffs);
List<DiffEntry> renames = renameDetector.compute();
for (DiffEntry e : renames) {
if (e.getNewPath().equals(gitPath)) {
oldPath = e.getOldPath();
break;
}
}
}
} catch (IOException err) {
String msg = NLS.bind(UIText.GitDocument_errorLoadCommit, new Object[] { commitId, baseline, resource, repository });
Activator.logError(msg, err);
// $NON-NLS-1$
setResolved(null, null, null, "");
return;
}
RevTree treeId = baselineCommit.getTree();
if (treeId.equals(lastTree)) {
if (GitTraceLocation.QUICKDIFF.isActive())
GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), // $NON-NLS-1$
"(GitDocument) already resolved");
return;
}
try (TreeWalk tw = TreeWalk.forPath(repository, oldPath, treeId)) {
if (tw == null) {
if (GitTraceLocation.QUICKDIFF.isActive())
GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"(GitDocument) resource " + resource + " not found in " + treeId + " in " + repository + ", baseline=" + baseline);
// $NON-NLS-1$
setResolved(null, null, null, "");
return;
}
ObjectId id = tw.getObjectId(0);
if (id.equals(ObjectId.zeroId())) {
// $NON-NLS-1$
setResolved(null, null, null, "");
String msg = NLS.bind(UIText.GitDocument_errorLoadTree, new Object[] { treeId.getName(), baseline, resource, repository });
Activator.logError(msg, new Throwable());
// $NON-NLS-1$
setResolved(null, null, null, "");
return;
}
if (!id.equals(lastBlob)) {
if (GitTraceLocation.QUICKDIFF.isActive())
GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), // $NON-NLS-1$
"(GitDocument) compareTo: " + baseline);
ObjectLoader loader = repository.open(id, Constants.OBJ_BLOB);
byte[] bytes = loader.getBytes();
String charset;
charset = CompareCoreUtils.getResourceEncoding(resource);
// Finally we could consider validating the content with respect
// to the content. We don't do that here.
String s = new String(bytes, charset);
setResolved(commitId, treeId, id, s);
if (GitTraceLocation.QUICKDIFF.isActive())
GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), // $NON-NLS-1$ //$NON-NLS-2$
"(GitDocument) has reference doc, size=" + s.length() + " bytes");
} else {
if (GitTraceLocation.QUICKDIFF.isActive())
GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), // $NON-NLS-1$
"(GitDocument) already resolved");
}
} finally {
if (GitTraceLocation.QUICKDIFF.isActive()) {
GitTraceLocation.getTrace().traceExit(GitTraceLocation.QUICKDIFF.getLocation());
}
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class AddCommand method autoShareProjects.
private void autoShareProjects(File repositoryDir) {
// Don't even try to auto-share for bare repositories.
IPath workingDirPath;
try {
Repository repo = Activator.getDefault().getRepositoryCache().lookupRepository(repositoryDir);
if (repo.isBare()) {
return;
}
workingDirPath = new Path(repo.getWorkTree().getAbsolutePath());
} catch (IOException e) {
org.eclipse.egit.ui.Activator.logError(e.getLocalizedMessage(), e);
return;
}
Map<IProject, File> connections = new HashMap<>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
// Skip closed projects
if (!project.isAccessible()) {
continue;
}
RepositoryProvider provider = RepositoryProvider.getProvider(project);
if (provider != null) {
continue;
}
IPath location = project.getLocation();
if (location == null) {
continue;
}
// even search for a mapping.
if (!workingDirPath.isPrefixOf(location)) {
continue;
}
RepositoryFinder f = new RepositoryFinder(project);
f.setFindInChildren(false);
try {
List<RepositoryMapping> mappings = f.find(new NullProgressMonitor());
if (!mappings.isEmpty()) {
// Connect to the first one; it's the innermost.
IPath gitDir = mappings.get(0).getGitDirAbsolutePath();
if (gitDir != null) {
connections.put(project, gitDir.toFile());
}
}
} catch (CoreException e) {
// Ignore this project in that case
continue;
}
}
if (!connections.isEmpty()) {
ConnectProviderOperation operation = new ConnectProviderOperation(connections);
operation.setRefreshResources(false);
JobUtil.scheduleUserJob(operation, CoreText.Activator_AutoShareJobName, JobFamilies.AUTO_SHARE);
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitSynchronizeData method setIncludedResources.
/**
* @param includedResources
* list of resources to be synchronized
*/
public void setIncludedResources(Set<IResource> includedResources) {
this.includedResources = includedResources;
Set<String> paths = new HashSet<>();
RepositoryMapping rm = RepositoryMapping.findRepositoryMapping(repo);
if (rm != null) {
for (IResource resource : includedResources) {
String repoRelativePath = rm.getRepoRelativePath(resource);
if (repoRelativePath != null && repoRelativePath.length() > 0)
paths.add(repoRelativePath);
}
}
if (!paths.isEmpty())
pathFilter = PathFilterGroup.createFromStrings(paths);
}
Aggregations