diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2020-10-12 22:33:05 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2020-10-22 17:10:25 +0200 |
| commit | 298f9d29d6c26e408a90d08d147d926aa6f81ab3 (patch) | |
| tree | 69da018ebe34a7639a27611dc12f7946b0f3f541 | |
| parent | 59bb1ae3a9aeae75a75b20090253613a7a8800d8 (diff) | |
git: Display a progress bar while fetching a repo.
Fixes <https://bugs.gnu.org/39260>.
This uses the API of the yet-to-be-released Guile-Git 0.4.0. Using an
older version is still possible, but progress report is disabled.
* guix/git.scm (show-progress, make-default-fetch-options): New
procedures.
(clone*, update-cached-checkout): Use it instead of
'make-fetch-options'.
| -rw-r--r-- | guix/git.scm | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/guix/git.scm b/guix/git.scm index cfb8d626f5e..b81a011443f 100644 --- a/guix/git.scm +++ b/guix/git.scm | |||
| @@ -31,7 +31,9 @@ | |||
| 31 | #:use-module (guix gexp) | 31 | #:use-module (guix gexp) |
| 32 | #:use-module (guix sets) | 32 | #:use-module (guix sets) |
| 33 | #:use-module ((guix diagnostics) #:select (leave)) | 33 | #:use-module ((guix diagnostics) #:select (leave)) |
| 34 | #:use-module (guix progress) | ||
| 34 | #:use-module (rnrs bytevectors) | 35 | #:use-module (rnrs bytevectors) |
| 36 | #:use-module (ice-9 format) | ||
| 35 | #:use-module (ice-9 match) | 37 | #:use-module (ice-9 match) |
| 36 | #:use-module (srfi srfi-1) | 38 | #:use-module (srfi srfi-1) |
| 37 | #:use-module (srfi srfi-11) | 39 | #:use-module (srfi srfi-11) |
| @@ -117,6 +119,59 @@ the 'SSL_CERT_FILE' and 'SSL_CERT_DIR' environment variables." | |||
| 117 | (string-append "R:" url) | 119 | (string-append "R:" url) |
| 118 | url)))))) | 120 | url)))))) |
| 119 | 121 | ||
| 122 | (define (show-progress progress) | ||
| 123 | "Display a progress bar as we fetch Git code. PROGRESS is an | ||
| 124 | <indexer-progress> record from (git)." | ||
| 125 | (define total | ||
| 126 | (indexer-progress-total-objects progress)) | ||
| 127 | |||
| 128 | (define hundredth | ||
| 129 | (match (quotient (indexer-progress-total-objects progress) 100) | ||
| 130 | (0 1) | ||
| 131 | (x x))) | ||
| 132 | |||
| 133 | (define-values (done label) | ||
| 134 | (if (< (indexer-progress-received-objects progress) total) | ||
| 135 | (values (indexer-progress-received-objects progress) | ||
| 136 | (G_ "receiving objects")) | ||
| 137 | (values (indexer-progress-indexed-objects progress) | ||
| 138 | (G_ "indexing objects")))) | ||
| 139 | |||
| 140 | (define % | ||
| 141 | (* 100. (/ done total))) | ||
| 142 | |||
| 143 | (when (and (< % 100) (zero? (modulo done hundredth))) | ||
| 144 | (erase-current-line (current-error-port)) | ||
| 145 | (let ((width (max (- (current-terminal-columns) | ||
| 146 | (string-length label) 7) | ||
| 147 | 3))) | ||
| 148 | (format (current-error-port) "~a ~3,d% ~a" | ||
| 149 | label (inexact->exact (round %)) | ||
| 150 | (progress-bar % width))) | ||
| 151 | (force-output (current-error-port))) | ||
| 152 | |||
| 153 | (when (= % 100.) | ||
| 154 | ;; We're done, erase the line. | ||
| 155 | (erase-current-line (current-error-port)) | ||
| 156 | (force-output (current-error-port))) | ||
| 157 | |||
| 158 | ;; Return true to indicate that we should go on. | ||
| 159 | #t) | ||
| 160 | |||
| 161 | (define (make-default-fetch-options) | ||
| 162 | "Return the default fetch options." | ||
| 163 | (let ((auth-method (%make-auth-ssh-agent))) | ||
| 164 | ;; The #:transfer-progress option appeared in Guile-Git 0.4.0. Omit it | ||
| 165 | ;; when using an older version. | ||
| 166 | (catch 'wrong-number-of-args | ||
| 167 | (lambda () | ||
| 168 | (make-fetch-options auth-method | ||
| 169 | #:transfer-progress | ||
| 170 | (and (isatty? (current-error-port)) | ||
| 171 | show-progress))) | ||
| 172 | (lambda args | ||
| 173 | (make-fetch-options auth-method))))) | ||
| 174 | |||
| 120 | (define (clone* url directory) | 175 | (define (clone* url directory) |
| 121 | "Clone git repository at URL into DIRECTORY. Upon failure, | 176 | "Clone git repository at URL into DIRECTORY. Upon failure, |
| 122 | make sure no empty directory is left behind." | 177 | make sure no empty directory is left behind." |
| @@ -127,7 +182,7 @@ make sure no empty directory is left behind." | |||
| 127 | (let ((auth-method (%make-auth-ssh-agent))) | 182 | (let ((auth-method (%make-auth-ssh-agent))) |
| 128 | (clone url directory | 183 | (clone url directory |
| 129 | (make-clone-options | 184 | (make-clone-options |
| 130 | #:fetch-options (make-fetch-options auth-method))))) | 185 | #:fetch-options (make-default-fetch-options))))) |
| 131 | (lambda _ | 186 | (lambda _ |
| 132 | (false-if-exception (rmdir directory))))) | 187 | (false-if-exception (rmdir directory))))) |
| 133 | 188 | ||
| @@ -300,7 +355,7 @@ it unchanged." | |||
| 300 | (not (reference-available? repository ref))) | 355 | (not (reference-available? repository ref))) |
| 301 | (let ((auth-method (%make-auth-ssh-agent))) | 356 | (let ((auth-method (%make-auth-ssh-agent))) |
| 302 | (remote-fetch (remote-lookup repository "origin") | 357 | (remote-fetch (remote-lookup repository "origin") |
| 303 | #:fetch-options (make-fetch-options auth-method)))) | 358 | #:fetch-options (make-default-fetch-options)))) |
| 304 | (when recursive? | 359 | (when recursive? |
| 305 | (update-submodules repository #:log-port log-port)) | 360 | (update-submodules repository #:log-port log-port)) |
| 306 | 361 | ||
