List of usage examples for org.eclipse.jgit.lib ObjectId fromString
public static ObjectId fromString(String str)
From source file:com.google.gerrit.acceptance.server.change.ConsistencyCheckerIT.java
License:Apache License
private void updatePatchSetRef(PatchSet ps) throws Exception { testRepo.update(ps.getId().toRefName(), ObjectId.fromString(ps.getRevision().get())); }
From source file:com.google.gerrit.acceptance.server.change.ConsistencyCheckerIT.java
License:Apache License
private RevCommit parseCommit(PatchSet ps) throws Exception { RevCommit commit = testRepo.getRevWalk().parseCommit(ObjectId.fromString(ps.getRevision().get())); testRepo.getRevWalk().parseBody(commit); return commit; }
From source file:com.google.gerrit.acceptance.server.change.GetRelatedIT.java
License:Apache License
@Test public void getRelatedEdit() throws Exception { RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create(); String id1 = getChangeId(c1_1); RevCommit c2_1 = commitBuilder().add("b.txt", "2").message("subject: 2").create(); String id2 = getChangeId(c2_1); RevCommit c3_1 = commitBuilder().add("c.txt", "3").message("subject: 3").create(); String id3 = getChangeId(c3_1); pushHead(testRepo, "refs/for/master", false); Change ch2 = getChange(c2_1).change(); editModifier.createEdit(ch2, getPatchSet(ch2)); editModifier.modifyFile(editUtil.byChange(ch2).get(), "a.txt", RestSession.newRawInput(new byte[] { 'a' })); ObjectId editRev = ObjectId.fromString(editUtil.byChange(ch2).get().getRevision().get()); PatchSet.Id ps1_1 = getPatchSetId(c1_1); PatchSet.Id ps2_1 = getPatchSetId(c2_1); PatchSet.Id ps2_edit = new PatchSet.Id(ch2.getId(), 0); PatchSet.Id ps3_1 = getPatchSetId(c3_1); for (PatchSet.Id ps : ImmutableList.of(ps1_1, ps2_1, ps3_1)) { assertRelated(ps, changeAndCommit(id3, c3_1, 1, 1), changeAndCommit(id2, c2_1, 1, 1), changeAndCommit(id1, c1_1, 1, 1)); }/*from ww w. ja v a 2s . c o m*/ assertRelated(ps2_edit, changeAndCommit(id3, c3_1, 1, 1), changeAndCommit(id2, editRev, 0, 1), changeAndCommit(id1, c1_1, 1, 1)); }
From source file:com.google.gerrit.acceptance.server.change.PatchListCacheIT.java
License:Apache License
private ObjectId getCurrentRevisionId(String changeId) throws RestApiException { return ObjectId.fromString(gApi.changes().id(changeId).get().currentRevision); }
From source file:com.google.gerrit.httpd.raw.CatServlet.java
License:Apache License
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse rsp) throws IOException { String keyStr = req.getPathInfo(); // We shouldn't have to do this extra decode pass, but somehow we // are now receiving our "^1" suffix as "%5E1", which confuses us // downstream. Other times we get our embedded "," as "%2C", which // is equally bad. And yet when these happen a "%2F" is left as-is, // rather than escaped as "%252F", which makes me feel really really // uncomfortable with a blind decode right here. ////w w w. jav a 2 s .c om keyStr = Url.decode(keyStr); if (!keyStr.startsWith("/")) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } keyStr = keyStr.substring(1); final Patch.Key patchKey; final int side; { final int c = keyStr.lastIndexOf('^'); if (c == 0) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } if (c < 0) { side = 0; } else { try { side = Integer.parseInt(keyStr.substring(c + 1)); keyStr = keyStr.substring(0, c); } catch (NumberFormatException e) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } try { patchKey = Patch.Key.parse(keyStr); } catch (NumberFormatException e) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } final Change.Id changeId = patchKey.getParentKey().getParentKey(); final Project project; final String revision; try { final ReviewDb db = requestDb.get(); final ChangeControl control = changeControl.validateFor(changeId, userProvider.get()); project = control.getProject(); if (patchKey.getParentKey().get() == 0) { // change edit try { Optional<ChangeEdit> edit = changeEditUtil.byChange(control.getChange()); if (edit.isPresent()) { revision = edit.get().getRevision().get(); } else { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } catch (AuthException e) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } else { PatchSet patchSet = db.patchSets().get(patchKey.getParentKey()); if (patchSet == null) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } revision = patchSet.getRevision().get(); } } catch (NoSuchChangeException e) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (OrmException e) { getServletContext().log("Cannot query database", e); rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } ObjectLoader blobLoader; RevCommit fromCommit; String suffix; String path = patchKey.getFileName(); try (Repository repo = repoManager.openRepository(project.getNameKey())) { try (ObjectReader reader = repo.newObjectReader(); RevWalk rw = new RevWalk(reader)) { RevCommit c; c = rw.parseCommit(ObjectId.fromString(revision)); if (side == 0) { fromCommit = c; suffix = "new"; } else if (1 <= side && side - 1 < c.getParentCount()) { fromCommit = rw.parseCommit(c.getParent(side - 1)); if (c.getParentCount() == 1) { suffix = "old"; } else { suffix = "old" + side; } } else { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } try (TreeWalk tw = TreeWalk.forPath(reader, path, fromCommit.getTree())) { if (tw == null) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } if (tw.getFileMode(0).getObjectType() == Constants.OBJ_BLOB) { blobLoader = reader.open(tw.getObjectId(0), Constants.OBJ_BLOB); } else { rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } } } catch (RepositoryNotFoundException e) { getServletContext().log("Cannot open repository", e); rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } catch (IOException | RuntimeException e) { getServletContext().log("Cannot read repository", e); rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } final byte[] raw = blobLoader.isLarge() ? null : blobLoader.getCachedBytes(); final long when = fromCommit.getCommitTime() * 1000L; rsp.setDateHeader("Last-Modified", when); CacheHeaders.setNotCacheable(rsp); try (OutputStream out = openOutputStream(req, rsp, blobLoader, fromCommit, when, path, suffix, raw)) { if (raw != null) { out.write(raw); } else { blobLoader.copyTo(out); } } }
From source file:com.google.gerrit.httpd.rpc.changedetail.IncludedInDetailFactory.java
License:Apache License
@Override public IncludedInDetail call() throws OrmException, NoSuchChangeException, IOException, InvalidRevisionException { control = changeControlFactory.validateFor(changeId); final PatchSet patch = db.patchSets().get(control.getChange().currentPatchSetId()); final Repository repo = repoManager.openRepository(control.getProject().getNameKey()); try {// w w w .ja v a 2 s . c o m final RevWalk rw = new RevWalk(repo); try { rw.setRetainBody(false); final RevCommit rev; try { rev = rw.parseCommit(ObjectId.fromString(patch.getRevision().get())); } catch (IncorrectObjectTypeException err) { throw new InvalidRevisionException(); } catch (MissingObjectException err) { throw new InvalidRevisionException(); } detail = new IncludedInDetail(); detail.setBranches(includedIn(repo, rw, rev, Constants.R_HEADS)); detail.setTags(includedIn(repo, rw, rev, Constants.R_TAGS)); return detail; } finally { rw.release(); } } finally { repo.close(); } }
From source file:com.google.gerrit.httpd.rpc.changedetail.PatchSetDetailFactory.java
License:Apache License
private ObjectId toObjectId(final PatchSet.Id psId) throws OrmException, NoSuchEntityException { final PatchSet ps = db.patchSets().get(psId); if (ps == null) { throw new NoSuchEntityException(); }//from w w w . ja va 2 s .c om try { return ObjectId.fromString(ps.getRevision().get()); } catch (IllegalArgumentException e) { log.error("Patch set " + psId + " has invalid revision"); throw new NoSuchEntityException(); } }
From source file:com.google.gerrit.httpd.rpc.patch.PatchScriptFactory.java
License:Apache License
private ObjectId toObjectId(final ReviewDb db, final PatchSet.Id psId) throws OrmException, NoSuchChangeException { if (!changeId.equals(psId.getParentKey())) { throw new NoSuchChangeException(changeId); }/*from w w w . ja v a 2s . c o m*/ final PatchSet ps = db.patchSets().get(psId); if (ps == null || ps.getRevision() == null || ps.getRevision().get() == null) { throw new NoSuchChangeException(changeId); } try { return ObjectId.fromString(ps.getRevision().get()); } catch (IllegalArgumentException e) { log.error("Patch set " + psId + " has invalid revision"); throw new NoSuchChangeException(changeId, e); } }
From source file:com.google.gerrit.httpd.rpc.project.ListBranchesTest.java
License:Apache License
@Override @Before// w w w .ja v a 2 s . c o m public void setUp() throws Exception { super.setUp(); idA = ObjectId.fromString("df84c2f4f7ce7e0b25cdeac84b8870bcff319885"); name = new Project.NameKey("test"); realDb = createBareRepository(); mockDb = createStrictMock(Repository.class); pc = createStrictMock(ProjectControl.class); pcf = createStrictMock(ProjectControl.Factory.class); grm = createStrictMock(GitRepositoryManager.class); refMocks = new ArrayList<RefControl>(); }
From source file:com.google.gerrit.httpd.rpc.project.ProjectAdminServiceImpl.java
License:Apache License
private static ObjectId getBase(final String baseRevision) { if (baseRevision != null && !baseRevision.isEmpty()) { return ObjectId.fromString(baseRevision); }/*from w w w . j ava2 s . c o m*/ return null; }