How to create a git repository in memory?
Asked Answered
V

1

9

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?

Violation answered 5/10, 2016 at 1:26 Comment(1)
Status of flash card app? 😇Morion
J
10

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)
Jarredjarrell answered 5/10, 2016 at 1:41 Comment(5)
Thanks. I don't really understand Backend though. Why do I need one?Violation
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 hereJarredjarrell
@Jarredjarrell Do you know if that works for clone_at? I can't find in the documentationDillman
@Tiago I didn't test it but it looks so. Check the example in this linkJarredjarrell
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.Cruet

© 2022 - 2024 — McMap. All rights reserved.