Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. How can I best handle treating decks as a Git repository in this way?

like image 505
birdoftheday Avatar asked Oct 05 '16 01:10

birdoftheday


1 Answers

Take a look at libgit2. It supports the in-memory git repository scenario and also has bindings to many languages:

https://libgit2.github.com

For example, by using rugged, the ruby binding for libgit2, you could do things like this:

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

repo = Rugged::Repository.init_at('repo_name', :bare, backend: a_backend)
like image 108
rpepato Avatar answered Oct 20 '22 20:10

rpepato