List of usage examples for org.eclipse.jgit.revplot PlotWalk PlotWalk
public PlotWalk(Repository repo)
From source file:com.gitblit.servlet.BranchGraphServlet.java
License:Eclipse Distribution License
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { InputStream is = null;/*from ww w .ja v a 2 s . c om*/ Repository r = null; PlotWalk rw = null; try { String repository = request.getParameter("r"); if (StringUtils.isEmpty(repository)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().append("Bad request"); return; } String objectId = request.getParameter("h"); String length = request.getParameter("l"); r = repositoryManager.getRepository(repository); if (r == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().append("Bad request"); return; } rw = new PlotWalk(r); if (StringUtils.isEmpty(objectId)) { objectId = JGitUtils.getHEADRef(r); } ObjectId id = r.resolve(objectId); if (id == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().append("Bad request"); return; } rw.markStart(rw.lookupCommit(id)); // default to the items-per-page setting, unless specified int maxCommits = settings.getInteger(Keys.web.itemsPerPage, 50); int requestedCommits = maxCommits; if (!StringUtils.isEmpty(length)) { int l = Integer.parseInt(length); if (l > 0) { requestedCommits = l; } } // fetch the requested commits plus some extra so that the last // commit displayed *likely* has correct lane assignments CommitList commitList = new CommitList(); commitList.source(rw); commitList.fillTo(2 * Math.max(requestedCommits, maxCommits)); // determine the appropriate width for the image int numLanes = 1; int numCommits = Math.min(requestedCommits, commitList.size()); if (numCommits > 1) { // determine graph width Set<String> parents = new TreeSet<String>(); for (int i = 0; i < commitList.size(); i++) { PlotCommit<Lane> commit = commitList.get(i); boolean checkLane = false; if (i < numCommits) { // commit in visible list checkLane = true; // remember parents for (RevCommit p : commit.getParents()) { parents.add(p.getName()); } } else if (parents.contains(commit.getName())) { // commit outside visible list, but it is a parent of a // commit in the visible list so we need to know it's lane // assignment checkLane = true; } if (checkLane) { int pos = commit.getLane().getPosition(); numLanes = Math.max(numLanes, pos + 1); } } } int graphWidth = numLanes * LANE_WIDTH + RIGHT_PAD; int rowHeight = ROW_HEIGHT; // create an image buffer and render the lanes BufferedImage image = new BufferedImage(graphWidth, rowHeight * numCommits, BufferedImage.TYPE_INT_ARGB); Graphics2D g = null; try { g = image.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); LanesRenderer renderer = new LanesRenderer(); for (int i = 0; i < commitList.size(); i++) { PlotCommit<Lane> commit = commitList.get(i); Graphics row = g.create(0, i * rowHeight, graphWidth, rowHeight); try { renderer.paint(row, commit, rowHeight, graphWidth); } finally { row.dispose(); row = null; } } } finally { if (g != null) { g.dispose(); g = null; } } // write the image buffer to the client response.setContentType("image/png"); if (numCommits > 1) { response.setHeader("Cache-Control", "public, max-age=60, must-revalidate"); response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commitList.get(0)).getTime()); } OutputStream os = response.getOutputStream(); ImageIO.write(image, "png", os); os.flush(); image.flush(); image = null; } catch (Exception e) { e.printStackTrace(); } finally { if (is != null) { is.close(); is = null; } if (rw != null) { rw.dispose(); rw = null; } if (r != null) { r.close(); r = null; } } }
From source file:com.gitblit.tests.JGitUtilsTest.java
License:Apache License
@Test public void testPlots() throws Exception { Repository repository = GitBlitSuite.getTicgitRepository(); PlotWalk pw = new PlotWalk(repository); PlotCommitList<PlotLane> commits = new PlotCommitList<PlotLane>(); commits.source(pw);//from w w w . j a v a 2 s . c o m commits.fillTo(25); for (PlotCommit<PlotLane> commit : commits) { System.out.println(commit); } repository.close(); }
From source file:com.madgag.agit.CommitViewerActivity.java
License:Open Source License
private PlotWalk generatePlotWalk() throws IOException { long start = currentTimeMillis(); PlotWalk revWalk = new PlotWalk(repo()); for (ObjectId startId : logStartProvider.get()) { revWalk.markStart(revWalk.parseCommit(startId)); }/*from w w w . ja v a 2 s. c om*/ PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>(); plotCommitList.source(revWalk); plotCommitList.fillTo(Integer.MAX_VALUE); long duration = currentTimeMillis() - start; Log.d(TAG, "generatePlotWalk duration" + duration); return revWalk; }
From source file:de.br0tbox.gitfx.ui.sync.SynchronizationTask.java
License:Apache License
private void refreshCommits() throws MissingObjectException, IncorrectObjectTypeException, IOException { final Repository repository = projectModel.getFxProject().getGit().getRepository(); final RevWalk revWalk = new PlotWalk(repository); revWalk.markStart(revWalk.parseCommit(repository.getRef("master").getObjectId())); final JavaFxCommitList commitList = new JavaFxCommitList(); commitList.source(revWalk);/*from ww w . j av a 2 s . c o m*/ commitList.fillTo(512); PlotCommit<?>[] array = new PlotCommit[commitList.size()]; array = commitList.toArray(array); final List<GitFxCommit> commits = new ArrayList<>(array.length); for (final PlotCommit<?> commit : array) { final GitFxCommit gitFxCommit = new GitFxCommit(commit.abbreviate(7).name(), commit.getAuthorIdent().getName(), commit.getShortMessage(), commit); commits.add(gitFxCommit); } revWalk.release(); Platform.runLater(new Runnable() { @Override public void run() { projectModel.getCommitsProperty().clear(); projectModel.getCommitsProperty().addAll(commits); } }); }
From source file:de.fau.osr.core.vcs.impl.GitVcsClient.java
License:Open Source License
public Iterator<String> getCommitListForFileodification(String path) { String filename = path.replaceAll(Matcher.quoteReplacement("\\"), "/"); PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>(); PlotWalk revWalk = new PlotWalk(repo); ArrayList<String> commitIDList = new ArrayList<String>(); try {/*from w w w. j a v a 2 s.c om*/ ObjectId rootId = repo.resolve("HEAD"); if (rootId != null) { RevCommit root = revWalk.parseCommit(rootId); revWalk.markStart(root); revWalk.setTreeFilter( // VERY IMPORTANT: This works only with unix-style file paths. NO "\" allowed. AndTreeFilter.create(PathFilter.create(filename), TreeFilter.ANY_DIFF)); plotCommitList.source(revWalk); plotCommitList.fillTo(Integer.MAX_VALUE); Iterator<PlotCommit<PlotLane>> commitListIterator = plotCommitList.iterator(); while (commitListIterator.hasNext()) { commitIDList.add(commitListIterator.next().getName()); } return commitIDList.iterator(); } } catch (AmbiguousObjectException ex) { } catch (IOException ex) { } return commitIDList.iterator(); }
From source file:edu.nju.cs.inform.jgit.unfinished.ListChildrenOfCommit.java
License:Apache License
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (PlotWalk revWalk = new PlotWalk(repository)) { ObjectId rootId = repository.resolve("refs/heads/master"); RevCommit root = revWalk.parseCommit(rootId); revWalk.markStart(root);/* w w w .j a va 2 s . co m*/ PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<>(); plotCommitList.source(revWalk); plotCommitList.fillTo(Integer.MAX_VALUE); System.out.println("Printing children of commit " + root); for (RevCommit com : revWalk) { System.out.println("Child: " + com); } System.out.println("Printing with next()"); System.out.println("next: " + revWalk.next()); } } }
From source file:kr.re.ec.grigit.graph.ui.GrigitGraph.java
License:Eclipse Distribution License
@Override protected RevWalk createWalk() { // if (objects) // logger.info(CLIText.get().cannotUseObjectsWithGlog); final PlotWalk w = new PlotWalk(db); w.sort(RevSort.BOUNDARY, true);//from www.j ava 2 s .c o m w.sort(RevSort.COMMIT_TIME_DESC, true); return w; }
From source file:org.commonjava.aprox.subsys.git.GitManager.java
License:Apache License
public ChangeSummary getHeadCommit(final File f) throws GitSubsystemException { try {/*w w w. j a v a 2 s . co m*/ final ObjectId oid = repo.resolve("HEAD"); final PlotWalk pw = new PlotWalk(repo); final RevCommit rc = pw.parseCommit(oid); pw.markStart(rc); final String filepath = relativize(f); pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF)); final PlotCommitList<PlotLane> cl = new PlotCommitList<>(); cl.source(pw); cl.fillTo(1); final PlotCommit<PlotLane> commit = cl.get(0); return toChangeSummary(commit); } catch (RevisionSyntaxException | IOException e) { throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f, e.getMessage()); } }
From source file:org.commonjava.aprox.subsys.git.GitManager.java
License:Apache License
public List<ChangeSummary> getChangelog(final File f, final int start, final int length) throws GitSubsystemException { if (length == 0) { return Collections.emptyList(); }/*from w ww . jav a2 s . com*/ try { final ObjectId oid = repo.resolve(Constants.HEAD); final PlotWalk pw = new PlotWalk(repo); final RevCommit rc = pw.parseCommit(oid); toChangeSummary(rc); pw.markStart(rc); final String filepath = relativize(f); logger.info("Getting changelog for: {} (start: {}, length: {})", filepath, start, length); if (!isEmpty(filepath) && !filepath.equals("/")) { pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF)); } else { pw.setTreeFilter(TreeFilter.ANY_DIFF); } final List<ChangeSummary> changelogs = new ArrayList<ChangeSummary>(); int count = 0; final int stop = length > 0 ? length + 1 : 0; RevCommit commit = null; while ((commit = pw.next()) != null && (stop < 1 || count < stop)) { if (count < start) { count++; continue; } // printFiles( commit ); changelogs.add(toChangeSummary(commit)); count++; } if (length < -1) { final int remove = (-1 * length) - 1; for (int i = 0; i < remove; i++) { changelogs.remove(changelogs.size() - 1); } } return changelogs; } catch (RevisionSyntaxException | IOException e) { throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f, e.getMessage()); } }
From source file:org.commonjava.indy.subsys.git.GitManager.java
License:Apache License
public ChangeSummary getHeadCommit(final File f) throws GitSubsystemException { return lockAnd(me -> { try {// w ww . jav a2 s . c om final ObjectId oid = repo.resolve("HEAD"); final PlotWalk pw = new PlotWalk(repo); final RevCommit rc = pw.parseCommit(oid); pw.markStart(rc); final String filepath = relativize(f); pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF)); final PlotCommitList<PlotLane> cl = new PlotCommitList<>(); cl.source(pw); cl.fillTo(1); final PlotCommit<PlotLane> commit = cl.get(0); return toChangeSummary(commit); } catch (RevisionSyntaxException | IOException e) { throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f, e.getMessage()); } }); }