List of usage examples for org.eclipse.jgit.lib Constants HEAD
String HEAD
To view the source code for org.eclipse.jgit.lib Constants HEAD.
Click Source Link
From source file:org.eclipse.orion.server.git.objects.Branch.java
License:Open Source License
@PropertyDescription(name = GitConstants.KEY_HEAD) private URI getHeadLocation() throws IOException, URISyntaxException { return BaseToCommitConverter.getCommitLocation(cloneLocation, Constants.HEAD, BaseToCommitConverter.REMOVE_FIRST_2); }
From source file:org.eclipse.orion.server.git.objects.Clone.java
License:Open Source License
@PropertyDescription(name = GitConstants.KEY_HEAD) private URI getHeadLocation() throws URISyntaxException { IPath np = new Path(GitServlet.GIT_URI).append(Commit.RESOURCE).append(Constants.HEAD).append(getId()); return createUriWithPath(np); }
From source file:org.eclipse.orion.server.git.objects.Diff.java
License:Open Source License
private URI getOldLocation(URI location, IPath path) throws URISyntaxException { 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)); }//from ww w .j av a 2s .c o m IPath p = new Path(GitServlet.GIT_URI + '/' + Commit.RESOURCE).append(commits[0]) .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)) { 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 if (scope.equals(GitConstants.KEY_DIFF_DEFAULT)) { 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); } else { IPath p = new Path(GitServlet.GIT_URI + '/' + Commit.RESOURCE).append(scope) .append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), "parts=body", null); //$NON-NLS-1$ } }
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)); }//from w w w . ja v a2s.c om 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.objects.Status.java
License:Open Source License
@PropertyDescription(name = GitConstants.KEY_COMMIT) private URI getCommitLocation() throws URISyntaxException { return statusToCommitLocation(baseLocation, Constants.HEAD); }
From source file:org.eclipse.orion.server.git.objects.Status.java
License:Open Source License
private JSONArray toJSONArray(Set<String> set, IPath basePath, URI baseLocation, String diffType) throws JSONException, URISyntaxException { JSONArray result = new JSONArray(); for (String s : set) { JSONObject object = new JSONObject(); object.put(ProtocolConstants.KEY_NAME, s); IPath relative = new Path(s).makeRelativeTo(basePath); object.put(ProtocolConstants.KEY_PATH, relative); URI fileLocation = statusToFileLocation(baseLocation); object.put(ProtocolConstants.KEY_LOCATION, URIUtil.append(fileLocation, relative.toString())); JSONObject gitSection = new JSONObject(); URI diffLocation = statusToDiffLocation(baseLocation, diffType); gitSection.put(GitConstants.KEY_DIFF, URIUtil.append(diffLocation, relative.toString())); object.put(GitConstants.KEY_GIT, gitSection); URI commitLocation = statusToCommitLocation(baseLocation, Constants.HEAD); gitSection.put(GitConstants.KEY_COMMIT, URIUtil.append(commitLocation, relative.toString())); object.put(GitConstants.KEY_GIT, gitSection); URI indexLocation = statusToIndexLocation(baseLocation); gitSection.put(GitConstants.KEY_INDEX, URIUtil.append(indexLocation, relative.toString())); object.put(GitConstants.KEY_GIT, gitSection); result.put(object);/*from www . j a v a 2s. c o m*/ } return result; }
From source file:org.eclipse.orion.server.git.servlets.GitCloneHandlerV1.java
License:Open Source License
private JSONObject toJSON(Entry<IPath, File> entry, URI baseLocation) throws URISyntaxException { IPath k = entry.getKey();//ww w . jav a 2 s . c om JSONObject result = new JSONObject(); try { result.put(ProtocolConstants.KEY_ID, k); result.put(ProtocolConstants.KEY_NAME, k.segmentCount() == 1 ? WebProject.fromId(k.segment(0)).getName() : k.lastSegment()); IPath np = new Path(GitServlet.GIT_URI).append(GitConstants.CLONE_RESOURCE).append("file").append(k); //$NON-NLS-1$ URI location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(ProtocolConstants.KEY_LOCATION, location); np = new Path("file").append(k).makeAbsolute(); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(ProtocolConstants.KEY_CONTENT_LOCATION, location); np = new Path(GitServlet.GIT_URI).append(GitConstants.REMOTE_RESOURCE).append("file").append(k); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(GitConstants.KEY_REMOTE, location); np = new Path(GitServlet.GIT_URI).append(GitConstants.CONFIG_RESOURCE) .append(GitConstants.CLONE_RESOURCE).append("file").append(k); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(GitConstants.KEY_CONFIG, location); np = new Path(GitServlet.GIT_URI).append(GitConstants.COMMIT_RESOURCE).append(Constants.HEAD) .append("file").append(k); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(GitConstants.KEY_HEAD, location); np = new Path(GitServlet.GIT_URI).append(GitConstants.COMMIT_RESOURCE).append("file").append(k); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(GitConstants.KEY_COMMIT, location); np = new Path(GitServlet.GIT_URI).append(GitConstants.BRANCH_RESOURCE).append("file").append(k); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(GitConstants.KEY_BRANCH, location); np = new Path(GitServlet.GIT_URI).append(GitConstants.INDEX_RESOURCE).append("file").append(k); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(GitConstants.KEY_INDEX, location); np = new Path(GitServlet.GIT_URI).append(GitConstants.STATUS_RESOURCE).append("file").append(k); //$NON-NLS-1$ location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment()); result.put(GitConstants.KEY_STATUS, location); try { FileBasedConfig config = new FileRepository(entry.getValue()).getConfig(); String remoteUri = config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL); if (remoteUri != null) result.put(GitConstants.KEY_URL, remoteUri); } catch (IOException e) { // ignore and skip Git URL } } catch (JSONException e) { //cannot happen, we know keys and values are valid } return result; }
From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java
License:Open Source License
private boolean handlePost(HttpServletRequest request, HttpServletResponse response, Repository db, Path path) throws ServletException, NoFilepatternException, IOException, JSONException, CoreException, URISyntaxException {/*ww w . j ava 2 s .c o m*/ IPath filePath = path.hasTrailingSeparator() ? path.removeFirstSegments(1) : path.removeFirstSegments(1).removeLastSegments(1); Set<Entry<IPath, File>> set = GitUtils.getGitDirs(filePath, Traverse.GO_UP).entrySet(); File gitDir = set.iterator().next().getValue(); if (gitDir == null) return false; // TODO: or an error response code, 405? db = new FileRepository(gitDir); JSONObject requestObject = OrionServlet.readJSONRequest(request); String commitToMerge = requestObject.optString(GitConstants.KEY_MERGE, null); if (commitToMerge != null) { return merge(request, response, db, commitToMerge); } String commitToRebase = requestObject.optString(GitConstants.KEY_REBASE, null); String rebaseOperation = requestObject.optString(GitConstants.KEY_OPERATION, null); if (commitToRebase != null) { return rebase(request, response, db, commitToRebase, rebaseOperation); } String commitToCherryPick = requestObject.optString(GitConstants.KEY_CHERRY_PICK, null); if (commitToCherryPick != null) { return cherryPick(request, response, db, commitToCherryPick); } // continue with creating new commit location String newCommitToCreatelocation = requestObject.optString(GitConstants.KEY_COMMIT_NEW, null); if (newCommitToCreatelocation != null) return createCommitLocation(request, response, db, newCommitToCreatelocation); ObjectId refId = db.resolve(path.segment(0)); if (refId == null || !Constants.HEAD.equals(path.segment(0))) { String msg = NLS.bind("Commit failed. Ref must be HEAD and is {0}", path.segment(0)); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } String message = requestObject.optString(GitConstants.KEY_COMMIT_MESSAGE, null); if (message == null || message.isEmpty()) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Missing commit message.", null)); } boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null)); String committerName = requestObject.optString(GitConstants.KEY_COMMITTER_NAME, null); String committerEmail = requestObject.optString(GitConstants.KEY_COMMITTER_EMAIL, null); String authorName = requestObject.optString(GitConstants.KEY_AUTHOR_NAME, null); String authorEmail = requestObject.optString(GitConstants.KEY_AUTHOR_EMAIL, null); Git git = new Git(db); CommitCommand commit = git.commit(); // workaround of a bug in JGit which causes invalid // support of null values of author/committer name/email PersonIdent defPersonIdent = new PersonIdent(db); if (committerName == null) committerName = defPersonIdent.getName(); if (committerEmail == null) committerEmail = defPersonIdent.getEmailAddress(); if (authorName == null) authorName = committerName; if (authorEmail == null) authorEmail = committerEmail; commit.setCommitter(committerName, committerEmail); commit.setAuthor(authorName, authorEmail); // support for committing by path: "git commit -o path" boolean isRoot = true; String pattern = GitUtils.getRelativePath(path.removeFirstSegments(1), set.iterator().next().getKey()); if (!pattern.isEmpty()) { commit.setOnly(pattern); isRoot = false; } try { // "git commit [--amend] -m '{message}' [-a|{path}]" RevCommit lastCommit = commit.setAmend(amend).setMessage(message).call(); Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(db); JSONObject result = toJSON(db, lastCommit, commitToBranchMap, getURI(request), null, isRoot); OrionServlet.writeJSONResponse(request, response, result); return true; } catch (GitAPIException e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "An error occured when commiting.", e)); } catch (JGitInternalException e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An internal error occured when commiting.", e)); } }
From source file:org.eclipse.orion.server.git.servlets.GitDiffHandlerV1.java
License:Open Source License
private URI getOldLocation(URI location, Path path) throws URISyntaxException { 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 ww w . j a v a 2 s . c o m // TODO: decode commits[0] IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE).append(commits[0]) .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)) { 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 if (scope.equals(GitConstants.KEY_DIFF_DEFAULT)) { 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); } else { IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE).append(scope) .append(path.removeFirstSegments(1)); return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), "parts=body", null); //$NON-NLS-1$ } }
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(); }// www . j av a2 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); } }