On Sun, May 12, 2013 at 05:25:46PM +0100, Richard Maw wrote:
diff --git a/lib/gitano/copycommand.lua b/lib/gitano/copycommand.lua
+
+local function builtin_copy_validate(config, srcrepo, cmdline)
+ local tgtrepo, msg = repository.find(config, cmdline[3])
A trick here is to cache tgtrepo in cmdline (any non-numeric key won't be
touched). If you do that, then double-check that it works even if the command
is being run under 'as'.
+local function builtin_copy_prep(config, srcrepo, cmdline, context)
+ local ctx, action, reason
+ -- Check 0, is the source repository nascent
+ if srcrepo.is_nascent then
+ return "deny", "Cannot copy a repository which does not
exist"
+ end
Why was this not done in validate? I'm beginning to think that _prep should be
renamed as _permissions or similar, and I'd like to start rationalising the
calls.
+ local tgtrepo, msg = repository.find(config, cmdline[3])
+ if not tgtrepo then
+ return "deny", msg
+ end
+ if not tgtrepo.is_nascent then
+ return "deny", "Destination location is in use"
+ end
These checks would be unnecessary if you'd cached tgtrepo from before.
+local function builtin_copy_run(config, repo, cmdline, env)
+ local ok, msg = repo:copy_to(cmdline[3])
And here you'd pass in tgtrepo all neat and tidy and ready.
+ if not ok then
+ log.error(msg)
+ return "exit", 1
+ end
+ log.state("Copied", cmdline[2], "to", cmdline[3])
It'd be a good idea at this point to ensure that you construct a fresh
(non-nascent) repository object on the target repo name, then set the owner
(which you can get from the env). That will allow Gitano to set up all the
appropriate bits like export rules, etc.
D.
--
Daniel Silverstone
http://www.digital-scurf.org/
PGP mail accepted and encouraged. Key Id: 3CCE BABE 206C 3B69