use of org.eclipse.jgit.lib.Repository 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.lib.Repository in project gerrit by GerritCodeReview.
the class ChangeEditIT method updateMessageRest.
@Test
public void updateMessageRest() throws Exception {
adminRestSession.get(urlEditMessage(changeId, false)).assertNotFound();
EditMessage.Input in = new EditMessage.Input();
in.message = String.format("New commit message\n\n" + CONTENT_NEW2_STR + "\n\nChange-Id: %s\n", changeId);
adminRestSession.put(urlEditMessage(changeId, false), in).assertNoContent();
RestResponse r = adminRestSession.getJsonAccept(urlEditMessage(changeId, false));
r.assertOK();
assertThat(readContentFromJson(r)).isEqualTo(in.message);
String commitMessage = gApi.changes().id(changeId).edit().getCommitMessage();
assertThat(commitMessage).isEqualTo(in.message);
in.message = String.format("New commit message2\n\nChange-Id: %s\n", changeId);
adminRestSession.put(urlEditMessage(changeId, false), in).assertNoContent();
String updatedCommitMessage = gApi.changes().id(changeId).edit().getCommitMessage();
assertThat(updatedCommitMessage).isEqualTo(in.message);
r = adminRestSession.getJsonAccept(urlEditMessage(changeId, true));
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(ObjectId.fromString(ps.getRevision().get()));
assertThat(readContentFromJson(r)).isEqualTo(commit.getFullMessage());
}
PublishChangeEditInput publishInput = new PublishChangeEditInput();
publishInput.notify = NotifyHandling.NONE;
gApi.changes().id(changeId).edit().publish(publishInput);
assertChangeMessages(changeId, ImmutableList.of("Uploaded patch set 1.", "Uploaded patch set 2.", "Patch Set 3: Commit message was updated."));
}
use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class AbstractPushForReview method mergedOptionFailsWhenCommitIsMergedOnOtherBranch.
@Test
public void mergedOptionFailsWhenCommitIsMergedOnOtherBranch() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master");
r.assertOkStatus();
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(r.getChangeId()).current().submit();
try (Repository repo = repoManager.openRepository(project)) {
TestRepository<?> tr = new TestRepository<>(repo);
tr.branch("refs/heads/branch").commit().message("Initial commit on branch").create();
}
pushTo("refs/for/master%merged").assertErrorStatus("not merged into branch");
}
use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class CreateProjectIT method assertEmptyCommit.
private void assertEmptyCommit(String projectName, String... refs) throws Exception {
Project.NameKey projectKey = new Project.NameKey(projectName);
try (Repository repo = repoManager.openRepository(projectKey);
RevWalk rw = new RevWalk(repo);
TreeWalk tw = new TreeWalk(rw.getObjectReader())) {
for (String ref : refs) {
RevCommit commit = rw.lookupCommit(repo.exactRef(ref).getObjectId());
rw.parseBody(commit);
tw.addTree(commit.getTree());
assertThat(tw.next()).isFalse();
tw.reset();
}
}
}
use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class NoteDbOnlyIT method noRetryOnLockFailureWithoutAtomicUpdates.
@Test
public void noRetryOnLockFailureWithoutAtomicUpdates() throws Exception {
assume().that(notesMigration.fuseUpdates()).isFalse();
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
String master = "refs/heads/master";
ObjectId initial;
try (Repository repo = repoManager.openRepository(project)) {
initial = repo.exactRef(master).getObjectId();
}
AtomicInteger updateRepoCalledCount = new AtomicInteger();
AtomicInteger updateChangeCalledCount = new AtomicInteger();
AtomicInteger afterUpdateReposCalledCount = new AtomicInteger();
try {
retryHelper.execute(batchUpdateFactory -> {
try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
bu.addOp(id, new UpdateRefAndAddMessageOp(updateRepoCalledCount, updateChangeCalledCount));
bu.execute(new ConcurrentWritingListener(afterUpdateReposCalledCount));
}
return null;
});
assert_().fail("expected RestApiException");
} catch (RestApiException e) {
// Expected.
}
assertThat(updateRepoCalledCount.get()).isEqualTo(1);
assertThat(afterUpdateReposCalledCount.get()).isEqualTo(1);
assertThat(updateChangeCalledCount.get()).isEqualTo(0);
// updateChange was never called, so no message was ever added.
assertThat(getMessages(id)).doesNotContain(UpdateRefAndAddMessageOp.CHANGE_MESSAGE);
try (Repository repo = repoManager.openRepository(project)) {
// Op lost the race, so the other writer's commit happened first. Op didn't retry, because the
// ref updates weren't atomic, so it didn't throw LockFailureException on failure.
assertThat(commitMessages(repo, initial, repo.exactRef(master).getObjectId())).containsExactly(ConcurrentWritingListener.MSG_PREFIX + "1");
}
}
Aggregations