From patchwork Fri Oct 7 14:38:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Sonbolian X-Patchwork-Id: 13001174 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 31207C433FE for ; Fri, 7 Oct 2022 14:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbiJGOiO (ORCPT ); Fri, 7 Oct 2022 10:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbiJGOiM (ORCPT ); Fri, 7 Oct 2022 10:38:12 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB57FBCF2 for ; Fri, 7 Oct 2022 07:38:11 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b7so7589949wrq.9 for ; Fri, 07 Oct 2022 07:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=HEXXiNQRXzyufaE/CBl8ayERAzueYPkY9LqKzWZB1H8=; b=OWZD6IaNbldzdAjuDpppGUz59DL+8mgU1emDy8fKH611sykg59OcIr2+CbJADfynuN gsVFC+i39JSKovuUe9blBR6ujaZDCoRIFwX8pmqhZ1egCpMTO/stHRn1rFtY5vxroxL5 mdQ/qaiVfdZB6VCpaexokqo3ov6Il0SMNb480mCbDwv5D+I4+qLUjmD99AyAMUgJ5L0s NuKzH1dqp0HohshiKEA1g5zKjP9ldIf8qaXn7G9U+zyP2ze6ziGlIGgKLxP/qAihKXZC +2p77qTvTF5eJ3PJvmGMcrOfZGvvl+e2iQawZLQ4C+XQhGNOva+2wmLR9nfilDkwSLMK iEgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HEXXiNQRXzyufaE/CBl8ayERAzueYPkY9LqKzWZB1H8=; b=sKPrDc6W8BBu78NVZkSdEmwF5JzULQV1kA5bLYz4pMZAEolbCiIuywcSS5PZSQw1U6 d4WLd0IC6GwZQcqSekRlYDjIw6CLY70uXT9HO4PJ6zFOMMCGB7sudx6BlXVXKcMXmWeo Ovn8rOs7t4VooSG6TAJzhFitO8hiiV4w2QyI1Vm9plS5vNWNgeFh8b2zzDfFpZKxaj5E 1Uo8Hs+X4pItUkqYwPlBTF51fxgHiaaJ761FWZtyCCwPanBPTXFZKjjMmX/RyHPsii4z qSDABnZWyfS9XxPjo0ZTWaVkybUVaRMLC7Xtw7g8tKD7aUhHJodAruw3GUzm3HxFHGZ/ kHrA== X-Gm-Message-State: ACrzQf0dOWnZBSx2Eh5hhMREGlAcUsI4Jdt03Ta4/q4YSmRfxFiQqaC9 IGChlpAr+a3EAP/ZCZlF5DitROrnTfo= X-Google-Smtp-Source: AMsMyM5xEXi9xTSB3ffXxvDtPeje5wf1PSH7yKge1cvhl6+qHigpTBS9KPiYtO0gbfecuqXpo9VGJw== X-Received: by 2002:a5d:4106:0:b0:22d:494:ca05 with SMTP id l6-20020a5d4106000000b0022d0494ca05mr3456194wrp.714.1665153489480; Fri, 07 Oct 2022 07:38:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id iv14-20020a05600c548e00b003b4c40378casm8860003wmb.39.2022.10.07.07.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 07:38:08 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 07 Oct 2022 14:38:05 +0000 Subject: [PATCH v2 1/2] git-p4: minor optimization in read_pip_lines Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Daniel Sonbolian , Daniel Sonbolian Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Daniel Sonbolian From: Daniel Sonbolian checking for an error condition before reading and/or decoding lines from the pip stream to avoid unnecessary computation Signed-off-by: Daniel Sonbolian --- git-p4.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/git-p4.py b/git-p4.py index d26a980e5ac..097272a5543 100755 --- a/git-p4.py +++ b/git-p4.py @@ -399,11 +399,15 @@ def read_pipe_lines(c, raw=False, *k, **kw): p = subprocess.Popen(c, stdout=subprocess.PIPE, *k, **kw) pipe = p.stdout + + if p.wait(): + die('Command failed: {}'.format(' '.join(c))) + lines = pipe.readlines() + pipe.close() + if not raw: - lines = [decode_text_stream(line) for line in lines] - if pipe.close() or p.wait(): - die('Command failed: {}'.format(' '.join(c))) + return [decode_text_stream(line) for line in lines] return lines From patchwork Fri Oct 7 14:38:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Sonbolian X-Patchwork-Id: 13001175 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 E076DC433FE for ; Fri, 7 Oct 2022 14:38:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbiJGOiX (ORCPT ); Fri, 7 Oct 2022 10:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbiJGOiO (ORCPT ); Fri, 7 Oct 2022 10:38:14 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7629CFBCF2 for ; Fri, 7 Oct 2022 07:38:12 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id b7so7590043wrq.9 for ; Fri, 07 Oct 2022 07:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=48/iS7LeqJsjy4OT+ueXQXou+jViItrDvxmBZ6Vw0sQ=; b=Fas+nPvg8XxhE/EqbDLV4nflOhQx1Qo1pIm0fIQKCEsm9w4sHqK/O6/UYwKFbAQvvt T7GeQEQOzj3bRiFW1Hhb8cFHbKvnoyM/oJ47iLIKYiZLkipB7QVFx94jwTXQ0/dAcLnb X84GK53KgGnO5bv1TY3Lek4rwFwRd3C3aihoNh2mpj0/1p1gvBBtNnLiAB/rD5DXWud0 rwL6oUQ3FPBC9lgXa8Pp3Hg38CiFVP1daK9IDAMQwRIMg75d++M8vDSyl4hgvbFRLp4Y TwkPv8nSSc5uTKdtm2m1qjF/aq3ZCsbs9ElzqjkC005CcnXYtFD4tkkSI/p9vR3poAcj yhJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=48/iS7LeqJsjy4OT+ueXQXou+jViItrDvxmBZ6Vw0sQ=; b=thqzmn/prRGJRrPgNVUUK2ImIjfUSGbxX+UzPexcVyDAhu/28vIZ2ArX3Lypls0nha zwPStd+IskolFObQSCPHEVZGm3nsYs2CiwyqE1s+BTt+3iKvPBskdR64zTJEk6gZVgiL WHmiHqtTp6Fg5SIqxty8kaUif3ve9jboX8hi5pObYKFEryrYUYPCpNi/+m+J4jeIg52Q bjK1qtFGSSvwcIetQ+YTmTc0xBT+EAhOv+9Vx2Adegnre7nxcxkAmMNjTL1qCXdb8HQb 4XF1MZWwh3zRR0UpjXKCD8DzB9Jcpz0HjeOnYT7utubE/8wHXOxmb1bnHDFsWRQmmXmA k8mg== X-Gm-Message-State: ACrzQf2ABpfs/zTipwNjEzY0oiWLiq4462WLfmD/heHJFQIE0LU3ZMbM D+X+WYHNGxRHP5MIRoI9U004rPHAkco= X-Google-Smtp-Source: AMsMyM6WRT/aBtFN2BCys+3lnNnZ2NGWLLmP2MuY183mYBlLcEtv4ENfoHdFFZB2yAi3zDMFP8fyDg== X-Received: by 2002:a05:6000:5ca:b0:22e:5477:1296 with SMTP id bh10-20020a05600005ca00b0022e54771296mr3552027wrb.377.1665153490601; Fri, 07 Oct 2022 07:38:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z2-20020a5d44c2000000b0022e55f40bc7sm2211203wrr.82.2022.10.07.07.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 07:38:10 -0700 (PDT) Message-Id: <7fe59688018d195f27456af029d5b4fd8e40206b.1665153486.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 07 Oct 2022 14:38:06 +0000 Subject: [PATCH v2 2/2] git.c: improve code readability in cmd_main Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Daniel Sonbolian , Daniel Sonbolian Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Daniel Sonbolian From: Daniel Sonbolian checking for an error condition whose body unconditionally exists first, and then the special casing of "version" and "help" as part of the preparation for the "normal codepath", making the code simpler to read Signed-off-by: Daniel Sonbolian --- git.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index da411c53822..340ec8bcb31 100644 --- a/git.c +++ b/git.c @@ -894,12 +894,8 @@ int cmd_main(int argc, const char **argv) argv++; argc--; handle_options(&argv, &argc, NULL); - if (argc > 0) { - if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0])) - argv[0] = "version"; - else if (!strcmp("--help", argv[0]) || !strcmp("-h", argv[0])) - argv[0] = "help"; - } else { + + if (argc <= 0) { /* The user didn't specify a command; give them help */ commit_pager_choice(); printf(_("usage: %s\n\n"), git_usage_string); @@ -907,6 +903,12 @@ int cmd_main(int argc, const char **argv) printf("\n%s\n", _(git_more_info_string)); exit(1); } + + if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0])) + argv[0] = "version"; + else if (!strcmp("--help", argv[0]) || !strcmp("-h", argv[0])) + argv[0] = "help"; + cmd = argv[0]; /*