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>tags/v0.9.1
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 { | ||||
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()) | |||||
dstGitdir = new File(dstGitdir, Constants.DOT_GIT); | |||||
db = new Repository(dstGitdir); | |||||
if (!db.getObjectsDirectory().isDirectory()) | |||||
throw die(MessageFormat.format(CLIText.get().notAGitRepository, dstGitdir.getPath())); | |||||
try { | |||||
FileKey key = FileKey.lenient(dstGitdir, FS.DETECTED); | |||||
db = key.open(true /* must exist */); | |||||
} catch (RepositoryNotFoundException notFound) { | |||||
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); | ||||
} | } |
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 { | ||||
@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()) | |||||
srcGitdir = new File(srcGitdir, Constants.DOT_GIT); | |||||
db = new Repository(srcGitdir); | |||||
if (!db.getObjectsDirectory().isDirectory()) | |||||
throw die(MessageFormat.format(CLIText.get().notAGitRepository, srcGitdir.getPath())); | |||||
rp = new org.eclipse.jgit.transport.UploadPack(db); | |||||
try { | |||||
FileKey key = FileKey.lenient(srcGitdir, FS.DETECTED); | |||||
db = key.open(true /* must exist */); | |||||
} catch (RepositoryNotFoundException notFound) { | |||||
throw die(MessageFormat.format(CLIText.get().notAGitRepository, | |||||
srcGitdir.getPath())); | |||||
} | |||||
up = new org.eclipse.jgit.transport.UploadPack(db); | |||||
if (0 <= timeout) | if (0 <= timeout) | ||||
rp.setTimeout(timeout); | |||||
rp.upload(System.in, System.out, System.err); | |||||
up.setTimeout(timeout); | |||||
up.upload(System.in, System.out, System.err); | |||||
} | } | ||||
} | } |