import static org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource.GC;
import static org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE;
+import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT;
+import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT;
import java.io.IOException;
import java.util.ArrayList;
import org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource;
import org.eclipse.jgit.storage.file.PackIndex;
import org.eclipse.jgit.storage.pack.PackConfig;
-import org.eclipse.jgit.storage.pack.PackConstants;
import org.eclipse.jgit.storage.pack.PackWriter;
import org.eclipse.jgit.util.io.CountingOutputStream;
DfsPackDescription pack = repo.getObjectDatabase().newPack(source);
newPackDesc.add(pack);
- out = objdb.writeFile(pack, PackConstants.PACK_EXT);
+ out = objdb.writeFile(pack, PACK_EXT);
try {
pw.writePack(pm, pm, out);
} finally {
out.close();
}
- out = objdb.writeFile(pack, PackConstants.PACK_INDEX_EXT);
+ out = objdb.writeFile(pack, PACK_INDEX_EXT);
try {
CountingOutputStream cnt = new CountingOutputStream(out);
pw.writeIndex(cnt);
- pack.setIndexSize(cnt.getCount());
+ pack.setFileSize(PACK_INDEX_EXT, cnt.getCount());
} finally {
out.close();
}
PackWriter.Statistics stats = pw.getStatistics();
pack.setPackStats(stats);
- pack.setPackSize(stats.getTotalBytes());
+ pack.setFileSize(PACK_EXT, stats.getTotalBytes());
pack.setObjectCount(stats.getTotalObjects());
pack.setDeltaCount(stats.getTotalDeltas());
objectsPacked += stats.getTotalObjects();
throw new IOException();
byte[] packHash = packOut.writePackFooter();
- packDsc.setPackSize(packOut.getCount());
+ packDsc.setFileSize(PACK_EXT, packOut.getCount());
packOut.close();
packOut = null;
buf.writeTo(cnt, null);
else
index(cnt, packHash, list);
- pack.setIndexSize(cnt.getCount());
+ pack.setFileSize(PACK_INDEX_EXT, cnt.getCount());
} finally {
os.close();
}
DfsObjDatabase objdb = repo.getObjectDatabase();
for (DfsPackFile pack : objdb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSize() < autoAddSize)
+ if (d.getFileSize(PACK_EXT) < autoAddSize)
add(pack);
}
return this;
CountingOutputStream cnt = new CountingOutputStream(out);
pw.writePack(pm, pm, cnt);
pack.setObjectCount(pw.getObjectCount());
- pack.setPackSize(cnt.getCount());
+ pack.setFileSize(PACK_EXT, cnt.getCount());
} finally {
out.close();
}
try {
CountingOutputStream cnt = new CountingOutputStream(out);
pw.writeIndex(cnt);
- pack.setIndexSize(cnt.getCount());
+ pack.setFileSize(PACK_INDEX_EXT, cnt.getCount());
} finally {
out.close();
}
package org.eclipse.jgit.storage.dfs;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.lib.ObjectId;
private long lastModified;
- private long packSize;
-
- private long indexSize;
+ private Map<String, Long> sizeMap;
private long objectCount;
this.repoDesc = repoDesc;
int dot = name.lastIndexOf('.');
this.packName = (dot < 0) ? name : name.substring(0, dot);
+ this.sizeMap = new HashMap<String, Long>(5);
}
/** @return description of the repository. */
return this;
}
- /** @return size of the pack, in bytes. If 0 the pack size is not yet known. */
- public long getPackSize() {
- return packSize;
- }
-
/**
+ * @param ext
+ * the file extension.
* @param bytes
- * size of the pack in bytes. If 0 the size is not known and will
+ * size of the file in bytes. If 0 the file is not known and will
* be determined on first read.
* @return {@code this}
*/
- public DfsPackDescription setPackSize(long bytes) {
- packSize = Math.max(0, bytes);
+ public DfsPackDescription setFileSize(String ext, long bytes) {
+ sizeMap.put(ext, Long.valueOf(Math.max(0, bytes)));
return this;
}
/**
- * @return size of the index, in bytes. If 0 the index size is not yet
- * known.
- */
- public long getIndexSize() {
- return indexSize;
- }
-
- /**
- * @param bytes
- * size of the index in bytes. If 0 the size is not known and
- * will be determined on first read.
- * @return {@code this}
+ * @param ext
+ * the file extension.
+ * @return size of the file, in bytes. If 0 the file size is not yet known.
*/
- public DfsPackDescription setIndexSize(long bytes) {
- indexSize = Math.max(0, bytes);
- return this;
+ public long getFileSize(String ext) {
+ Long size = sizeMap.get(ext);
+ return size == null ? 0 : size.longValue();
}
/**
this.packDesc = desc;
this.key = key;
- length = desc.getPackSize();
+ length = desc.getFileSize(PACK_EXT);
if (length <= 0)
length = -1;
}
package org.eclipse.jgit.storage.dfs;
+import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT;
+
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.storage.file.PackIndex;
import org.eclipse.jgit.storage.file.PackLock;
-import org.eclipse.jgit.storage.pack.PackConstants;
import org.eclipse.jgit.transport.PackParser;
import org.eclipse.jgit.transport.PackedObjectInfo;
out = null;
currBuf = null;
readBlock = null;
- packDsc.setPackSize(packEnd);
+ packDsc.setFileSize(PACK_EXT, packEnd);
writePackIndex();
objdb.commitPack(Collections.singletonList(packDsc), null);
packDsc = objdb.newPack(DfsObjDatabase.PackSource.RECEIVE);
packKey = new DfsPackKey();
- out = objdb.writeFile(packDsc, PackConstants.PACK_EXT);
+ out = objdb.writeFile(packDsc, PACK_EXT);
int size = out.blockSize();
if (size <= 0)
size = blockCache.getBlockSize();