/** * Create a new update command by path name. * * @param entryPath * path of the file within the repository. */ public PathEdit(String entryPath) { path = Constants.encode(entryPath); }
void writeHeader(OutputStream out, int type, long len) throws IOException { out.write(Constants.encodedTypeString(type)); out.write((byte) ' '); out.write(Constants.encodeASCII(len)); out.write((byte) 0); }
/** * Initialize a new pack parser. * * @param db * database the objects will be imported into. * @param ins * inserter the parser will use to help it inject the objects. * @param in * the stream to parse. */ protected DfsPackParser(DfsObjDatabase db, DfsInserter ins, InputStream in) { super(db, in); this.objdb = db; this.objins = ins; this.crc = new CRC32(); this.packDigest = Constants.newMessageDigest(); }
/** * Output the first header line * * @param o * The stream the formatter will write the first header line to * @param type * The {@link org.eclipse.jgit.diff.DiffEntry.ChangeType} * @param oldPath * old path to the file * @param newPath * new path to the file * @throws java.io.IOException * the stream threw an exception while writing to it. */ protected void formatGitDiffFirstHeaderLine(ByteArrayOutputStream o, final ChangeType type, final String oldPath, final String newPath) throws IOException { o.write(encodeASCII("diff --git ")); //$NON-NLS-1$ o.write(encode(quotePath(oldPrefix + (type == ADD ? newPath : oldPath)))); o.write(' '); o.write(encode(quotePath(newPrefix + (type == DELETE ? oldPath : newPath)))); o.write('\n'); }
private static void assertHash(RevObject id, byte[] bin) { MessageDigest md = Constants.newMessageDigest(); md.update(Constants.encodedTypeString(id.getType())); md.update((byte) ' '); md.update(Constants.encodeASCII(bin.length)); md.update((byte) 0); md.update(bin); assertEquals(id, ObjectId.fromRaw(md.digest())); }
/** * Convert an integer into its decimal representation. * * @param s * the integer to convert. * @return a decimal representation of the input integer. The returned array * is the smallest array that will hold the value. */ public static byte[] encodeASCII(long s) { return encodeASCII(Long.toString(s)); }
/** * Construct a MissingObjectException for the specified object id. * Expected type is reported to simplify tracking down the problem. * * @param id SHA-1 * @param type object type */ public MissingObjectException(ObjectId id, int type) { this(id, Constants.typeString(type)); }
void parseCanonical(RevWalk walk, byte[] rawTag) throws CorruptObjectException { final MutableInteger pos = new MutableInteger(); final int oType; pos.value = 53; // "object $sha1\ntype " oType = Constants.decodeTypeString(this, rawTag, (byte) '\n', pos); walk.idBuffer.fromString(rawTag, 7); object = walk.lookupAny(walk.idBuffer, oType); int p = pos.value += 4; // "tag " final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1; tagName = RawParseUtils.decode(UTF_8, rawTag, p, nameEnd); if (walk.isRetainBody()) buffer = rawTag; flags |= PARSED; }
private static void assertHash(RevObject id, byte[] bin) { MessageDigest md = Constants.newMessageDigest(); md.update(Constants.encodedTypeString(id.getType())); md.update((byte) ' '); md.update(Constants.encodeASCII(bin.length)); md.update((byte) 0); md.update(bin); assertEquals(id, ObjectId.fromRaw(md.digest())); }
o.write(encodeASCII("old mode ")); //$NON-NLS-1$ oldMode.copyTo(o); o.write('\n'); o.write(encodeASCII("new mode ")); //$NON-NLS-1$ newMode.copyTo(o); o.write('\n'); o.write(encodeASCII("new file mode ")); //$NON-NLS-1$ newMode.copyTo(o); o.write('\n'); o.write(encodeASCII("deleted file mode ")); //$NON-NLS-1$ oldMode.copyTo(o); o.write('\n'); o.write(encodeASCII("similarity index " + ent.getScore() + "%")); //$NON-NLS-1$ //$NON-NLS-2$ o.write('\n'); o.write(encode("rename from " + quotePath(oldp))); //$NON-NLS-1$ o.write('\n'); o.write(encode("rename to " + quotePath(newp))); //$NON-NLS-1$ o.write('\n'); break; o.write(encodeASCII("similarity index " + ent.getScore() + "%")); //$NON-NLS-1$ //$NON-NLS-2$ o.write('\n');
private void writeRange(char prefix, int begin, int cnt) throws IOException { out.write(' '); out.write(prefix); switch (cnt) { case 0: // If the range is empty, its beginning number must be the // line just before the range, or 0 if the range is at the // start of the file stream. Here, begin is always 1 based, // so an empty file would produce "0,0". // out.write(encodeASCII(begin - 1)); out.write(','); out.write('0'); break; case 1: // If the range is exactly one line, produce only the number. // out.write(encodeASCII(begin)); break; default: out.write(encodeASCII(begin)); out.write(','); out.write(encodeASCII(cnt)); break; } }
/** * Construct and IncorrectObjectTypeException for the specified object id. * * Provide the type to make it easier to track down the problem. * * @param id SHA-1 * @param type object type */ public IncorrectObjectTypeException(ObjectId id, int type) { this(id, Constants.typeString(type)); } }
Constants.decodeTypeString(id, hdr, (byte) ' ', p); long size = RawParseUtils.parseLongBase10(hdr, p.value, p); if (size < 0)
private PathFilter(String s) { pathStr = s; pathRaw = Constants.encode(pathStr); }
/** * Compute the name of an object, without inserting it. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. */ public ObjectId idFor(int type, byte[] data, int off, int len) { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); md.update(data, off, len); return md.toObjectId(); }
private static void assertHash(RevObject id, byte[] bin) { MessageDigest md = Constants.newMessageDigest(); md.update(Constants.encodedTypeString(id.getType())); md.update((byte) ' '); md.update(Constants.encodeASCII(bin.length)); md.update((byte) 0); md.update(bin); assertEquals(id, ObjectId.fromRaw(md.digest())); }
/** * Create a new writer instance. * * @param dst * the stream this instance outputs to. If not already buffered * it will be automatically wrapped in a buffered stream. */ protected PackIndexWriter(OutputStream dst) { out = new DigestOutputStream(dst instanceof BufferedOutputStream ? dst : new BufferedOutputStream(dst), Constants.newMessageDigest()); tmp = new byte[4 + Constants.OBJECT_ID_LENGTH]; }
/** * Convert an ObjectId from hex characters. * * @param str * the string to read from. Must be 40 characters long. */ public void fromString(String str) { if (str.length() != Constants.OBJECT_ID_STRING_LENGTH) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().invalidId, str)); fromHexString(Constants.encodeASCII(str), 0); }
/** {@inheritDoc} */ @Override public String toString() { final StringBuilder s = new StringBuilder(); s.append(Constants.typeString(getType())); s.append(' '); s.append(name()); s.append(' '); appendCoreFlags(s); return s.toString(); }
int type = Constants.decodeTypeString(id, hdr, (byte) ' ', p); long size = RawParseUtils.parseLongBase10(hdr, p.value, p); if (size < 0)