From patchwork Thu Apr 2 07:09:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 11470185 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 035801892 for ; Thu, 2 Apr 2020 07:09:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D53D320784 for ; Thu, 2 Apr 2020 07:09:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="dLsraSyD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mROyA6zA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387453AbgDBHJa (ORCPT ); Thu, 2 Apr 2020 03:09:30 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:53855 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728612AbgDBHJ3 (ORCPT ); Thu, 2 Apr 2020 03:09:29 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 62B465C0293; Thu, 2 Apr 2020 03:09:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 02 Apr 2020 03:09:28 -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=TTGqwR3oq5EKMx2DqlfVM/DTzGx jU2VK2vU2N75/Hk4=; b=dLsraSyDLJtCJFXU0W5aRXLV3oZOWg3jDWgG6cy9giA UzA7BJBUEpojlsfbAz4l58nstATpuaETC7X6SMN2eE2f+IuL+syzyvLEoXGNwZ5b ToRkZCq8ekzn6B/rRaEAfCnit76Ninpi88J9TAdAmd3jB84dR5nUttpoWajuh+pu 3HqrLjlVPcYW9osSulEMVtfqEEd8piW28XeVdLLx5rTBpxMfNICZftfcTiYm9rFx v/38S1NLUHqmRho63KMO9MTg4gE5KJB+mKmMM+2T2gswaAcwOdxAWBG7Y1d1PB8k YO06A4iTmd7wObmCG20NiDCviMErSh5Eo/dP2RmmU8Q== 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=TTGqwR 3oq5EKMx2DqlfVM/DTzGxjU2VK2vU2N75/Hk4=; b=mROyA6zAuI7neI3ai2EkEO Tiq3SBVgdf6nGo9zsIVFxfv0Ok916bWwE7soKW7rJowXlCXJnAd/PGrYURu8Apzq KCyl81LDQl3JsO8aS+mcsYHazUf5vaGkD7iJycG0ixxmOV2/dl2cpZOioklNNGo7 CCigrt2tN2KLofJXwwAL0W6+pjL7UP8m5Jf3HGKvhtckC1uKpbiiKQAk8yNfp5c7 HbrXG4BK5IEBc+seQP/PZWuhdJKL+UaGM9TAuAFvyMEbTEY79zSCW9fh8GJwAyME KKyPuh6xNLGeQW04ab1E6Lp0MpWa2lJZQDIuADu6C3MEaWgCDbRrlkCkRJYYfTwg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrtdefgdduudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucfkphepkeelrdduvd drleegrddvkeenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (x590c5e1c.dyn.telefonica.de [89.12.94.28]) by mail.messagingengine.com (Postfix) with ESMTPA id C63DF306CD98; Thu, 2 Apr 2020 03:09:27 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 8f61b50f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 Apr 2020 07:09:26 +0000 (UTC) Date: Thu, 2 Apr 2020 09:09:33 +0200 From: Patrick Steinhardt To: git Cc: Christian Couder , Junio C Hamano Subject: [PATCH v3 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