From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EHhTJHXGhF8NRQAA0tVLHw (envelope-from ) for ; Mon, 12 Oct 2020 21:11:17 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id UJosIHXGhF83WgAAbx9fmQ (envelope-from ) for ; Mon, 12 Oct 2020 21:11:17 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E2B959400D3 for ; Mon, 12 Oct 2020 21:11:16 +0000 (UTC) Received: from localhost ([::1]:39448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kS56B-0005r3-Bn for larch@yhetil.org; Mon, 12 Oct 2020 17:11:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kS55z-0005qI-Ng for guix-patches@gnu.org; Mon, 12 Oct 2020 17:11:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:60786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kS55z-0006yc-EB for guix-patches@gnu.org; Mon, 12 Oct 2020 17:11:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kS55z-00065X-AR for guix-patches@gnu.org; Mon, 12 Oct 2020 17:11:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#43968] [PATCH 2/3] git: Display a progress bar while fetching a repo. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 12 Oct 2020 21:11:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43968 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 43968@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 43968-submit@debbugs.gnu.org id=B43968.160253702123333 (code B ref 43968); Mon, 12 Oct 2020 21:11:03 +0000 Received: (at 43968) by debbugs.gnu.org; 12 Oct 2020 21:10:21 +0000 Received: from localhost ([127.0.0.1]:44096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kS55I-00064C-RJ for submit@debbugs.gnu.org; Mon, 12 Oct 2020 17:10:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38644) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kS55A-00063U-U7 for 43968@debbugs.gnu.org; Mon, 12 Oct 2020 17:10:16 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:50497) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kS555-0006i5-N0; Mon, 12 Oct 2020 17:10:07 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=54554 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kS554-0005SP-0d; Mon, 12 Oct 2020 17:10:07 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 12 Oct 2020 23:09:54 +0200 Message-Id: <20201012210955.8753-2-ludo@gnu.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012210955.8753-1-ludo@gnu.org> References: <20201012210955.8753-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 4.99 X-TUID: WAG6fwGeQ2CZ Fixes . 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'. --- guix/git.scm | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/guix/git.scm b/guix/git.scm index cfb8d626f5..b81a011443 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -31,7 +31,9 @@ #:use-module (guix gexp) #:use-module (guix sets) #:use-module ((guix diagnostics) #:select (leave)) + #:use-module (guix progress) #:use-module (rnrs bytevectors) + #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) @@ -117,6 +119,59 @@ the 'SSL_CERT_FILE' and 'SSL_CERT_DIR' environment variables." (string-append "R:" url) url)))))) +(define (show-progress progress) + "Display a progress bar as we fetch Git code. PROGRESS is an + record from (git)." + (define total + (indexer-progress-total-objects progress)) + + (define hundredth + (match (quotient (indexer-progress-total-objects progress) 100) + (0 1) + (x x))) + + (define-values (done label) + (if (< (indexer-progress-received-objects progress) total) + (values (indexer-progress-received-objects progress) + (G_ "receiving objects")) + (values (indexer-progress-indexed-objects progress) + (G_ "indexing objects")))) + + (define % + (* 100. (/ done total))) + + (when (and (< % 100) (zero? (modulo done hundredth))) + (erase-current-line (current-error-port)) + (let ((width (max (- (current-terminal-columns) + (string-length label) 7) + 3))) + (format (current-error-port) "~a ~3,d% ~a" + label (inexact->exact (round %)) + (progress-bar % width))) + (force-output (current-error-port))) + + (when (= % 100.) + ;; We're done, erase the line. + (erase-current-line (current-error-port)) + (force-output (current-error-port))) + + ;; Return true to indicate that we should go on. + #t) + +(define (make-default-fetch-options) + "Return the default fetch options." + (let ((auth-method (%make-auth-ssh-agent))) + ;; The #:transfer-progress option appeared in Guile-Git 0.4.0. Omit it + ;; when using an older version. + (catch 'wrong-number-of-args + (lambda () + (make-fetch-options auth-method + #:transfer-progress + (and (isatty? (current-error-port)) + show-progress))) + (lambda args + (make-fetch-options auth-method))))) + (define (clone* url directory) "Clone git repository at URL into DIRECTORY. Upon failure, make sure no empty directory is left behind." @@ -127,7 +182,7 @@ make sure no empty directory is left behind." (let ((auth-method (%make-auth-ssh-agent))) (clone url directory (make-clone-options - #:fetch-options (make-fetch-options auth-method))))) + #:fetch-options (make-default-fetch-options))))) (lambda _ (false-if-exception (rmdir directory))))) @@ -300,7 +355,7 @@ it unchanged." (not (reference-available? repository ref))) (let ((auth-method (%make-auth-ssh-agent))) (remote-fetch (remote-lookup repository "origin") - #:fetch-options (make-fetch-options auth-method)))) + #:fetch-options (make-default-fetch-options)))) (when recursive? (update-submodules repository #:log-port log-port)) -- 2.28.0