use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.
the class ModelAwareGitSynchronizer method synchronize.
@Override
protected void synchronize(IResource[] resources, Repository repository, String leftRev, String rightRev, boolean includeLocal) throws IOException {
if (rightRev.equals(GitFileRevision.INDEX)) {
openGitTreeCompare(resources, leftRev, CompareTreeView.INDEX_VERSION, includeLocal);
} else {
final Set<IResource> includedResources = new HashSet<>(Arrays.asList(resources));
final Set<ResourceMapping> allMappings = new HashSet<>();
Set<IResource> newResources = new HashSet<>(includedResources);
do {
final Set<IResource> copy = newResources;
newResources = new HashSet<>();
for (IResource resource : copy) {
Assert.isNotNull(resource);
ResourceMapping[] mappings = ResourceUtil.getResourceMappings(resource, context);
allMappings.addAll(Arrays.asList(mappings));
newResources.addAll(collectResources(mappings));
}
} while (includedResources.addAll(newResources));
if (GitFileRevision.INDEX.equals(leftRev)) {
// Even git tree compare cannot handle index as
// source...
// Synchronize using the local data for now.
final ResourceMapping[] mappings = allMappings.toArray(new ResourceMapping[allMappings.size()]);
final GitSynchronizeData data = new GitSynchronizeData(repository, leftRev, rightRev, true, includedResources);
GitModelSynchronize.launch(new GitSynchronizeDataSet(data), mappings);
} else {
final ResourceMapping[] mappings = allMappings.toArray(new ResourceMapping[allMappings.size()]);
final GitSynchronizeData data = new GitSynchronizeData(repository, leftRev, rightRev, includeLocal, includedResources);
GitModelSynchronize.launch(new GitSynchronizeDataSet(data), mappings);
}
}
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.
the class PullAction method getSubscriberOperation.
@Override
protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
return new SynchronizeModelOperation(configuration, elements) {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
GitSynchronizeDataSet gsds = (GitSynchronizeDataSet) getConfiguration().getProperty(SYNCHRONIZATION_DATA);
Set<Repository> repositories = new HashSet<>();
for (GitSynchronizeData gsd : gsds) repositories.add(gsd.getRepository());
PullOperationUI pull = new PullOperationUI(repositories);
pull.execute(monitor);
}
};
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.
the class PushAction method runPushOperation.
private void runPushOperation() {
GitSynchronizeDataSet gsds = (GitSynchronizeDataSet) getConfiguration().getProperty(SYNCHRONIZATION_DATA);
for (GitSynchronizeData gsd : gsds) {
String remoteName = gsd.getDstRemoteName();
if (remoteName == null)
continue;
RemoteConfig rc;
Repository repo = gsd.getRepository();
StoredConfig config = repo.getConfig();
try {
rc = new RemoteConfig(config, remoteName);
} catch (URISyntaxException e) {
Activator.logError("Unable to create RemoteConfiguration for remote: " + remoteName, // $NON-NLS-1$
e);
continue;
}
if (rc.getPushRefSpecs().isEmpty())
// $NON-NLS-1$
rc.addPushRefSpec(new RefSpec(HEAD + ":" + gsd.getDstMerge()));
PushOperationUI push = new PushOperationUI(repo, rc, false);
push.setCredentialsProvider(new EGitCredentialsProvider());
push.start();
}
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.
the class GitResourceVariantTree method fetchVariant.
private IResourceVariant fetchVariant(IResource resource) {
if (gitCache == null)
return null;
IResourceVariant cachedVariant = cache.get(resource);
if (cachedVariant != null)
return cachedVariant;
GitSynchronizeData gsd = gsds.getData(resource.getProject());
if (gsd == null)
return null;
Repository repo = gsd.getRepository();
String path = getPath(resource, repo);
GitSyncObjectCache syncCache = gitCache.get(repo);
GitSyncObjectCache cachedData = syncCache.get(path);
if (cachedData == null)
return null;
IResourceVariant variant = null;
ObjectId objectId = getObjectId(cachedData.getDiffEntry());
if (!objectId.equals(zeroId())) {
if (resource.getType() == IResource.FILE)
variant = new GitRemoteFile(repo, getCommitId(gsd), objectId, path);
else
variant = new GitRemoteFolder(repo, cachedData, getCommitId(gsd), objectId, path);
cache.put(resource, variant);
}
return variant;
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.
the class GitResourceVariantTreeSubscriber method refresh.
@Override
public void refresh(IResource[] resources, int depth, IProgressMonitor monitor) throws TeamException {
for (IResource resource : resources) {
// check to see if there is a full refresh
if (resource.getType() == IResource.ROOT) {
// refresh entire cache
cache = GitSyncCache.getAllData(gsds, monitor);
super.refresh(resources, depth, monitor);
return;
}
}
// not refreshing the workspace, locate and collect target resources
Map<GitSynchronizeData, Collection<String>> updateRequests = new HashMap<GitSynchronizeData, Collection<String>>();
for (IResource resource : resources) {
IProject project = resource.getProject();
GitSynchronizeData data = gsds.getData(project.getName());
if (data != null) {
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
// mapping may be null if the project has been closed
if (mapping != null) {
Collection<String> paths = updateRequests.get(data);
if (paths == null) {
paths = new ArrayList<String>();
updateRequests.put(data, paths);
}
String path = mapping.getRepoRelativePath(resource);
// null path may be returned, check for this
if (path == null)
// unknown, force a refresh of the whole repository
// $NON-NLS-1$
path = "";
paths.add(path);
}
}
}
// scan only the repositories that were affected
if (!updateRequests.isEmpty()) {
// refresh cache
GitSyncCache.mergeAllDataIntoCache(updateRequests, monitor, cache);
}
super.refresh(resources, depth, monitor);
}
Aggregations