]> gitweb.factorcode.org Git - factor.git/blob - extra/cli/git/git.factor
extra: Add cli.git and github.sync.
[factor.git] / extra / cli / git / git.factor
1 ! Copyright (C) 2017 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays concurrency.combinators concurrency.semaphores fry
4 io.directories io.files.info io.launcher io.pathnames kernel
5 math namespaces sequences splitting system-info ;
6 IN: cli.git
7
8 SYMBOL: cli-git-num-parallel
9 cli-git-num-parallel [ cpus 2 * ] initialize
10
11 : git-clone-as ( ssh-url path -- process )
12     [ { "git" "clone" } ] 2dip 2array append run-process ;
13
14 : git-clone ( ssh-url -- process )
15     [ { "git" "clone" } ] dip suffix run-process ;
16
17 : git-pull ( path -- process )
18     [ { "git" "pull" } run-process ] with-directory ;
19
20 : git-repository? ( directory -- ? )
21     ".git" append-path current-directory get prepend-path
22     ?file-info dup [ directory? ] when ;
23
24 : repository-url>name ( string -- string' )
25     file-name ".git" ?tail drop ;
26
27 : update-repository ( url -- process )
28     dup repository-url>name git-repository?
29     [ repository-url>name git-pull ] [ git-clone ] if ;
30
31 : sync-repositories ( directory urls -- )
32     '[
33         _ cli-git-num-parallel get <semaphore> '[
34             _ [ update-repository ] with-semaphore
35         ] parallel-each
36     ] with-ensure-directory ;
37