Java Code Examples for org.eclipse.jgit.lib.ObjectId#name()
The following examples show how to use
org.eclipse.jgit.lib.ObjectId#name() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultUrlManager.java From onedev with MIT License | 4 votes |
@Override public String urlFor(Project project, ObjectId commitId) { return urlFor(project) + "/commits/" + commitId.name(); }
Example 2
Source File: Project.java From onedev with MIT License | 4 votes |
/** * Read blob content and cache result in repository in case the same blob * content is requested again. * * We made this method thread-safe as we are using ForkJoinPool to calculate * diffs of multiple blob changes concurrently, and this method will be * accessed concurrently in that special case. * * @param blobIdent * ident of the blob * @return * blob of specified blob ident * @throws * ObjectNotFoundException if blob of specified ident can not be found in repository * */ @Nullable public Blob getBlob(BlobIdent blobIdent, boolean mustExist) { Preconditions.checkArgument(blobIdent.revision!=null && blobIdent.path!=null && blobIdent.mode!=null, "Revision, path and mode of ident param should be specified"); Optional<Blob> blob = getBlobCache().get(blobIdent); if (blob == null) { try (RevWalk revWalk = new RevWalk(getRepository())) { ObjectId revId = getObjectId(blobIdent.revision, mustExist); if (revId != null) { RevCommit commit = GitUtils.parseCommit(revWalk, revId); if (commit != null) { RevTree revTree = commit.getTree(); TreeWalk treeWalk = TreeWalk.forPath(getRepository(), blobIdent.path, revTree); if (treeWalk != null) { ObjectId blobId = treeWalk.getObjectId(0); if (blobIdent.isGitLink()) { String url = getSubmodules(blobIdent.revision).get(blobIdent.path); if (url == null) { if (mustExist) throw new ObjectNotFoundException("Unable to find submodule '" + blobIdent.path + "' in .gitmodules"); else blob = Optional.absent(); } else { String hash = blobId.name(); blob = Optional.of(new Blob(blobIdent, blobId, new Submodule(url, hash).toString().getBytes())); } } else if (blobIdent.isTree()) { throw new NotFileException("Path '" + blobIdent.path + "' is a tree"); } else { blob = Optional.of(new Blob(blobIdent, blobId, treeWalk.getObjectReader())); } } } } if (blob == null) { if (mustExist) throw new ObjectNotFoundException("Unable to find blob ident: " + blobIdent); else blob = Optional.absent(); } getBlobCache().put(blobIdent, blob); } catch (IOException e) { throw new RuntimeException(e); } } return blob.orNull(); }
Example 3
Source File: ProjectAndRevision.java From onedev with MIT License | 4 votes |
public String getObjectName(boolean mustExist) { ObjectId objectId = getObjectId(mustExist); return objectId!=null?objectId.name():null; }
Example 4
Source File: CherryPickCommand.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected void run () throws GitException { Repository repository = getRepository(); ObjectId originalCommit = getOriginalCommit(); ObjectId head = getHead(); List<RebaseTodoLine> steps; try { switch (operation) { case BEGIN: // initialize sequencer and cherry-pick steps if there are // more commits to cherry-pick steps = prepareCommand(head); // apply the selected steps applySteps(steps, false); break; case ABORT: // delete the sequencer and reset to the original head if (repository.getRepositoryState() == RepositoryState.CHERRY_PICKING || repository.getRepositoryState() == RepositoryState.CHERRY_PICKING_RESOLVED) { if (originalCommit == null) { // maybe the sequencer is not created in that case simply reset to HEAD originalCommit = head; } } Utils.deleteRecursively(getSequencerFolder()); if (originalCommit != null) { ResetCommand reset = new ResetCommand(repository, getClassFactory(), originalCommit.name(), GitClient.ResetType.HARD, new DelegatingGitProgressMonitor(monitor), listener); reset.execute(); } result = createCustomResult(GitCherryPickResult.CherryPickStatus.ABORTED); break; case QUIT: // used to reset the sequencer only Utils.deleteRecursively(getSequencerFolder()); switch (repository.getRepositoryState()) { case CHERRY_PICKING: // unresolved conflicts result = createResult(CherryPickResult.CONFLICT); break; case CHERRY_PICKING_RESOLVED: result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED); break; default: result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK); break; } break; case CONTINUE: switch (repository.getRepositoryState()) { case CHERRY_PICKING: // unresolved conflicts, cannot continue result = createResult(CherryPickResult.CONFLICT); break; case CHERRY_PICKING_RESOLVED: // cannot continue without manual commit result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED); break; default: // read steps from sequencer and apply them // if sequencer is empty this will be a noop steps = readTodoFile(repository); applySteps(steps, true); break; } break; default: throw new IllegalStateException("Unexpected operation " + operation.name()); } } catch (GitAPIException | IOException ex) { throw new GitException(ex); } }