From patchwork Thu May 27 14:18:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Whatson X-Patchwork-Id: 29626 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 18DF527BC81; Thu, 27 May 2021 15:19:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 60C7227BC78 for ; Thu, 27 May 2021 15:19:11 +0100 (BST) Received: from localhost ([::1]:50852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmGqs-0000fm-9H for patchwork@mira.cbaines.net; Thu, 27 May 2021 10:19:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGqk-0000bl-PF for guix-patches@gnu.org; Thu, 27 May 2021 10:19:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lmGqk-00013Z-H8 for guix-patches@gnu.org; Thu, 27 May 2021 10:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lmGqk-0004zx-DO for guix-patches@gnu.org; Thu, 27 May 2021 10:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48699] [PATCH] git-download: Support submodules in 'git-predicate'. Resent-From: Andrew Whatson Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 27 May 2021 14:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48699 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48699@debbugs.gnu.org Cc: Andrew Whatson X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162212513019179 (code B ref -1); Thu, 27 May 2021 14:19:02 +0000 Received: (at submit) by debbugs.gnu.org; 27 May 2021 14:18:50 +0000 Received: from localhost ([127.0.0.1]:52481 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lmGqX-0004zH-GS for submit@debbugs.gnu.org; Thu, 27 May 2021 10:18:49 -0400 Received: from lists.gnu.org ([209.51.188.17]:37852) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lmGqV-0004z8-MY for submit@debbugs.gnu.org; Thu, 27 May 2021 10:18:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGqS-0000HW-3L for guix-patches@gnu.org; Thu, 27 May 2021 10:18:45 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:41723) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lmGqP-0000qW-Uw for guix-patches@gnu.org; Thu, 27 May 2021 10:18:43 -0400 Received: by mail-pl1-x632.google.com with SMTP id z4so36792plg.8 for ; Thu, 27 May 2021 07:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LxIRvnkQu52Rd9EyviM+kO435ObL1ipfudmxHdSHhBE=; b=lpkilXelZAc0rZUM6ljMY+q7gSdZypK2uOstUyN+rBHQ+TMDnYv2tEBXYiTC4lVlak MzmrMu741gItpORMxPBM6zdIYbKBe4Zn9LspJ8t1UMg6H4RzlaUge5Usw9bYKrswariJ 7JAUlCd0wkYNzy42CoVfNiaczCFdFG9FxiF//Xmbrai//Eckp0qjJiE7cRhwtdpdEx4y BVU+jqjT/mQiNmUGEp3PKpxFzFEs0vBUFFhbMjbl//fxts4egbz7sj1qvMZ7rhrH2rWQ 8a03U05Y+j5gwGPN99uGyM2HaYOUUxL2IVWv3pcs16AylAig5xbr6+NZD7cta2nczHlc i84Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LxIRvnkQu52Rd9EyviM+kO435ObL1ipfudmxHdSHhBE=; b=eNw9TU3Sgrhabh4nB0AE9/OqD+7R/Ko7M6tWaWxoyG02Yn0mgwIjns+mnkAmgE1lgu 7SvIjifWjdsDOuTZ1D4foFkQ82V1IxxkNpfxcYocBD4vLutes0PPo5iGdShiC9xalNuW xmWTztunJ0C7oqDspgDQEoqson9pLa1P8LlsY5DCp5T6jkcr1JzUWt50Rcj1MBP/blrH PzGlkF9KvKObXIG+ovTtMXt2y17VqY1y9TbH6UjZNCv/6+1RNKAOnSC+YM+pwcslbsAy PQbiO1ab306rgxYdF3b+hEaU9zQOf6CM4m3USjgndz6S5PPL2a8PVcQ5YFYhyXegX64w VZOA== X-Gm-Message-State: AOAM532oA/epa1UUpBz/d/qfkFMGjU3K1MbGN4jpiMVJUimHBd3A9I9Q fB2uf0keu4dIufNqEvRJOXJC92XGk0s= X-Google-Smtp-Source: ABdhPJywvP7KnrmZJQ4/ndRKwknMl2gD157JYxOlV2HwbY2JdEkvdTCtETnLWxNeKOn3PDxH+W+3AQ== X-Received: by 2002:a17:902:7244:b029:f5:2ffd:37f9 with SMTP id c4-20020a1709027244b02900f52ffd37f9mr3449020pll.26.1622125120068; Thu, 27 May 2021 07:18:40 -0700 (PDT) Received: from muon.fritz.box ([203.221.113.127]) by smtp.gmail.com with ESMTPSA id g202sm2203966pfb.54.2021.05.27.07.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 07:18:39 -0700 (PDT) From: Andrew Whatson Date: Fri, 28 May 2021 00:18:27 +1000 Message-Id: <20210527141827.2868641-1-whatson@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=whatson@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/git-download.scm (git-file-list): Add prefix and recursive? arguments. Recurse into submodules when requested. (git-predicate): Add recursive? argument. --- guix/git-download.scm | 67 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/guix/git-download.scm b/guix/git-download.scm index 8d8e1c865f..8094e5e5c7 100644 --- a/guix/git-download.scm +++ b/guix/git-download.scm @@ -33,6 +33,9 @@ repository-discover repository-head repository-working-directory) + #:autoload (git submodule) (repository-submodules + submodule-lookup + submodule-path) #:autoload (git commit) (commit-lookup commit-tree) #:autoload (git reference) (reference-target) #:autoload (git tree) (tree-list) @@ -194,11 +197,17 @@ HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." ;;; 'git-predicate'. ;;; -(define (git-file-list directory) +(define* (git-file-list directory #:optional prefix #:key (recursive? #t)) "Return the list of files checked in in the Git repository at DIRECTORY. The result is similar to that of the 'git ls-files' command, except that it -also includes directories, not just regular files. The returned file names -are relative to DIRECTORY, which is not necessarily the root of the checkout." +also includes directories, not just regular files. + +When RECURSIVE? is true, also list files in submodules, similar to the 'git +ls-files --recurse-submodules' command. This is enabled by default. + +The returned file names are relative to DIRECTORY, which is not necessarily +the root of the checkout. If a PREFIX is provided, it is prepended to each +file name." (let* (;; 'repository-working-directory' always returns a trailing "/", ;; so add one here to ease the comparisons below. (directory (string-append (canonicalize-path directory) "/")) @@ -209,27 +218,57 @@ are relative to DIRECTORY, which is not necessarily the root of the checkout." (oid (reference-target head)) (commit (commit-lookup repository oid)) (tree (commit-tree commit)) - (files (tree-list tree))) + (files (tree-list tree)) + (submodules (if recursive? + (map (lambda (name) + (submodule-path + (submodule-lookup repository name))) + (repository-submodules repository)) + '())) + (relative (and (not (string=? workdir directory)) + (string-drop directory (string-length workdir)))) + (included? (lambda (path) + (or (not relative) + (string-prefix? relative path)))) + (make-relative (lambda (path) + (if relative + (string-drop path (string-length relative)) + path))) + (add-prefix (lambda (path) + (if prefix + (string-append prefix "/" path) + path))) + (rectify (compose add-prefix make-relative))) (repository-close! repository) - (if (string=? workdir directory) - files - (let ((relative (string-drop directory (string-length workdir)))) - (filter-map (lambda (file) - (and (string-prefix? relative file) - (string-drop file (string-length relative)))) - files))))) - -(define (git-predicate directory) + (append + (if (or relative prefix) + (filter-map (lambda (file) + (and (included? file) + (rectify file))) + files) + files) + (append-map (lambda (submodule) + (if (included? submodule) + (git-file-list + (string-append workdir submodule) + (rectify submodule)) + '())) + submodules)))) + +(define* (git-predicate directory #:key (recursive? #t)) "Return a predicate that returns true if a file is part of the Git checkout living at DIRECTORY. If DIRECTORY does not lie within a Git checkout, and upon Git errors, return #f instead of a predicate. +When RECURSIVE? is true, the predicate also returns true if a file is part of +any Git submodule under DIRECTORY. This is enabled by default. + The returned predicate takes two arguments FILE and STAT where FILE is an absolute file name and STAT is the result of 'lstat'." (libgit2-init!) (catch 'git-error (lambda () - (let* ((files (git-file-list directory)) + (let* ((files (git-file-list directory #:recursive? recursive?)) (inodes (fold (lambda (file result) (let* ((path (string-append directory "/" file)) (stat (and (file-exists? path)