JGit:如何使用InMemoryRepository来学习dfs实现 [英] JGit: How to use InMemoryRepository to learn about dfs implementations

查看:328
本文介绍了JGit:如何使用InMemoryRepository来学习dfs实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习如何为jgit实现替代的dfs后端,并且正在研究 https ://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/InMemoryRepository.java 例如.

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.

我一直很难弄清楚如何将其设置为独立的git守护程序. 基本上,我希望能够启动一个Java进程,该进程是单个(空)内存git存储库的git服务器,然后我希望能够使用git客户端从该存储库守护进程中进行推送/拉取.

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.

推荐答案

您需要执行以下操作:

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();
}

然后您应该能够运行git clone git://localhost/repo.git,并且将创建一个新的内存"repo.git"存储库.如果要上传,请确保将uploadsEnabled设置为"true"-默认情况下,它设置为"false".

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'.

这篇关于JGit:如何使用InMemoryRepository来学习dfs实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆