diff options
author | Colby Ranger <cranger@google.com> | 2013-01-15 14:24:30 -0800 |
---|---|---|
committer | Colby Ranger <cranger@google.com> | 2013-01-15 15:12:47 -0800 |
commit | 510a60554696586301f1300f3fbef66cc0be1a8f (patch) | |
tree | 007646a5ff4f3376a3d541852feecff23440cbec | |
parent | 5dcc8693d7d1ab81e3d6e6583a3918a3b6003bad (diff) | |
download | jgit-510a60554696586301f1300f3fbef66cc0be1a8f.tar.gz jgit-510a60554696586301f1300f3fbef66cc0be1a8f.zip |
Use file extension with DfsPackDescription get/set file size.
Previously the size getters and setters had explicit methods for index
and pack. Update the api to be based on the file extension. This will
make it possible to support other extensions in the future, such as
the forthcoming bitmap extensions.
Change-Id: Iab9d4abe0af65b2fc71ad71ef1db0feb6b3b5c58
6 files changed, 31 insertions, 40 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java index 5da958a0b7..dd01fa3f17 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.storage.dfs; 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; @@ -65,7 +67,6 @@ import org.eclipse.jgit.revwalk.RevWalk; 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; @@ -319,25 +320,25 @@ public class DfsGarbageCollector { 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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java index a86326e396..51872667f1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java @@ -153,7 +153,7 @@ public class DfsInserter extends ObjectInserter { throw new IOException(); byte[] packHash = packOut.writePackFooter(); - packDsc.setPackSize(packOut.getCount()); + packDsc.setFileSize(PACK_EXT, packOut.getCount()); packOut.close(); packOut = null; @@ -260,7 +260,7 @@ public class DfsInserter extends ObjectInserter { buf.writeTo(cnt, null); else index(cnt, packHash, list); - pack.setIndexSize(cnt.getCount()); + pack.setFileSize(PACK_INDEX_EXT, cnt.getCount()); } finally { os.close(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java index 8515acd7af..ff4c320893 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java @@ -139,7 +139,7 @@ public class DfsPackCompactor { 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; @@ -290,7 +290,7 @@ public class DfsPackCompactor { 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(); } @@ -302,7 +302,7 @@ public class DfsPackCompactor { try { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); - pack.setIndexSize(cnt.getCount()); + pack.setFileSize(PACK_INDEX_EXT, cnt.getCount()); } finally { out.close(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java index e23f14c8fe..62fce3b73a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.storage.dfs; +import java.util.HashMap; +import java.util.Map; import java.util.Set; import org.eclipse.jgit.lib.ObjectId; @@ -67,9 +69,7 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> { private long lastModified; - private long packSize; - - private long indexSize; + private Map<String, Long> sizeMap; private long objectCount; @@ -98,6 +98,7 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> { 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. */ @@ -144,39 +145,27 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> { 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(); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java index 2212116240..8a4bd2e534 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java @@ -165,7 +165,7 @@ public final class DfsPackFile { this.packDesc = desc; this.key = key; - length = desc.getPackSize(); + length = desc.getFileSize(PACK_EXT); if (length <= 0) length = -1; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java index 13943d1a6f..5956f6448e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java @@ -43,6 +43,8 @@ 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; @@ -58,7 +60,6 @@ import org.eclipse.jgit.lib.Constants; 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; @@ -147,7 +148,7 @@ public class DfsPackParser extends PackParser { out = null; currBuf = null; readBlock = null; - packDsc.setPackSize(packEnd); + packDsc.setFileSize(PACK_EXT, packEnd); writePackIndex(); objdb.commitPack(Collections.singletonList(packDsc), null); @@ -206,7 +207,7 @@ public class DfsPackParser extends PackParser { 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(); |