Search in sources :

Example 36 with GitSynchronizeData

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);
        }
    }
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 37 with GitSynchronizeData

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);
        }
    };
}
Also used : SynchronizeModelOperation(org.eclipse.team.ui.synchronize.SynchronizeModelOperation) GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) PullOperationUI(org.eclipse.egit.ui.internal.pull.PullOperationUI) HashSet(java.util.HashSet)

Example 38 with GitSynchronizeData

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();
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) RefSpec(org.eclipse.jgit.transport.RefSpec) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) URISyntaxException(java.net.URISyntaxException) PushOperationUI(org.eclipse.egit.ui.internal.push.PushOperationUI) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)

Example 39 with GitSynchronizeData

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;
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant)

Example 40 with GitSynchronizeData

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);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) HashMap(java.util.HashMap) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) Collection(java.util.Collection) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Aggregations

GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)42 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)26 Test (org.junit.Test)15 Repository (org.eclipse.jgit.lib.Repository)14 IResource (org.eclipse.core.resources.IResource)13 IFile (org.eclipse.core.resources.IFile)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)9 IOException (java.io.IOException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IStorage (org.eclipse.core.resources.IStorage)6 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)5 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3