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 | |
parent | 50e2bf82ae69390d4517f040219f2bce991253b4 (diff) | |
download | gitano-efc8035be1ba941b95f194bfa66642839baf3a53.tar.gz |
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.
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | lib/gitano/command.lua | 54 | ||||
-rw-r--r-- | lib/gitano/repocommand.lua | 70 |
3 files changed, 74 insertions, 53 deletions
@@ -30,7 +30,8 @@ MODS := gitano \ gitano.util \ gitano.actions gitano.config gitano.lace gitano.log \ gitano.markdown gitano.repository gitano.supple \ - gitano.command gitano.admincommand gitano.usercommand + gitano.command gitano.admincommand gitano.usercommand \ + gitano.repocommand SKEL_FILES := gitano-admin/rules/selfchecks.lace \ gitano-admin/rules/aschecks.lace \ diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua index da20dea..c8f537a 100644 --- a/lib/gitano/command.lua +++ b/lib/gitano/command.lua @@ -937,63 +937,13 @@ assert(register_cmd("ls", builtin_ls_short, builtin_ls_helptext, builtin_ls_validate, builtin_ls_prep, builtin_ls_run, false, false)) -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 - -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)) local usercmds = require 'gitano.usercommand' usercmds.register(register_cmd) local admincmds = require 'gitano.admincommand' admincmds.register(register_cmd) +local repocmds = require 'gitano.repocommand' +repocmds.register(register_cmd) return { register = register_cmd, 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 +} |