diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2013-05-27 10:16:03 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2013-05-27 10:16:03 +0100 |
commit | efc8035be1ba941b95f194bfa66642839baf3a53 (patch) | |
tree | 35a2b9e71803392a56db0a87a0472ad8c4ff4e29 /lib/gitano/repocommand.lua | |
parent | 50e2bf82ae69390d4517f040219f2bce991253b4 (diff) | |
download | gitano-efc8035be1ba941b95f194bfa66642839baf3a53.tar.bz2 |
REPOCOMMAND: Shunt gc and count-objects to gitano.repocommand
Move the gc and count-objects commands to a separate repocommand
module so that we can group fsck in with them neatly.
This new module is for commands which operate neatly on a repository with
little to no extra dependencies.
Diffstat (limited to 'lib/gitano/repocommand.lua')
-rw-r--r-- | lib/gitano/repocommand.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/gitano/repocommand.lua b/lib/gitano/repocommand.lua new file mode 100644 index 0000000..6cdcf0a --- /dev/null +++ b/lib/gitano/repocommand.lua @@ -0,0 +1,70 @@ +-- gitano.repocommand +-- +-- Gitano repository related commands such as gc, count-objects and fsck +-- +-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org> + +local log = require 'gitano.log' +local util = require 'gitano.util' +local repository = require 'gitano.repository' + +local sp = require "luxio.subprocess" + +local builtin_gc_short = "Invoke git gc on your repository" +local builtin_gc_helptext = [[ +usage: gc repo [options] + +Invoke, git gc, passing the given options, on the given repository. +You must have basic write access to the repository in order to invoke a gc. +]] + +local function builtin_gc_prep(config, repo, cmdline, context) + context.operation = "write" + return repo:run_lace(context) +end + +local builtin_count_objects_short = "Count objects in your projects" +local builtin_count_objects_helptext = [[ +usage: count-objects repo [options] + +Counts objects in your repository. + +You must have read access to the repository in order +to run count-objects. +]] + +local function builtin_count_objects_prep(config, repo, cmdline, context) + context.operation = "read" + return repo:run_lace(context) +end + +local function builtin_simple_validate(config, repo, cmdline) + if not repo or repo.is_nascent then + log.error("Unable to proceed, repository does not exist") + return false + end + return true +end + +local function builtin_simple_run(config, repo, cmdline, env) + local cmdcopy = {env=util.deep_copy(env), "git", cmdline[1]} + cmdcopy.env.GIT_DIR=repo:fs_path() + for i = 3, #cmdline do cmdcopy[#cmdcopy+1] = cmdline[i] end + local proc = sp.spawn(cmdcopy) + return proc:wait() +end + +local function register_repocommand(register_cmd) + assert(register_cmd("gc", builtin_gc_short, builtin_gc_helptext, + builtin_simple_validate, builtin_gc_prep, + builtin_simple_run, true, false)) + + assert(register_cmd("count-objects", builtin_count_objects_short, + builtin_count_objects_helptext, builtin_simple_validate, + builtin_count_objects_prep, builtin_simple_run, + true, false)) +end + +return { + register = register_repocommand +} |