简体   繁体   English

如何在内存中创建一个git存储库?

[英]How to create a git repository in memory?

I am currently working on a flashcard application where decks created by the user act as Git repositories. 我目前正在开发一个flashcard应用程序,其中用户创建的decks充当Git存储库。 When a card is created in the app, a new file is committed to the repository, when a card is changed, the file is changed, and when a card is deleted--well, you get the point. 在应用程序中创建卡片时,会在更换卡片,更改文件以及删除卡片时将新文件提交到存储库 - 嗯,您明白了。

The file format that the application saves to is a gzipped Git repository, so at no point will I ever need to write the repository to disk. 应用程序保存到的文件格式是一个gzip压缩的Git存储库,所以在任何时候我都不需要将存储库写入磁盘。 How can I best handle treating decks as a Git repository in this way? 我怎样才能以这种方式最好地处理甲板作为Git存储库?

Take a look at libgit2. 看看libgit2。 It supports the in-memory git repository scenario and also has bindings to many languages: 它支持内存中的git存储库场景,并且还绑定了许多语言:

https://libgit2.github.com https://libgit2.github.com

For example, by using rugged , the ruby binding for libgit2, you could do things like this: 例如,通过使用坚固的 ,libgit2的ruby绑定,你可以这样做:

a_backend = Rugged::InMemory::Backend.new(opt1: 'setting', opt2: 'setting')

repo = Rugged::Repository.init_at('repo_name', :bare, backend: a_backend)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM