Example usage for org.eclipse.jgit.lib Constants R_HEADS

List of usage examples for org.eclipse.jgit.lib Constants R_HEADS

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants R_HEADS.

Prototype

String R_HEADS

To view the source code for org.eclipse.jgit.lib Constants R_HEADS.

Click Source Link

Document

Prefix for branch refs

Usage

From source file:com.google.gerrit.server.project.PerformCreateProject.java

License:Apache License

private void validateParameters() throws ProjectCreationFailedException {
    if (createProjectArgs.getProjectName() == null || createProjectArgs.getProjectName().isEmpty()) {
        throw new ProjectCreationFailedException("Project name is required");
    }/*from w ww  .  jav a  2 s.c o  m*/

    String nameWithoutSuffix = ProjectUtil.stripGitSuffix(createProjectArgs.getProjectName());
    createProjectArgs.setProjectName(nameWithoutSuffix);

    if (!currentUser.getCapabilities().canCreateProject()) {
        throw new ProjectCreationFailedException(
                String.format("%s does not have \"Create Project\" capability.", currentUser.getUserName()));
    }

    if (createProjectArgs.ownerIds == null || createProjectArgs.ownerIds.isEmpty()) {
        createProjectArgs.ownerIds = new ArrayList<>(projectOwnerGroups);
    }

    List<String> transformedBranches = new ArrayList<>();
    if (createProjectArgs.branch == null || createProjectArgs.branch.isEmpty()) {
        createProjectArgs.branch = Collections.singletonList(Constants.MASTER);
    }
    for (String branch : createProjectArgs.branch) {
        while (branch.startsWith("/")) {
            branch = branch.substring(1);
        }
        if (!branch.startsWith(Constants.R_HEADS)) {
            branch = Constants.R_HEADS + branch;
        }
        if (!Repository.isValidRefName(branch)) {
            throw new ProjectCreationFailedException(
                    String.format("Branch \"%s\" is not a valid name.", branch));
        }
        if (!transformedBranches.contains(branch)) {
            transformedBranches.add(branch);
        }
    }
    createProjectArgs.branch = transformedBranches;
}

From source file:com.google.gerrit.server.project.RefControl.java

License:Apache License

private boolean isMergedIntoBranchOrTag(ReviewDb db, RevWalk rw, RevCommit commit) {
    try (Repository repo = projectControl.openRepository()) {
        List<Ref> refs = new ArrayList<>(repo.getRefDatabase().getRefs(Constants.R_HEADS).values());
        refs.addAll(repo.getRefDatabase().getRefs(Constants.R_TAGS).values());
        return projectControl.isMergedIntoVisibleRef(repo, db, rw, commit, refs);
    } catch (IOException e) {
        String msg = String.format("Cannot verify permissions to commit object %s in repository %s",
                commit.name(), projectControl.getProject().getNameKey());
        log.error(msg, e);//from w w  w  .j a  v  a  2  s . co  m
    }
    return false;
}

From source file:com.google.gerrit.server.project.RefUtil.java

License:Apache License

public static RevWalk verifyConnected(Repository repo, ObjectId revid) throws InvalidRevisionException {
    try {//from   w ww  .  j  av  a2s.  c o  m
        ObjectWalk rw = new ObjectWalk(repo);
        try {
            rw.markStart(rw.parseCommit(revid));
        } catch (IncorrectObjectTypeException err) {
            throw new InvalidRevisionException();
        }
        RefDatabase refDb = repo.getRefDatabase();
        Iterable<Ref> refs = Iterables.concat(refDb.getRefs(Constants.R_HEADS).values(),
                refDb.getRefs(Constants.R_TAGS).values());
        Ref rc = refDb.exactRef(RefNames.REFS_CONFIG);
        if (rc != null) {
            refs = Iterables.concat(refs, Collections.singleton(rc));
        }
        for (Ref r : refs) {
            try {
                rw.markUninteresting(rw.parseAny(r.getObjectId()));
            } catch (MissingObjectException err) {
                continue;
            }
        }
        rw.checkConnectivity();
        return rw;
    } catch (IncorrectObjectTypeException | MissingObjectException err) {
        throw new InvalidRevisionException();
    } catch (IOException err) {
        log.error("Repository \"" + repo.getDirectory() + "\" may be corrupt; suggest running git fsck", err);
        throw new InvalidRevisionException();
    }
}

From source file:com.google.gerrit.server.project.RefUtil.java

License:Apache License

public static String getRefPrefix(String refName) {
    int i = refName.lastIndexOf('/');
    if (i > Constants.R_HEADS.length() - 1) {
        return refName.substring(0, i);
    }//w w  w. j a  v a 2s.  com
    return Constants.R_HEADS;
}

From source file:com.google.gerrit.server.schema.Schema_108.java

License:Apache License

private static void updateProjectGroups(ReviewDb db, Repository repo, RevWalk rw, Set<Change.Id> changes)
        throws OrmException, IOException {
    // Match sorting in ReceiveCommits.
    rw.reset();//from w  w w  . j a  v a 2 s .c  o m
    rw.sort(RevSort.TOPO);
    rw.sort(RevSort.REVERSE, true);

    RefDatabase refdb = repo.getRefDatabase();
    for (Ref ref : refdb.getRefs(Constants.R_HEADS).values()) {
        RevCommit c = maybeParseCommit(rw, ref.getObjectId());
        if (c != null) {
            rw.markUninteresting(c);
        }
    }

    Multimap<ObjectId, Ref> changeRefsBySha = ArrayListMultimap.create();
    Multimap<ObjectId, PatchSet.Id> patchSetsBySha = ArrayListMultimap.create();
    for (Ref ref : refdb.getRefs(RefNames.REFS_CHANGES).values()) {
        ObjectId id = ref.getObjectId();
        if (ref.getObjectId() == null) {
            continue;
        }
        id = id.copy();
        changeRefsBySha.put(id, ref);
        PatchSet.Id psId = PatchSet.Id.fromRef(ref.getName());
        if (psId != null && changes.contains(psId.getParentKey())) {
            patchSetsBySha.put(id, psId);
            RevCommit c = maybeParseCommit(rw, id);
            if (c != null) {
                rw.markStart(c);
            }
        }
    }

    GroupCollector collector = new GroupCollector(changeRefsBySha, db);
    RevCommit c;
    while ((c = rw.next()) != null) {
        collector.visit(c);
    }

    updateGroups(db, collector, patchSetsBySha);
}

From source file:com.google.gerrit.server.schema.Schema_25.java

License:Apache License

private RefRight toRefRight(ResultSet rs) throws SQLException {
    short min_value = rs.getShort("min_value");
    short max_value = rs.getShort("max_value");
    String category_id = rs.getString("category_id");
    int group_id = rs.getInt("group_id");
    String project_name = rs.getString("project_name");

    ApprovalCategory.Id category = new ApprovalCategory.Id(category_id);
    Project.NameKey project = new Project.NameKey(project_name);
    AccountGroup.Id group = new AccountGroup.Id(group_id);

    RefRight.RefPattern ref;/*from w  w  w  .j  a v a 2 s.co  m*/
    if (category.equals(ApprovalCategory.SUBMIT) || category.equals(ApprovalCategory.PUSH_HEAD)
            || nonActions.contains(category)) {
        // Explicitly related to a branch head.
        ref = new RefRight.RefPattern(Constants.R_HEADS + "*");

    } else if (category.equals(ApprovalCategory.PUSH_TAG)) {
        // Explicitly related to the tag namespace.
        ref = new RefRight.RefPattern(Constants.R_TAGS + "/*");

    } else if (category.equals(ApprovalCategory.READ) || category.equals(ApprovalCategory.OWN)) {
        // Currently these are project-wide rights, so apply that way.
        ref = new RefRight.RefPattern(RefRight.ALL);

    } else {
        // Assume project wide for the default.
        ref = new RefRight.RefPattern(RefRight.ALL);
    }

    RefRight.Key key = new RefRight.Key(project, ref, category, group);
    RefRight r = new RefRight(key);
    r.setMinValue(min_value);
    r.setMaxValue(max_value);
    return r;
}

From source file:com.google.gerrit.sshd.commands.CreateProject.java

License:Apache License

private void validateParameters() throws Failure {
    if (projectName.endsWith(Constants.DOT_GIT_EXT)) {
        projectName = projectName.substring(0, //
                projectName.length() - Constants.DOT_GIT_EXT.length());
    }//from  w  ww. j  a v a2 s .c  om

    if (!CollectionsUtil.isAnyIncludedIn(currentUser.getEffectiveGroups(), projectCreatorGroups)) {
        throw new Failure(1, "fatal: Not permitted to create " + projectName);
    }

    if (ownerIds != null && !ownerIds.isEmpty()) {
        ownerIds = new ArrayList<AccountGroup.UUID>(new HashSet<AccountGroup.UUID>(ownerIds));
    } else {
        ownerIds = new ArrayList<AccountGroup.UUID>(projectOwnerGroups);
    }

    while (branch.startsWith("/")) {
        branch = branch.substring(1);
    }
    if (!branch.startsWith(Constants.R_HEADS)) {
        branch = Constants.R_HEADS + branch;
    }
    if (!Repository.isValidRefName(branch)) {
        throw new Failure(1, "--branch \"" + branch + "\" is not a valid name");
    }
}

From source file:com.google.gitiles.CommitSoyData.java

License:Open Source License

public Map<String, Object> toSoyData(RevCommit commit, KeySet keys) throws IOException {
    Map<String, Object> data = Maps.newHashMapWithExpectedSize(KeySet.DEFAULT.keys.size());
    if (keys.keys.contains("author")) {
        data.put("author", toSoyData(commit.getAuthorIdent(), dateFormatter));
    }/*from  w w  w.j a  v  a  2  s  .  c om*/
    if (keys.keys.contains("committer")) {
        data.put("committer", toSoyData(commit.getCommitterIdent(), dateFormatter));
    }
    if (keys.keys.contains("sha")) {
        data.put("sha", ObjectId.toString(commit));
    }
    if (keys.keys.contains("abbrevSha")) {
        ObjectReader reader = repo.getObjectDatabase().newReader();
        try {
            data.put("abbrevSha", reader.abbreviate(commit).name());
        } finally {
            reader.release();
        }
    }
    if (keys.keys.contains("url")) {
        data.put("url", GitilesView.revision().copyFrom(view).setRevision(commit).toUrl());
    }
    if (keys.keys.contains("logUrl")) {
        Revision rev = view.getRevision();
        GitilesView.Builder logView = GitilesView.log().copyFrom(view)
                .setRevision(rev.getId().equals(commit) ? rev.getName() : commit.name(), commit)
                .setOldRevision(Revision.NULL).setTreePath(null);
        data.put("logUrl", logView.toUrl());
    }
    if (keys.keys.contains("tree")) {
        data.put("tree", ObjectId.toString(commit.getTree()));
    }
    if (keys.keys.contains("treeUrl")) {
        data.put("treeUrl", GitilesView.path().copyFrom(view).setTreePath("/").toUrl());
    }
    if (keys.keys.contains("parents")) {
        data.put("parents", toSoyData(view, commit.getParents()));
    }
    if (keys.keys.contains("shortMessage")) {
        data.put("shortMessage", commit.getShortMessage());
    }
    if (keys.keys.contains("branches")) {
        data.put("branches", getRefsById(commit, Constants.R_HEADS));
    }
    if (keys.keys.contains("tags")) {
        data.put("tags", getRefsById(commit, Constants.R_TAGS));
    }
    if (keys.keys.contains("message")) {
        if (linkifier != null) {
            data.put("message", linkifier.linkify(req, commit.getFullMessage()));
        } else {
            data.put("message", commit.getFullMessage());
        }
    }
    if (keys.keys.contains("diffTree")) {
        data.put("diffTree", computeDiffTree(commit));
    }
    checkState(keys.keys.size() == data.size(), "bad commit data keys: %s != %s", keys.keys, data.keySet());
    return ImmutableMap.copyOf(data);
}

From source file:com.google.gitiles.RefServlet.java

License:Open Source License

static List<Map<String, Object>> getBranchesSoyData(HttpServletRequest req, int limit) throws IOException {
    RefDatabase refdb = ServletUtils.getRepository(req).getRefDatabase();
    Ref head = refdb.getRef(Constants.HEAD);
    Ref headLeaf = head != null && head.isSymbolic() ? head.getLeaf() : null;
    return getRefsSoyData(refdb, ViewFilter.getView(req), Constants.R_HEADS, branchComparator(headLeaf),
            headLeaf, limit);//from   ww  w  .  j a  v  a 2s  .c o  m
}

From source file:com.google.gitiles.RepositoryIndexServlet.java

License:Open Source License

@VisibleForTesting
Map<String, ?> buildData(HttpServletRequest req) throws IOException {
    RepositoryDescription desc = accessFactory.forRequest(req).getRepositoryDescription();
    return ImmutableMap.of("cloneUrl", desc.cloneUrl, "description", Strings.nullToEmpty(desc.description),
            "branches", getRefs(req, Constants.R_HEADS), "tags", getRefs(req, Constants.R_TAGS));
}