private long decodeTS(int pIdx) { final int base = infoOffset + pIdx; final int sec = NB.decodeInt32(info, base); final int ms = NB.decodeInt32(info, base + 4) / 1000000; return 1000L * sec + ms; }
/** * Obtain the raw {@link org.eclipse.jgit.lib.FileMode} bits for this entry. * * @return mode bits for the entry. * @see FileMode#fromBits(int) */ public int getRawMode() { return NB.decodeInt32(info, infoOffset + P_MODE); }
/** * Convert an ObjectId from raw binary representation. * * @param bs * the raw byte buffer to read from. At least 20 bytes after p * must be available within this byte array. * @param p * position to read the first byte of data from. */ public void fromRaw(byte[] bs, int p) { w1 = NB.decodeInt32(bs, p); w2 = NB.decodeInt32(bs, p + 4); w3 = NB.decodeInt32(bs, p + 8); w4 = NB.decodeInt32(bs, p + 12); w5 = NB.decodeInt32(bs, p + 16); }
/** * Get the cached size (mod 4 GB) (in bytes) of this file. * <p> * One of the indicators that the file has been modified by an application * changing the working tree is if the size of the file (in bytes) differs * from the size stored in this entry. * <p> * Note that this is the length of the file in the working directory, which * may differ from the size of the decompressed blob if work tree filters * are being used, such as LF<->CRLF conversion. * <p> * Note also that for very large files, this is the size of the on-disk file * truncated to 32 bits, i.e. modulo 4294967296. If that value is larger * than 2GB, it will appear negative. * * @return cached size of the working directory file, in bytes. */ public int getLength() { return NB.decodeInt32(info, infoOffset + P_SIZE); }
private void initBlock(byte[] block, int p) { for (int t = 0; t < 16; t++) { w[t] = NB.decodeInt32(block, p + (t << 2)); } // RFC 3174 6.1.b, extend state vector to 80 words. for (int t = 16; t < 80; t++) { int x = w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]; w[t] = rotateLeft(x, 1); // S^1(...) } }
/** * Convert an ObjectId from raw binary representation. * * @param bs * the raw byte buffer to read from. At least 20 bytes after p * must be available within this byte array. * @param p * position to read the first byte of data from. * @return the converted object id. */ public static final ObjectId fromRaw(byte[] bs, int p) { final int a = NB.decodeInt32(bs, p); final int b = NB.decodeInt32(bs, p + 4); final int c = NB.decodeInt32(bs, p + 8); final int d = NB.decodeInt32(bs, p + 12); final int e = NB.decodeInt32(bs, p + 16); return new ObjectId(a, b, c, d, e); }
/** * Is it possible for this entry to be accidentally assumed clean? * <p> * The "racy git" problem happens when a work file can be updated faster * than the filesystem records file modification timestamps. It is possible * for an application to edit a work file, update the index, then edit it * again before the filesystem will give the work file a new modification * timestamp. This method tests to see if file was written out at the same * time as the index. * * @param smudge_s * seconds component of the index's last modified time. * @param smudge_ns * nanoseconds component of the index's last modified time. * @return true if extra careful checks should be used. */ public final boolean mightBeRacilyClean(int smudge_s, int smudge_ns) { // If the index has a modification time then it came from disk // and was not generated from scratch in memory. In such cases // the entry is 'racily clean' if the entry's cached modification // time is equal to or later than the index modification time. In // such cases the work file is too close to the index to tell if // it is clean or not based on the modification time alone. // final int base = infoOffset + P_MTIME; final int mtime = NB.decodeInt32(info, base); if (smudge_s == mtime) return smudge_ns <= NB.decodeInt32(info, base + 4); return false; }
/** {@inheritDoc} */ @Override public int readInt() throws IOException { readFully(buf, 0, 4); return NB.decodeInt32(buf, 0); }
/** * Compare this ObjectId to a network-byte-order ObjectId. * * @param bs * array containing the other ObjectId in network byte order. * @param p * position within {@code bs} to start the compare at. At least * 20 bytes, starting at this position are required. * @return a negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. */ public final int compareTo(byte[] bs, int p) { int cmp; cmp = NB.compareUInt32(w1, NB.decodeInt32(bs, p)); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w2, NB.decodeInt32(bs, p + 4)); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w3, NB.decodeInt32(bs, p + 8)); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w4, NB.decodeInt32(bs, p + 12)); if (cmp != 0) return cmp; return NB.compareUInt32(w5, NB.decodeInt32(bs, p + 16)); }
private int readBlockLen(long pos) throws IOException { int sz = pos == 0 ? FILE_HEADER_LEN + 4 : 4; ByteBuffer tmp = src.read(pos, sz); if (tmp.position() < sz) { throw new IOException(JGitText.get().invalidReftableFile); } byte[] buf; if (tmp.hasArray() && tmp.arrayOffset() == 0) { buf = tmp.array(); } else { buf = new byte[sz]; tmp.flip(); tmp.get(buf); } if (pos == 0 && buf[FILE_HEADER_LEN] == FILE_BLOCK_TYPE) { return FILE_HEADER_LEN; } int p = pos == 0 ? FILE_HEADER_LEN : 0; return decodeBlockLen(NB.decodeInt32(buf, p)); }
/** * Compare this abbreviation to a network-byte-order ObjectId. * * @param bs * array containing the other ObjectId in network byte order. * @param p * position within {@code bs} to start the compare at. At least * 20 bytes, starting at this position are required. * @return <0 if this abbreviation names an object that is less than * <code>other</code>; 0 if this abbreviation exactly matches the * first {@link #length()} digits of <code>other.name()</code>; * >0 if this abbreviation names an object that is after * <code>other</code>. */ public final int prefixCompare(byte[] bs, int p) { int cmp; cmp = NB.compareUInt32(w1, mask(1, NB.decodeInt32(bs, p))); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w2, mask(2, NB.decodeInt32(bs, p + 4))); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w3, mask(3, NB.decodeInt32(bs, p + 8))); if (cmp != 0) return cmp; cmp = NB.compareUInt32(w4, mask(4, NB.decodeInt32(bs, p + 12))); if (cmp != 0) return cmp; return NB.compareUInt32(w5, mask(5, NB.decodeInt32(bs, p + 16))); }
private byte[] readHeaderOrFooter(long pos, int len) throws IOException { ByteBuffer buf = src.read(pos, len); if (buf.position() != len) { throw new IOException(JGitText.get().shortReadOfBlock); } byte[] tmp = new byte[len]; buf.flip(); buf.get(tmp); if (!isFileHeaderMagic(tmp, 0, len)) { throw new IOException(JGitText.get().invalidReftableFile); } int v = NB.decodeInt32(tmp, 4); int version = v >>> 24; if (VERSION_1 != version) { throw new IOException(MessageFormat.format( JGitText.get().unsupportedReftableVersion, Integer.valueOf(version))); } if (blockSize == -1) { blockSize = v & 0xffffff; } minUpdateIndex = NB.decodeInt64(tmp, 8); maxUpdateIndex = NB.decodeInt64(tmp, 16); return tmp; }
for (int i = 0; i < (int) numEntries; i++) { IO.readFully(fd, scratch, 0, 6); int nthObjectId = NB.decodeInt32(scratch, 0); int xorOffset = scratch[4]; int flags = scratch[5];
IO.readFully(fd, raw, 0, raw.length); for (int i = 0; i < bin.length; i++) bin[i] = NB.decodeInt32(raw, i << 2);
IO.readFully(fd, hdr, 0, hdr.length); if (isTOC(hdr)) { final int v = NB.decodeInt32(hdr, 4); switch (v) { case 2:
if (!is_DIRC(hdr)) throw new CorruptObjectException(JGitText.get().notADIRCFile); final int ver = NB.decodeInt32(hdr, 4); boolean extended = false; if (ver == 3) throw new CorruptObjectException(MessageFormat.format( JGitText.get().unknownDIRCVersion, Integer.valueOf(ver))); entryCnt = NB.decodeInt32(hdr, 8); if (entryCnt < 0) throw new CorruptObjectException(JGitText.get().DIRCHasTooManyEntries); switch (NB.decodeInt32(hdr, 0)) { case EXT_TREE: { if (Integer.MAX_VALUE < sz) {
int typeAndSize = NB.decodeInt32(buf, ptr); ptr += 4;
private long decodeTS(int pIdx) { final int base = infoOffset + pIdx; final int sec = NB.decodeInt32(info, base); final int ms = NB.decodeInt32(info, base + 4) / 1000000; return 1000L * sec + ms; }
@Override protected int hashRegion(byte[] raw, int ptr, int end) { md.reset(); md.update(raw, ptr, end - ptr); return NB.decodeInt32(md.digest(), 0); } };
/** {@inheritDoc} */ @Override public int readInt() throws IOException { readFully(buf, 0, 4); return NB.decodeInt32(buf, 0); }