Java Code Examples for org.eclipse.jgit.lib.ObjectId#copyRawTo()

The following examples show how to use org.eclipse.jgit.lib.ObjectId#copyRawTo() . 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: DefaultPullRequestInfoManager.java    From onedev with MIT License 5 votes vote down vote up
private ByteIterable getComparisonBaseKey(PullRequest request, ObjectId commitId1, ObjectId commitId2) {
	byte[] keyBytes = new byte[40 + Long.BYTES];
	ByteBuffer.wrap(keyBytes, 0, Long.BYTES).putLong(request.getId());
	commitId1.copyRawTo(keyBytes, Long.BYTES);
	commitId2.copyRawTo(keyBytes, Long.BYTES + 20);
	return new ArrayByteIterable(keyBytes);
}
 
Example 2
Source File: AbstractEnvironmentManager.java    From onedev with MIT License 5 votes vote down vote up
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));
}
 
Example 3
Source File: CommitIdDatabase.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
private synchronized void put(Revision revision, ObjectId commitId, boolean safeMode) {
    if (safeMode) {
        final Revision expected;
        if (headRevision == null) {
            expected = Revision.INIT;
        } else {
            expected = headRevision.forward(1);
        }
        checkState(revision.equals(expected), "incorrect revision: %s (expected: %s)", revision, expected);
    }

    // Build a record.
    final ByteBuffer buf = threadLocalBuffer.get();
    buf.clear();
    buf.putInt(revision.major());
    commitId.copyRawTo(buf);
    buf.flip();

    // Append a record to the file.
    long pos = (long) (revision.major() - 1) * RECORD_LEN;
    try {
        do {
            pos += channel.write(buf, pos);
        } while (buf.hasRemaining());

        if (safeMode && fsync) {
            channel.force(true);
        }
    } catch (IOException e) {
        throw new StorageException("failed to update the commit ID database: " + path, e);
    }

    if (safeMode ||
        headRevision == null ||
        headRevision.major() < revision.major()) {
        headRevision = revision;
    }
}
 
Example 4
Source File: AbstractEnvironmentManager.java    From onedev with MIT License 4 votes vote down vote up
private static byte[] getBytes(ObjectId commit) {
	byte[] commitBytes = new byte[20];
	commit.copyRawTo(commitBytes, 0);
	return commitBytes;
}
 
Example 5
Source File: ObjectIdSerializer.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull ObjectId value) throws IOException {
  value.copyRawTo(out);
}