项目作者: nilium

项目描述 :
SQLite storage implementation for go-git (Migrated to https://git.sr.ht/~nilium/go-git-sqlite)
高级语言: Go
项目地址: git://github.com/nilium/go-git-sqlite.git
创建时间: 2020-01-26T11:25:54Z
项目社区:https://github.com/nilium/go-git-sqlite

开源协议:BSD 2-Clause "Simplified" License

下载


go-git-sqlite

This is a rudimentary implementation of a go-git storage layer using SQLite.
The intent behind this is to use it as a single-file repository for things like
CI and GitHub Apps where increasing isolation between the underlying filesystem
and whatever is using the repository is desirable.

Usage

First, create an sqlitex.Pool and then hand it to gitsqlite.New. Afterward, you can
pass the resulting gitsqlite.Storer to git.Clone, git.Open, or other functions.

For example:

  1. pool, err := sqlitex.Open("file:git.db", 0, 2)
  2. if err != nil {
  3. log.Panic(fmt.Errorf("unable to create sqlite pool: %w", err))
  4. }
  5. defer pool.Close()
  6. // The first parameter is the name of the repo. You can use this to
  7. // differentiate root-level storage inside the same DB if you want.
  8. storage, err := gitsqlite.New("", pool)
  9. if err != nil {
  10. log.Panic(fmt.Errorf("unable to create storage: %w", err))
  11. }
  12. defer storage.Close()
  13. // Create a gopkg.in/billy.v4/memfs filesystem:
  14. fs := memfs.New()
  15. // Clone the repository into sqlite with a memory filesystem:
  16. repo, err := git.Clone(storage, fs, &git.CloneOptions{
  17. URL: "https://github.com/nilium/flagenv",
  18. })
  19. if err != nil {
  20. log.Panic(fmt.Errorf("error cloning repository: %w", err))
  21. }
  22. // Now you have a repo with files in the memory fs.

Notes

  • go-git-sqlite does not currently encode the config or index data from go-git
    in any special way, and this is all kept in a GitKV table that just holds
    key-value pairs (where the value is a blob).

  • There is no implementation of packed refs, which as far as I can tell is
    a detail that only a .git-dir implementation needs to care about.

  • Repositories and modules are currently named using quoted strings, with
    modules of the root repository being separated by slashes. There’s likely
    a better way to do this, but for now it works. The only reason for quoting
    names is to ensure that the slash separator can’t be spoofed by a clever
    module name.

  • This uses crawshaw.io/sqlite (and the sqlitex package) for SQLite. This
    is because there’s no reason to support the database/sql package for
    go-git-sqlite and that this package provides a clean interface to the
    standard SQLite library instead of making it look like a database with
    network connections and so on.

License

go-git-sqlite is available under the two-clause BSD license. It can be found in
the COPYING file.