Constants for objects and info/{http-,}alternates
These are useful to avoid typos, and also for tab completion. Change-Id: I0f2d267e46b36bc40297c9657c447f3fd8b9f831 Signed-off-by: David Turner <dturner@twosigma.com>
This commit is contained in:
parent
e9dd131d55
commit
59640fb4f0
|
@ -248,13 +248,13 @@ public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
.through(enabled)//
|
.through(enabled)//
|
||||||
.with(new TextFileServlet(Constants.HEAD));
|
.with(new TextFileServlet(Constants.HEAD));
|
||||||
|
|
||||||
final String info_alternates = "objects/info/alternates";
|
final String info_alternates = Constants.OBJECTS + "/" + Constants.INFO_ALTERNATES;
|
||||||
serve("*/" + info_alternates)//
|
serve("*/" + info_alternates)//
|
||||||
.through(mustBeLocal)//
|
.through(mustBeLocal)//
|
||||||
.through(enabled)//
|
.through(enabled)//
|
||||||
.with(new TextFileServlet(info_alternates));
|
.with(new TextFileServlet(info_alternates));
|
||||||
|
|
||||||
final String http_alternates = "objects/info/http-alternates";
|
final String http_alternates = Constants.OBJECTS + "/" + Constants.INFO_HTTP_ALTERNATES;
|
||||||
serve("*/" + http_alternates)//
|
serve("*/" + http_alternates)//
|
||||||
.through(mustBeLocal)//
|
.through(mustBeLocal)//
|
||||||
.through(enabled)//
|
.through(enabled)//
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.jgit.lfs;
|
package org.eclipse.jgit.lfs;
|
||||||
|
|
||||||
|
import static org.eclipse.jgit.lib.Constants.OBJECTS;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -104,7 +106,7 @@ public Path getLfsTmpDir() {
|
||||||
*/
|
*/
|
||||||
public Path getLfsObjDir() {
|
public Path getLfsObjDir() {
|
||||||
if (objDir == null) {
|
if (objDir == null) {
|
||||||
objDir = root.resolve("objects"); //$NON-NLS-1$
|
objDir = root.resolve(OBJECTS);
|
||||||
}
|
}
|
||||||
return objDir;
|
return objDir;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.jgit.internal.storage.file;
|
package org.eclipse.jgit.internal.storage.file;
|
||||||
|
|
||||||
|
import static org.eclipse.jgit.lib.Constants.INFO_ALTERNATES;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -76,7 +77,7 @@ public void setUp() throws Exception {
|
||||||
private void setAlternate(FileRepository from, FileRepository to)
|
private void setAlternate(FileRepository from, FileRepository to)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
File alt = new File(from.getObjectDatabase().getDirectory(),
|
File alt = new File(from.getObjectDatabase().getDirectory(),
|
||||||
"info/alternates");
|
INFO_ALTERNATES);
|
||||||
alt.getParentFile().mkdirs();
|
alt.getParentFile().mkdirs();
|
||||||
File fromDir = from.getObjectDatabase().getDirectory();
|
File fromDir = from.getObjectDatabase().getDirectory();
|
||||||
File toDir = to.getObjectDatabase().getDirectory();
|
File toDir = to.getObjectDatabase().getDirectory();
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
package org.eclipse.jgit.internal.storage.file;
|
package org.eclipse.jgit.internal.storage.file;
|
||||||
|
|
||||||
import static org.eclipse.jgit.internal.storage.pack.PackWriter.NONE;
|
import static org.eclipse.jgit.internal.storage.pack.PackWriter.NONE;
|
||||||
|
import static org.eclipse.jgit.lib.Constants.INFO_ALTERNATES;
|
||||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -138,7 +139,7 @@ public void setUp() throws Exception {
|
||||||
config = new PackConfig(db);
|
config = new PackConfig(db);
|
||||||
|
|
||||||
dst = createBareRepository();
|
dst = createBareRepository();
|
||||||
File alt = new File(dst.getObjectDatabase().getDirectory(), "info/alternates");
|
File alt = new File(dst.getObjectDatabase().getDirectory(), INFO_ALTERNATES);
|
||||||
alt.getParentFile().mkdirs();
|
alt.getParentFile().mkdirs();
|
||||||
write(alt, db.getObjectDatabase().getDirectory().getAbsolutePath() + "\n");
|
write(alt, db.getObjectDatabase().getDirectory().getAbsolutePath() + "\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
|
||||||
public void test001_Initalize() {
|
public void test001_Initalize() {
|
||||||
final File gitdir = new File(trash, Constants.DOT_GIT);
|
final File gitdir = new File(trash, Constants.DOT_GIT);
|
||||||
final File hooks = new File(gitdir, "hooks");
|
final File hooks = new File(gitdir, "hooks");
|
||||||
final File objects = new File(gitdir, "objects");
|
final File objects = new File(gitdir, Constants.OBJECTS);
|
||||||
final File objects_pack = new File(objects, "pack");
|
final File objects_pack = new File(objects, "pack");
|
||||||
final File objects_info = new File(objects, "info");
|
final File objects_info = new File(objects, "info");
|
||||||
final File refs = new File(gitdir, "refs");
|
final File refs = new File(gitdir, "refs");
|
||||||
|
@ -148,7 +148,7 @@ public void test000_openrepo_default_gitDirSet() throws IOException {
|
||||||
assertEqualsPath(theDir, r.getDirectory());
|
assertEqualsPath(theDir, r.getDirectory());
|
||||||
assertEqualsPath(repo1Parent, r.getWorkTree());
|
assertEqualsPath(repo1Parent, r.getWorkTree());
|
||||||
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
||||||
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
|
assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
|
||||||
.getDirectory());
|
.getDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ public void test000_openrepo_default_gitDirAndWorkTreeSet()
|
||||||
assertEqualsPath(theDir, r.getDirectory());
|
assertEqualsPath(theDir, r.getDirectory());
|
||||||
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
|
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
|
||||||
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
||||||
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
|
assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
|
||||||
.getDirectory());
|
.getDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ public void test000_openrepo_default_workDirSet() throws IOException {
|
||||||
assertEqualsPath(theDir, r.getDirectory());
|
assertEqualsPath(theDir, r.getDirectory());
|
||||||
assertEqualsPath(repo1Parent, r.getWorkTree());
|
assertEqualsPath(repo1Parent, r.getWorkTree());
|
||||||
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
||||||
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
|
assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
|
||||||
.getDirectory());
|
.getDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ public void test000_openrepo_default_absolute_workdirconfig()
|
||||||
assertEqualsPath(theDir, r.getDirectory());
|
assertEqualsPath(theDir, r.getDirectory());
|
||||||
assertEqualsPath(workdir, r.getWorkTree());
|
assertEqualsPath(workdir, r.getWorkTree());
|
||||||
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
||||||
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
|
assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
|
||||||
.getDirectory());
|
.getDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ public void test000_openrepo_default_relative_workdirconfig()
|
||||||
assertEqualsPath(theDir, r.getDirectory());
|
assertEqualsPath(theDir, r.getDirectory());
|
||||||
assertEqualsPath(workdir, r.getWorkTree());
|
assertEqualsPath(workdir, r.getWorkTree());
|
||||||
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
|
||||||
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
|
assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
|
||||||
.getDirectory());
|
.getDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ public void test002_WriteEmptyTree() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
final File o = new File(new File(new File(newdb.getDirectory(),
|
final File o = new File(new File(new File(newdb.getDirectory(),
|
||||||
"objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904");
|
Constants.OBJECTS), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904");
|
||||||
assertTrue("Exists " + o, o.isFile());
|
assertTrue("Exists " + o, o.isFile());
|
||||||
assertTrue("Read-only " + o, !o.canWrite());
|
assertTrue("Read-only " + o, !o.canWrite());
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ public void test002_WriteEmptyTree2() throws IOException {
|
||||||
final ObjectId treeId = insertTree(new TreeFormatter());
|
final ObjectId treeId = insertTree(new TreeFormatter());
|
||||||
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
|
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
|
||||||
final File o = new File(new File(
|
final File o = new File(new File(
|
||||||
new File(db.getDirectory(), "objects"), "4b"),
|
new File(db.getDirectory(), Constants.OBJECTS), "4b"),
|
||||||
"825dc642cb6eb9a060e54bf8d69288fbee4904");
|
"825dc642cb6eb9a060e54bf8d69288fbee4904");
|
||||||
assertFalse("Exists " + o, o.isFile());
|
assertFalse("Exists " + o, o.isFile());
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ public ObjectDirectory(final Config cfg, final File dir,
|
||||||
infoDirectory = new File(objects, "info"); //$NON-NLS-1$
|
infoDirectory = new File(objects, "info"); //$NON-NLS-1$
|
||||||
packDirectory = new File(objects, "pack"); //$NON-NLS-1$
|
packDirectory = new File(objects, "pack"); //$NON-NLS-1$
|
||||||
preservedDirectory = new File(packDirectory, "preserved"); //$NON-NLS-1$
|
preservedDirectory = new File(packDirectory, "preserved"); //$NON-NLS-1$
|
||||||
alternatesFile = new File(infoDirectory, "alternates"); //$NON-NLS-1$
|
alternatesFile = new File(objects, Constants.INFO_ALTERNATES);
|
||||||
packList = new AtomicReference<>(NO_PACKS);
|
packList = new AtomicReference<>(NO_PACKS);
|
||||||
unpackedObjectCache = new UnpackedObjectCache();
|
unpackedObjectCache = new UnpackedObjectCache();
|
||||||
this.fs = fs;
|
this.fs = fs;
|
||||||
|
|
|
@ -681,7 +681,7 @@ protected void setupWorkTree() throws IOException {
|
||||||
*/
|
*/
|
||||||
protected void setupInternals() throws IOException {
|
protected void setupInternals() throws IOException {
|
||||||
if (getObjectDirectory() == null && getGitDir() != null)
|
if (getObjectDirectory() == null && getGitDir() != null)
|
||||||
setObjectDirectory(safeFS().resolve(getGitDir(), "objects")); //$NON-NLS-1$
|
setObjectDirectory(safeFS().resolve(getGitDir(), Constants.OBJECTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -275,9 +275,27 @@ public final class Constants {
|
||||||
/** Logs folder name */
|
/** Logs folder name */
|
||||||
public static final String LOGS = "logs";
|
public static final String LOGS = "logs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Objects folder name
|
||||||
|
* @since 5.5
|
||||||
|
*/
|
||||||
|
public static final String OBJECTS = "objects";
|
||||||
|
|
||||||
/** Info refs folder */
|
/** Info refs folder */
|
||||||
public static final String INFO_REFS = "info/refs";
|
public static final String INFO_REFS = "info/refs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Info alternates file (goes under OBJECTS)
|
||||||
|
* @since 5.5
|
||||||
|
*/
|
||||||
|
public static final String INFO_ALTERNATES = "info/alternates";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP alternates file (goes under OBJECTS)
|
||||||
|
* @since 5.5
|
||||||
|
*/
|
||||||
|
public static final String INFO_HTTP_ALTERNATES = "info/http-alternates";
|
||||||
|
|
||||||
/** Packed refs file */
|
/** Packed refs file */
|
||||||
public static final String PACKED_REFS = "packed-refs";
|
public static final String PACKED_REFS = "packed-refs";
|
||||||
|
|
||||||
|
|
|
@ -474,7 +474,7 @@ public String toString() {
|
||||||
* Git directory.
|
* Git directory.
|
||||||
*/
|
*/
|
||||||
public static boolean isGitRepository(File dir, FS fs) {
|
public static boolean isGitRepository(File dir, FS fs) {
|
||||||
return fs.resolve(dir, "objects").exists() //$NON-NLS-1$
|
return fs.resolve(dir, Constants.OBJECTS).exists()
|
||||||
&& fs.resolve(dir, "refs").exists() //$NON-NLS-1$
|
&& fs.resolve(dir, "refs").exists() //$NON-NLS-1$
|
||||||
&& isValidHead(new File(dir, Constants.HEAD));
|
&& isValidHead(new File(dir, Constants.HEAD));
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ URIish getURI() {
|
||||||
@Override
|
@Override
|
||||||
Collection<WalkRemoteObjectDatabase> getAlternates() throws IOException {
|
Collection<WalkRemoteObjectDatabase> getAlternates() throws IOException {
|
||||||
try {
|
try {
|
||||||
return readAlternates(INFO_ALTERNATES);
|
return readAlternates(Constants.INFO_ALTERNATES);
|
||||||
} catch (FileNotFoundException err) {
|
} catch (FileNotFoundException err) {
|
||||||
// Fall through.
|
// Fall through.
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.eclipse.jgit.lib.Constants.HEAD;
|
import static org.eclipse.jgit.lib.Constants.HEAD;
|
||||||
|
import static org.eclipse.jgit.lib.Constants.INFO_ALTERNATES;
|
||||||
|
import static org.eclipse.jgit.lib.Constants.INFO_HTTP_ALTERNATES;
|
||||||
import static org.eclipse.jgit.util.HttpSupport.ENCODING_GZIP;
|
import static org.eclipse.jgit.util.HttpSupport.ENCODING_GZIP;
|
||||||
import static org.eclipse.jgit.util.HttpSupport.ENCODING_X_GZIP;
|
import static org.eclipse.jgit.util.HttpSupport.ENCODING_X_GZIP;
|
||||||
import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT;
|
import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT;
|
||||||
|
|
|
@ -43,7 +43,9 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.transport;
|
package org.eclipse.jgit.transport;
|
||||||
|
|
||||||
|
import static org.eclipse.jgit.lib.Constants.INFO_ALTERNATES;
|
||||||
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
|
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
|
||||||
|
import static org.eclipse.jgit.lib.Constants.OBJECTS;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -172,7 +174,7 @@ class SftpObjectDB extends WalkRemoteObjectDatabase {
|
||||||
try {
|
try {
|
||||||
ftp = newSftp();
|
ftp = newSftp();
|
||||||
ftp.cd(path);
|
ftp.cd(path);
|
||||||
ftp.cd("objects"); //$NON-NLS-1$
|
ftp.cd(OBJECTS);
|
||||||
objectsPath = ftp.pwd();
|
objectsPath = ftp.pwd();
|
||||||
} catch (FtpChannel.FtpException f) {
|
} catch (FtpChannel.FtpException f) {
|
||||||
throw new TransportException(MessageFormat.format(
|
throw new TransportException(MessageFormat.format(
|
||||||
|
|
|
@ -82,10 +82,6 @@ abstract class WalkRemoteObjectDatabase {
|
||||||
|
|
||||||
static final String INFO_PACKS = "info/packs"; //$NON-NLS-1$
|
static final String INFO_PACKS = "info/packs"; //$NON-NLS-1$
|
||||||
|
|
||||||
static final String INFO_ALTERNATES = "info/alternates"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
static final String INFO_HTTP_ALTERNATES = "info/http-alternates"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
static final String INFO_REFS = ROOT_DIR + Constants.INFO_REFS;
|
static final String INFO_REFS = ROOT_DIR + Constants.INFO_REFS;
|
||||||
|
|
||||||
abstract URIish getURI();
|
abstract URIish getURI();
|
||||||
|
@ -107,8 +103,10 @@ abstract class WalkRemoteObjectDatabase {
|
||||||
/**
|
/**
|
||||||
* Obtain alternate connections to alternate object databases (if any).
|
* Obtain alternate connections to alternate object databases (if any).
|
||||||
* <p>
|
* <p>
|
||||||
* Alternates are typically read from the file {@link #INFO_ALTERNATES} or
|
* Alternates are typically read from the file
|
||||||
* {@link #INFO_HTTP_ALTERNATES}. The content of each line must be resolved
|
* {@link org.eclipse.jgit.lib.Constants#INFO_ALTERNATES} or
|
||||||
|
* {@link org.eclipse.jgit.lib.Constants#INFO_HTTP_ALTERNATES}.
|
||||||
|
* The content of each line must be resolved
|
||||||
* by the implementation and a new database reference should be returned to
|
* by the implementation and a new database reference should be returned to
|
||||||
* represent the additional location.
|
* represent the additional location.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
Loading…
Reference in New Issue