I have a bunch of object ids referring to blobs in a given git repository.
Using JGit, I would like to obtain the sizes of these blobs. That is, the number of bytes their content represent (uncompressed, thus).
If I understand correctly, this information is stored in git in a way that permits fast access to it.
But the way I currently access it through JGit is slow. It often takes several tens of milliseconds to get a blob size. (See code below.) If I understand correctly, JGit reads the whole blob when it is small enough, a waste of time in my case as I most often only need the size. (I am ready to pay an extra access time cost if I then need to access the blob content.)
Can I get a blob size faster?
Here is my current code. Given a FileRepository repository and reader = repository.newObjectReader() (initialized only once).
long getSize(ObjectId objectId) throws IOException {
ObjectLoader fileLoader = reader.open(objectId);
return fileLoader.getSize();
}
Oddly enough, setting reader.setStreamFileThreshold(8); does not seem to help.
[Updated on: Tue, 26 January 2021 05:42] by Moderator