use of org.eclipse.jgit.revwalk.RevObject in project gitiles by GerritCodeReview.
the class LogServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
Repository repo = ServletUtils.getRepository(req);
GitilesView view = getView(req, repo);
Paginator paginator = null;
try {
GitilesAccess access = getAccess(req);
paginator = newPaginator(repo, view, access);
if (paginator == null) {
res.setStatus(SC_NOT_FOUND);
return;
}
DateFormatter df = new DateFormatter(access, Format.DEFAULT);
// Allow the user to select a logView variant with the "pretty" param.
String pretty = Iterables.getFirst(view.getParameters().get(PRETTY_PARAM), "default");
Map<String, Object> data = Maps.newHashMapWithExpectedSize(2);
if (!view.getRevision().nameIsId()) {
List<Map<String, Object>> tags = Lists.newArrayListWithExpectedSize(1);
for (RevObject o : RevisionServlet.listObjects(paginator.getWalk(), view.getRevision())) {
if (o instanceof RevTag) {
tags.add(new TagSoyData(linkifier, req).toSoyData((RevTag) o, df));
}
}
if (!tags.isEmpty()) {
data.put("tags", tags);
}
}
String title = "Log - ";
if (view.getOldRevision() != Revision.NULL) {
title += view.getRevisionRange();
} else {
title += view.getRevision().getName();
}
data.put("title", title);
try (OutputStream out = startRenderStreamingHtml(req, res, "gitiles.logDetail", data)) {
Writer w = newWriter(out, res);
new LogSoyData(req, access, pretty).renderStreaming(paginator, null, renderer, w, df);
w.flush();
}
} catch (RevWalkException e) {
log.warn("Error in rev walk", e);
res.setStatus(SC_INTERNAL_SERVER_ERROR);
return;
} finally {
if (paginator != null) {
paginator.getWalk().close();
}
}
}
use of org.eclipse.jgit.revwalk.RevObject in project che by eclipse.
the class JGitConnection method tagCreate.
@Override
public Tag tagCreate(TagCreateParams params) throws GitException {
String commit = params.getCommit();
if (commit == null) {
commit = Constants.HEAD;
}
try {
RevWalk revWalk = new RevWalk(repository);
RevObject revObject;
try {
revObject = revWalk.parseAny(repository.resolve(commit));
} finally {
revWalk.close();
}
TagCommand tagCommand = getGit().tag().setName(params.getName()).setObjectId(revObject).setMessage(params.getMessage()).setForceUpdate(params.isForce());
GitUser tagger = getUser();
if (tagger != null) {
tagCommand.setTagger(new PersonIdent(tagger.getName(), tagger.getEmail()));
}
Ref revTagRef = tagCommand.call();
RevTag revTag = revWalk.parseTag(revTagRef.getLeaf().getObjectId());
return newDto(Tag.class).withName(revTag.getTagName());
} catch (IOException | GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.jgit.revwalk.RevObject in project gitblit by gitblit.
the class JGitUtils method getRefs.
/**
* Returns a list of references in the repository matching "refs". If the
* repository is null or empty, an empty list is returned.
*
* @param repository
* @param refs
* if unspecified, all refs are returned
* @param fullName
* if true, /refs/something/yadayadayada is returned. If false,
* yadayadayada is returned.
* @param maxCount
* if < 0, all references are returned
* @param offset
* if maxCount provided sets the starting point of the records to return
* @return list of references
*/
private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName, int maxCount, int offset) {
List<RefModel> list = new ArrayList<RefModel>();
if (maxCount == 0) {
return list;
}
if (!hasCommits(repository)) {
return list;
}
try {
Map<String, Ref> map = repository.getRefDatabase().getRefs(refs);
RevWalk rw = new RevWalk(repository);
for (Entry<String, Ref> entry : map.entrySet()) {
Ref ref = entry.getValue();
RevObject object = rw.parseAny(ref.getObjectId());
String name = entry.getKey();
if (fullName && !StringUtils.isEmpty(refs)) {
name = refs + name;
}
list.add(new RefModel(name, ref, object));
}
rw.dispose();
Collections.sort(list);
Collections.reverse(list);
if (maxCount > 0 && list.size() > maxCount) {
if (offset < 0) {
offset = 0;
}
int endIndex = offset + maxCount;
if (endIndex > list.size()) {
endIndex = list.size();
}
list = new ArrayList<RefModel>(list.subList(offset, endIndex));
}
} catch (IOException e) {
error(e, repository, "{0} failed to retrieve {1}", refs);
}
return list;
}
use of org.eclipse.jgit.revwalk.RevObject in project gerrit by GerritCodeReview.
the class SubmitOnPushIT method assertTag.
private void assertTag(Project.NameKey project, String branch, PushOneCommit.Tag tag) throws Exception {
try (Repository repo = repoManager.openRepository(project)) {
Ref tagRef = repo.findRef(tag.name);
assertThat(tagRef).isNotNull();
ObjectId taggedCommit = null;
if (tag instanceof PushOneCommit.AnnotatedTag) {
PushOneCommit.AnnotatedTag annotatedTag = (PushOneCommit.AnnotatedTag) tag;
try (RevWalk rw = new RevWalk(repo)) {
RevObject object = rw.parseAny(tagRef.getObjectId());
assertThat(object).isInstanceOf(RevTag.class);
RevTag tagObject = (RevTag) object;
assertThat(tagObject.getFullMessage()).isEqualTo(annotatedTag.message);
assertThat(tagObject.getTaggerIdent()).isEqualTo(annotatedTag.tagger);
taggedCommit = tagObject.getObject();
}
} else {
taggedCommit = tagRef.getObjectId();
}
ObjectId headCommit = repo.exactRef(branch).getObjectId();
assertThat(taggedCommit).isNotNull();
assertThat(taggedCommit).isEqualTo(headCommit);
}
}
use of org.eclipse.jgit.revwalk.RevObject in project gerrit by GerritCodeReview.
the class ConfigChangeIT method readProjectConfig.
private Config readProjectConfig() throws Exception {
RevWalk rw = testRepo.getRevWalk();
RevTree tree = rw.parseTree(testRepo.getRepository().resolve("HEAD"));
RevObject obj = rw.parseAny(testRepo.get(tree, "project.config"));
ObjectLoader loader = rw.getObjectReader().open(obj);
String text = new String(loader.getCachedBytes(), UTF_8);
Config cfg = new Config();
cfg.fromText(text);
return cfg;
}
Aggregations