Browse Source

Merge "Constants for objects and info/{http-,}alternates"

stable-5.5
Jonathan Nieder 5 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
863c2687df
  1. 4
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java
  2. 4
      org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/Lfs.java
  3. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AlternatesTest.java
  4. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
  5. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
  6. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
  7. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java
  8. 18
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
  9. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java
  10. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
  11. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
  12. 4
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java
  13. 10
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java

4
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java

@ -248,13 +248,13 @@ public class GitFilter extends MetaFilter {
.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)//

4
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/Lfs.java

@ -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 class Lfs {
*/ */
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;
} }

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AlternatesTest.java

@ -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 class AlternatesTest extends SampleDataRepositoryTestCase {
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();

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java

@ -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 class PackWriterTest extends SampleDataRepositoryTestCase {
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");
} }

16
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java

@ -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 class T0003_BasicTest extends SampleDataRepositoryTestCase {
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 class T0003_BasicTest extends SampleDataRepositoryTestCase {
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 class T0003_BasicTest extends SampleDataRepositoryTestCase {
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 class T0003_BasicTest extends SampleDataRepositoryTestCase {
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 class T0003_BasicTest extends SampleDataRepositoryTestCase {
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 class T0003_BasicTest extends SampleDataRepositoryTestCase {
} }
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 class T0003_BasicTest extends SampleDataRepositoryTestCase {
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());
} }

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java

@ -171,7 +171,7 @@ public class ObjectDirectory extends FileObjectDatabase {
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;

2
org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java

@ -681,7 +681,7 @@ public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Re
*/ */
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));
} }
/** /**

18
org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java

@ -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";

2
org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java

@ -474,7 +474,7 @@ public class RepositoryCache {
* 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));
} }

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java

@ -259,7 +259,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport {
@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.
} }

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

@ -48,6 +48,8 @@ package org.eclipse.jgit.transport;
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;

4
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java

@ -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 @@ public class TransportSftp extends SshTransport implements WalkTransport {
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(

10
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java

@ -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…
Cancel
Save