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 io.directories io.encodings.utf8 io.files.info io.launcher
5 io.pathnames kernel math namespaces sequences splitting
9 SYMBOL: cli-git-num-parallel
10 cli-git-num-parallel [ cpus 2 * ] initialize
12 : git-clone-as ( ssh-url path -- process )
13 [ { "git" "clone" } ] 2dip 2array append run-process ;
15 : git-clone ( ssh-url -- process )
16 [ { "git" "clone" } ] dip suffix run-process ;
18 : git-pull ( path -- process )
19 [ { "git" "pull" } run-process ] with-directory ;
21 : git-repository? ( directory -- ? )
22 ".git" append-path current-directory get prepend-path
23 ?file-info dup [ directory? ] when ;
25 : git-current-branch ( directory -- name )
27 { "git" "rev-parse" "--abbrev-ref" "HEAD" }
28 utf8 <process-reader> stream-contents
29 ] with-directory [ blank? ] trim-tail ;
31 : repository-url>name ( string -- string' )
32 file-name ".git" ?tail drop ;
34 : update-repository ( url -- process )
35 dup repository-url>name git-repository?
36 [ repository-url>name git-pull ] [ git-clone ] if ;
38 : sync-repositories ( directory urls -- )
40 _ cli-git-num-parallel get <semaphore> '[
41 _ [ update-repository ] with-semaphore
43 ] with-ensure-directory ;