/** * Obtain a unique abbreviation (prefix) of an object SHA-1. * * This method uses a reasonable default for the minimum length. Callers who * don't care about the minimum length should prefer this method. * * The returned abbreviation would expand back to the argument ObjectId when * passed to {@link #resolve(AbbreviatedObjectId)}, assuming no new objects * are added to this repository between calls. * * @param objectId * object identity that needs to be abbreviated. * @return SHA-1 abbreviation. * @throws java.io.IOException * the object store cannot be read. */ public AbbreviatedObjectId abbreviate(AnyObjectId objectId) throws IOException { return abbreviate(objectId, 7); }
@Override public AbbreviatedObjectId abbreviate(AnyObjectId objectId) throws IOException { return delegate().abbreviate(objectId); }
@Override public AbbreviatedObjectId abbreviate(AnyObjectId objectId, int len) throws IOException { return delegate().abbreviate(objectId, len); }
/** * JGit won't ever use 1 char as abbreviated ID, that's why only values of: * <ul> * <li>0 (special meaning - don't show commit id at all),</li> * <li>the range from 2 to 40 (inclusive) are valid</li> * </ul> * * @return the abbreviated commit id, possibly longer than the requested len (if it wouldn't be unique) */ private static Optional<AbbreviatedObjectId> createAbbreviatedCommitId(@Nonnull ObjectReader objectReader, ObjectId commitId, int requestedLength) { if (requestedLength < 2) { // 0 means we don't want to print commit id's at all return Optional.empty(); } try { AbbreviatedObjectId abbreviatedObjectId = objectReader.abbreviate(commitId, requestedLength); return Optional.of(abbreviatedObjectId); } catch (IOException e) { return Optional.empty(); } }
private String longDescription(Ref tag, int depth, ObjectId tip) throws IOException { return String.format( "%s-%d-g%s", tag.getName().substring(R_TAGS.length()), //$NON-NLS-1$ Integer.valueOf(depth), w.getObjectReader().abbreviate(tip) .name()); }
private String getAbbrevCommitId(ObjectReader objectReader, RevCommit headCommit, int abbrevLength) throws GitCommitIdExecutionException { try { AbbreviatedObjectId abbreviatedObjectId = objectReader.abbreviate(headCommit, abbrevLength); return abbreviatedObjectId.name(); } catch (IOException e) { throw new GitCommitIdExecutionException("Unable to abbreviate commit id! " + "You may want to investigate the <abbrevLength/> element in your configuration.", e); } }
private String format(AbbreviatedObjectId id) { if (id.isComplete() && reader != null) { try { id = reader.abbreviate(id.toObjectId(), abbreviationLength); } catch (IOException cannotAbbreviate) { // Ignore this. We'll report the full identity. } } return id.name(); }
private RebaseResult stop(RevCommit commitToPick, RebaseResult.Status status) throws IOException { PersonIdent author = commitToPick.getAuthorIdent(); String authorScript = toAuthorScript(author); rebaseState.createFile(AUTHOR_SCRIPT, authorScript); rebaseState.createFile(MESSAGE, commitToPick.getFullMessage()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (DiffFormatter df = new DiffFormatter(bos)) { df.setRepository(repo); df.format(commitToPick.getParent(0), commitToPick); } rebaseState.createFile(PATCH, new String(bos.toByteArray(), UTF_8)); rebaseState.createFile(STOPPED_SHA, repo.newObjectReader() .abbreviate( commitToPick).name()); // Remove cherry pick state file created by CherryPickCommand, it's not // needed for rebase repo.writeCherryPickHead(null); return RebaseResult.result(status, commitToPick); }
@Override public AbbreviatedObjectId abbreviate(AnyObjectId objectId) throws IOException { return delegate().abbreviate(objectId); }
@Override public AbbreviatedObjectId abbreviate(AnyObjectId objectId, int len) throws IOException { return delegate().abbreviate(objectId, len); }
@Override public AbbreviatedObjectId abbreviate(AnyObjectId objectId) throws IOException { return delegate().abbreviate(objectId); }
@Override public AbbreviatedObjectId abbreviate(AnyObjectId objectId, int len) throws IOException { return delegate().abbreviate(objectId, len); }
for (RevCommit commit : cherryPickList) toDoSteps.add(new RebaseTodoLine(Action.PICK, reader .abbreviate(commit), commit.getShortMessage())); repo.writeRebaseTodoFile(rebaseState.getPath(GIT_REBASE_TODO), toDoSteps, false);
private String safeAbbreviate(ObjectId id) { String abbrev = abbrevations.get(id); if (abbrev == null) { try { abbrev = reader.abbreviate(id).name(); } catch (IOException cannotAbbreviate) { abbrev = id.name(); } abbrevations.put(id, abbrev); } return abbrev; }
private String longDescription(Ref tag, int depth, ObjectId tip) throws IOException { return String.format( "%s-%d-g%s", tag.getName().substring(R_TAGS.length()), //$NON-NLS-1$ Integer.valueOf(depth), w.getObjectReader().abbreviate(tip) .name()); }
private String longDescription(Ref tag, int depth, ObjectId tip) throws IOException { return String.format( "%s-%d-g%s", tag.getName().substring(R_TAGS.length()), //$NON-NLS-1$ Integer.valueOf(depth), w.getObjectReader().abbreviate(tip) .name()); }
private static String safeAbbreviate(ObjectReader reader, ObjectId id) { try { return reader.abbreviate(id).name(); } catch (IOException cannotAbbreviate) { return id.name(); } }
private static String safeAbbreviate(ObjectReader reader, ObjectId id) { try { return reader.abbreviate(id).name(); } catch (IOException cannotAbbreviate) { return id.name(); } }
private String getAbbrevCommitId(ObjectReader objectReader, RevCommit headCommit, int abbrevLength) throws GitCommitIdExecutionException { try { AbbreviatedObjectId abbreviatedObjectId = objectReader.abbreviate(headCommit, abbrevLength); return abbreviatedObjectId.name(); } catch (IOException e) { throw new GitCommitIdExecutionException("Unable to abbreviate commit id! " + "You may want to investigate the <abbrevLength/> element in your configuration.", e); } }
private String format(AbbreviatedObjectId id) { if (id.isComplete() && reader != null) { try { id = reader.abbreviate(id.toObjectId(), abbreviationLength); } catch (IOException cannotAbbreviate) { // Ignore this. We'll report the full identity. } } return id.name(); }