Search in sources :

Example 1 with RevObject

use of org.eclipse.jgit.revwalk.RevObject in project gitblit by gitblit.

the class JGitUtils method createTag.

/**
	 * creates a tag in a repository
	 *
	 * @param repository
	 * @param objectId, the ref the tag points towards
	 * @param tagger, the person tagging the object
	 * @param tag, the string label
	 * @param message, the string message
	 * @return boolean, true if operation was successful, otherwise false
	 */
public static boolean createTag(Repository repository, String objectId, PersonIdent tagger, String tag, String message) {
    try {
        Git gitClient = Git.open(repository.getDirectory());
        TagCommand tagCommand = gitClient.tag();
        tagCommand.setTagger(tagger);
        tagCommand.setMessage(message);
        if (objectId != null) {
            RevObject revObj = getCommit(repository, objectId);
            tagCommand.setObjectId(revObj);
        }
        tagCommand.setName(tag);
        Ref call = tagCommand.call();
        return call != null ? true : false;
    } catch (Exception e) {
        error(e, repository, "Failed to create tag {1} in repository {0}", objectId, tag);
    }
    return false;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) RevObject(org.eclipse.jgit.revwalk.RevObject) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) LargeObjectException(org.eclipse.jgit.errors.LargeObjectException) GitBlitException(com.gitblit.GitBlitException) AmbiguousObjectException(org.eclipse.jgit.errors.AmbiguousObjectException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) StopWalkException(org.eclipse.jgit.errors.StopWalkException) TagCommand(org.eclipse.jgit.api.TagCommand)

Example 2 with RevObject

use of org.eclipse.jgit.revwalk.RevObject in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.

protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, ObjectId expectedId) throws Exception {
    submodule = name(submodule);
    ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
    RevWalk rw = repo.getRevWalk();
    RevCommit c = rw.parseCommit(commitId);
    rw.parseBody(c.getTree());
    RevTree tree = c.getTree();
    RevObject actualId = repo.get(tree, submodule);
    assertThat(actualId).isEqualTo(expectedId);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with RevObject

use of org.eclipse.jgit.revwalk.RevObject in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.

protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, TestRepository<?> subRepo, String subBranch) throws Exception {
    submodule = name(submodule);
    ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
    ObjectId subHead = subRepo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + subBranch).getObjectId();
    RevWalk rw = repo.getRevWalk();
    RevCommit c = rw.parseCommit(commitId);
    rw.parseBody(c.getTree());
    RevTree tree = c.getTree();
    RevObject actualId = repo.get(tree, submodule);
    assertThat(actualId).isEqualTo(subHead);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with RevObject

use of org.eclipse.jgit.revwalk.RevObject in project gitiles by GerritCodeReview.

the class RepositoryIndexServlet method doGetHtml.

@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    Repository repo = ServletUtils.getRepository(req);
    GitilesAccess access = getAccess(req);
    RepositoryDescription desc = access.getRepositoryDescription();
    try (RevWalk walk = new RevWalk(repo)) {
        Paginator paginator = null;
        Map<String, Object> data = Maps.newHashMapWithExpectedSize(7);
        List<Map<String, Object>> tags = RefServlet.getTagsSoyData(req, timeCache, walk, REF_LIMIT);
        ObjectId headId = repo.resolve(Constants.HEAD);
        if (headId != null) {
            RevObject head = walk.parseAny(headId);
            int limit = LOG_LIMIT;
            Map<String, Object> readme = renderReadme(req, walk, view, access.getConfig(), head);
            if (readme != null) {
                data.putAll(readme);
                limit = LOG_WITH_README_LIMIT;
            }
            // TODO(dborowitz): Handle non-commit or missing HEAD?
            if (head.getType() == Constants.OBJ_COMMIT) {
                walk.reset();
                walk.markStart((RevCommit) head);
                paginator = new Paginator(walk, limit, null);
            }
        }
        if (!data.containsKey("entries")) {
            data.put("entries", ImmutableList.of());
        }
        List<Map<String, Object>> branches = RefServlet.getBranchesSoyData(req, REF_LIMIT);
        data.put("cloneUrl", desc.cloneUrl);
        data.put("mirroredFromUrl", Strings.nullToEmpty(desc.mirroredFromUrl));
        data.put("description", Strings.nullToEmpty(desc.description));
        data.put("branches", trim(branches));
        if (branches.size() > REF_LIMIT) {
            data.put("moreBranchesUrl", GitilesView.refs().copyFrom(view).toUrl());
        }
        data.put("tags", trim(tags));
        data.put("hasLog", paginator != null);
        if (tags.size() > REF_LIMIT) {
            data.put("moreTagsUrl", GitilesView.refs().copyFrom(view).toUrl());
        }
        GitilesConfig.putVariant(getAccess(req).getConfig(), "logEntry", "logEntryVariant", data);
        if (paginator != null) {
            DateFormatter df = new DateFormatter(access, Format.DEFAULT);
            try (OutputStream out = startRenderStreamingHtml(req, res, "gitiles.repositoryIndex", data)) {
                Writer w = newWriter(out, res);
                new LogSoyData(req, access, "oneline").renderStreaming(paginator, "HEAD", renderer, w, df);
                w.flush();
            }
        } else {
            renderHtml(req, res, "gitiles.repositoryIndex", data);
        }
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) OutputStream(java.io.OutputStream) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) RevObject(org.eclipse.jgit.revwalk.RevObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Writer(java.io.Writer)

Example 5 with RevObject

use of org.eclipse.jgit.revwalk.RevObject in project gitiles by GerritCodeReview.

the class RevisionParser method parse.

Result parse(String path) throws IOException {
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    try (RevWalk walk = new RevWalk(repo)) {
        Revision oldRevision = null;
        StringBuilder b = new StringBuilder();
        boolean first = true;
        for (String part : PathUtil.SPLITTER.split(path)) {
            if (part.isEmpty()) {
                // No valid revision contains empty segments.
                return null;
            }
            if (!first) {
                b.append('/');
            }
            if (oldRevision == null) {
                int dots = part.indexOf("..");
                int firstParent = part.indexOf("^!");
                if (dots == 0 || firstParent == 0) {
                    return null;
                } else if (dots > 0) {
                    b.append(part, 0, dots);
                    String oldName = b.toString();
                    if (!isValidRevision(oldName)) {
                        return null;
                    }
                    RevObject old = resolve(oldName, walk);
                    if (old == null) {
                        return null;
                    }
                    oldRevision = Revision.peel(oldName, old, walk);
                    part = part.substring(dots + 2);
                    b = new StringBuilder();
                } else if (firstParent > 0) {
                    if (firstParent != part.length() - 2) {
                        return null;
                    }
                    b.append(part, 0, part.length() - 2);
                    String name = b.toString();
                    if (!isValidRevision(name)) {
                        return null;
                    }
                    RevObject obj = resolve(name, walk);
                    if (obj == null) {
                        return null;
                    }
                    while (obj instanceof RevTag) {
                        obj = ((RevTag) obj).getObject();
                        walk.parseHeaders(obj);
                    }
                    if (!(obj instanceof RevCommit)) {
                        // Not a commit, ^! is invalid.
                        return null;
                    }
                    RevCommit c = (RevCommit) obj;
                    if (c.getParentCount() > 0) {
                        oldRevision = Revision.peeled(name + "^", c.getParent(0));
                    } else {
                        oldRevision = Revision.NULL;
                    }
                    Result result = new Result(Revision.peeled(name, c), oldRevision, path.substring(name.length() + 2));
                    return isVisible(walk, result) ? result : null;
                }
            }
            b.append(part);
            String name = b.toString();
            if (!isValidRevision(name)) {
                return null;
            }
            RevObject obj = resolve(name, walk);
            if (obj != null) {
                int pathStart;
                if (oldRevision == null) {
                    // foo
                    pathStart = name.length();
                } else {
                    // foo..bar (foo may be empty)
                    pathStart = oldRevision.getName().length() + 2 + name.length();
                }
                Result result = new Result(Revision.peel(name, obj, walk), oldRevision, path.substring(pathStart));
                return isVisible(walk, result) ? result : null;
            }
            first = false;
        }
        return null;
    }
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) RevObject(org.eclipse.jgit.revwalk.RevObject) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RevObject (org.eclipse.jgit.revwalk.RevObject)25 RevWalk (org.eclipse.jgit.revwalk.RevWalk)14 IOException (java.io.IOException)10 ObjectId (org.eclipse.jgit.lib.ObjectId)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Repository (org.eclipse.jgit.lib.Repository)8 Ref (org.eclipse.jgit.lib.Ref)7 RevTag (org.eclipse.jgit.revwalk.RevTag)6 RevTree (org.eclipse.jgit.revwalk.RevTree)6 Map (java.util.Map)4 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)4 TagCommand (org.eclipse.jgit.api.TagCommand)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 PersonIdent (org.eclipse.jgit.lib.PersonIdent)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)2 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 OutputStream (java.io.OutputStream)2 Writer (java.io.Writer)2