From efc8035be1ba941b95f194bfa66642839baf3a53 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 27 May 2013 10:16:03 +0100 Subject: 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. --- lib/gitano/command.lua | 54 ++--------------------------------- lib/gitano/repocommand.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 52 deletions(-) create mode 100644 lib/gitano/repocommand.lua (limited to 'lib') 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 + +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 +} -- cgit v1.2.1