Browse Source

Enhance statistics for repo by sizes and ref-counts

The statistics for a repo now expose how many bytes are used in the
filesystem to store all loose/packed objects. The number of packed/loose
refs are also exposed.

Change-Id: I335a4c7630a2629a86f13a2a5cd99f79a2c2afa4
stable-2.1
Christian Halstrick 12 years ago
parent
commit
6b9b024c91
  1. 45
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java

45
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java

@ -74,6 +74,8 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Ref.Storage;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
@ -716,6 +718,26 @@ public class GC {
* The number of objects stored as loose objects.
*/
public long numberOfLooseObjects;
/**
* The sum of the sizes of all files used to persist loose objects.
*/
public long sizeOfLooseObjects;
/**
* The sum of the sizes of all pack files.
*/
public long sizeOfPackedObjects;
/**
* The number of loose refs.
*/
public long numberOfLooseRefs;
/**
* The number of refs stored in pack files.
*/
public long numberOfPackedRefs;
}
/**
@ -728,25 +750,38 @@ public class GC {
public RepoStatistics getStatistics() throws IOException {
RepoStatistics ret = new RepoStatistics();
Collection<PackFile> packs = repo.getObjectDatabase().getPacks();
for (PackFile f : packs)
for (PackFile f : packs) {
ret.numberOfPackedObjects += f.getIndex().getObjectCount();
ret.numberOfPackFiles = packs.size();
ret.numberOfPackFiles++;
ret.sizeOfPackedObjects += f.getPackFile().length();
}
File objDir = repo.getObjectsDirectory();
String[] fanout = objDir.list();
if (fanout != null && fanout.length > 0) {
for (String d : fanout) {
if (d.length() != 2)
continue;
String[] entries = new File(objDir, d).list();
File[] entries = new File(objDir, d).listFiles();
if (entries == null)
continue;
for (String e : entries) {
if (e.length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
for (File f : entries) {
if (f.getName().length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
continue;
ret.numberOfLooseObjects++;
ret.sizeOfLooseObjects += f.length();
}
}
}
RefDatabase refDb = repo.getRefDatabase();
for (Ref r : refDb.getRefs(RefDatabase.ALL).values()) {
Storage storage = r.getStorage();
if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
ret.numberOfLooseRefs++;
if (storage == Storage.PACKED || storage == Storage.LOOSE_PACKED)
ret.numberOfPackedRefs++;
}
return ret;
}

Loading…
Cancel
Save