private static byte[] key(int idLen, ObjectId id) { byte[] key = new byte[OBJECT_ID_LENGTH]; id.copyRawTo(key, 0); if (idLen < OBJECT_ID_LENGTH) { return Arrays.copyOf(key, idLen); } return key; }
void writeId(ObjectId id) { ensureBytesAvailableInBlockBuf(OBJECT_ID_LENGTH); id.copyRawTo(blockBuf, cur); cur += OBJECT_ID_LENGTH; }
void write(byte[] tmp, OutputStream os) throws IOException { int ptr = tmp.length; tmp[--ptr] = '\n'; ptr = RawParseUtils.formatBase10(tmp, ptr, childCnt); tmp[--ptr] = ' '; ptr = RawParseUtils.formatBase10(tmp, ptr, isValid() ? entrySpan : -1); tmp[--ptr] = 0; os.write(encodedName); os.write(tmp, ptr, tmp.length - ptr); if (isValid()) { id.copyRawTo(tmp, 0); os.write(tmp, 0, Constants.OBJECT_ID_LENGTH); } for (int i = 0; i < childCnt; i++) children[i].write(tmp, os); }
/** * Get submodule id using the repository at the location of the entry * relative to the directory. * * @param directory * a {@link java.io.File} object. * @param e * a {@link org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry} * object. * @return non-null submodule id */ protected byte[] idSubmodule(File directory, Entry e) { try (Repository submoduleRepo = SubmoduleWalk.getSubmoduleRepository( directory, e.getName(), repository != null ? repository.getFS() : FS.DETECTED)) { if (submoduleRepo == null) { return zeroid; } ObjectId head = submoduleRepo.resolve(Constants.HEAD); if (head == null) { return zeroid; } byte[] id = new byte[Constants.OBJECT_ID_LENGTH]; head.copyRawTo(id, 0); return id; } catch (IOException exception) { return zeroid; } }
@Override public byte[] idBuffer() { byte[] ret = new byte[OBJECT_ID_LENGTH]; id.copyRawTo(ret, 0); return ret; }
private static byte[] getBytes(ObjectId commit) { byte[] commitBytes = new byte[20]; commit.copyRawTo(commitBytes, 0); return commitBytes; }
@Override public byte[] idBuffer() { byte[] ret = new byte[OBJECT_ID_LENGTH]; id.copyRawTo(ret, 0); return ret; }
void initSeek() throws IOException { byte[] rawId = new byte[OBJECT_ID_LENGTH]; match.copyRawTo(rawId, 0); byte[] key = Arrays.copyOf(rawId, objIdLen);
private static byte[] key(int idLen, ObjectId id) { byte[] key = new byte[OBJECT_ID_LENGTH]; id.copyRawTo(key, 0); if (idLen < OBJECT_ID_LENGTH) { return Arrays.copyOf(key, idLen); } return key; }
@Override public void serialize(@NotNull DataOutput2 out, @NotNull ObjectId value) throws IOException { value.copyRawTo(out); }
} else if (otp.isDeltaRepresentation()) { int n = objectHeader(rawLength, OBJ_REF_DELTA, headerBuffer); otp.getDeltaBaseId().copyRawTo(headerBuffer, n); write(headerBuffer, 0, n + 20); } else {
void writeId(ObjectId id) { ensureBytesAvailableInBlockBuf(OBJECT_ID_LENGTH); id.copyRawTo(blockBuf, cur); cur += OBJECT_ID_LENGTH; }
s.getObjectId().copyRawTo(subtreeId, 0); mode = FileMode.TREE.getBits(); path = cep;
protected void writeCommits(Store store, Transaction txn, ByteIterable key, Collection<ObjectId> commits) { byte[] bytes = new byte[commits.size()*20]; int index = 0; for (ObjectId commit: commits) { commit.copyRawTo(bytes, index); index += 20; } store.put(txn, key, new ArrayByteIterable(bytes)); }
void write(final byte[] tmp, final OutputStream os) throws IOException { int ptr = tmp.length; tmp[--ptr] = '\n'; ptr = RawParseUtils.formatBase10(tmp, ptr, childCnt); tmp[--ptr] = ' '; ptr = RawParseUtils.formatBase10(tmp, ptr, isValid() ? entrySpan : -1); tmp[--ptr] = 0; os.write(encodedName); os.write(tmp, ptr, tmp.length - ptr); if (isValid()) { id.copyRawTo(tmp, 0); os.write(tmp, 0, Constants.OBJECT_ID_LENGTH); } for (int i = 0; i < childCnt; i++) children[i].write(tmp, os); }
void write(byte[] tmp, OutputStream os) throws IOException { int ptr = tmp.length; tmp[--ptr] = '\n'; ptr = RawParseUtils.formatBase10(tmp, ptr, childCnt); tmp[--ptr] = ' '; ptr = RawParseUtils.formatBase10(tmp, ptr, isValid() ? entrySpan : -1); tmp[--ptr] = 0; os.write(encodedName); os.write(tmp, ptr, tmp.length - ptr); if (isValid()) { id.copyRawTo(tmp, 0); os.write(tmp, 0, Constants.OBJECT_ID_LENGTH); } for (int i = 0; i < childCnt; i++) children[i].write(tmp, os); }
return zeroid; final byte[] id = new byte[Constants.OBJECT_ID_LENGTH]; head.copyRawTo(id, 0); return id;
@Test public void mismatchingRevision() throws Exception { db.close(); // Append a record with incorrect revision number. try (FileChannel f = FileChannel.open(new File(tmpDir.getRoot(), "commit_ids.dat").toPath(), StandardOpenOption.APPEND)) { final ByteBuffer buf = ByteBuffer.allocate(24); buf.putInt(42); // Expected to be 1. randomCommitId().copyRawTo(buf); buf.flip(); do { f.write(buf); } while (buf.hasRemaining()); assertThat(f.size()).isEqualTo(buf.capacity()); } // Reopen the database and see if it fails to resolve the revision 1. db = new CommitIdDatabase(tmpDir.getRoot()); assertThatThrownBy(() -> db.get(Revision.INIT)) .isInstanceOf(StorageException.class) .hasMessageContaining("incorrect revision number"); }
ObjectInfo info(ChunkKey chunkKey) { GitStore.ObjectInfo.Builder b = GitStore.ObjectInfo.newBuilder(); b.setObjectType(GitStore.ObjectInfo.ObjectType.valueOf(getType())); b.setOffset(offsetOf(chunkPtr)); b.setPackedSize(packedSize); b.setInflatedSize(inflatedSize); if (base != null) { byte[] t = new byte[Constants.OBJECT_ID_LENGTH]; base.copyRawTo(t, 0); b.setDeltaBase(ByteString.copyFrom(t)); } if (isFragmented()) b.setIsFragmented(true); return new ObjectInfo(chunkKey, b.build()); } }
ObjectInfo info(ChunkKey chunkKey) { GitStore.ObjectInfo.Builder b = GitStore.ObjectInfo.newBuilder(); b.setObjectType(GitStore.ObjectInfo.ObjectType.valueOf(getType())); b.setOffset(offsetOf(chunkPtr)); b.setPackedSize(packedSize); b.setInflatedSize(inflatedSize); if (base != null) { byte[] t = new byte[Constants.OBJECT_ID_LENGTH]; base.copyRawTo(t, 0); b.setDeltaBase(ByteString.copyFrom(t)); } if (isFragmented()) b.setIsFragmented(true); return new ObjectInfo(chunkKey, b.build()); } }