Browse Source

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>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
2370ad9514
  1. 18
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java
  2. 26
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java

18
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java

@ -47,9 +47,10 @@ package org.eclipse.jgit.pgm;
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 @@ class ReceivePack extends TextBuiltin {
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);
} }

26
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java

@ -47,10 +47,11 @@ package org.eclipse.jgit.pgm;
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 @@ class UploadPack extends TextBuiltin {
@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…
Cancel
Save