6

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?

birdoftheday
  • 736
  • 5
  • 13

1 Answers1

8

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)
rpepato
  • 117
  • 4
  • Thanks. I don't really understand `Backend` though. Why do I need one? – birdoftheday Oct 05 '16 at 12:14
  • A backend int he context of libgit2 is just a storage mechanism for your repo. It could be in-memory storage, disk storage, database storage, cache storage, etc. You can find a detailed explanation about backends in libgit2 [here](http://blog.deveo.com/your-git-repository-in-a-database-pluggable-backends-in-libgit2/) – rpepato Oct 05 '16 at 16:55
  • @rpepato Do you know if that works for `clone_at`? I can't find in the documentation – Tiago Lopo Dec 14 '16 at 14:17
  • @Tiago I didn't test it but it looks so. Check the example in this [link](http://www.rubydoc.info/github/libgit2/rugged/Rugged%2FRepository.clone_at) – rpepato Dec 27 '16 at 15:26
  • 2
    The `rugged` code example does not seem to work. As of Rugged 0.27.0, the README says you can create an in-memory repo using that code but the gem doesn't provide a `Rugged::InMemory` class. – Brian Morearty May 08 '18 at 14:28