问题
I want to learn how to implement an alternative dfs backend for jgit and am looking at https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/InMemoryRepository.java as an example.
How ever I am having a hard time figuring out how to set this up as a standalone git daemon. Basically I want to be able to start a java process that is the git server for a single (empty) in-memory git repository, and then I want to be able to use a git client to push/pull from that repository daemon process.
回答1:
You need to do something like this:
private static final class RepositoryResolverImplementation implements
RepositoryResolver<DaemonClient> {
@Override
public Repository open(DaemonClient client, String name)
throws RepositoryNotFoundException,
ServiceNotAuthorizedException, ServiceNotEnabledException,
ServiceMayNotContinueException {
InMemoryRepository repo = repositories.get(name);
if (repo == null) {
repo = new InMemoryRepository(
new DfsRepositoryDescription(name));
repositories.put(name, repo);
}
return repo;
}
}
private static Map<String, InMemoryRepository> repositories = new HashMap<String, InMemoryRepository>();
public static void main(String[] args) throws IOException {
Daemon server = new Daemon(new InetSocketAddress(9418));
boolean uploadsEnabled = true;
server.getService("git-receive-pack").setEnabled(uploadsEnabled);
server.setRepositoryResolver(new RepositoryResolverImplementation());
server.start();
}
You should then be able to run git clone git://localhost/repo.git
and a new in-memory 'repo.git' repository will be created. If you want to upload, make sure that the uploadsEnabled is set to 'true' - by default, it is set to 'false'.
来源:https://stackoverflow.com/questions/14360909/jgit-how-to-use-inmemoryrepository-to-learn-about-dfs-implementations