From patchwork Wed Dec 29 06:23:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 12700758 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 77C07C433FE for ; Wed, 29 Dec 2021 06:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238938AbhL2GXr (ORCPT ); Wed, 29 Dec 2021 01:23:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238933AbhL2GXp (ORCPT ); Wed, 29 Dec 2021 01:23:45 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD874C061574 for ; Tue, 28 Dec 2021 22:23:44 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id t26so42447204wrb.4 for ; Tue, 28 Dec 2021 22:23:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=pDX3Gi8DkdnhZmn25zn+bLE7BwP9kqRagaRhQytA2uk=; b=Fl1KPPrpwyshddfVAjRHoPNGlCtiY4H/6HZf0097B0eAJwhByCCk7HIHtM+Gh6f5UL g2fVXVGPSup4404tXpjNIHHtKN5wgxatRB8n27obp3CZfuL8roc4bIKHSgXeXc1RpKEU Jzg4xSj3phKCuy92vpZd0vvhuMMmwHc5vx4WGcRs0s/Tod6PWbEqUAE2f9qwFfMKVbxE +viyEMx83oSHD64p2y+qEoev6lKwi5rEC4kTDXlkXrCuKUKzFYGm/xgnDOOMwRsN4czq 9UuKPkoqT3nV85ZEz3l+pfmjdoiag38e8OY8g6yLDBa2Is9G0/IcbQOzDim9NQ5yBLJk vVmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=pDX3Gi8DkdnhZmn25zn+bLE7BwP9kqRagaRhQytA2uk=; b=d8FQxCE3N+RxuJu7JwqHimSdkVIgvi8adkwE6rGeLhoAJjKVMgMM/p8SnVnSFdLPfl oBT/oJ07hulWHd58Kq/+vJD9X727yBfU/CsCCRHk2oApbhOvmHgk/aNnddmScWcxLVPI JsjgFYmsyZjiiGsp8Qcwi6lDupapFf5VI+LrdtqzpXACXxXCzze1BfDjI+dr0bxAOGeb l8d5MOc/WCli67r6kr+fx8yCSw+UmpVpdvtIXM/7/MZKv42q70ctJDrQw1YyZiHlRIzv isZBPjfQvR338Z5buDC9LPSeY4/wj5X9xB5R2L9xQKR+6kvSm1oFu6+mXIkd0v8CTOLL +r3A== X-Gm-Message-State: AOAM530fUh2U43++UUmglrA4PAx0i0fs/MuifEzwIl8BjEdYWdB4QwoC OdjItU8ssOcu10CR+a1iDQJ2x2shA14= X-Google-Smtp-Source: ABdhPJw8C0Uy2CKqX9Hk+YgcFy5AT6UUnMovJbDw4M3Dfc8k2mrSuXtycEFMS7sHlYu+GYRWtIb21w== X-Received: by 2002:adf:a111:: with SMTP id o17mr18708084wro.526.1640759023219; Tue, 28 Dec 2021 22:23:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n4sm20365321wrc.1.2021.12.28.22.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Dec 2021 22:23:42 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 29 Dec 2021 06:23:40 +0000 Subject: [PATCH v2 1/2] name-rev: deprecate --stdin in favor of --annotate-text Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: John Cai , John Cai Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: John Cai From: John Cai Introduce a --annotate-text that is functionally equivalent of --stdin. --stdin does not behave as --stdin in other subcommands, such as pack-objects whereby it takes one argument per line. Since --stdin can be a confusing and misleading name, rename it to --annotate-text. This change adds a warning to --stdin warning that it will be removed in the future. Signed-off-by: "John Cai" --- Documentation/git-name-rev.txt | 29 ++++++++++++++++++++++++++++- builtin/name-rev.c | 19 ++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt index 5cb0eb0855f..ee11b2ca9e7 100644 --- a/Documentation/git-name-rev.txt +++ b/Documentation/git-name-rev.txt @@ -43,10 +43,37 @@ OPTIONS List all commits reachable from all refs --stdin:: + This option is deprecated in favor of 'git name-rev --annotate-stdin'. + They are functionally equivalent. + +--annotate-stdin:: Transform stdin by substituting all the 40-character SHA-1 hexes (say $hex) with "$hex ($rev_name)". When used with --name-only, substitute with "$rev_name", omitting $hex - altogether. Intended for the scripter's use. + altogether. + + For example: ++ +---------- +$ cat sample.txt + +An abbreviated revision 2ae0a9cb82 will not be substituted. +The full name after substitution is 2ae0a9cb8298185a94e5998086f380a355dd8907, +while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad + +$ git name-rev --annotate-stdin 1) { + + if (transform_stdin) { + warning("--stdin is deprecated. Please use --annotate-stdin instead, " + "which is functionally equivalent.\n" + "This option will be removed in a future release."); + annotate_stdin = 1; + } + + if (all + annotate_stdin + !!argc > 1) { error("Specify either a list, or --all, not both!"); usage_with_options(name_rev_usage, opts); } - if (all || transform_stdin) + if (all || annotate_stdin) cutoff = 0; for (; argc; argc--, argv++) { @@ -613,8 +622,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) for_each_ref(name_ref, &data); name_tips(); - if (transform_stdin) { - char buffer[2048]; + if (annotate_stdin) { + struct strbuf sb = STRBUF_INIT; while (!feof(stdin)) { char *p = fgets(buffer, sizeof(buffer), stdin); From patchwork Wed Dec 29 06:23:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 12700759 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 D65F6C433F5 for ; Wed, 29 Dec 2021 06:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238947AbhL2GXu (ORCPT ); Wed, 29 Dec 2021 01:23:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238937AbhL2GXq (ORCPT ); Wed, 29 Dec 2021 01:23:46 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E7A8C061574 for ; Tue, 28 Dec 2021 22:23:45 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id d9so42563787wrb.0 for ; Tue, 28 Dec 2021 22:23:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=3xEi0GzwO3pJ210HIyppg03Rk7RBaWeMVlmPpH+mMEc=; b=KkPm4lNa7mYq3P1UojczTpgN9s+B4VqpPXL35wKOIumGQVcO7GYXuNzQbEVkkvoJOV BUIQT4mH6u3PE4jio1EiEDirssWc992u7jnmcMS/bbXGwuM3H9+FW1LNdKzatyDI0tnf GubRgHGlqof8kdYamL82InhzIxsw58eLmbWl1s8KwAX51wrQrkv9LpLtXJfZlq9oABOa RzhaW56BsXsqDrodxZb7IqQcbBn1zTSvLvTWg4lx0txYZHjmKfJCaVLJHfQFqRg2+gkL LKR8PoPzcNrhDppW+2rCAPijvRll43wnLRYCPrHNwPdp7JXpMaCG2TRIuSBzybpKYRW4 3YeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=3xEi0GzwO3pJ210HIyppg03Rk7RBaWeMVlmPpH+mMEc=; b=yqmr5P3/bgO3QPNxpgQefiGNolkfedzhXx4QSho45KD+qRDPbfQeXjNLdeJ51oLiLt EJf/KSS8nxy74XcxHM/PNAOzDGHsp1D5KBB1bdqMoZl1nS/M6qNZdym9oA8QwmIwgLsx lUX5p4K2q/evh5qjLZjuNE9XhINgtyIm/Z7Q3nDCNZJ9T50518w2yEUzlxTcXKLj4lTM nssFoh64/B0/rY1917WCjvdgVOBlm1PMaaIwo1sP9Wl6qFku+IyM4E7JO1x1F0fWcnW2 QcjB4Ezhz9hTjP2M6m2yIGtlakerU6nay+0nfeZIVZ6qY0ejtLHH1mziED60M6keyXMx pGHQ== X-Gm-Message-State: AOAM530Vgn/N7c9kVL1yk+zvzHxCL6+flHCjGZ9WApkS7m6TFBqLkgFc gn0bxA77r1YSubTsEFZ7MJ+/KNqeEBM= X-Google-Smtp-Source: ABdhPJyobTMi43IYP56OIIblsO0Xm8PJEVkjKYLXDkF++V6DUDpy0/TiJiLJizSt63dM0lZQVoXabg== X-Received: by 2002:adf:f24e:: with SMTP id b14mr19089877wrp.612.1640759024006; Tue, 28 Dec 2021 22:23:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a22sm20331954wme.19.2021.12.28.22.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Dec 2021 22:23:43 -0800 (PST) Message-Id: <4636e27f53e0e6ac2c11b227d4dac32d975c82f4.1640759021.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 29 Dec 2021 06:23:41 +0000 Subject: [PATCH v2 2/2] name-rev.c: use strbuf_getline instead of limited size buffer Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: John Cai , John Cai Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: John Cai From: John Cai Using a buffer limited to 2048 is unnecessarily limiting. Switch to using a string buffer to read in stdin for annotation. Signed-off-by: "John Cai" --- builtin/name-rev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 21370afdaf9..85993bc2b38 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -625,12 +625,10 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) if (annotate_stdin) { struct strbuf sb = STRBUF_INIT; - while (!feof(stdin)) { - char *p = fgets(buffer, sizeof(buffer), stdin); - if (!p) - break; - name_rev_line(p, &data); + while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) { + name_rev_line(sb.buf, &data); } + strbuf_release(&sb); } else if (all) { int i, max;