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 ;
8 SYMBOL: cli-git-num-parallel
9 cli-git-num-parallel [ cpus 2 * ] initialize
11 : git-clone-as ( ssh-url path -- process )
12 [ { "git" "clone" } ] 2dip 2array append run-process ;
14 : git-clone ( ssh-url -- process )
15 [ { "git" "clone" } ] dip suffix run-process ;
17 : git-pull ( path -- process )
18 [ { "git" "pull" } run-process ] with-directory ;
20 : git-repository? ( directory -- ? )
21 ".git" append-path current-directory get prepend-path
22 ?file-info dup [ directory? ] when ;
24 : repository-url>name ( string -- string' )
25 file-name ".git" ?tail drop ;
27 : update-repository ( url -- process )
28 dup repository-url>name git-repository?
29 [ repository-url>name git-pull ] [ git-clone ] if ;
31 : sync-repositories ( directory urls -- )
33 _ cli-git-num-parallel get <semaphore> '[
34 _ [ update-repository ] with-semaphore
36 ] with-ensure-directory ;