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 static org.eclipse.jgit.storage.pack.PackExt.PACK;
+import static org.eclipse.jgit.storage.pack.PackExt.INDEX;
import java.io.IOException;
import java.util.ArrayList;
DfsPackDescription pack = repo.getObjectDatabase().newPack(source);
newPackDesc.add(pack);
- out = objdb.writeFile(pack, PACK_EXT);
+ out = objdb.writeFile(pack, PACK);
try {
pw.writePack(pm, pm, out);
} finally {
out.close();
}
- out = objdb.writeFile(pack, PACK_INDEX_EXT);
+ out = objdb.writeFile(pack, INDEX);
try {
CountingOutputStream cnt = new CountingOutputStream(out);
pw.writeIndex(cnt);
- pack.setFileSize(PACK_INDEX_EXT, cnt.getCount());
+ pack.setFileSize(INDEX, cnt.getCount());
} finally {
out.close();
}
PackWriter.Statistics stats = pw.getStatistics();
pack.setPackStats(stats);
- pack.setFileSize(PACK_EXT, stats.getTotalBytes());
+ pack.setFileSize(PACK, stats.getTotalBytes());
pack.setObjectCount(stats.getTotalObjects());
pack.setDeltaCount(stats.getTotalDeltas());
objectsPacked += stats.getTotalObjects();
package org.eclipse.jgit.storage.dfs;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT;
+import static org.eclipse.jgit.storage.pack.PackExt.PACK;
+import static org.eclipse.jgit.storage.pack.PackExt.INDEX;
import java.io.EOFException;
import java.io.IOException;
throw new IOException();
byte[] packHash = packOut.writePackFooter();
- packDsc.setFileSize(PACK_EXT, packOut.getCount());
+ packDsc.setFileSize(PACK, packOut.getCount());
packOut.close();
packOut = null;
rollback = true;
packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT);
- packOut = new PackStream(db.writeFile(packDsc, PACK_EXT));
+ packOut = new PackStream(db.writeFile(packDsc, PACK));
packKey = new DfsPackKey();
// Write the header as though it were a single object pack.
packIndex = PackIndex.read(buf.openInputStream());
}
- DfsOutputStream os = db.writeFile(pack, PACK_INDEX_EXT);
+ DfsOutputStream os = db.writeFile(pack, INDEX);
try {
CountingOutputStream cnt = new CountingOutputStream(os);
if (buf != null)
buf.writeTo(cnt, null);
else
index(cnt, packHash, list);
- pack.setFileSize(PACK_INDEX_EXT, cnt.getCount());
+ pack.setFileSize(INDEX, cnt.getCount());
} finally {
os.close();
}
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectReader;
+import org.eclipse.jgit.storage.pack.PackExt;
/** Manages objects stored in {@link DfsPackFile} on a storage system. */
public abstract class DfsObjDatabase extends ObjectDatabase {
* the file cannot be opened.
*/
protected abstract ReadableChannel openFile(
- DfsPackDescription desc, String ext)
+ DfsPackDescription desc, PackExt ext)
throws FileNotFoundException, IOException;
/**
* the file cannot be opened.
*/
protected abstract DfsOutputStream writeFile(
- DfsPackDescription desc, String ext) throws IOException;
+ DfsPackDescription desc, PackExt ext) throws IOException;
void addPack(DfsPackFile newPack) throws IOException {
PackList o, n;
package org.eclipse.jgit.storage.dfs;
import static org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource.COMPACT;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT;
+import static org.eclipse.jgit.storage.pack.PackExt.PACK;
+import static org.eclipse.jgit.storage.pack.PackExt.INDEX;
import java.io.IOException;
import java.util.ArrayList;
DfsObjDatabase objdb = repo.getObjectDatabase();
for (DfsPackFile pack : objdb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getFileSize(PACK_EXT) < autoAddSize)
+ if (d.getFileSize(PACK) < autoAddSize)
add(pack);
}
return this;
private void writePack(DfsObjDatabase objdb, DfsPackDescription pack,
PackWriter pw, ProgressMonitor pm) throws IOException {
- DfsOutputStream out = objdb.writeFile(pack, PACK_EXT);
+ DfsOutputStream out = objdb.writeFile(pack, PACK);
try {
CountingOutputStream cnt = new CountingOutputStream(out);
pw.writePack(pm, pm, cnt);
pack.setObjectCount(pw.getObjectCount());
- pack.setFileSize(PACK_EXT, cnt.getCount());
+ pack.setFileSize(PACK, cnt.getCount());
} finally {
out.close();
}
private void writeIndex(DfsObjDatabase objdb, DfsPackDescription pack,
PackWriter pw) throws IOException {
- DfsOutputStream out = objdb.writeFile(pack, PACK_INDEX_EXT);
+ DfsOutputStream out = objdb.writeFile(pack, INDEX);
try {
CountingOutputStream cnt = new CountingOutputStream(out);
pw.writeIndex(cnt);
- pack.setFileSize(PACK_INDEX_EXT, cnt.getCount());
+ pack.setFileSize(INDEX, cnt.getCount());
} finally {
out.close();
}
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource;
-import org.eclipse.jgit.storage.pack.PackConstants;
+import org.eclipse.jgit.storage.pack.PackExt;
import org.eclipse.jgit.storage.pack.PackWriter;
/**
private long lastModified;
- private Map<String, Long> sizeMap;
+ private Map<PackExt, 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);
+ this.sizeMap = new HashMap<PackExt, Long>(5);
}
/** @return description of the repository. */
* the file extension
* @return name of the file.
* */
- public String getFileName(String ext) {
- return packName + '.' + ext;
+ public String getFileName(PackExt ext) {
+ return packName + '.' + ext.getExtension();
}
/** @return the source of the pack. */
* be determined on first read.
* @return {@code this}
*/
- public DfsPackDescription setFileSize(String ext, long bytes) {
+ public DfsPackDescription setFileSize(PackExt ext, long bytes) {
sizeMap.put(ext, Long.valueOf(Math.max(0, bytes)));
return this;
}
* the file extension.
* @return size of the file, in bytes. If 0 the file size is not yet known.
*/
- public long getFileSize(String ext) {
+ public long getFileSize(PackExt ext) {
Long size = sizeMap.get(ext);
return size == null ? 0 : size.longValue();
}
@Override
public String toString() {
- return getFileName(PackConstants.PACK_EXT);
+ return getFileName(PackExt.PACK);
}
}
package org.eclipse.jgit.storage.dfs;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT;
+import static org.eclipse.jgit.storage.pack.PackExt.PACK;
+import static org.eclipse.jgit.storage.pack.PackExt.INDEX;
import java.io.BufferedInputStream;
import java.io.EOFException;
this.packDesc = desc;
this.key = key;
- length = desc.getFileSize(PACK_EXT);
+ length = desc.getFileSize(PACK);
if (length <= 0)
length = -1;
}
}
private String getPackName() {
- return packDesc.getFileName(PACK_EXT);
+ return packDesc.getFileName(PACK);
}
void setBlockSize(int newSize) {
PackIndex idx;
try {
- ReadableChannel rc = ctx.db.openFile(packDesc, PACK_INDEX_EXT);
+ ReadableChannel rc = ctx.db.openFile(packDesc, INDEX);
try {
InputStream in = Channels.newInputStream(rc);
int wantSize = 8192;
invalid = true;
IOException e2 = new IOException(MessageFormat.format(
DfsText.get().shortReadOfIndex,
- packDesc.getFileName(PACK_INDEX_EXT)));
+ packDesc.getFileName(INDEX)));
e2.initCause(e);
throw e2;
} catch (IOException e) {
invalid = true;
IOException e2 = new IOException(MessageFormat.format(
DfsText.get().cannotReadIndex,
- packDesc.getFileName(PACK_INDEX_EXT)));
+ packDesc.getFileName(INDEX)));
e2.initCause(e);
throw e2;
}
throw new PackInvalidException(getPackName());
boolean close = true;
- ReadableChannel rc = ctx.db.openFile(packDesc, PACK_EXT);
+ ReadableChannel rc = ctx.db.openFile(packDesc, PACK);
try {
// If the block alignment is not yet known, discover it. Prefer the
// larger size from either the cache or the file itself.
package org.eclipse.jgit.storage.dfs;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT;
+import static org.eclipse.jgit.storage.pack.PackExt.PACK;
import java.io.EOFException;
import java.io.IOException;
out = null;
currBuf = null;
readBlock = null;
- packDsc.setFileSize(PACK_EXT, packEnd);
+ packDsc.setFileSize(PACK, packEnd);
writePackIndex();
objdb.commitPack(Collections.singletonList(packDsc), null);
packDsc = objdb.newPack(DfsObjDatabase.PackSource.RECEIVE);
packKey = new DfsPackKey();
- out = objdb.writeFile(packDsc, PACK_EXT);
+ out = objdb.writeFile(packDsc, PACK);
int size = out.blockSize();
if (size <= 0)
size = blockCache.getBlockSize();
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.eclipse.jgit.lib.Constants.OBJ_TREE;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT;
+import static org.eclipse.jgit.storage.pack.PackExt.PACK;
import java.io.IOException;
import java.io.InterruptedIOException;
pack.setInvalid();
throw new IOException(MessageFormat.format(
JGitText.get().packfileCorruptionDetected,
- pack.getPackDescription().getFileName(PACK_EXT)));
+ pack.getPackDescription().getFileName(PACK)));
}
}
}
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Ref.Storage;
+import org.eclipse.jgit.storage.pack.PackExt;
import org.eclipse.jgit.util.RefList;
/**
}
@Override
- protected ReadableChannel openFile(DfsPackDescription desc, String ext)
+ protected ReadableChannel openFile(DfsPackDescription desc, PackExt ext)
throws FileNotFoundException, IOException {
MemPack memPack = (MemPack) desc;
byte[] file = memPack.fileMap.get(ext);
@Override
protected DfsOutputStream writeFile(
- DfsPackDescription desc, final String ext) throws IOException {
+ DfsPackDescription desc, final PackExt ext) throws IOException {
final MemPack memPack = (MemPack) desc;
return new Out() {
@Override
}
private static class MemPack extends DfsPackDescription {
- private final Map<String, byte[]>
- fileMap = new HashMap<String, byte[]>();
+ private final Map<PackExt, byte[]>
+ fileMap = new HashMap<PackExt, byte[]>();
MemPack(String name, DfsRepositoryDescription repoDesc) {
super(repoDesc, name);
package org.eclipse.jgit.storage.file;
-import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT;
+import static org.eclipse.jgit.storage.pack.PackExt.INDEX;
import java.io.EOFException;
import java.io.File;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.storage.pack.BinaryDelta;
import org.eclipse.jgit.storage.pack.ObjectToPack;
+import org.eclipse.jgit.storage.pack.PackExt;
import org.eclipse.jgit.storage.pack.PackOutputStream;
import org.eclipse.jgit.util.LongList;
import org.eclipse.jgit.util.NB;
throw new PackInvalidException(packFile);
try {
- final PackIndex idx = PackIndex.open(extFile(PACK_INDEX_EXT));
+ final PackIndex idx = PackIndex.open(extFile(INDEX));
if (packChecksum == null)
packChecksum = idx.packChecksum;
}
}
- private File extFile(String ext) {
+ private File extFile(PackExt ext) {
String p = packFile.getName();
int dot = p.lastIndexOf('.');
String b = (dot < 0) ? p : p.substring(0, dot);
- return new File(packFile.getParentFile(), b + '.' + ext);
+ return new File(packFile.getParentFile(), b + '.' + ext.getExtension());
}
}
+++ /dev/null
-/*
- * Copyright (C) 2013, Google Inc.
- * and other copyright owners as documented in the project's IP log.
- *
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package org.eclipse.jgit.storage.pack;
-
-/** Misc. constants used with pack files. */
-public class PackConstants {
-
- /** A pack file extension. */
- public static final String PACK_EXT = "pack"; //$NON-NLS-1$
-
- /** A pack index file extension. */
- public static final String PACK_INDEX_EXT = "idx"; //$NON-NLS-1$
-
- private PackConstants() {
- }
-}
--- /dev/null
+/*
+ * Copyright (C) 2013, Google Inc.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.storage.pack;
+
+/** A pack file extension. */
+public class PackExt {
+
+ /** A pack file extension. */
+ public static final PackExt PACK = new PackExt("pack"); //$NON-NLS-1$
+
+ /** A pack index file extension. */
+ public static final PackExt INDEX = new PackExt("idx"); //$NON-NLS-1$
+
+ private final String ext;
+
+ /**
+ * @param ext
+ * the file extension.
+ */
+ public PackExt(String ext) {
+ this.ext = ext;
+ }
+
+ /** @return the file extension. */
+ public String getExtension() {
+ return ext;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof PackExt) {
+ return ((PackExt) obj).getExtension().equals(getExtension());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return getExtension().hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return String.format("PackExt[%s]", getExtension()); //$NON-NLS-1$
+ }
+}