diff options
author | Tom Willemse | 2014-03-01 20:40:06 +0100 |
---|---|---|
committer | Tom Willemse | 2014-03-01 21:18:39 +0100 |
commit | 9df3b848e01661db574137348eb86e867eeaede5 (patch) | |
tree | 582fef0e7c59cd6c065f30923014cc0a45e3c7ae | |
parent | 95125d682cb70efbbbd41646b8ebe1f0518fa1f5 (diff) | |
download | gitto-9df3b848e01661db574137348eb86e867eeaede5.tar.gz gitto-9df3b848e01661db574137348eb86e867eeaede5.zip |
Simplify save-repositories-list
Simplify `save-repositories-list' by extracting some of the
functionality into its own procedures.
Since there is now a `repository-name<?' procedure the `repository<?'
procedure is renamed to `repository-location<?' for clarity and
accuracy, since that is what it really checks.
-rw-r--r-- | gitto/git.scm | 11 | ||||
-rw-r--r-- | gitto/main.scm | 26 | ||||
-rw-r--r-- | gitto/path.scm | 11 |
3 files changed, 30 insertions, 18 deletions
diff --git a/gitto/git.scm b/gitto/git.scm index a0cec3a..c7b2cdf 100644 --- a/gitto/git.scm +++ b/gitto/git.scm @@ -37,7 +37,8 @@ repo-location repo-name repository? - repository<? + repository-location<? + repository-name<? same-repository?)) (define show-unchanged-branches? #f) @@ -60,10 +61,14 @@ (define (repository? repo) (is-a? repo <repository>)) -(define (repository<? repo1 repo2) - "Compary REPO1 and REPO2 to see if REPO1 should be considered smaller." +(define (repository-location<? repo1 repo2) + "Compary REPO1 and REPO2 to see if REPO1 should be considered less." (string<? (repo-location repo1) (repo-location repo2))) +(define (repository-name<? repo1 repo2) + "Compare REPO1 and REPO2 to see if REPO1 should be considered less." + (string<? (repo-name repo1) (repo-name repo2))) + (define-method (branch-pullable (branch <branch>)) (force (slot-ref branch 'pullable))) diff --git a/gitto/main.scm b/gitto/main.scm index f8eeb18..f4efeae 100644 --- a/gitto/main.scm +++ b/gitto/main.scm @@ -43,7 +43,8 @@ (define (list-repository-locations) "List the registered locations of repositories." - (for-each print-repository-location (sort repositories repository<?))) + (for-each print-repository-location + (sort repositories repository-location<?))) (define (print-repository-location repo) "Print the location of REPO." @@ -60,20 +61,10 @@ (define (save-repositories-list) "Save the list of repositories." - (let ((dir (data-dir))) - (unless (file-exists? dir) - (mkdir dir))) - + (ensure-directory-exists. (data-dir)) ;; Sort first - (set! repositories - (sort repositories - (lambda (s1 s2) - (string<? (repo-name s1) (repo-name s2))))) - - (let ((port (open-output-file repositories-file)) - (repos (map repo-location repositories))) - (write repos port) - (close-port port))) + (set! repositories (sort repositories repository-name<?)) + (write-repositories!)) (define (show-global-config) "Show the template specified in `global-config'." @@ -112,6 +103,13 @@ Don't do anything if REPO has been added to `config-exclusion-list'." "Check if REPO is or could be made usable as a repository." (or (repository? repo) (string? repo))) +(define (write-repositories!) + "Write the repositories to the repositories file." + (let ((port (open-output-file repositories-file)) + (repos (map repo-location repositories))) + (write repos port) + (close-port port))) + (define config-exclusion-list '()) (define repositories-file (data-file "repos.scm")) diff --git a/gitto/path.scm b/gitto/path.scm index 1326118..373bf94 100644 --- a/gitto/path.scm +++ b/gitto/path.scm @@ -17,6 +17,15 @@ ;; along with gitto. If not, see <http://www.gnu.org/licenses/>. (define-module (gitto path) - #:export (realpath)) + #:export (realpath + ensure-directory-exists.)) (load-extension "libguile-gitto-path" "init_gitto") + +(define (ensure-directory-exists. path) + "Make sure PATH exists. + +Check if PATH exists, and if so do nothing. If PATH doesn't exist, +create it." + (unless (file-exists? path) + (mkdir path))) |