Search in sources :

Example 1 with SubscribeSection

use of com.google.gerrit.common.data.SubscribeSection in project gerrit by GerritCodeReview.

the class SubmoduleOp method superProjectSubscriptionsForSubmoduleBranch.

public Collection<SubmoduleSubscription> superProjectSubscriptionsForSubmoduleBranch(Branch.NameKey srcBranch) throws IOException {
    logDebug("Calculating possible superprojects for " + srcBranch);
    Collection<SubmoduleSubscription> ret = new ArrayList<>();
    Project.NameKey srcProject = srcBranch.getParentKey();
    ProjectConfig cfg = projectCache.get(srcProject).getConfig();
    for (SubscribeSection s : projectStateFactory.create(cfg).getSubscribeSections(srcBranch)) {
        logDebug("Checking subscribe section " + s);
        Collection<Branch.NameKey> branches = getDestinationBranches(srcBranch, s);
        for (Branch.NameKey targetBranch : branches) {
            Project.NameKey targetProject = targetBranch.getParentKey();
            try {
                OpenRepo or = orm.getRepo(targetProject);
                ObjectId id = or.repo.resolve(targetBranch.get());
                if (id == null) {
                    logDebug("The branch " + targetBranch + " doesn't exist.");
                    continue;
                }
            } catch (NoSuchProjectException e) {
                logDebug("The project " + targetProject + " doesn't exist");
                continue;
            }
            GitModules m = branchGitModules.get(targetBranch);
            if (m == null) {
                m = gitmodulesFactory.create(targetBranch, orm);
                branchGitModules.put(targetBranch, m);
            }
            ret.addAll(m.subscribedTo(srcBranch));
        }
    }
    logDebug("Calculated superprojects for " + srcBranch + " are " + ret);
    return ret;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ArrayList(java.util.ArrayList) SubscribeSection(com.google.gerrit.common.data.SubscribeSection) Project(com.google.gerrit.reviewdb.client.Project) Branch(com.google.gerrit.reviewdb.client.Branch) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) SubmoduleSubscription(com.google.gerrit.reviewdb.client.SubmoduleSubscription)

Example 2 with SubscribeSection

use of com.google.gerrit.common.data.SubscribeSection in project gerrit by GerritCodeReview.

the class ProjectConfig method saveSubscribeSections.

private void saveSubscribeSections(Config rc) {
    for (Project.NameKey p : subscribeSections.keySet()) {
        SubscribeSection s = subscribeSections.get(p);
        List<String> matchings = new ArrayList<>();
        for (RefSpec r : s.getMatchingRefSpecs()) {
            matchings.add(r.toString());
        }
        rc.setStringList(SUBSCRIBE_SECTION, p.get(), SUBSCRIBE_MATCH_REFS, matchings);
        List<String> multimatchs = new ArrayList<>();
        for (RefSpec r : s.getMultiMatchRefSpecs()) {
            multimatchs.add(r.toString());
        }
        rc.setStringList(SUBSCRIBE_SECTION, p.get(), SUBSCRIBE_MULTI_MATCH_REFS, multimatchs);
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) RefSpec(org.eclipse.jgit.transport.RefSpec) ArrayList(java.util.ArrayList) SubscribeSection(com.google.gerrit.common.data.SubscribeSection)

Example 3 with SubscribeSection

use of com.google.gerrit.common.data.SubscribeSection in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method allowSubmoduleSubscription.

protected void allowSubmoduleSubscription(String submodule, String subBranch, String superproject, String superBranch, boolean match) throws Exception {
    Project.NameKey sub = new Project.NameKey(name(submodule));
    Project.NameKey superName = new Project.NameKey(name(superproject));
    try (MetaDataUpdate md = metaDataUpdateFactory.create(sub)) {
        md.setMessage("Added superproject subscription");
        SubscribeSection s;
        ProjectConfig pc = ProjectConfig.read(md);
        if (pc.getSubscribeSections().containsKey(superName)) {
            s = pc.getSubscribeSections().get(superName);
        } else {
            s = new SubscribeSection(superName);
        }
        String refspec;
        if (superBranch == null) {
            refspec = subBranch;
        } else {
            refspec = subBranch + ":" + superBranch;
        }
        if (match) {
            s.addMatchingRefSpec(refspec);
        } else {
            s.addMultiMatchRefSpec(refspec);
        }
        pc.addSubscribeSection(s);
        ObjectId oldId = pc.getRevision();
        ObjectId newId = pc.commit(md);
        assertThat(newId).isNotEqualTo(oldId);
        projectCache.evict(pc.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) ObjectId(org.eclipse.jgit.lib.ObjectId) SubscribeSection(com.google.gerrit.common.data.SubscribeSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 4 with SubscribeSection

use of com.google.gerrit.common.data.SubscribeSection in project gerrit by GerritCodeReview.

the class Schema_120 method allowSubmoduleSubscription.

private void allowSubmoduleSubscription(Branch.NameKey subbranch, Branch.NameKey superBranch) throws OrmException {
    try (Repository git = mgr.openRepository(subbranch.getParentKey());
        RevWalk rw = new RevWalk(git)) {
        BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
        try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, subbranch.getParentKey(), git, bru)) {
            md.getCommitBuilder().setAuthor(serverUser);
            md.getCommitBuilder().setCommitter(serverUser);
            md.setMessage("Added superproject subscription during upgrade");
            ProjectConfig pc = ProjectConfig.read(md);
            SubscribeSection s = null;
            for (SubscribeSection s1 : pc.getSubscribeSections(subbranch)) {
                if (s1.getProject().equals(superBranch.getParentKey())) {
                    s = s1;
                }
            }
            if (s == null) {
                s = new SubscribeSection(superBranch.getParentKey());
                pc.addSubscribeSection(s);
            }
            RefSpec newRefSpec = new RefSpec(subbranch.get() + ":" + superBranch.get());
            if (!s.getMatchingRefSpecs().contains(newRefSpec)) {
                // For the migration we use only exact RefSpecs, we're not trying to
                // generalize it.
                s.addMatchingRefSpec(newRefSpec);
            }
            pc.commit(md);
        }
        bru.execute(rw, NullProgressMonitor.INSTANCE);
    } catch (ConfigInvalidException | IOException e) {
        throw new OrmException(e);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Repository(org.eclipse.jgit.lib.Repository) RefSpec(org.eclipse.jgit.transport.RefSpec) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) OrmException(com.google.gwtorm.server.OrmException) SubscribeSection(com.google.gerrit.common.data.SubscribeSection) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 5 with SubscribeSection

use of com.google.gerrit.common.data.SubscribeSection in project gerrit by GerritCodeReview.

the class ProjectConfig method loadSubscribeSections.

private void loadSubscribeSections(Config rc) throws ConfigInvalidException {
    Set<String> subsections = rc.getSubsections(SUBSCRIBE_SECTION);
    subscribeSections = new HashMap<>();
    try {
        for (String projectName : subsections) {
            Project.NameKey p = new Project.NameKey(projectName);
            SubscribeSection ss = new SubscribeSection(p);
            for (String s : rc.getStringList(SUBSCRIBE_SECTION, projectName, SUBSCRIBE_MULTI_MATCH_REFS)) {
                ss.addMultiMatchRefSpec(s);
            }
            for (String s : rc.getStringList(SUBSCRIBE_SECTION, projectName, SUBSCRIBE_MATCH_REFS)) {
                ss.addMatchingRefSpec(s);
            }
            subscribeSections.put(p, ss);
        }
    } catch (IllegalArgumentException e) {
        throw new ConfigInvalidException(e.getMessage());
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) SubscribeSection(com.google.gerrit.common.data.SubscribeSection)

Aggregations

SubscribeSection (com.google.gerrit.common.data.SubscribeSection)5 Project (com.google.gerrit.reviewdb.client.Project)4 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)2 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 ArrayList (java.util.ArrayList)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RefSpec (org.eclipse.jgit.transport.RefSpec)2 Branch (com.google.gerrit.reviewdb.client.Branch)1 SubmoduleSubscription (com.google.gerrit.reviewdb.client.SubmoduleSubscription)1 OpenRepo (com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo)1 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)1 OrmException (com.google.gwtorm.server.OrmException)1 IOException (java.io.IOException)1 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)1 Repository (org.eclipse.jgit.lib.Repository)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1