List of usage examples for org.eclipse.jgit.lib ObjectId fromString
public static ObjectId fromString(String str)
From source file:com.google.gerrit.server.project.FilesCollection.java
License:Apache License
@Override public FileResource parse(BranchResource parent, IdString id) { return new FileResource(parent.getControl(), ObjectId.fromString(parent.getRevision()), id.get()); }
From source file:com.google.gerrit.server.query.change.ChangeData.java
License:Apache License
private boolean loadCommitData() throws OrmException, RepositoryNotFoundException, IOException, MissingObjectException, IncorrectObjectTypeException { PatchSet ps = currentPatchSet();// www. j a va 2 s .c o m if (ps == null) { return false; } String sha1 = ps.getRevision().get(); try (Repository repo = repoManager.openRepository(change().getProject()); RevWalk walk = new RevWalk(repo)) { RevCommit c = walk.parseCommit(ObjectId.fromString(sha1)); commitMessage = c.getFullMessage(); commitFooters = c.getFooterLines(); author = c.getAuthorIdent(); committer = c.getCommitterIdent(); } return true; }
From source file:com.google.gerrit.server.query.change.ChangeData.java
License:Apache License
public Boolean isMergeable() throws OrmException { if (mergeable == null) { Change c = change();// w ww . ja v a 2 s . c om if (c == null) { return null; } if (c.getStatus() == Change.Status.MERGED) { mergeable = true; } else { PatchSet ps = currentPatchSet(); if (ps == null || !changeControl().isPatchVisible(ps, db)) { return null; } try (Repository repo = repoManager.openRepository(c.getProject())) { Ref ref = repo.getRefDatabase().exactRef(c.getDest().get()); SubmitTypeRecord rec = new SubmitRuleEvaluator(this).getSubmitType(); if (rec.status != SubmitTypeRecord.Status.OK) { throw new OrmException("Error in mergeability check: " + rec.errorMessage); } String mergeStrategy = mergeUtilFactory.create(projectCache.get(c.getProject())) .mergeStrategyName(); mergeable = mergeabilityCache.get(ObjectId.fromString(ps.getRevision().get()), ref, rec.type, mergeStrategy, c.getDest(), repo, db); } catch (IOException e) { throw new OrmException(e); } } } return mergeable; }
From source file:com.google.gerrit.server.query.change.ConflictsPredicate.java
License:Apache License
private static List<Predicate<ChangeData>> predicates(final Arguments args, String value, List<Change> changes) throws OrmException { List<Predicate<ChangeData>> changePredicates = Lists.newArrayListWithCapacity(changes.size()); final Provider<ReviewDb> db = args.db; for (final Change c : changes) { final ChangeDataCache changeDataCache = new ChangeDataCache(c, db, args.changeDataFactory, args.projectCache);//from ww w.j a v a2 s .c o m List<String> files = args.changeDataFactory.create(db.get(), c).currentFilePaths(); List<Predicate<ChangeData>> filePredicates = Lists.newArrayListWithCapacity(files.size()); for (String file : files) { filePredicates.add(new EqualsPathPredicate(ChangeQueryBuilder.FIELD_PATH, file)); } List<Predicate<ChangeData>> predicatesForOneChange = Lists.newArrayListWithCapacity(5); predicatesForOneChange.add(not(new LegacyChangeIdPredicate(args.getSchema(), c.getId()))); predicatesForOneChange.add(new ProjectPredicate(c.getProject().get())); predicatesForOneChange.add(new RefPredicate(c.getDest().get())); predicatesForOneChange.add(or(filePredicates)); predicatesForOneChange .add(new OperatorPredicate<ChangeData>(ChangeQueryBuilder.FIELD_CONFLICTS, value) { @Override public boolean match(ChangeData object) throws OrmException { Change otherChange = object.change(); if (otherChange == null) { return false; } if (!otherChange.getDest().equals(c.getDest())) { return false; } SubmitType submitType = getSubmitType(object); if (submitType == null) { return false; } ObjectId other = ObjectId.fromString(object.currentPatchSet().getRevision().get()); ConflictKey conflictsKey = new ConflictKey(changeDataCache.getTestAgainst(), other, submitType, changeDataCache.getProjectState().isUseContentMerge()); Boolean conflicts = args.conflictsCache.getIfPresent(conflictsKey); if (conflicts != null) { return conflicts; } try (Repository repo = args.repoManager.openRepository(otherChange.getProject()); CodeReviewRevWalk rw = CodeReviewCommit.newRevWalk(repo)) { RevFlag canMergeFlag = rw.newFlag("CAN_MERGE"); CodeReviewCommit commit = rw.parseCommit(changeDataCache.getTestAgainst()); SubmitStrategy strategy = args.submitStrategyFactory.create(submitType, db.get(), repo, rw, null, canMergeFlag, getAlreadyAccepted(repo, rw, commit), otherChange.getDest(), null); CodeReviewCommit otherCommit = rw.parseCommit(other); otherCommit.add(canMergeFlag); conflicts = !strategy.dryRun(commit, otherCommit); args.conflictsCache.put(conflictsKey, conflicts); return conflicts; } catch (MergeException | NoSuchProjectException | IOException e) { throw new IllegalStateException(e); } } @Override public int getCost() { return 5; } private SubmitType getSubmitType(ChangeData cd) throws OrmException { SubmitTypeRecord r = new SubmitRuleEvaluator(cd).getSubmitType(); if (r.status != SubmitTypeRecord.Status.OK) { return null; } return r.type; } private Set<RevCommit> getAlreadyAccepted(Repository repo, RevWalk rw, CodeReviewCommit tip) throws MergeException { Set<RevCommit> alreadyAccepted = Sets.newHashSet(); if (tip != null) { alreadyAccepted.add(tip); } try { for (ObjectId id : changeDataCache.getAlreadyAccepted(repo)) { try { alreadyAccepted.add(rw.parseCommit(id)); } catch (IncorrectObjectTypeException iote) { // Not a commit? Skip over it. } } } catch (IOException e) { throw new MergeException("Failed to determine already accepted commits.", e); } return alreadyAccepted; } }); changePredicates.add(and(predicatesForOneChange)); } return changePredicates; }
From source file:com.google.gerrit.server.query.change.IsMergePredicate.java
License:Apache License
@Override public boolean match(ChangeData cd) throws OrmException { ObjectId id = ObjectId.fromString(cd.currentPatchSet().getRevision().get()); try (Repository repo = args.repoManager.openRepository(cd.change().getProject()); RevWalk rw = CodeReviewCommit.newRevWalk(repo)) { RevCommit commit = rw.parseCommit(id); return commit.getParentCount() > 1; } catch (IOException e) { throw new IllegalStateException(e); }//from w ww.j a va 2 s . c o m }
From source file:com.google.gerrit.server.query.change.MessagePredicate.java
License:Apache License
@Override public boolean match(ChangeData object) throws OrmException { final PatchSet patchSet = object.currentPatchSet(db); if (patchSet == null) { return false; }//from w ww . ja va 2 s . c o m final RevId revision = patchSet.getRevision(); if (revision == null) { return false; } final AnyObjectId objectId = ObjectId.fromString(revision.get()); if (objectId == null) { return false; } final Change change = object.change(db); if (change == null) { return false; } final Project.NameKey projectName = change.getProject(); if (projectName == null) { return false; } try { final Repository repo = repoManager.openRepository(projectName); try { final RevWalk rw = new RevWalk(repo); try { return rFilter.include(rw, rw.parseCommit(objectId)); } finally { rw.release(); } } finally { repo.close(); } } catch (RepositoryNotFoundException e) { log.error("Repository \"" + projectName.get() + "\" unknown.", e); } catch (MissingObjectException e) { log.error(projectName.get() + "\" commit does not exist.", e); } catch (IncorrectObjectTypeException e) { log.error(projectName.get() + "\" revision is not a commit.", e); } catch (IOException e) { log.error("Could not search for commit message in \"" + projectName.get() + "\" repository.", e); } return false; }
From source file:com.google.gerrit.server.query.change.RevWalkPredicate.java
License:Apache License
@Override public boolean match(ChangeData object) throws OrmException { final PatchSet patchSet = object.currentPatchSet(); if (patchSet == null) { return false; }//from ww w . j a v a2 s . co m final RevId revision = patchSet.getRevision(); if (revision == null) { return false; } final AnyObjectId objectId = ObjectId.fromString(revision.get()); if (objectId == null) { return false; } Change change = object.change(); if (change == null) { return false; } final Project.NameKey projectName = change.getProject(); if (projectName == null) { return false; } Arguments args = new Arguments(patchSet, revision, objectId, change, projectName); try { final Repository repo = repoManager.openRepository(projectName); try { final RevWalk rw = new RevWalk(repo); try { return match(repo, rw, args); } finally { rw.release(); } } finally { repo.close(); } } catch (RepositoryNotFoundException e) { log.error("Repository \"" + projectName.get() + "\" unknown.", e); } catch (IOException e) { log.error(projectName.get() + " cannot be read as a repository", e); } return false; }
From source file:com.google.gitiles.GitilesViewTest.java
License:Open Source License
public void testRefWithRevision() throws Exception { ObjectId id = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); GitilesView view = GitilesView.revision().copyFrom(HOST).setRepositoryName("foo/bar") .setRevision(Revision.unpeeled("master", id)).build(); assertEquals("/b", view.getServletPath()); assertEquals(Type.REVISION, view.getType()); assertEquals("host", view.getHostName()); assertEquals("foo/bar", view.getRepositoryName()); assertEquals(id, view.getRevision().getId()); assertEquals("master", view.getRevision().getName()); assertNull(view.getTreePath());//from w w w. j a v a 2s. c o m assertTrue(HOST.getParameters().isEmpty()); assertEquals("/b/foo/bar/+show/master", view.toUrl()); assertEquals(ImmutableList.of(breadcrumb("host", "/b/?format=HTML"), breadcrumb("foo/bar", "/b/foo/bar/"), breadcrumb("master", "/b/foo/bar/+show/master")), view.getBreadcrumbs()); }
From source file:com.google.gitiles.GitilesViewTest.java
License:Open Source License
public void testNoPathComponents() throws Exception { ObjectId id = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); GitilesView view = GitilesView.path().copyFrom(HOST).setRepositoryName("foo/bar") .setRevision(Revision.unpeeled("master", id)).setTreePath("/").build(); assertEquals("/b", view.getServletPath()); assertEquals(Type.PATH, view.getType()); assertEquals("host", view.getHostName()); assertEquals("foo/bar", view.getRepositoryName()); assertEquals(id, view.getRevision().getId()); assertEquals("master", view.getRevision().getName()); assertEquals("", view.getTreePath()); assertTrue(HOST.getParameters().isEmpty()); assertEquals("/b/foo/bar/+/master/", view.toUrl()); assertEquals(/* w w w . j a va2 s . c o m*/ ImmutableList.of(breadcrumb("host", "/b/?format=HTML"), breadcrumb("foo/bar", "/b/foo/bar/"), breadcrumb("master", "/b/foo/bar/+show/master"), breadcrumb(".", "/b/foo/bar/+/master/")), view.getBreadcrumbs()); }
From source file:com.google.gitiles.GitilesViewTest.java
License:Open Source License
public void testOnePathComponent() throws Exception { ObjectId id = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); GitilesView view = GitilesView.path().copyFrom(HOST).setRepositoryName("foo/bar") .setRevision(Revision.unpeeled("master", id)).setTreePath("/file").build(); assertEquals("/b", view.getServletPath()); assertEquals(Type.PATH, view.getType()); assertEquals("host", view.getHostName()); assertEquals("foo/bar", view.getRepositoryName()); assertEquals(id, view.getRevision().getId()); assertEquals("master", view.getRevision().getName()); assertEquals("file", view.getTreePath()); assertTrue(HOST.getParameters().isEmpty()); assertEquals("/b/foo/bar/+/master/file", view.toUrl()); assertEquals(ImmutableList.of(breadcrumb("host", "/b/?format=HTML"), breadcrumb("foo/bar", "/b/foo/bar/"), breadcrumb("master", "/b/foo/bar/+show/master"), breadcrumb(".", "/b/foo/bar/+/master/"), breadcrumb("file", "/b/foo/bar/+/master/file")), view.getBreadcrumbs()); }