From patchwork Fri Nov 5 21:56:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 12606081 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E30CFC433F5 for ; Fri, 5 Nov 2021 21:56:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD1AB611EE for ; Fri, 5 Nov 2021 21:56:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233935AbhKEV7Z (ORCPT ); Fri, 5 Nov 2021 17:59:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233931AbhKEV7Y (ORCPT ); Fri, 5 Nov 2021 17:59:24 -0400 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 189AEC061714 for ; Fri, 5 Nov 2021 14:56:44 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id r8so15828904wra.7 for ; Fri, 05 Nov 2021 14:56:44 -0700 (PDT) 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=ue8zd+YmaRB3vmi67R97EfU4ma9kx4Wcq6E/c+/N0pU=; b=OA/uPWz5mlPQ/nopqiGQhJxpnqgkRWgu6ArqxofMZaCKoWCDUpcy5y7OBlLjOd89iZ N7N0NIUNP+zvVltkufSo3EG+g2B7VDW043XlNFTeoz0danAQq/RQILX8bFm6B8/HtwYQ FHmM606w2qll7Mdtjr0XH9LUdl8+gZUVtSjalmLnsPor3D1CAjyWN9ww/PaBU6IKxRBE PKz4XvP6M5rRMDCUmiXCVprYZQXEj1YGoEXJ2IXO3A1rkQZ567z1o57p2lny4n1MiOv9 XlJEWjsXcfXPKnIE4jrB1kOf1FfoR/TjLVX+qQCnCpaGh2yDAf4Aia3F4owPOaB3pYMj z7JQ== 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=ue8zd+YmaRB3vmi67R97EfU4ma9kx4Wcq6E/c+/N0pU=; b=PneaXKG3LVthcHhIvHsK9HTHtuPPLyuRfx02lw9dzlQ0cH7ieAKsCKjv2X+uUBAu+Z SZWcUiXS0CiMR6xw6j7uhS68lXdOeddj2jW2b8LLlMBi3DWjpTkdUc5+gHwfx70fbG3n rwcFLkDMSC9PTc798jgRUdVOwCHDOED7NzCAWzsahBCvq2DZ0nugl0SrueUQBl/vqeMC +PEqrlyETkuK07rVJ1F3m0L+DesYL4owopBmHPZGkHqSDy90noZ03aeAz0CY/rw8xQNR MH08jFXGBiRZJWB9scUwTqJDI7gnRmq41c3m7LMz5eH7AHn8sdDqJNU26n3JILjuix8H koFg== X-Gm-Message-State: AOAM531sF7RR4aR7YWuvtLnG0kMGPLUY0PX9csha0NpJdJ1auviMmjyh J2TGF+DoetiRLcxJomjIoQfA7yhKhh8= X-Google-Smtp-Source: ABdhPJwmAOufj4OS5G8x1LOE9WdBeZyGbqSe8DGWYPhw1O0/IBAVvMiRHufL3Kgst1Rm1sZbMSKJxw== X-Received: by 2002:adf:c40f:: with SMTP id v15mr68188309wrf.302.1636149402593; Fri, 05 Nov 2021 14:56:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g4sm8842894wro.12.2021.11.05.14.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 14:56:42 -0700 (PDT) Message-Id: <2d687baeed82e7b90d383bad8e209f50e0ce8c87.1636149400.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 05 Nov 2021 21:56:39 +0000 Subject: [PATCH 1/2] cat-file: force flush of stdout on empty string 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 When in --buffer mode, it is very useful for the caller to have control over when the buffer is flushed. Currently there is no convenient way to signal for the buffer to be flushed. One workaround is to provide any nonexisting commit to git-cat-file's stdin, in which case the buffer will be flushed and a "$FOO missing" message will be displayed. However, this is not an ideal workaround. Instead, this commit teaches git-cat-file to look for an empty string in stdin, which will trigger a flush of stdout. Signed-off-by: John Cai Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 86fc03242b8..4d17f30f24e 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -405,6 +405,11 @@ static void batch_one_object(const char *obj_name, int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0; enum get_oid_result result; + if (opt->buffer_output && obj_name[0] == '\0') { + fflush(stdout); + return; + } + result = get_oid_with_context(the_repository, obj_name, flags, &data->oid, &ctx); if (result != FOUND) { @@ -609,7 +614,11 @@ static int batch_objects(struct batch_options *opt) data.rest = p; } - batch_one_object(input.buf, &output, opt, &data); + /* + * When in buffer mode and input.buf is an empty string, + * flush to stdout. + */ + batch_one_object(input.buf, &output, opt, &data); } strbuf_release(&input); From patchwork Fri Nov 5 21:56: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: 12606083 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A428EC433EF for ; Fri, 5 Nov 2021 21:56:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ED3D6120A for ; Fri, 5 Nov 2021 21:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233937AbhKEV70 (ORCPT ); Fri, 5 Nov 2021 17:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233934AbhKEV7Z (ORCPT ); Fri, 5 Nov 2021 17:59:25 -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 C0610C061570 for ; Fri, 5 Nov 2021 14:56:44 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id d5so15897248wrc.1 for ; Fri, 05 Nov 2021 14:56:44 -0700 (PDT) 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=zax8OmvdfoHLqwvXAXnFDBiRPtXzNwixobyyQerpoIY=; b=IoV/OXYoGcG+31f40Q/US1FXOgcjbWLirtG4t66N4yM3nSf6sjpQqh40fljTCUjOLX MyXdQeZQXBHhrmuumkkCUySBr9WAqdOwG6q8plDrsnuEDfIEtSkTSXR2BYkXbyRTNrj2 +T7Eq2V3sXLhBC1oSv0Q/7kr7Y1HESeO0EGgv2LX74j6qTNO9PqT6YGfMEC+YJ8/J2uR e2bVZTg9QwIcU5u/6NepdhwZaJ+ojyGaDu5Dfe8ms7qDPBqkoXa1gZdxsRFsGrhKxxgg D3rMaNfNsNxGlTv/Ru+Gy0QC2EtkSm9QD22chzgDKWnE2Q8pbtf/0NoMKel38bQYs84c Hp8Q== 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=zax8OmvdfoHLqwvXAXnFDBiRPtXzNwixobyyQerpoIY=; b=GZ7AMHn54ay6eNO8/2gQFbS1Tw00DbhcfXWzDgkOhV9wZIh4e6M7RkIl10taEGuB93 3xx+Wbgp0xDkaSorSnEkptbPNs6r00jhaGFkg5KI3+IWbeqSXd+WWI/RlC1BTRwpHJPA kcjlhfhFoAB3fFsDTX3cp72vX9s8iIh3kWgRVhRYp85W0+t0p+z5YUZWQyLuoFgVOIhv 3pbS+oXtlJg5It2mXOMkROozD6uzYHBS0BKNgT7DXb7POB2MD1cHN/REjv65qKTHxRXj CB/4PIbNQ+Y6mSs4LDaTnvSV8CvycY3bOb0EMKx89yV1mHJMYCfX53/xbJWCnZoXkr85 AMbw== X-Gm-Message-State: AOAM533LqvaHsx2EVUVvk9W10UFlK58xhWY/OPv2qicIaWrAdP85Hssv S4Rfr0Wzbbc7h0Q1TsUXMjdHUM1oNqo= X-Google-Smtp-Source: ABdhPJxcOZxoC9RjdHB27ZBc/r0Rz8uthPAxJWuFIHn3OjGuZmUFpqfEPtgfExz07No1D/rhAgho7A== X-Received: by 2002:a5d:694a:: with SMTP id r10mr55917719wrw.170.1636149403257; Fri, 05 Nov 2021 14:56:43 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h7sm8679976wrt.64.2021.11.05.14.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 14:56:42 -0700 (PDT) Message-Id: <18d6c2819ade2e514a408e4173c6a5048e3f2cd1.1636149400.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 05 Nov 2021 21:56:40 +0000 Subject: [PATCH 2/2] docs: update behavior of git-cat-file --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 When an empty string is entered into stdin, git-cat-file --buffer will flush stdout immediately. This commit updates the man page accordingly. Signed-off-by: John Cai --- Documentation/git-cat-file.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index 27b27e2b300..c98e8dc3669 100644 --- a/Documentation/git-cat-file.txt +++ b/Documentation/git-cat-file.txt @@ -104,7 +104,8 @@ OPTIONS that a process can interactively read and write from `cat-file`. With this option, the output uses normal stdio buffering; this is much more efficient when invoking - `--batch-check` on a large number of objects. + `--batch-check` on a large number of objects. An empty string will + force a flush of stdout. --unordered:: When `--batch-all-objects` is in use, visit objects in an