From patchwork Thu Apr 17 20:22:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 41744 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 B738427BC4B; Thu, 17 Apr 2025 21:24:18 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3982E27BC49 for ; Thu, 17 Apr 2025 21:24:18 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5VmO-0007XN-5r; Thu, 17 Apr 2025 16:24:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u5VmM-0007WN-7Z for guix-patches@gnu.org; Thu, 17 Apr 2025 16:24:10 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u5VmL-0001S5-St; Thu, 17 Apr 2025 16:24:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=Ek0b6MjAtxP2i7+AFFBK7M+srxS3Ru7MceiyMIc9GPM=; b=fOwfJpugEHzaJSu9KjgwY4D7aCEN1wOUWfRLTk0GAjS8JbIl44VZw9poPAIAIQR6O4B1xdaGSXr+twPEbeVjnaYhJh2x9lsOh327S1AhlflJLcd7MkIS5Ksdehm9yxNv7GpUUaHKaEbfNntN7LOB3vVYuP4FG5RVl/MQj3WKH8WoztumvlQ3jLnRr91ApXfrkT8Wl5hl4zCQJVnOMeNu0PktTBDxU9girxYr1OuY3gCi2IE0BYz9aKbQ07N1nIaGlNQhxVkYcon9aaHcTbVERsqGIEJlGTrt0AQKAN5PjTAbNbU0nmY0BO8i2UEJEER5tqLEVYGzOcl2tKFHU+5qJQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1u5VmK-0006uY-9l; Thu, 17 Apr 2025 16:24:08 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77875] [PATCH 1/2] git: Use =?utf-8?b?4oCYZ3JhcGgtZGVzY2VuZGFu?= =?utf-8?b?dD/igJk=?= from Guile-Git >= 0.10.0 when available. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 17 Apr 2025 20:24:08 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77875 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77875@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Tomas Volf <~@wolfsden.cz>, Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 77875-submit@debbugs.gnu.org id=B77875.174492139926062 (code B ref 77875); Thu, 17 Apr 2025 20:24:08 +0000 Received: (at 77875) by debbugs.gnu.org; 17 Apr 2025 20:23:19 +0000 Received: from localhost ([127.0.0.1]:48583 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u5VlU-0006m0-MQ for submit@debbugs.gnu.org; Thu, 17 Apr 2025 16:23:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52368) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u5Vl6-0006gM-7l for 77875@debbugs.gnu.org; Thu, 17 Apr 2025 16:22:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u5Vkz-00019v-Ug; Thu, 17 Apr 2025 16:22:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=Ek0b6MjAtxP2i7+AFFBK7M+srxS3Ru7MceiyMIc9GPM=; b=Yr/wT4OQ/2j+grB4K4Lf H9QUJ8/o9QalRbKCFPYNwYZtQq0myc9lCi3d2Gt+YC8D0y7bbv0KOoNCkEk2/baY0V5oavTvBr4Gr xQdJbmUSrZcChRASPe37A0AXduYQMq5HPrBNEC+EQ0SpkybpncMc/FNP0NjDM4Cky9mwb0Ovhe003 6s9/2QLFyyu6p+lK5q7HHxqzaBMpwuuUPcwek4Kj5cB1fqRYZrz8Ji4Zi5Jj8FwYkRMzEwp0DGmSe LmAVRo7Gcy5aHD7lnwjloKtbNg2SeMwEVZYtF9prsSQJ1W5dTFSXzNPqf0USzUIyD5rm1T5nxJuv+ MQl15mCJWnW0KA==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 17 Apr 2025 22:22:36 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Fixes . Fixes a bug whereby ‘commit-relation’ and ‘commit-descendant?’ would provide an incorrect result when two distinct objects would exist for the same commit, which can happen when the commit’s metadata is beyond 4 KiB, as of libgit2 1.8/1.9. This, in turn, would lead ‘guix pull’ & co. to wrongfully report an attempt to downgrade and pull to an unrelated commit. * guix/git.scm (commit-relation): When (guix graph) is available, rewrite in terms of ‘graph-descendant?’. (commit-descendant?): Likewise. Change-Id: Ie52b188a8dfa90c95a73387c3ab2fdd04d2bf3e9 Reported-by: Tomas Volf <~@wolfsden.cz> --- guix/git.scm | 83 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/guix/git.scm b/guix/git.scm index 01e0918588..cb26714d2d 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -732,7 +732,7 @@ (define (print-git-error port key args default-printer) ;;; Commit difference. ;;; -(define* (commit-closure commit #:optional (visited (setq))) +(define* (commit-closure commit #:optional (visited (setq))) ;to remove "Return the closure of COMMIT as a set. Skip commits contained in VISITED, a set, and adjoin VISITED to the result." (let loop ((commits (list commit)) @@ -768,39 +768,60 @@ (define* (commit-difference new old #:optional (excluded '())) (cons head result) (set-insert head visited))))))) -(define (commit-relation old new) - "Return a symbol denoting the relation between OLD and NEW, two commit +(define commit-relation + (if (resolve-module '(guix graph) #:ensure #f) ;Guile-Git >= 0.10.0 + (lambda (old new) + "Return a symbol denoting the relation between OLD and NEW, two commit objects: 'ancestor (meaning that OLD is an ancestor of NEW), 'descendant, or 'unrelated, or 'self (OLD and NEW are the same commit)." - (if (eq? old new) - 'self - (let ((newest (commit-closure new))) - (if (set-contains? newest old) - 'ancestor - (let* ((seen (list->setq (commit-parents new))) - (oldest (commit-closure old seen))) - (if (set-contains? oldest new) - 'descendant - 'unrelated)))))) + (let ((repository (commit-owner old)) + (old (commit-id old)) + (new (commit-id new))) + (cond ((graph-descendant? repository new old) + 'ancestor) + ((oid=? old new) + 'self) + ((graph-descendant? repository old new) + 'descendant) + (else 'unrelated)))) + (lambda (old new) ;remove when Guile-Git 0.10.0 is widespread + (if (eq? old new) + 'self + (let ((newest (commit-closure new))) + (if (set-contains? newest old) + 'ancestor + (let* ((seen (list->setq (commit-parents new))) + (oldest (commit-closure old seen))) + (if (set-contains? oldest new) + 'descendant + 'unrelated)))))))) -(define (commit-descendant? new old) - "Return true if NEW is the descendant of one of OLD, a list of commits. - -When the expected result is likely #t, this is faster than using -'commit-relation' since fewer commits need to be traversed." - (let ((old (list->setq old))) - (let loop ((commits (list new)) - (visited (setq))) - (match commits - (() - #f) - (_ - ;; Perform a breadth-first search as this is likely going to - ;; terminate more quickly than a depth-first search. - (let ((commits (remove (cut set-contains? visited <>) commits))) - (or (any (cut set-contains? old <>) commits) - (loop (append-map commit-parents commits) - (fold set-insert visited commits))))))))) +(define commit-descendant? + (if (resolve-module '(guix graph) #:ensure #f) ;Guile-Git >= 0.10.0 + (lambda (new old) + "Return true if NEW is the descendant of one of OLD, a list of +commits." + (let ((repository (commit-owner new)) + (new (commit-id new))) + (any (lambda (old) + (let ((old (commit-id old))) + (or (graph-descendant? repository new old) + (oid=? old new)))) + old))) + (lambda (new old) ;remove when Guile-Git 0.10.0 is widespread + (let ((old (list->setq old))) + (let loop ((commits (list new)) + (visited (setq))) + (match commits + (() + #f) + (_ + ;; Perform a breadth-first search as this is likely going to + ;; terminate more quickly than a depth-first search. + (let ((commits (remove (cut set-contains? visited <>) commits))) + (or (any (cut set-contains? old <>) commits) + (loop (append-map commit-parents commits) + (fold set-insert visited commits))))))))))) ;;