List of usage examples for org.eclipse.jgit.merge ThreeWayMerger getBaseCommit
protected RevCommit getBaseCommit(RevCommit a, RevCommit b) throws IncorrectObjectTypeException, IOException
From source file:org.eclipse.orion.server.git.objects.Diff.java
License:Open Source License
private URI getBaseLocation(URI location, Repository db, IPath path) throws URISyntaxException, IOException { String scope = path.segment(0); if (scope.contains("..")) { //$NON-NLS-1$ String[] commits = scope.split("\\.\\."); //$NON-NLS-1$ if (commits.length != 2) { throw new IllegalArgumentException( NLS.bind("Illegal scope format, expected {old}..{new}, was {0}", scope)); }//w ww.j a va 2s . c o m ThreeWayMerger merger = new ResolveMerger(db) { protected boolean mergeImpl() throws IOException { // do nothing return false; } }; // use #merge to set sourceObjects String tip0 = GitUtils.decode(commits[0]); String tip1 = GitUtils.decode(commits[1]); merger.merge(new ObjectId[] { db.resolve(tip0), db.resolve(tip1) }); RevCommit baseCommit = merger.getBaseCommit(0, 1); IPath p = new Path(GitServlet.GIT_URI + '/' + Commit.RESOURCE).append(baseCommit.getId().getName()) .append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), "parts=body", null); //$NON-NLS-1$ } else if (scope.equals(GitConstants.KEY_DIFF_CACHED)) { // HEAD is the base IPath p = new Path(GitServlet.GIT_URI + '/' + Commit.RESOURCE).append(Constants.HEAD) .append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), "parts=body", null); //$NON-NLS-1$ } else { // index is the base IPath p = new Path(GitServlet.GIT_URI + '/' + Index.RESOURCE).append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), null, null); } }
From source file:org.eclipse.orion.server.git.servlets.GitDiffHandlerV1.java
License:Open Source License
private URI getBaseLocation(URI location, Repository db, Path path) throws URISyntaxException, IOException { String scope = path.segment(0); if (scope.contains("..")) { //$NON-NLS-1$ String[] commits = scope.split("\\.\\."); //$NON-NLS-1$ if (commits.length != 2) { // TODO: throw new IllegalArgumentException(); }//from w w w . j a v a 2 s .com // TODO: decode commits[] ThreeWayMerger merger = new ResolveMerger(db) { protected boolean mergeImpl() throws IOException { // do nothing return false; } }; // use #merge to set sourceObjects merger.merge(new ObjectId[] { db.resolve(commits[0]), db.resolve(commits[1]) }); RevCommit baseCommit = merger.getBaseCommit(0, 1); IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE) .append(baseCommit.getId().getName()).append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), "parts=body", null); //$NON-NLS-1$ } else if (scope.equals(GitConstants.KEY_DIFF_CACHED)) { // HEAD is the base IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE).append(Constants.HEAD) .append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), "parts=body", null); //$NON-NLS-1$ } else { // index is the base IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.INDEX_RESOURCE) .append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), null, null); } }