From patchwork Mon Dec 13 22:54:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Holdsworth X-Patchwork-Id: 12674787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C5DDC433F5 for ; Mon, 13 Dec 2021 22:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244041AbhLMWzR (ORCPT ); Mon, 13 Dec 2021 17:55:17 -0500 Received: from mail-bn7nam10on2085.outbound.protection.outlook.com ([40.107.92.85]:28160 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244017AbhLMWzJ (ORCPT ); Mon, 13 Dec 2021 17:55:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=llluau0891owRQKDXd0oW5upE1o8yzpYQNSDdfmMBPa/IPvKM9p5ET3uXzr4KE12Y7IV+WPAnHeMq0dk8df0iYyNnZ8atk3q+4UdgihX/FoLbAI8UeWpuGGWhAa2CkN7WkEvF/kA22zzISACpRkIbIWXCXekPqOUuzX+qq/aHgtRoYcuSXOHDECuwtzWaNECJ7wve1/WP3FHs6vAaTRrAFDpvE34ihr1nbhzMnfFnTC4nN7rNjcgftgfFMbsmB77Eg352XRhxjockSEJuNKVI8Rlprf8k1bwjiJ5nHTL8gq3xnKOr2CNDzkhwOXbFT3l0YWAVQcdSZaD1vS2om0bkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lHpeo7RglVVW8Q65y/TZB5lZBJAOg9LZoFd87gAJ6Wg=; b=k4L25U2+b+T2M4UXJr/3ti5Y2YdRuoUapw8tltefwG7LYrEiYyjYNUA2Fmdp+M/Bg04JLBa+nwf9Do535NEV5AK6r6VVeJKmoGem+/NlHqzldB6De0H5/H/V31JwAfmsBL1LQDXv+Ldj/GnYgx1lMBJccafq0mJ/QvVPrl0oF0PAhqEa8E62YyWtDBG7OtysWt9Rtqgi64bUptZs8OjSqbSkb+fGNnskvIspeRQJu1ukhAuLfgF4TOmrGaeI4oUkSaW9dyQDmq78sigfwe+7PvttX5jYy9pX+lNb+jRViHwRNabK6tAedUGywmRe4iLVs4Z+h5uYGLgKWh60L5kEVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lHpeo7RglVVW8Q65y/TZB5lZBJAOg9LZoFd87gAJ6Wg=; b=YkM23RU83MrliYGJjpl8xSzD+K1MRIdqwNv6O2A78+eIE6zT7ln3ONfPu7JPPtwNkNy9greqI4Q/1yie0dtoRA51mCxy2EfrxTLFFdQQDGSwsaLxvf3/4FmD0n1BuYCVcGczgt8MeXfhsUj2KBAgv2LY+97tzkdlwTa/41NYd8iS05zxPEYzqxaohm13cI+jkxQaBDAXuxx0y2EZLlyI/AUX52NbsfA93Qzo8Oyx5SoOchHzmHDgHeKFTfXO4ty2DmmOrGUDfgzmBoXvTj12iCJE2IdCbDaQbOsiA8KzSwxwpEMEklH3OcI4BbBLGcwcm6U98TEDXwWpPckm0U9WrQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) by BN6PR12MB1377.namprd12.prod.outlook.com (2603:10b6:404:1c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Mon, 13 Dec 2021 22:55:03 +0000 Received: from BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592]) by BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592%3]) with mapi id 15.20.4778.017; Mon, 13 Dec 2021 22:55:03 +0000 From: Joel Holdsworth To: git@vger.kernel.org Cc: Tzadik Vanderhoof , Dorgon Chang , Joachim Kuebart , Daniel Levin , Johannes Schindelin , Luke Diamand , Ben Keene , Andrew Oakley , Joel Holdsworth Subject: [PATCH 1/4] git-p4: use with statements to close files after use in patchRCSKeywords Date: Mon, 13 Dec 2021 22:54:38 +0000 Message-Id: <20211213225441.1865782-2-jholdsworth@nvidia.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213225441.1865782-1-jholdsworth@nvidia.com> References: <20211213225441.1865782-1-jholdsworth@nvidia.com> X-ClientProxiedBy: VI1PR08CA0263.eurprd08.prod.outlook.com (2603:10a6:803:dc::36) To BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8362a441-4555-4b97-e5b0-08d9be8b998f X-MS-TrafficTypeDiagnostic: BN6PR12MB1377:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cBYl2r6AM3Nmgq6bC1e9BLV0dOtkl9Pc57Dtghx/WhLOLqBcbi/xWmULu8oS/nFTv/225R8fUwjzlB2zhrKdDbBiqtMjzGXVtHiMpoAlpqFHgkiUWYRpM+pw7T5blvKJFAVx0qE6BHrUhvTIeJxD4C/r4+Jr6HIA6mmVKvohIS11kxczZ+0tyAOiScLTaYJyv2MKV79XblNOhjHrMmoMHv9Q9wurRnlbiiJN7oKQtfzwMBBVL466j9ZH0cJaRSwFvevYoF1mjEbEKVmuHIUtTdml1GUOv+Atih+rC34aeKopBFVFjf4uNAx4O1OluvkZyg9cZUIFoH6oUA2HBRsM7/73HDRQ3n9+IwTNuKxpcEgMeMNVOFa4Q9f3rIey9wEtWX/X8ZY6zakKX5gUobPXkP6mbaJ7RPQTjFHpz02fFMm7Ji3oHTJRSB1KMcyEmLwaGG1pVpoeV6w1GUt/7iZ6M8P+JcqlTleRAgdoW//4PPYPqAvpiNgPvtzuw3W1EbPFQtJjSmgXxCr1EFh5kTV1By+XAgeNgsFBHQsZrAkJrkU9GxCyzFpPHVpDQ/8omzE26nxapySQTP9GqaWuNPLli1nOk6P7qpaeNqTNMVS5mMFMiPoVvzsEZe5ab2ctBF4TMeAbkWko9xEgpsl+pTGzw5GO3jK8jjAOh8tx/OsuVpBCjYP6K4cjFzQWklaI9rWrBWXn0+IbOkfGIBWKeu/1a63pruiNQGLDnoPxA75llY0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3361.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(5660300002)(508600001)(6486002)(2906002)(54906003)(8676002)(8936002)(6666004)(66476007)(1076003)(6512007)(316002)(66556008)(38350700002)(66946007)(107886003)(36756003)(4326008)(38100700002)(86362001)(6916009)(52116002)(83380400001)(55236004)(6506007)(186003)(2616005)(26005)(156123004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: k4cGuyfdHFn+4wofEzZPLSZIZrA66n4pfvY0dqCfvFBt7x1Ag/8yO1b4s9y5YVGwEdaeixZ9kj9Tqp6exvaxHsGJswah9x4iriWGS0P+ymywJyoyq9rSNaiR3ELYdl9ju8v5vBJIPKaBau6ofwON9lOWISpgiSNTwPvLvZinS6NYP9DD4jW4ZTgR7DRUEDcVJqe+fNQFyHFcOQYf1bxfaWtlN3IpY50qfVd4McpbGisp4cnB0xB6DAANxHIRE3XtLs9sGUGGABNjFBQZRW84L5wPAoHP60lrkgn86k6q0xkb1JPqfq3rR2n3riI9H/KLX/8GN5LJCDVEOdSwFPv4ZVJR1HNpjGiM/PKJ8hMi0UcNpW7mpigsKPS8naJwaukzOhbIFPqLC2mHXKuGFVRE9mlLZn0zOj5thnaKYXU7Cklw6EA9hVn94TStPsVuw2PPg/eIgXEcbGnYPfZOEVUfPiyB04/fUAtvbM+L8zHYW3DPPKGRrnf39NM0BNRlzk14HntcgvrzBzgcwdA6b790F/0XRzq+MYjlaBI7vpnlEnPqm9FiQd5a53KHWs0xqIKJ3rnlbzJ/7Sfw4iMbMkC5qDrCSmK1DTa9dhoj1xcyoBKfO4rbMZWcuJZZs2HEGDGEZsjd1pJpvqz/E1vSIxGTkldKra81NNaVQo2CBJiIKWMIt2CNZvpcXebJlvEy0ZknUQwxR9UfJ0Eo+EkaTdVp8p8J48nBmSudni34O1ow3urmJ7i0woKpeynty2pYcFwnKBKDDKISnMB3OtHTtdTYITaX9DiPv4SD7B2FpuCGOUv4kpSK9MEW8NhABkQpKS96jDi+uLZDF5cyIEe5nJDA/04ZVAhyB38//flUz6+RnMZevkRa/txTci1C9yySHwH8dSzCbyw5J+3OCAFrKgVvtKb5qGOcxWx9aucMfxd5n30GGsZ5OOItKumqKlp9XuvP07wwJfxET7NiJAWqNuYiof3C5Br7t4mV8/BwDeTPU0GgyTXZ2xRoroKcJvw5a392endzJpeAPT4hVCUKancUPMQoQ3quz3wYWQkSuod1Y5WOi52zpSgLJ/OwxpiVc7IgTcWwBzux4DH08manxaMsSD1R8z5/XEcbtZHAXOhOhXwJM94JLEHuq4PbUpJxRAGAZXNcPwCnEawkjn2BBgV6Ip2uGl9QA7mviREyJjRdBSX4qThB+wx5TV8FP8k2hf0qaxpBlvocA++1nXQtZ20haYlkgtoyzQ3xekPHxnJ4XIyuXc9RUEmPO1cW93E8tigjGRSXYyESJbTYoi0xcnxa6lPuSMhgI+w5bJj0GdYChTmkIQBoSjFrQeOXDtUwSDaDZAMbRGBpouj2VMAUZR6YOODV9wjXrIGmljW3dM/8tOt+icrh2jP9SCR7MfXE5W2zZtHK159/J5zyGFoNhGN0lZKRaOYGj+p6NhJqsIzmFRxxAJfLzd6DLLhNPXlNpuXXIgrkFiywaCjCpLIRuFMT/G5Rkn7RuDc3m8RNPNz3zQUuBaLOpDefdy1YWWOhPyBBEh8MDRg/j1kgrfCGlHB7ejMQMmvIpnR16JQEEZ9LOZkQSSgdmjZAKm+cjMrxdBWOLyMylv1/Z4csJU8axFU85Po6oMZek1Y43GqtApOZs5w= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8362a441-4555-4b97-e5b0-08d9be8b998f X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3361.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2021 22:55:03.8410 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SNhMhnjT5kDDk6WOY05cC+FajgJtlNX0DtVhHhoa94ryntUVtbHDYMJepiOG5gFeog2Srj9l1DL5dY7Q46cg+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1377 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Python with statements are used to wrap the execution of a block of code so that an object can be safely released when execution leaves the scope. They are desirable for improving code tidyness, and to ensure that objects are properly destroyed even when exceptions are thrown. Signed-off-by: Joel Holdsworth --- git-p4.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/git-p4.py b/git-p4.py index 2b4500226a..226cdef424 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1757,14 +1757,11 @@ def patchRCSKeywords(self, file, pattern): # Attempt to zap the RCS keywords in a p4 controlled file matching the given pattern (handle, outFileName) = tempfile.mkstemp(dir='.') try: - outFile = os.fdopen(handle, "w+") - inFile = open(file, "r") - regexp = re.compile(pattern, re.VERBOSE) - for line in inFile.readlines(): - line = regexp.sub(r'$\1$', line) - outFile.write(line) - inFile.close() - outFile.close() + with os.fdopen(handle, "w+") as outFile, open(file, "r") as inFile: + regexp = re.compile(pattern, re.VERBOSE) + for line in inFile.readlines(): + line = regexp.sub(r'$\1$', line) + outFile.write(line) # Forcibly overwrite the original file os.unlink(file) shutil.move(outFileName, file) From patchwork Mon Dec 13 22:54:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Holdsworth X-Patchwork-Id: 12674789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71D2DC433EF for ; Mon, 13 Dec 2021 22:55:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244012AbhLMWzX (ORCPT ); Mon, 13 Dec 2021 17:55:23 -0500 Received: from mail-bn7nam10on2085.outbound.protection.outlook.com ([40.107.92.85]:28160 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244044AbhLMWzO (ORCPT ); Mon, 13 Dec 2021 17:55:14 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jnYpHaSRaXVMHUbfikBjgbMCZVHkZmxDJl4MXi4Q0T9OhR+7XbTtqDWN9lnZoOuX+5IMUfXFt2gg0LaP9U5VE1+rSFTR0+k1KPti3hCI2Nd4NkBNrRKqG7Xv9yMWvS6RfQQ8NwZ+/CKvP28BNnvspIv2TrujHFFviEjliW/m3KCS8Yt9PWviQ5NXQwpEsxIV9vDjYLTETeu+bZ0ioc60+agJvabRn/7IFNk4rkGdIELbsAwXy1Ffcq5lkBi6/OK9RH4sGALUfcB46IJiFJuTeHZ3Ch/WqxpXnHd8GZALJGU4rNVJZvNcUTNxY3IP5BP2/3RbmjUI4BelpaRyQzb6XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MBuWx8XTLcF7AIBJQtkfyHUjCNrH03f1Iouh3/jPxiY=; b=lsFvPbQlP11JUW8oK+IrAWS9lE2HrmEiaKCaM5EJUsCCE6noVNj4TGTlhtoWw8FwZZw0wCZwU5L2cndsRy/nvBFbY0ulnIWkJqzmeOkKqG1QJiibSu7yiM+8TihQBzp5OshCshvSK5lt9pUKKDfvdlubdq3Nu6KVoMtO/YodrtvfuvvcUtWxElDeReSPhEE3tWfrGdOCsNAPlLu+T8v1g5gA4h2eSQbWk9wBhsjFG9Z0A9C+Jxvfp/iepZho8bmqcRffrzbgvupPEoVQUv6NBz2srZOrdla65ZnvqE49ffkc8GLaTDIUgvbSM/3XZ/q82n5glVIWa3ehJazfUmczYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MBuWx8XTLcF7AIBJQtkfyHUjCNrH03f1Iouh3/jPxiY=; b=NDQviA0rWIw2s85dsaa/Mw9II9DWVTaKMES2J3s2I5pW1ohQA/7zujs/APjIYuAH2omHmU6NOhdoolHTmBdE5GAQqiVdXEhdXzEac6LRiLXO5wLk8ce6evI02Ro+ca3oDOyYz915tmLoqt0HqfeLlV4V6573lj72RWG2q/dMYfnB9cFLAR8l9zX2M1KJroXogam9YN8fLjNxnDoRPTl+ARIMXgA3chRbUiG1BYXf44koimejlu5YI8fMPuoSloQWHnqiyG+nGb9mqhJLx1wQu9j5wQSClsTHlq/qocoEWeu/HrMI+2UFJbODQxzo2MswMGxSxcXAG0A3afU+ZFN6KA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) by BN6PR12MB1377.namprd12.prod.outlook.com (2603:10b6:404:1c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Mon, 13 Dec 2021 22:55:06 +0000 Received: from BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592]) by BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592%3]) with mapi id 15.20.4778.017; Mon, 13 Dec 2021 22:55:06 +0000 From: Joel Holdsworth To: git@vger.kernel.org Cc: Tzadik Vanderhoof , Dorgon Chang , Joachim Kuebart , Daniel Levin , Johannes Schindelin , Luke Diamand , Ben Keene , Andrew Oakley , Joel Holdsworth Subject: [PATCH 2/4] git-p4: pre-compile RCS keyword regexes Date: Mon, 13 Dec 2021 22:54:39 +0000 Message-Id: <20211213225441.1865782-3-jholdsworth@nvidia.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213225441.1865782-1-jholdsworth@nvidia.com> References: <20211213225441.1865782-1-jholdsworth@nvidia.com> X-ClientProxiedBy: VI1PR08CA0263.eurprd08.prod.outlook.com (2603:10a6:803:dc::36) To BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f1eb0389-70a0-426e-42f1-08d9be8b9aef X-MS-TrafficTypeDiagnostic: BN6PR12MB1377:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UWQHrOe4J2CgArkjLOvtbYdyqGGMQMEgSKINWDL7hfH23ju3H939drBm9td8oEcYVO5NwuT2SFX3gQbIfHilwNoimuc1Y3m6BAhq2ih27NTbPCe3997ifmPN1Vyn9nxGeUH7V+QGji7wIBLgo1tf8Tq6UThn35Bxq+yw6aiTA5LEMV7GAd52NkE7ODDzgU2gkEuENKy8+lmstwdx9SkHs5Ps+uatiOdyFz74t/5Yy1pvmTidna55XdsJ+S6zvYTAVrYje/sx2JoGIViyvqOvRlqE1/2O9T6hZ3WUe5yqS1gMCvqAdpez0FvGYUi4AQZ7knsbwXrc0Qik91/YKBe/+x2sxORaxCscIIynF1G/ycXMBbh95Z3+2WVPonq1tyGt7e0eZyVebQ17s8yQccdZ/9vzrvm9+Qn6hW5GL13V8Fqo4h+JjClZ6vjARqMDauG/8xly5xCWhnSXuXQrDPkOj9cxUH7QWZeqA/wdxeX+a85TTigMQIr/k6j5gTmOOcx2YLCOxYim7SMATOYdTQZ3AOO/ujLPk1ihofBnwrFPY5JUNb7YkfVxRCWYkgsYGy+q9mspfk+Aksj9/C/W2eKADtsJ4gwuNScWr0pJ2/dPzQ7ExOP2Yeh7tVG9CZspI7jHql3c0VY4KdmnEk21vNj+gdT+reluD3744i8BufiVuJUXZcKx7g2hHPOiCe4h/gL3IGsNZSsdsMPu5+pG45VYqA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3361.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(5660300002)(508600001)(6486002)(2906002)(54906003)(8676002)(8936002)(6666004)(66476007)(1076003)(6512007)(316002)(66556008)(38350700002)(66946007)(107886003)(36756003)(4326008)(38100700002)(86362001)(6916009)(52116002)(83380400001)(55236004)(6506007)(186003)(2616005)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nYMvLJAn7zo8+LNh5YiYLsa2NN6SLE2ALwsUTHmqy34V/DQ4xoZ3CDU7vuGgcEyXo1n6ap/Kp52Q8FXCdN5BxeyBrBLp8XXTkCGmrIchvacyL4j6rWbeZ1d0hec+v3q9NktA3vECD8EJ+pe/2Wcfxurabo28aEbKWIL63CALwt3U6LxD7x/vn/Jwe4CfQXqbZgBn9lI4fV+IEiKLDIICl9wLWqHbVcSGI2lVxBT5wK5N9dFtmT1AI918FcpapO6/eoKwqjJFUKlHvfQ1humFxN1JrSn05EUGLALiuvUl60gUShr8BxMzBUuB1I3qKjV1IO+RIGFE7rJlZFnMBYRg3f0HPqhvmvpUq4gJsTcCUm3EW9A0ipbFMQbynTflAtHiApBk7RvYYmQXy5gIMcLTT6nUX7RvfjwEKQzNNRxSFZSbhxhEbT8vsY3BK4Cw063jitH/yNABbiE+xgFi6oEINTjf/ozByLuUxJRs6X6X7ewqxzJGfu3IlzPLzMivY/Df7/hH1n0TopyydADpMucs5567irVTZEUlOYLfGCovQXhRINYFVoXvTXeoaFHrEJbfEuw+kK+oOfBYa/62YeeNcZEiHGVW86p1NcTZgLBfc7oj/xhKotWk2llIFZ6C3nMSe4yb/E+aH0Vu/03uUEx6hMTeNuj0Dk5hl7B0/xWTg+JGilZMYnUNwi3surUSwqkKkPC7+/auN9U0lps49iM6RgxCoDiVADSIH7BJgK1pSRF+vfwpZ2xVSsJ/Et9UjwGK/i842QvNwoJRZORmdEhb0TQEUrKSqLJpOF8GJEPixwE3zKpGfJfAeyIyShKyZIjKnyb4Lh7EvdDUTcTBqNsQxTQoonieTNw5MImDCXDlC76rJiRhbgpT7DPMfuDfzz2vxLKeu6d8uwVAW9Ae8FMVsUtIWkEjiWiiRiQs9CWtzCsobl8z7c4Ws6qxTiUuv/TmJXIa29PhNyuqoZpMDu7vK2sKeIHpEE3H+IsUs7mAbLhyG0NJBNOd9ThcqV8OALErLeMG/JSfYu+SvSQ3GT1zg/jxnIAlTIQ74dS93HGw1wLXWU1EOeLNFG66JUub/YBDrcnzouURF6A4UfGYp2tAG8fnHfmkQS4RZGFxYAzF+XxaZEHyx7z4kscGwSXbFC378rO4mQTBr3h/KSdALg/CO4uoCJZhhNug16P8sFHEfXxqKqcu5nx3F+Y68w4uEIJWfmUkduhUBxE5k4Hpud4jf3tOGKxlAVb1AHZA7C/GHyHSHLlYXa5l+14fPJyV+wE7U3zl0a0Rbd2/W2RxJJNAvzfOhWjjvKVALvG0zr2DnsRyGYAN4OS7H+GzEXOSRlbwzncQAhPN7uBcmGOrTfameGe8zqLI1OKKvKyiJhAn6SB0BbVl+rLQ1Rt+/EH/rJI3QdpX9c9hUi7rIkItSBtan54UpY87f2uNmeMOzGYyyGsZCRY0R1jxdA9hhQh3cujaYx3Vk56bcw8vLt6SMMDrca3wxh41CEoDjFvjNmdxzo21tHDg9m/V7SAeJV5ORH+Zn+FTt5P1SU4EUnwSzVUa7k8Xzi9hX4Vla4afUtH56Jte/aNCYpkQJMe5L62gJEnntB9T1rtW+P+Iy7obCJ8VOT4gm4XjZRFlvEr0qkJBj0Q= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1eb0389-70a0-426e-42f1-08d9be8b9aef X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3361.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2021 22:55:06.0937 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VbqirBuP7rgJdvkz1rQv0K4uvulDFnvSt4TsQ+GR7NWStjpcgpuDw+bySmGdLrjtYdQjJEuRO1ko/sNrTP3xNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1377 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Previously git-p4.py would compile one of two regular expressions for ever RCS keyword-enabled file. This patch improves simplifies the code by pre-compiling the two regular expressions when the script first loads. Signed-off-by: Joel Holdsworth --- git-p4.py | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/git-p4.py b/git-p4.py index 226cdef424..0af83b9c72 100755 --- a/git-p4.py +++ b/git-p4.py @@ -56,6 +56,9 @@ p4_access_checked = False +re_ko_keywords = re.compile(r'\$(Id|Header)(:[^$\n]+)?\$') +re_k_keywords = re.compile(r'\$(Id|Header|Author|Date|DateTime|Change|File|Revision)(:[^$\n]+)?\$') + def p4_build_cmd(cmd): """Build a suitable p4 command line. @@ -577,20 +580,12 @@ def p4_type(f): # def p4_keywords_regexp_for_type(base, type_mods): if base in ("text", "unicode", "binary"): - kwords = None if "ko" in type_mods: - kwords = 'Id|Header' + return re_ko_keywords elif "k" in type_mods: - kwords = 'Id|Header|Author|Date|DateTime|Change|File|Revision' + return re_k_keywords else: return None - pattern = r""" - \$ # Starts with a dollar, followed by... - (%s) # one of the keywords, followed by... - (:[^$\n]+)? # possibly an old expansion, followed by... - \$ # another dollar - """ % kwords - return pattern else: return None @@ -1753,15 +1748,13 @@ def prepareLogMessage(self, template, message, jobs): return result - def patchRCSKeywords(self, file, pattern): - # Attempt to zap the RCS keywords in a p4 controlled file matching the given pattern + def patchRCSKeywords(self, file, regexp): + # Attempt to zap the RCS keywords in a p4 controlled file matching the given regex (handle, outFileName) = tempfile.mkstemp(dir='.') try: with os.fdopen(handle, "w+") as outFile, open(file, "r") as inFile: - regexp = re.compile(pattern, re.VERBOSE) for line in inFile.readlines(): - line = regexp.sub(r'$\1$', line) - outFile.write(line) + outFile.write(regexp.sub(r'$\1$', line)) # Forcibly overwrite the original file os.unlink(file) shutil.move(outFileName, file) @@ -2088,25 +2081,22 @@ def applyCommit(self, id): # the patch to see if that's possible. if gitConfigBool("git-p4.attemptRCSCleanup"): file = None - pattern = None kwfiles = {} for file in editedFiles | filesToDelete: # did this file's delta contain RCS keywords? - pattern = p4_keywords_regexp_for_file(file) - - if pattern: + regexp = p4_keywords_regexp_for_file(file) + if regexp: # this file is a possibility...look for RCS keywords. - regexp = re.compile(pattern, re.VERBOSE) for line in read_pipe_lines(["git", "diff", "%s^..%s" % (id, id), file]): if regexp.search(line): if verbose: - print("got keyword match on %s in %s in %s" % (pattern, line, file)) - kwfiles[file] = pattern + print("got keyword match on %s in %s in %s" % (regex.pattern, line, file)) + kwfiles[file] = regexp break - for file in kwfiles: + for file, regexp in kwfiles.items(): if verbose: - print("zapping %s with %s" % (line,pattern)) + print("zapping %s with %s" % (line, regexp.pattern)) # File is being deleted, so not open in p4. Must # disable the read-only bit on windows. if self.isWindows and file not in editedFiles: @@ -3026,12 +3016,10 @@ def streamOneP4File(self, file, contents): # Note that we do not try to de-mangle keywords on utf16 files, # even though in theory somebody may want that. - pattern = p4_keywords_regexp_for_type(type_base, type_mods) - if pattern: - regexp = re.compile(pattern, re.VERBOSE) - text = ''.join(decode_text_stream(c) for c in contents) - text = regexp.sub(r'$\1$', text) - contents = [ encode_text_stream(text) ] + regexp = p4_keywords_regexp_for_type(type_base, type_mods) + if regexp: + contents = [encode_text_stream(regexp.sub( + r'$\1$', ''.join(decode_text_stream(c) for c in contents)))] if self.largeFileSystem: (git_mode, contents) = self.largeFileSystem.processContent(git_mode, relPath, contents) From patchwork Mon Dec 13 22:54:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Holdsworth X-Patchwork-Id: 12674791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 478EFC433EF for ; Mon, 13 Dec 2021 22:55:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244095AbhLMWz2 (ORCPT ); Mon, 13 Dec 2021 17:55:28 -0500 Received: from mail-bn7nam10on2085.outbound.protection.outlook.com ([40.107.92.85]:28160 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244049AbhLMWzX (ORCPT ); Mon, 13 Dec 2021 17:55:23 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h0/qMKNl62kyFYXvG3FrS5UzjEPzgwAzU1KmqxrcNyfxlGyh6OdexTM9bbZdNSbDP3F/JVKjQx+t2REA8Aad+KfiO/aJc8MLIYi7SKQ6K3DTmX9aPXS/Gziii8qCNPnTKH9cbdaFv96bET3NuK1yCr/bWpyWW/h0QuXc1vfVilHIy9XqemtHiLrhw1d2UCNVZzkx4ZpRiC+WWJ2e2t0HyL3japPtFSychvPwHEDB2idSYvS/ObJTzBP0P/7Hix1NVPIwTfUrFFB8qp9LnnToRqpsqdSq2KXze0AWMvhWzIM/h1PNC77nuBqgJfjWmm6HJtDy82W0K7a1cpIIOHaT/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UqZoIJbSMvjCqfj86vBEPU+rETWkpGUjUTrnc9+NIig=; b=SrAt2LoFDCf9Osg6jkBR+1Vr+8+j5zpsyc+tqQx1j7NTLIkkVzvjRUJd38JCtLGcOfSRsjT/fMykFg7G0Mw8N9nymLn9T6EWFZEhefd8MGxFsdTVffbZ0S3nDXGoIRlfRx+oG+FJ8tTePqKRyPx95mSA6gkLzuS1Yn5VCbEc/Et1MI3ZNcxRPkGIXLRGAzVg7Ic4TCGQNCGB0AIBmdHoOC6LvSucke7Iiu7HAkJIFj3KNxStytk9ENQpHE70WmaxMcc7XjS004JNLXw1ZkXa0dsuK26nDdljz3kgwkZM1VsCH+2FnY/aox5N45JdiIhXLQDPvT4Qh3rJ9HJP40SpLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UqZoIJbSMvjCqfj86vBEPU+rETWkpGUjUTrnc9+NIig=; b=KOgt1tJXQEfkfUOEO91qBEWdxafuXcC3bizgDwyMk0fCSMkf8OMfPm7/27MK8CoHUF4I2Jk5sUGBuDhl5mmT/WTDqFCKwXAxdBPWPlZA2Bc3IFWmdMrpJDfVIXHRELKXl7t+Eszzxq/rMMMEO71g5XQ5PkmYi9oSWRlK0w3BoqbBTJYWTp2V2eYGITEdVOpoOqKDjRJJ5uG39Gx+Zy95YoGjD3cxRwhDKpCVoLELcd6hskiIpaefa6Caiy7xmbRBHI1eXCVOwFhnGNppu8/2HNk2tDo9iz2mmaVCfYZMTqJjixNpwZOLKCbtao9+cHACD3PoVPav4PICpsY46LSdrw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) by BN6PR12MB1377.namprd12.prod.outlook.com (2603:10b6:404:1c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Mon, 13 Dec 2021 22:55:08 +0000 Received: from BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592]) by BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592%3]) with mapi id 15.20.4778.017; Mon, 13 Dec 2021 22:55:08 +0000 From: Joel Holdsworth To: git@vger.kernel.org Cc: Tzadik Vanderhoof , Dorgon Chang , Joachim Kuebart , Daniel Levin , Johannes Schindelin , Luke Diamand , Ben Keene , Andrew Oakley , Joel Holdsworth Subject: [PATCH 3/4] git-p4: add raw option to read_pipelines Date: Mon, 13 Dec 2021 22:54:40 +0000 Message-Id: <20211213225441.1865782-4-jholdsworth@nvidia.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213225441.1865782-1-jholdsworth@nvidia.com> References: <20211213225441.1865782-1-jholdsworth@nvidia.com> X-ClientProxiedBy: VI1PR08CA0263.eurprd08.prod.outlook.com (2603:10a6:803:dc::36) To BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cb6a1aee-9272-4037-0d00-08d9be8b9c4a X-MS-TrafficTypeDiagnostic: BN6PR12MB1377:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1468; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oAfZHu9IlWoysP2TgHWfWukUsDUO2f8cl4sfqioGngOYxD5huygq6DDtuZJ1vX5+0VXlGkilzkKK1UW9GATmX0UjlonX0bGJooVLZIrN5gpwzCeCbYNVHKB0Mqdegt0uuOfElSa1OIrgCnVVsH9scNrahXJVCmkfJT5bN79nK2PN6Js4rH2JZHPZtFj9eeVSB6YhafMJWxd+LxNDBh2ZCbiDX6v8NgjaHWbOqEd5h/Ps2202pfpE43FP4ZpyFCh4t0lhj2+hoddwcLCJ/YTAEMbo6nA9PxYjAYdX8Rc0fgqVyncjQ6kIzbCKCsuv007iIyr82edVRQ8IJ6FsS08vjuG7C5oLDEbK2CRGZ7pE8nlWa0CwOJk/+q5WzaCHi1L9qCy6FqqAoj+jbrzPYhj6f5ftIAwBwkm3Oz2XnUqsnEiqANwxhI3IAlHVmU+qzJbmL2iv2qBBJWmjwBvC5JSfx5vV1TyygL7fwvXNKxoCTuDiRPcSPtI5CwwpKXz6YseKOBCfIvW5+MT5W2IrwuwgfXtqPHBgESGSBzxiYyHCWY8pckN5oxJNcrdAaewwyw8+IsiBrZbmstk5+UUao5IYxBgflqHD9nIwyuHFyfSM1Wep+QU0wOymY3ldJOxG0eBl3Ug33yeGRQvrfyPU7DjDNJLywnO9JTrD0bz28r60/R5YTbKuXB0Y4LqX+bRiegGgp0dcll3v4jTxRRSjAVrJhQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3361.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(5660300002)(508600001)(6486002)(2906002)(54906003)(8676002)(8936002)(6666004)(66476007)(1076003)(6512007)(316002)(66556008)(38350700002)(66946007)(107886003)(36756003)(4326008)(38100700002)(86362001)(6916009)(52116002)(83380400001)(55236004)(6506007)(186003)(2616005)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8T8/o1GfLz+IEkUDxjVuFYZO5PW9Or7xxtOfv1AZfm560XRXf1Plcv2Lg5iUAHCERhftDFG/qUzu3FyiuYPunEQ/jAHBwB3I02dlsmIhKAtMj0KKzLB2jHo6vbHvDGBCn1xfdv75GDBYsfzcMP7CBu19Ux8XxvsT2cEgR6iMuOmMk5XbVvqNruf7u8hsa1a74H5WQOTtZmqsLwpeD5KJTHCTX8gMGMsWhShJ7tdnbj2S/+mqTmnDiPCDg3rm+tYyGOOj2NfWz6LVccTSHlG8A5ZIYb8zR5ExGxA6F/XSGQg8AMiIQzv+IAwmV1BCqE3QyLYMeVEAv1MrYsjS0IP0bKgjTUq8X/SZYIT2503p+jgA5k5SGnu0LyViXag6ob/PRnvmxtzwKcRn7pazSw1yfqhCiJ/ebFmNwU46ubSzkQ868gJj3oNZC4/tyOdsEYZVrrgsHYimhO18v7XGPtGi/junOtdtpuo39rczkHMKkotkhWV+jnzykfLyhMSiehZTazaUy8NQx7sCBCdjaQwaqI4bF+5tjDttcg2sbgmhDq1zCNZs5fqXaK/pDsHhHBnAI35tU0EDEZZK6PEZ3ktXAIizi4Jkw6/H9Xm74/suaTGLeNi/jOMPy3lVsc88l+OK/YUHMGDXamlKqCfFb/4AEeEZ9tr9y9mgp8hJ0egjff9oHhQLTTvlBejPSIbC5JE874Eyz2W2VME55AMobNWPr0/tDVBOFzYfm7sbu2e1QvwN2LrdjRZd9hhpaXLbN20YBmrXhnzylX9G01apphtrEpUv49EJrDRfU9YgUlilydsPwQBbPjnQ3pvTeGpd8n4xBkR1YFAq72B3O769g73yw0k/vEosaJS4x7E3DfrLwfHT3CrHnVnu7M4fvIzfpTuN82U4NqFBMqZKiEFn5+4ehYIlTdzuV5YOHUejy3zNNI07pBDD0J4C+vPwmUeE9eshQ+qbRn8LpT4lNLH/hlnEH2A2irIazVURtUU8yHl57MTQjAQRXe81pMNJypcKBSR+DzsNJLopqIKTXhzch+cX84lXwEo8e41Yg5O/6N3bXeAmpMdfUQLkqBqAP5yHMNbpMetHNLOtAai0MbS8zrIdEASoq8q940HHIIO6xvEPVpG5ijSLQ65hTt4z7dAizZ/yiYG7Q+JP1nn4HoRAsF3sIoFXhuSMbIq1EMLFDStE/7k/GKgS8zDK/5DHobYOsS1D8E7eqNKgi392ztEcKusUXllvJITuG+3L7L5lpzmts+Bcpn5HkNs59RpdE/7W6ayR48Ga+SgBhNQSjda+AJJzbNlUbInw1ttz8rHor1DceifMZxsaLJ8K/4ZezLrPIA9WIrCsTLmhdka3KaBYSyyrISA00oiibfq+/4xY1j9AvCczFN8oas5CYcSBPKd42uIeTgJBD3BqGt1HTrfbixucByD4jFLIUAsNdF+73HYrMvL+yk7SUnnHd6N3wgcpDMmUSO9gEtMkrt686wEmzz3rbqP0LSbf6NKM/VHv6bkf76+RR5NSTrBAkFtR0canU+FZVnOjvUst4hh1YoXB/iEoZ3wwdytHqKRgam8QZ5fEdSx6wPF16kTk/3UJeBQSSLkormn2u2f43BduxCEwrwSNiyaR1f++afZTYwxUqNHoucg= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb6a1aee-9272-4037-0d00-08d9be8b9c4a X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3361.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2021 22:55:08.4024 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f4cD6Kqib80XVhSzmS8+sZ2rThi1TPmpUP4Le+2/oWuYeyqrWXkrsodl8oLV2LDshidcXRTqt6YLWAdWTXi1gA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1377 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Previously the read_lines function always decoded the result lines. In order to improve support for non-decoded binary processing of data in git-p4.py, this patch adds a raw option to the function that allows decoding to be disabled. Signed-off-by: Joel Holdsworth --- git-p4.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/git-p4.py b/git-p4.py index 0af83b9c72..509feac2d8 100755 --- a/git-p4.py +++ b/git-p4.py @@ -340,17 +340,19 @@ def p4_read_pipe(c, ignore_error=False, raw=False): real_cmd = p4_build_cmd(c) return read_pipe(real_cmd, ignore_error, raw=raw) -def read_pipe_lines(c): +def read_pipe_lines(c, raw=False): if verbose: sys.stderr.write('Reading pipe: %s\n' % str(c)) expand = not isinstance(c, list) p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand) pipe = p.stdout - val = [decode_text_stream(line) for line in pipe.readlines()] + lines = pipe.readlines() + if not raw: + lines = [decode_text_stream(line) for line in lines] if pipe.close() or p.wait(): die('Command failed: %s' % str(c)) - return val + return lines def p4_read_pipe_lines(c): """Specifically invoke p4 on the command supplied. """ From patchwork Mon Dec 13 22:54:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Holdsworth X-Patchwork-Id: 12674793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0937C433F5 for ; Mon, 13 Dec 2021 22:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240221AbhLMWzu (ORCPT ); Mon, 13 Dec 2021 17:55:50 -0500 Received: from mail-bn7nam10on2085.outbound.protection.outlook.com ([40.107.92.85]:28160 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244070AbhLMWz0 (ORCPT ); Mon, 13 Dec 2021 17:55:26 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FH7lJdwstJ0gXc0qU99HhiPFipnMwD+X3mCOpwr4f0P+z8rJgweTXr0GgD9xaZnWdSv009pgMYZ7KMnqXmbQcyHEMVgsRfg+xwMqAg7edUEwH+YRwFE7rIHOgmKkL0dJJ1KedZlk5kQau8yr6F3uKwY+DN5Bwq/GA4AGZ+YaVLlkFFS/xK6Vv7Jul4LKQOluDhl5vyO7bnv3Oyzz2ztUHwZM6e88yeUXE2mLUZfyJ+cHm+ljYxT10vK9bq40fbeh6dbEw512Ol/5Zwv8irxmFl/ACp0Glj3Nv5f20YpWGe4e4YOSQnoQ/UC/TvSv2WyavNOxOMEieUQ4Is8j7fHNSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KKEfSDfUPs2D6VLClHxJvQLmVNyEUkTV5YaUp1aUSRQ=; b=SWeMq4Pl1zfUpduljxX98ffau0X9sulXUErpDRTotMCu5RD4ZH9O51oNjeWcGNaHYMqWqWNDeFaLjxEZYlUBdUA2DTPLUMdQXgIc22CFqSmjMj4QTPBp2OfXgsEwjBLWpQwSXt/w23m+Vno6q5cXgJYgRp5ksvdc+DbENGLT9OiPkCeAOkyt2RTdAHcavb5p3RjdSUqr2dLANAJAZxmBeL37jdHLo5JmJTAHm/C1WViq6a0XvljANwQO0Jvh3AfddWj183zbsFI2DpEm9XBzdPNuiklgx7GuZRGzjdzbIh+qHYfWfz5xUgC6BAIfHtnhQSFdYZwzDzZOvtgOBkx4dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KKEfSDfUPs2D6VLClHxJvQLmVNyEUkTV5YaUp1aUSRQ=; b=T1WBiTnOZzZ0sBIWP8eWIX4UhlZRrenJMdHfu8sdNX1jSVWgI/z/RSl3r1AZ9wT/l/sXvLhR+2auMvhwtNUDTn2RwUEw8GSqY4vye9wcd5JOJejNRwGbHO62H/tzk2dMH70yH+amugon7rRNVh8O3TF6c24srlr9pwNXyq4hT57S0Y539PW8xxj8yz5pKwcgk4vJZUmxKlXLgVC9UD9zZF3/MMk7I/GXMU8OwynrHZQeTaTuBPMRTFvXkP9RF980vrJHY5shWemUGbd601bY4wvhYMRw43DwbtbxczIL+OR8UntN/Oe2TqtVQMTEbk+koZ6Efzsi3vt++EPhwB3ZQw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) by BN6PR12MB1377.namprd12.prod.outlook.com (2603:10b6:404:1c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Mon, 13 Dec 2021 22:55:10 +0000 Received: from BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592]) by BN8PR12MB3361.namprd12.prod.outlook.com ([fe80::4063:6e26:a906:e592%3]) with mapi id 15.20.4778.017; Mon, 13 Dec 2021 22:55:10 +0000 From: Joel Holdsworth To: git@vger.kernel.org Cc: Tzadik Vanderhoof , Dorgon Chang , Joachim Kuebart , Daniel Levin , Johannes Schindelin , Luke Diamand , Ben Keene , Andrew Oakley , Joel Holdsworth Subject: [PATCH 4/4] git-p4: resolve RCS keywords in binary Date: Mon, 13 Dec 2021 22:54:41 +0000 Message-Id: <20211213225441.1865782-5-jholdsworth@nvidia.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213225441.1865782-1-jholdsworth@nvidia.com> References: <20211213225441.1865782-1-jholdsworth@nvidia.com> X-ClientProxiedBy: VI1PR08CA0263.eurprd08.prod.outlook.com (2603:10a6:803:dc::36) To BN8PR12MB3361.namprd12.prod.outlook.com (2603:10b6:408:67::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c210c99-9c46-45a0-e3cc-08d9be8b9da7 X-MS-TrafficTypeDiagnostic: BN6PR12MB1377:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ndPhegtxolLR/VU2KTOcGcon3wDeARmKYZP5ggdkPSrpJud+0W9swAomjKQrfbWYbopc83qqeXvBbbAtop/OaT/LwES9ZouInKM85mjoW1nv1DdsfE0j9RXS06o2/A4V8lu/pP81/LsNGi43/C8vnumobLc/ddC2vSZT0rOvSv6g5peY+tlxY+U/85XI9kWmpATsnLogi7lSp9Dctw53k/r+dP4VCT6e/2p52Vg/uWkXbP/Tkl9YlAItguvUFp4LQt+3f8fn3vUhDw+OgES96BcWIEvmn9L2Fe6qg5gAWqAh/egNAkGWLE+JNjrlFoncx6lrrEfAn2kCw0mgod1Dl0vn+EUSlyDam2z/5R9+NOHJTEHWGrfBUgnJGHWoRSHB6lrzIJMmM4dUCjGdz5mRJ1R248sifgQVqSTuglCs3APGBGQu+2nauNlWGBzt7TVz9gfkmxz0w5gQlsRrv9531IV9pDyq1bh/QwACkLX2IQ3k7CeTIm20VLz/DqoYnWiSYJgLTBYVtwoOWehf1+IuyBWNrfA2LVD8vxtWWUXnUwtiJ8gEoUdNImKmY9CI5NRIEcDi2SB4wxBcNGp5i4YOX9at8mmlKVyvERMOS9Xtshe6RLQ6SqQnPNiXYPQ8QOT8PcLYXHNEAsuYG2EYMFhpJlqyWV4WZrfCeIYik3RIPuLyd0nDdDiefkaBdecr7Xa8TMkji7PiAyIR+/AoovnU+Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3361.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(5660300002)(508600001)(6486002)(2906002)(54906003)(8676002)(8936002)(6666004)(66476007)(1076003)(6512007)(316002)(66556008)(38350700002)(66946007)(107886003)(36756003)(4326008)(38100700002)(86362001)(6916009)(52116002)(83380400001)(55236004)(6506007)(186003)(2616005)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IGwmzYvJLiWKvm44xdwRpfGxV+vfbZloU73KQ6pLM+sG9PaDth9sg6EXprYt1DPwWbJ1qWUqY5VYNEzLvuYEJE8svkCC9tIZGI4RJGZRII1H7IKED9iSWarNJADsm2tE0iCYKBq7qWuDFJM/qUPW8yb34KHsmMZc6jbTa5Lgvlfoe+nmu28LLdLQS4v7nC0U+oSs1/zA7t4DRHMEzqmGtPzgoxVtRUXZ56H0iuwUTrIXyA2z1brDnROR/3JjrI/Eu82XsbzzEBH1R0sfKzS07d4udwM9IhbmOz90F369g82AeuA5Kq3yCiBsd/CnCo/ArvHPQBJv+q/behkJ93akiEmgRZqrZm80MHY0+Gq51ylRB4qRr1A148vPLoP38tHkQ+oiENbQWAND/tqaVi/u5jrgcUpmJz1UCSXhAQtjjTz0ZnhA2jUBdeanqQ2i9gjnB1zSSEu9ib6eHhY0TWJuMFJ48dbXaC8/6CUyzZNiIFRwPZKlJ+pW39/vpj+UfT5Ii0xCi58DwJJhjrhRzZSIfnRNaa06NuHD4tQZAVh3cYC/dR8qWlTxT8jWo+039FoGIbrC1Yy/Vm7M/MDn0Kax1FXtMP7Lkk3MeL0ojfdCl0nGzx6q/IKONfW4gDL0CFiAb9zDshVPXMSI/WIOKlwjHIMQ0Apo+cPjGa/0xqfy6syq0N/X+TPMzdGH2cnHCk55rBBOSrFlAhseaqjEEILptg2SWL+uW2yhXWNXjGXkJzQVGytCX8chPR/3WrQP2tiZK9QEghA/bib9O1UM1AuX3x0i4WJ4BsT45WYY5SvC1mpWfS9jLF51Cy5EzdMGckHx2rFDgBBT2YMs243cv3b5vH8+D5Y3aGNTr3T4TYZ+xezVKZcUqT2OHqfithbfKiKuYZ+8x+3I77AB1Dc4oCF/pI0wR/Ph2yeNAniXWaLz/RRj9ua4JrQCFC5EGW1DvdTE7Vg+s56U8CoWg21+nkZJfjNM/2wn0pKfGqQjhOZwu7VYRPIKjCohJj+ra/+kAAuN8QMBSKT5XeF+rm4MXbcsTbV/Bv8SjisDuXBQMKIYBBQTZxCS01X7SprXnMG4Vox4CISlaubhvS4AUvXf7VbVzMs3ubtgY1lP5Z8P2kNb3uB4qtI2zMdG2hQtfL+4tw/bsIiNffABUhbXJuHO5yeTQ2nlusXV0Lxn8qWUNVWHIJf1S8OOIXOBydcGa8UXtaBRHx3k93MjX1puSo1FpFPA1EnFJuhZyx/q9SFcv4um6PtjynzPhw0aLQHw7dEvqQCZDdLyQ/qjiuGvI+w55AZcfI1jVIF9JusigmEEhcREjNvWIhqadKfqTzJ89ekWLmLLYUmk5qsFkLnVt80+t6z/eNwP6Yg7w81MqAM3+usj4B5MnLj5GUDfMoN/M9y2QP+hjUrP7JXwB3CUC6Qf77+nM2uE3hhs/HO8MUbBPhRplsUHTZP4Igsj8YFeJzOQbiLwbjxYwx7uA3gUu0yioQxPiIOfHHNNG10lRz8GTGwkCTJRj7H6sfBTpXjwjJ7Ymjcn6I4eIcERuUBmleVlXs0oQEc1st7mRcMQJ5c59fyw65MhdjAWNWNMJl0n4zQOJYZ87zPvrpx5mw5tH5/DIsU1LAEZgA+GYOEIBwMQG7zmOpI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c210c99-9c46-45a0-e3cc-08d9be8b9da7 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3361.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2021 22:55:10.6591 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UpvqkIHJPnNzCopEosOheEhvr3/3PGlsWaKoMHQ7e48QgjyEGx9PCTpVbGvUzj8f7ubpL8UZW9oXSCSS/xZQRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1377 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org RCS keywords are strings that will are replaced with information from Perforce. Examples include $Date$, $Author$, $File$, $Change$ etc. Perforce resolves these by expanding them with their expanded values when files are synced, but Git's data model requires these expanded values to be converted back into their unexpanded form. Previously, git-p4.py would implement this behaviour through the use of regular expressions. However, the regular expression substitution was applied using decoded strings i.e. the content of incoming commit diffs was first decoded from bytes into UTF-8, processed with regular expressions, then converted back to bytes. Not only is this behaviour inefficient, but it is also a cause of a common issue caused by text files containing invalid UTF-8 data. For files created in Windows, CP1252 Smart Quote Characters (0x93 and 0x94) are seen fairly frequently. These codes are invalid in UTF-8, so if the script encountered any file containing them, on Python 2 the symbols will be corrupted, and on Python 3 the script will fail with an exception. This patch replaces this decoding/encoding with bytes object regular expressions, so that the substitution is performed directly upon the source data with not conversions. A test for smart quote handling has been added to the t9810-git-p4-rcs.sh test suite. Signed-off-by: Joel Holdsworth --- git-p4.py | 15 ++++++++------- t/t9810-git-p4-rcs.sh | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/git-p4.py b/git-p4.py index 509feac2d8..986595bef0 100755 --- a/git-p4.py +++ b/git-p4.py @@ -56,8 +56,8 @@ p4_access_checked = False -re_ko_keywords = re.compile(r'\$(Id|Header)(:[^$\n]+)?\$') -re_k_keywords = re.compile(r'\$(Id|Header|Author|Date|DateTime|Change|File|Revision)(:[^$\n]+)?\$') +re_ko_keywords = re.compile(br'\$(Id|Header)(:[^$\n]+)?\$') +re_k_keywords = re.compile(br'\$(Id|Header|Author|Date|DateTime|Change|File|Revision)(:[^$\n]+)?\$') def p4_build_cmd(cmd): """Build a suitable p4 command line. @@ -1754,9 +1754,9 @@ def patchRCSKeywords(self, file, regexp): # Attempt to zap the RCS keywords in a p4 controlled file matching the given regex (handle, outFileName) = tempfile.mkstemp(dir='.') try: - with os.fdopen(handle, "w+") as outFile, open(file, "r") as inFile: + with os.fdopen(handle, "wb") as outFile, open(file, "rb") as inFile: for line in inFile.readlines(): - outFile.write(regexp.sub(r'$\1$', line)) + outFile.write(regexp.sub(br'$\1$', line)) # Forcibly overwrite the original file os.unlink(file) shutil.move(outFileName, file) @@ -2089,7 +2089,9 @@ def applyCommit(self, id): regexp = p4_keywords_regexp_for_file(file) if regexp: # this file is a possibility...look for RCS keywords. - for line in read_pipe_lines(["git", "diff", "%s^..%s" % (id, id), file]): + for line in read_pipe_lines( + ["git", "diff", "%s^..%s" % (id, id), file], + raw=True): if regexp.search(line): if verbose: print("got keyword match on %s in %s in %s" % (regex.pattern, line, file)) @@ -3020,8 +3022,7 @@ def streamOneP4File(self, file, contents): # even though in theory somebody may want that. regexp = p4_keywords_regexp_for_type(type_base, type_mods) if regexp: - contents = [encode_text_stream(regexp.sub( - r'$\1$', ''.join(decode_text_stream(c) for c in contents)))] + contents = [regexp.sub(br'$\1$', c) for c in contents] if self.largeFileSystem: (git_mode, contents) = self.largeFileSystem.processContent(git_mode, relPath, contents) diff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh index e3836888ec..5fe83315ec 100755 --- a/t/t9810-git-p4-rcs.sh +++ b/t/t9810-git-p4-rcs.sh @@ -4,6 +4,8 @@ test_description='git p4 rcs keywords' . ./lib-git-p4.sh +CP1252="\223\224" + test_expect_success 'start p4d' ' start_p4d ' @@ -32,6 +34,9 @@ test_expect_success 'init depot' ' p4 submit -d "filek" && p4 add -t text+ko fileko && p4 submit -d "fileko" && + printf "$CP1252" >fileko_cp1252 && + p4 add -t text+ko fileko_cp1252 && + p4 submit -d "fileko_cp1252" && p4 add -t text file_text && p4 submit -d "file_text" ) @@ -359,4 +364,14 @@ test_expect_failure 'Add keywords in git which do not match the default p4 value ) ' +test_expect_success 'check cp1252 smart quote are preserved through RCS keyword processing' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + printf "$CP1252" >expect && + test_cmp_bin expect fileko_cp1252 + ) +' + test_done