From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id AHmnB35XDGXBEgEAG6o9tA:P1 (envelope-from ) for ; Thu, 21 Sep 2023 16:47:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id AHmnB35XDGXBEgEAG6o9tA (envelope-from ) for ; Thu, 21 Sep 2023 16:47:26 +0200 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 111465D1FC for ; Thu, 21 Sep 2023 16:47:26 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=elephly.net header.s=zoho header.b=G4DwDjjP; arc=reject ("signature check failed: fail, {[1] = sig:zohomail.com:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1695307646; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=2sCtuGczjdVKVRe0xueDENm6iOweokxzh4DtmIal2s0=; b=BdKVb15H/JHmSlaxYLgGdFwdHx7QimlnVrWO5zDSFWUYnwAiOC3gnlQkH8GkKB+nXcCLLc FKYSY4Dcdfg+cK1xBam15mPcZmas/ogr/6SDc+osnYVsqu5us5KLwJkzwYEAu06smuxiXn Wv0aabQO1HPks8pwxm9JILmZZNoEciqu36Qz3OKNhsz101DyOENuMr5gtMIjgNP+lG8XUF kEvutx15wlVTjaTqGDRFhU5kC7pJ6fmfR94XLwLMzOFTXzxW1ayFJAyrphQzZasbEZwJqK 0zjhil4vQor1Z/0C632p3TqPSQvvlNrZIgRu8nvAXBgIxn4yAdki4vh9hfFY3w== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1695307646; a=rsa-sha256; cv=fail; b=BCGmHjm6dypmYsSOVju5RKmu7gHdBlcbYw8C083u43BqXDU+zX8BuoB6NNmSxT78VMNlpQ QJ7MGv/0/WXmiiZKt1Mhad06Xqwr5L51cINfQgNJrB/cz/8v0Pa7+Pz8m/0oBYj/xhGWkD kLY0yw2uxEKeyiiy0tQZguwFXlqES8YUTSyBuoIJnsm0scHSITNP4xe2S/D2yQj96DL0oO vnzvkevgi5xXW9RvRjerfx8GllXLgfWpMC1szxRhDqqXQXs8c6lN422uPIWneiFw0xUfC+ kvFjgxbYW7t/mgfqcJTFQu/22SoKODEEu1wGQr+RCfVfM58qjcs3Ook6mQuWcQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=elephly.net header.s=zoho header.b=G4DwDjjP; arc=reject ("signature check failed: fail, {[1] = sig:zohomail.com:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" 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 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 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset=utf8 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -0.25 X-Spam-Score: -0.25 X-Migadu-Queue-Id: 111465D1FC X-Migadu-Scanner: mx0.migadu.com X-TUID: A4gViSjxT46z * 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)))) =20 -(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)))))) =20 (define (new-sexp hunk) "Using the diff information in HUNK return the modified S-expression --=20 2.41.0