From patchwork Thu Sep 21 14:12:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ricardo Wurmus X-Patchwork-Id: 54137 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 60BDD27BBEA; Thu, 21 Sep 2023 15:14:36 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 04F8E27BBE9 for ; Thu, 21 Sep 2023 15:14:32 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjKRU-0007VI-Lu; Thu, 21 Sep 2023 10:14:08 -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 1qjKRE-0007SA-D6 for guix-patches@gnu.org; Thu, 21 Sep 2023 10:13:56 -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 1qjKRE-0002Sa-3f for guix-patches@gnu.org; Thu, 21 Sep 2023 10:13:52 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjKRN-0006Ts-Vq for guix-patches@gnu.org; Thu, 21 Sep 2023 10:14:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66138] [PATCH 1/4] etc/committer: Do not recompute changes when there are no definitions. Resent-From: Ricardo Wurmus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 21 Sep 2023 14:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66138 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66138@debbugs.gnu.org Cc: Ricardo Wurmus X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.169530560824863 (code B ref -1); Thu, 21 Sep 2023 14:14:01 +0000 Received: (at submit) by debbugs.gnu.org; 21 Sep 2023 14:13:28 +0000 Received: from localhost ([127.0.0.1]:34547 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKQm-0006St-FM for submit@debbugs.gnu.org; Thu, 21 Sep 2023 10:13:28 -0400 Received: from lists.gnu.org ([2001:470:142::17]:57040) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKQh-0006Sb-5X for submit@debbugs.gnu.org; Thu, 21 Sep 2023 10:13:23 -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 1qjKQO-00077Z-LL for guix-patches@gnu.org; Thu, 21 Sep 2023 10:13:01 -0400 Received: from sender4-of-o51.zoho.com ([136.143.188.51]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjKQJ-0002Jo-Pr for guix-patches@gnu.org; Thu, 21 Sep 2023 10:13:00 -0400 Delivered-To: rekado@elephly.net ARC-Seal: i=1; a=rsa-sha256; t=1695305570; cv=none; d=zohomail.com; s=zohoarc; b=cfitnZEUZJvMqBhA5oE7xb8P0aPduxxj5abBvAkTKzmUCCIJF37XOgyvayGwnI3MeAJ3PcKzrT8aJ15+KeolTrwY27jfFnH+voj4Qtp8EbHudbYp9IjYeW8Iw6PZUvUhSr4LMmiKI3IhKPjYpdiRXeoAyP+/Z4o9aqQN6lq4mpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695305570; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=gsth8uFPTU29ahGVgl+RULuetXwLlbOExpqxj5Y7MDM=; b=EB7Ye2WB3ZCKk3eAsd1HY8HCh1GKX+KYCmE0Bns+2QmBK2/6vbQZibEZG/2G+LsKdvEPuSSKVf0zEvE3Q15osfNWjVJ5BD+bn8VDsuV0uWz2Gbuhv+mGnNbtdWCcJ1WwEIgcmyGN0sfZOT4ROn8u5m4bNX30eTwUx/Lu0rZEWBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1695305570; s=zoho; d=elephly.net; i=rekado@elephly.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=gsth8uFPTU29ahGVgl+RULuetXwLlbOExpqxj5Y7MDM=; b=ECnfYFaZ88iDEDJ25HenVgrPa19xCoYb5JwoWWJcxvM2HaD8qWd7faqgurkLpAD9 WWEC5SVoGVXYS6qMVf39a8495uvMYBJOwia+UHclF29Mf9hbNusuN6rCRS6dkOedkz/ zata8418t7E+CFqXxPqQ66zoJmtRPJlH8OuMmEs8= Received: from localhost (141.80.245.246 [141.80.245.246]) by mx.zohomail.com with SMTPS id 1695305568374675.7386370858161; Thu, 21 Sep 2023 07:12:48 -0700 (PDT) From: Ricardo Wurmus Message-ID: <0ed6325c8784aacd4b46003bbde8542dd95e08aa.1695305549.git.rekado@elephly.net> Date: Thu, 21 Sep 2023 16:12:41 +0200 X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.51; envelope-from=rekado@elephly.net; helo=sender4-of-o51.zoho.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, 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * etc/committer.scm.in (main): Reuse previously computed changes if there are no changes to the number of definitions. --- etc/committer.scm.in | 75 +++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 35 deletions(-) base-commit: 4bdb8bd2674c2b630626be43a5cd3c2b65401b52 diff --git a/etc/committer.scm.in b/etc/committer.scm.in index e7f1ca8c45..cc3b572710 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -388,41 +388,46 @@ (define (main . args) (unless (eqv? 0 (status:exit-val (close-pipe port))) (error "Cannot commit")))) (usleep %delay)) - definitions)) + definitions) - ;; Changes. - (for-each - (match-lambda - ((new old . hunks) - (for-each (lambda (hunk) - (let ((port (open-pipe* OPEN_WRITE - "git" "apply" - "--cached" - "--unidiff-zero"))) - (hunk->patch hunk port) - (unless (eqv? 0 (status:exit-val (close-pipe port))) - (error "Cannot apply"))) - (usleep %delay)) - hunks) - (define copyright-line - (any (lambda (line) (and=> (string-prefix? "+;;; Copyright ©" line) - (const line))) - (hunk-diff-lines (first hunks)))) - (cond - (copyright-line - (add-copyright-line copyright-line)) - (else - (let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-"))) - (change-commit-message* (hunk-file-name (first hunks)) - old new) - (change-commit-message* (hunk-file-name (first hunks)) - old new - port) - (usleep %delay) - (unless (eqv? 0 (status:exit-val (close-pipe port))) - (error "Cannot commit"))))))) - ;; XXX: we recompute the hunks here because previous - ;; insertions lead to offsets. - (new+old+hunks (diff-info)))))) + ;; Changes. + (for-each + (match-lambda + ((new old . hunks) + (for-each (lambda (hunk) + (let ((port (open-pipe* OPEN_WRITE + "git" "apply" + "--cached" + "--unidiff-zero"))) + (hunk->patch hunk port) + (unless (eqv? 0 (status:exit-val (close-pipe port))) + (error "Cannot apply"))) + (usleep %delay)) + hunks) + (define copyright-line + (any (lambda (line) (and=> (string-prefix? "+;;; Copyright ©" line) + (const line))) + (hunk-diff-lines (first hunks)))) + (cond + (copyright-line + (add-copyright-line copyright-line)) + (else + (let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-"))) + (change-commit-message* (hunk-file-name (first hunks)) + old new) + (change-commit-message* (hunk-file-name (first hunks)) + old new + port) + (usleep %delay) + (unless (eqv? 0 (status:exit-val (close-pipe port))) + (error "Cannot commit"))))))) + (new+old+hunks (match definitions + ('() changes) ;reuse + (_ + ;; XXX: we recompute the hunks here because previous + ;; insertions lead to offsets. + (let-values (((definitions changes) + (partition hunk-type (diff-info)))) + changes))))))))) (apply main (cdr (command-line))) From patchwork Thu Sep 21 14:46:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Wurmus X-Patchwork-Id: 54138 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 0071627BBEA; Thu, 21 Sep 2023 15:47:09 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 3843E27BBE9 for ; Thu, 21 Sep 2023 15:47:05 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjKxB-0001xD-VE; Thu, 21 Sep 2023 10:46:53 -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 1qjKxA-0001wk-60 for guix-patches@gnu.org; Thu, 21 Sep 2023 10:46:52 -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 1qjKx9-0000iB-U1 for guix-patches@gnu.org; Thu, 21 Sep 2023 10:46:51 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjKxJ-0007Jf-K5 for guix-patches@gnu.org; Thu, 21 Sep 2023 10:47:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66138] [PATCH 2/4] etc/committer: Do not record positions when reading from git files. Resent-From: Ricardo Wurmus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 21 Sep 2023 14:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66138 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66138@debbugs.gnu.org Cc: Ricardo Wurmus Received: via spool by 66138-submit@debbugs.gnu.org id=B66138.169530761028088 (code B ref 66138); Thu, 21 Sep 2023 14:47:01 +0000 Received: (at 66138) by debbugs.gnu.org; 21 Sep 2023 14:46:50 +0000 Received: from localhost ([127.0.0.1]:34604 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKx3-0007Im-U5 for submit@debbugs.gnu.org; Thu, 21 Sep 2023 10:46:50 -0400 Received: from sender3-of-o57.zoho.com ([136.143.184.57]:21794) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKwu-0007IS-Nr for 66138@debbugs.gnu.org; Thu, 21 Sep 2023 10:46:43 -0400 Delivered-To: rekado@elephly.net ARC-Seal: i=1; a=rsa-sha256; t=1695307583; cv=none; d=zohomail.com; s=zohoarc; b=ks9fwm3feEGIBgKQTJAyRfW4F3QVBDada5pE3ifMHzaEv/ogeZc1BBogFtEG+mN2iSnXI2YhO6P2bgVzFAtbYvyxSvkGWHNTkqPqzToVh2SNZm2gfV31JBB4PlQLT8cBktRNwmjCVZF/rIfkVZyj+Kwl2R46eGVaqYS3DaBNUlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695307583; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=TR9FuU2Yn9xFe5Z8qpK+yBZleUnqGaJR1yGoBoD1z6A=; b=gTZuYvFd3P84bTiCcsQYyePt3iYDY+LND1BU4fYSjWAc3ODg/xQeH+KkF39TlF+sbYFMmrMpq3NAqVIHkrHwtEgKUdYeqLNIvX0U/UylWaVAVl2AqE9rGwzKQkawY74wNELEsy8akqirJydmQvyuoddN98nz10Vckdk1B/TqPKM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1695307583; s=zoho; d=elephly.net; i=rekado@elephly.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=TR9FuU2Yn9xFe5Z8qpK+yBZleUnqGaJR1yGoBoD1z6A=; b=W5xb8tNlWk1aDZF21QJ+NXP27v86zHdmlqgTQTKydwFXtqIyRDggfRAPUewRljaa KECswKMsYswMUKmeuONtyR+kWYR30nLIUXKNQtISd8iqlwKm69Kl0eoI7FxoarmrBa9 1GVPNVOwkwLI4CFEa2gq2JX2FQL54eks1f0gGw5s= Received: from localhost (141.80.245.246 [141.80.245.246]) by mx.zohomail.com with SMTPS id 1695307582761691.715689423495; Thu, 21 Sep 2023 07:46:22 -0700 (PDT) From: Ricardo Wurmus Message-ID: <9c0df8930cdc415953a2dce8172edaa8944333fc.1695305549.git.rekado@elephly.net> Date: Thu, 21 Sep 2023 16:46:15 +0200 X-Mailer: git-send-email 2.41.0 In-Reply-To: <0ed6325c8784aacd4b46003bbde8542dd95e08aa.1695305549.git.rekado@elephly.net> References: <0ed6325c8784aacd4b46003bbde8542dd95e08aa.1695305549.git.rekado@elephly.net> MIME-Version: 1.0 X-ZohoMailClient: External 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 This gives us a slight performance boost. * etc/committer.scm.in (main): Disable recording of positions. --- etc/committer.scm.in | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/committer.scm.in b/etc/committer.scm.in index cc3b572710..45efb68be2 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -358,6 +358,7 @@ (define (main . args) (_ (apply change-commit-message file-name old new rest))))) + (read-disable 'positions) (match (diff-info) (() (display "Nothing to be done.\n" (current-error-port))) From patchwork Thu Sep 21 14:46:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Wurmus X-Patchwork-Id: 54140 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 E060327BBE9; Thu, 21 Sep 2023 15:47:27 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 F263327BBE2 for ; Thu, 21 Sep 2023 15:47:25 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjKxC-0001xd-Or; Thu, 21 Sep 2023 10:46:54 -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 1qjKxA-0001wl-9N for guix-patches@gnu.org; Thu, 21 Sep 2023 10:46:52 -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 1qjKx9-0000iD-Vw for guix-patches@gnu.org; Thu, 21 Sep 2023 10:46:52 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjKxJ-0007Jn-Vc for guix-patches@gnu.org; Thu, 21 Sep 2023 10:47:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66138] [PATCH 3/4] etc/committer: Avoid reading original files more than once. Resent-From: Ricardo Wurmus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 21 Sep 2023 14:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66138 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66138@debbugs.gnu.org Cc: Ricardo Wurmus Received: via spool by 66138-submit@debbugs.gnu.org id=B66138.169530761228096 (code B ref 66138); Thu, 21 Sep 2023 14:47:01 +0000 Received: (at 66138) by debbugs.gnu.org; 21 Sep 2023 14:46:52 +0000 Received: from localhost ([127.0.0.1]:34606 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKx8-0007Iz-CH for submit@debbugs.gnu.org; Thu, 21 Sep 2023 10:46:52 -0400 Received: from sender3-of-o57.zoho.com ([136.143.184.57]:21797) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKx2-0007Ij-8Z for 66138@debbugs.gnu.org; Thu, 21 Sep 2023 10:46:48 -0400 Delivered-To: rekado@elephly.net ARC-Seal: i=1; a=rsa-sha256; t=1695307587; cv=none; d=zohomail.com; s=zohoarc; b=Bzyfw6oTh7gWkRZri0QaAqCuB4PXo0sDu81rlHxfCYqy+A/yk6aw4EiIJ2szwA2X55zKOFZmN4/PknJ34hcm5LBtg1tTpBG+GHd9mb8lWu8MpdZ54nXhsp4L7Y2/1tbk+gz3fenlv5xgDivxlG2Q187u0fnq9B9Yy/sQbMWiWyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695307587; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=2sCtuGczjdVKVRe0xueDENm6iOweokxzh4DtmIal2s0=; b=T3zLWmmQJLbZy9OS9aFLKCObu0p8yYyURPGQEAQ7lW2qQWuVBSbs4/YEdiWxbO52Dij2zaCboDkkTV0++C3dZfk3kHfiyfnH4tN1hypg+lpylFYssez+BPAmtKCakuGid0eiTMLgxd6syAu0056ODjlzim9EmUptuQQtRHYSHac= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1695307587; s=zoho; d=elephly.net; i=rekado@elephly.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=2sCtuGczjdVKVRe0xueDENm6iOweokxzh4DtmIal2s0=; b=G4DwDjjPK7mEmRWnfBYpKdU/tOJ1D1DgUBmBzONyKr+UqNvMqvXKIm6C96ecGxTy eU05B7Qiv/wZoe4PAkH73zAgvZSfOw9tA5wPWRWLrZWHm0WKEvlUB0dS+/UTNVN3jjH 563Nqp3Sr/jYrNGX/Cu1wENya4YlKGoZ7guMi3PI= Received: from localhost (141.80.245.246 [141.80.245.246]) by mx.zohomail.com with SMTPS id 1695307585901946.7685561359534; Thu, 21 Sep 2023 07:46:25 -0700 (PDT) From: Ricardo Wurmus Message-ID: Date: Thu, 21 Sep 2023 16:46:16 +0200 X-Mailer: git-send-email 2.41.0 In-Reply-To: <0ed6325c8784aacd4b46003bbde8542dd95e08aa.1695305549.git.rekado@elephly.net> References: <0ed6325c8784aacd4b46003bbde8542dd95e08aa.1695305549.git.rekado@elephly.net> MIME-Version: 1.0 X-ZohoMailClient: External 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 * etc/committer.scm.in (%original-file-cache): New variable. (read-original-file): New procedure. (read-original-file*): New procedure. (old-sexp): Use it. --- etc/committer.scm.in | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/etc/committer.scm.in b/etc/committer.scm.in index 45efb68be2..eb8865513e 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -196,21 +196,34 @@ (define (lines-to-first-change hunk) (string-ref line 0))) (hunk-diff-lines hunk)))) -(define (old-sexp hunk) - "Using the diff information in HUNK return the unmodified S-expression -corresponding to the top-level definition containing the staged changes." - ;; TODO: We can't seek with a pipe port... +(define %original-file-cache + (make-hash-table)) + +(define (read-original-file file-name) + "Return the contents of FILE-NAME prior to any changes." (let* ((port (open-pipe* OPEN_READ "git" "cat-file" "-p" (string-append - "HEAD:" - (hunk-file-name hunk)))) + "HEAD:" file-name))) (contents (get-string-all port))) (close-pipe port) - (call-with-input-string contents - (lambda (port) - (surrounding-sexp port - (+ (lines-to-first-change hunk) - (hunk-old-line-number hunk))))))) + contents)) + +(define (read-original-file* file-name) + "Caching variant of READ-ORIGINAL-FILE." + (or (hashv-ref %original-file-cache file-name) + (let ((value (read-original-file file-name))) + (hashv-set! %original-file-cache file-name value) + value))) + +(define (old-sexp hunk) + "Using the diff information in HUNK return the unmodified S-expression +corresponding to the top-level definition containing the staged changes." + ;; TODO: We can't seek with a pipe port... + (call-with-input-string (read-original-file* (hunk-file-name hunk)) + (lambda (port) + (surrounding-sexp port + (+ (lines-to-first-change hunk) + (hunk-old-line-number hunk)))))) (define (new-sexp hunk) "Using the diff information in HUNK return the modified S-expression From patchwork Thu Sep 21 14:46:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Wurmus X-Patchwork-Id: 54139 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 B95F627BBE2; Thu, 21 Sep 2023 15:47:14 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 7C51227BBE9 for ; Thu, 21 Sep 2023 15:47:10 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjKxC-0001xQ-My; Thu, 21 Sep 2023 10:46:54 -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 1qjKxA-0001wy-MI for guix-patches@gnu.org; Thu, 21 Sep 2023 10:46:52 -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 1qjKxA-0000iM-BH for guix-patches@gnu.org; Thu, 21 Sep 2023 10:46:52 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjKxK-0007Ju-Ai for guix-patches@gnu.org; Thu, 21 Sep 2023 10:47:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66138] [PATCH 4/4] etc/committer: Speed up surrounding-sexp. Resent-From: Ricardo Wurmus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 21 Sep 2023 14:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66138 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66138@debbugs.gnu.org Cc: Ricardo Wurmus Received: via spool by 66138-submit@debbugs.gnu.org id=B66138.169530761628112 (code B ref 66138); Thu, 21 Sep 2023 14:47:02 +0000 Received: (at 66138) by debbugs.gnu.org; 21 Sep 2023 14:46:56 +0000 Received: from localhost ([127.0.0.1]:34609 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKxE-0007JM-6R for submit@debbugs.gnu.org; Thu, 21 Sep 2023 10:46:56 -0400 Received: from sender4-of-o51.zoho.com ([136.143.188.51]:21144) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjKx8-0007Ix-Qi for 66138@debbugs.gnu.org; Thu, 21 Sep 2023 10:46:54 -0400 Delivered-To: rekado@elephly.net ARC-Seal: i=1; a=rsa-sha256; t=1695307591; cv=none; d=zohomail.com; s=zohoarc; b=kUayLwpi8+HdOq5xgLUv0waH/gA/LlhBOPQ0fIFvEehh02YbtfyH9MXRfWkfNDlqJhPRbnND55CaqsrkLHkZIGYgHC/5M5VCpnp5GSHFU+2Qp+arHczpLvMvGQSoh9ayaw52n/tvLbcBD+dWfsSE329s1W8hyHu4RUp2nWuYvnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695307591; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=C9hWs40LFEpYNDLxgjSVTCMJWBUd6tW8XqpJ1zGs0WY=; b=Z/QHi1Xn52T7okjaf8TifJY+DgrZr+vwlirf7aI22fKBHvDKoDPywggrdDHezWewpnOealwKRNWBFm8XpD9y+DnBhSM/OKZkawYCl/oM5GNNSVSFYt56zUOP38nzYwzM5jwgrspoWg+jD4n3p76GlmiO0/BWiPr7+UvN2+JumMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1695307591; s=zoho; d=elephly.net; i=rekado@elephly.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=C9hWs40LFEpYNDLxgjSVTCMJWBUd6tW8XqpJ1zGs0WY=; b=F+orDq/FST1Xj5mrZf9DcI5xE+QiJCnqhE9iHHPu2R8c2t7StR5JSLGy+HUncq7I ilHZFpMgCx8qIIewQyTt/8Vo+BsbuJqhcjpaY53dBOlBVdjCW2Rh4GyYtuD1vxck4kM DUdtKAkif151cQn3xgcg/tIZQawsm5U2EIZ+lnrQ= Received: from localhost (141.80.245.246 [141.80.245.246]) by mx.zohomail.com with SMTPS id 169530758900326.33740265246354; Thu, 21 Sep 2023 07:46:29 -0700 (PDT) From: Ricardo Wurmus Message-ID: <2bba46036e61fa5899b59372756ac9c5a7403762.1695305549.git.rekado@elephly.net> Date: Thu, 21 Sep 2023 16:46:17 +0200 X-Mailer: git-send-email 2.41.0 In-Reply-To: <0ed6325c8784aacd4b46003bbde8542dd95e08aa.1695305549.git.rekado@elephly.net> References: <0ed6325c8784aacd4b46003bbde8542dd95e08aa.1695305549.git.rekado@elephly.net> MIME-Version: 1.0 X-ZohoMailClient: External 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 The old surrounding-sexp procedure would read all S-expressions from the beginning of the file up to the given line number and then return the last encountered S-expression. This is quite wasteful. Instead we can record all lines that begin with an S-expression and jump straight to the offset closest to the desired line number to read the S-expression there. * etc/committer.scm.in (lines+offsets-with-opening-parens): New procedure. (surrounding-sexp): Use it. --- etc/committer.scm.in | 46 ++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/etc/committer.scm.in b/etc/committer.scm.in index eb8865513e..0705b29fd9 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -85,21 +85,39 @@ (define (read-excursion port) (seek port start SEEK_SET) result)) -(define (surrounding-sexp port line-no) +(define (lines+offsets-with-opening-parens port) + "Record all line numbers (and their offsets) where an opening parenthesis is +found in column 0. The resulting list is in reverse order." + (let loop ((acc '()) + (number 0)) + (let ((line (read-line port))) + (cond + ((eof-object? line) acc) + ((string-prefix? "(" line) + (loop (cons (cons number ;line number + (- (ftell port) + (string-length line) 1)) ;offset + acc) + (1+ number))) + (else (loop acc (1+ number))))))) + +(define (surrounding-sexp port target-line-no) "Return the top-level S-expression surrounding the change at line number -LINE-NO in PORT." - (let loop ((i (1- line-no)) - (last-top-level-sexp #f)) - (if (zero? i) - last-top-level-sexp - (match (peek-char port) - (#\( - (let ((sexp (read-excursion port))) - (read-line port) - (loop (1- i) sexp))) - (_ - (read-line port) - (loop (1- i) last-top-level-sexp)))))) +TARGET-LINE-NO in PORT." + (let* ((line-numbers+offsets + (lines+offsets-with-opening-parens port)) + (closest-offset + (or (and=> (list-index (match-lambda + ((line-number . offset) + (< line-number target-line-no))) + line-numbers+offsets) + (lambda (index) + (match (list-ref line-numbers+offsets index) + ((line-number . offset) offset)))) + (error "Could not find surrounding S-expression for line" + target-line-no)))) + (seek port closest-offset SEEK_SET) + (read port))) ;;; Whether the hunk contains a newly added package (definition), a removed ;;; package (removal) or something else (#false).