Use FileKey to resolve Git repository arguments
upload-pack and receive-pack take a git repository as an argument, but its a lenient path format. Locate the repository and open it. Change-Id: I4b377e57b28ba3b1717c13d9ab51a602de1ad257 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
553c2e5a42
commit
2370ad9514
|
@ -47,9 +47,10 @@
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
|
||||||
|
import org.eclipse.jgit.util.FS;
|
||||||
import org.kohsuke.args4j.Argument;
|
import org.kohsuke.args4j.Argument;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
|
||||||
import org.eclipse.jgit.lib.Repository;
|
|
||||||
|
|
||||||
@Command(common = false, usage = "usage_ServerSideBackendForJgitPush")
|
@Command(common = false, usage = "usage_ServerSideBackendForJgitPush")
|
||||||
class ReceivePack extends TextBuiltin {
|
class ReceivePack extends TextBuiltin {
|
||||||
|
@ -65,11 +66,14 @@ protected final boolean requiresRepository() {
|
||||||
protected void run() throws Exception {
|
protected void run() throws Exception {
|
||||||
final org.eclipse.jgit.transport.ReceivePack rp;
|
final org.eclipse.jgit.transport.ReceivePack rp;
|
||||||
|
|
||||||
if (new File(dstGitdir, Constants.DOT_GIT).isDirectory())
|
try {
|
||||||
dstGitdir = new File(dstGitdir, Constants.DOT_GIT);
|
FileKey key = FileKey.lenient(dstGitdir, FS.DETECTED);
|
||||||
db = new Repository(dstGitdir);
|
db = key.open(true /* must exist */);
|
||||||
if (!db.getObjectsDirectory().isDirectory())
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
throw die(MessageFormat.format(CLIText.get().notAGitRepository, dstGitdir.getPath()));
|
throw die(MessageFormat.format(CLIText.get().notAGitRepository,
|
||||||
|
dstGitdir.getPath()));
|
||||||
|
}
|
||||||
|
|
||||||
rp = new org.eclipse.jgit.transport.ReceivePack(db);
|
rp = new org.eclipse.jgit.transport.ReceivePack(db);
|
||||||
rp.receive(System.in, System.out, System.err);
|
rp.receive(System.in, System.out, System.err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,11 @@
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
|
||||||
|
import org.eclipse.jgit.util.FS;
|
||||||
import org.kohsuke.args4j.Argument;
|
import org.kohsuke.args4j.Argument;
|
||||||
import org.kohsuke.args4j.Option;
|
import org.kohsuke.args4j.Option;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
|
||||||
import org.eclipse.jgit.lib.Repository;
|
|
||||||
|
|
||||||
@Command(common = false, usage = "usage_ServerSideBackendForJgitFetch")
|
@Command(common = false, usage = "usage_ServerSideBackendForJgitFetch")
|
||||||
class UploadPack extends TextBuiltin {
|
class UploadPack extends TextBuiltin {
|
||||||
|
@ -67,16 +68,19 @@ protected final boolean requiresRepository() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run() throws Exception {
|
protected void run() throws Exception {
|
||||||
final org.eclipse.jgit.transport.UploadPack rp;
|
final org.eclipse.jgit.transport.UploadPack up;
|
||||||
|
|
||||||
if (new File(srcGitdir, Constants.DOT_GIT).isDirectory())
|
try {
|
||||||
srcGitdir = new File(srcGitdir, Constants.DOT_GIT);
|
FileKey key = FileKey.lenient(srcGitdir, FS.DETECTED);
|
||||||
db = new Repository(srcGitdir);
|
db = key.open(true /* must exist */);
|
||||||
if (!db.getObjectsDirectory().isDirectory())
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
throw die(MessageFormat.format(CLIText.get().notAGitRepository, srcGitdir.getPath()));
|
throw die(MessageFormat.format(CLIText.get().notAGitRepository,
|
||||||
rp = new org.eclipse.jgit.transport.UploadPack(db);
|
srcGitdir.getPath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
up = new org.eclipse.jgit.transport.UploadPack(db);
|
||||||
if (0 <= timeout)
|
if (0 <= timeout)
|
||||||
rp.setTimeout(timeout);
|
up.setTimeout(timeout);
|
||||||
rp.upload(System.in, System.out, System.err);
|
up.upload(System.in, System.out, System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue