From patchwork Mon Mar 30 13:46:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 11465539 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BD5F913 for ; Mon, 30 Mar 2020 13:46:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ECFD92073B for ; Mon, 30 Mar 2020 13:46:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="U4RK8Q6X"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fhp/DU67" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728504AbgC3Nq1 (ORCPT ); Mon, 30 Mar 2020 09:46:27 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:60103 "EHLO wout4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728065AbgC3Nq1 (ORCPT ); Mon, 30 Mar 2020 09:46:27 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 16EAC6EA; Mon, 30 Mar 2020 09:46:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 30 Mar 2020 09:46:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=aGdIsIuEkIsBzUW2WZeuoU2T9ED WX+IFhO79ANbcgfE=; b=U4RK8Q6Xnn5Xmwmp4/JSTcBhkTAxXXZNE021X+npBin cuN2RLoI0nz1qbgDf0sntL93G+kQFIJqUtPEDSPHRQhaPhDOD4iRGKkPTIWVCy/X qmMtlMhvf6iAZResLwAI6IbGPWqkqzVsxtXY98KsypbkVHbLXLzRBaFr1f2lIQSP H8FeGu6Bg//t1M/y475ZZ6WnHiKjgxr/5zqMUJ4pHrtoLm+Lxh1GxvzrATSA63Qm ynMNlbN2qVP5ysHM0HuLeHFW62AwzCnMO6VmdIeTkvDWqbPA+P7SAKadeBPqwFJt neG9ZQqRfLH0R5gj1oah9CURoECZfdpphjmoaxDxxLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=aGdIsI uEkIsBzUW2WZeuoU2T9EDWX+IFhO79ANbcgfE=; b=fhp/DU67sXvFWxkx5wnAoH y16EqDmO3SsHxV/XIpf3NNb3xbJkYiTJtKnhnmkWVwoIC6cw6cemzDQHqSwCtdu6 F04ZUlk6dDLx6yOljRQK4vQtWGLav4yR17bAsST1dBoObW8Eh6P7NiSLhc0XO4bx EWb100l+/lrz7WP38sxb9e+0CK/813AMUyScH+M5yk36gO+JFQpax/5ZmejAjZiK snEptuDwp6yRENRTkrIaQr+/LhYBEgLkA93+iaVKj04Z9ViPc462GXlRek8Air3Y mygO50TVm7gWLURO8Wf0a1gkg8IGXXZGK/lduhcmBHZ9RRef1yTq0KT96Jkcj6iQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgieekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucfkphepjeekrdehge drvddvtddruddtvdenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhl fhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (x4e36dc66.dyn.telefonica.de [78.54.220.102]) by mail.messagingengine.com (Postfix) with ESMTPA id 25C343280069; Mon, 30 Mar 2020 09:46:25 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 0f18be8f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 30 Mar 2020 13:46:23 +0000 (UTC) Date: Mon, 30 Mar 2020 15:46:27 +0200 From: Patrick Steinhardt To: git Cc: Christian Couder , Junio C Hamano Subject: [PATCH v2 3/9] strbuf: provide function to append whole lines Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org While the strbuf interface already provides functions to read a line into it that completely replaces its current contents, we do not have an interface that allows for appending lines without discarding current contents. Add a new function `strbuf_appendwholeline` that reads a line including its terminating character into a strbuf non-destructively. This is a preparatory step for git-update-ref(1) reading standard input line-wise instead of as a block. Signed-off-by: Patrick Steinhardt --- strbuf.c | 10 ++++++++++ strbuf.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/strbuf.c b/strbuf.c index bb0065ccaf..6e74901bfa 100644 --- a/strbuf.c +++ b/strbuf.c @@ -690,6 +690,16 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term) } #endif +int strbuf_appendwholeline(struct strbuf *sb, FILE *fp, int term) +{ + struct strbuf line = STRBUF_INIT; + if (strbuf_getwholeline(&line, fp, term)) + return EOF; + strbuf_addbuf(sb, &line); + strbuf_release(&line); + return 0; +} + static int strbuf_getdelim(struct strbuf *sb, FILE *fp, int term) { if (strbuf_getwholeline(sb, fp, term)) diff --git a/strbuf.h b/strbuf.h index ce8e49c0b2..411063ca76 100644 --- a/strbuf.h +++ b/strbuf.h @@ -502,6 +502,12 @@ int strbuf_getline(struct strbuf *sb, FILE *file); */ int strbuf_getwholeline(struct strbuf *sb, FILE *file, int term); +/** + * Like `strbuf_getwholeline`, but appends the line instead of + * resetting the buffer first. + */ +int strbuf_appendwholeline(struct strbuf *sb, FILE *file, int term); + /** * Like `strbuf_getwholeline`, but operates on a file descriptor. * It reads one character at a time, so it is very slow. Do not