Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save snapshots as tags so they don't get deleted by git gc #251

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

squeek502
Copy link
Member

@squeek502 squeek502 commented Mar 13, 2019

Creates a new tag for each snapshot hash at refs/snapshots/<author>/<name>/v<version> with the tag name snapshots/<author>/<name>/v<version>. The tag ref is created outside of refs/tags so that other methods that iterate the refs don't include snapshots in their iterations (i.e. db.authors() simply returns all nodes in refs/tags). It's confirmed that the tag being in refs/snapshots still makes it exempt from git gc: without the tag, git gc --prune=all prunes the snapshot hash, but with the tag it remains after git gc --prune=all.

Note: This is an incomplete implementation; it only creates the snapshot tag in lit add, not on the server during lit publish (or any other places where it might also need to be created)

This is the other half of #247


I feel like I'm getting a bit in over my head with this, since I'm not super familiar with the db structure/lit internals/git internals/etc, so I thought I'd push the bit that I've got so far for feedback. As far as I can tell, what needs to be done to finish this up is evaluate/update the other instances of db.write throughout the code (rdb.lua, handlers.lua) to also create the snapshot tag.

Creates a new tag for each snapshot hash at `refs/snapshots/<author>/<name>/v<version>` with the tag name `snapshots/<author>/<name>/v<version>`. The tag ref is created outside of `refs/tags` so that other methods that iterate the refs don't include snapshots in their iterations (i.e. db.authors() simply returns all nodes in `refs/tags`). It's confirmed that the tag being in `refs/snapshots` still makes it exempt from `git gc`: without the tag, `git gc --prune=all` prunes the snapshot hash, but with the tag it remains after `git gc --prune=all`.

Note: This is an incomplete implementation; it only creates the snapshot tag in `lit add`, not on the server during `lit publish` (or any other places where it might also need to be created)
@squeek502
Copy link
Member Author

Btw, here's a small little command I was using for testing the existence of a snapshot hash. Name it snapshot.lua and put it in lit/commands:

return function()
  local config = require('autoconfig')()
  local makeDb = require('db')
  local pkg = require('pkg')
  local log = require("log").log

  local db = makeDb(config.database)
  local author_arg = assert(args[2], "missing author argument")
  local name_arg = assert(args[3], "missing name argument")
  local version_arg = assert(args[4], "missing version argument")

  print("")
  if version_arg then
    local author = author_arg
    local name = name_arg
    local version = version_arg
    local package = db.read(author, name, version)
    assert(package, author .. "/" .. name .. "@" .. version .. " not found")
    local meta = pkg.queryDb(db, package)
    local snapshotHash = meta.snapshot
    log("snapshot hash", snapshotHash)
    assert(pkg.queryDb(db, snapshotHash))
  end
  print("")
end

Use it via luvi . -- snapshot <author> <name> <version>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant