public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Patryk Obara <patryk.obara@gmail•com>
Cc: git@vger•kernel.org, "brian m . carlson" <sandals@crustytoothpaste•net>
Subject: Re: [PATCH 3/5] commit: replace the raw buffer with strbuf in read_graft_line
Date: Tue, 15 Aug 2017 11:25:07 -0700	[thread overview]
Message-ID: <xmqqwp64r8n0.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <b5633a5425c623f3d2204325e99332b5bb511582.1502796628.git.patryk.obara@gmail.com> (Patryk Obara's message of "Tue, 15 Aug 2017 13:49:04 +0200")

Patryk Obara <patryk.obara@gmail•com> writes:

> This simplifies function declaration and allows for use of strbuf_rtrim
> instead of modifying buffer directly.
>
> Signed-off-by: Patryk Obara <patryk.obara@gmail•com>
> ---
>  builtin/blame.c |  2 +-
>  commit.c        | 11 ++++++-----
>  commit.h        |  2 +-
>  3 files changed, 8 insertions(+), 7 deletions(-)

Looks good; both existing callers already have strbuf, and we do not
expect we will gain a lot more callers to this ancient facility, so
there is no point to have a more accomodating API that separately
takes <ptr,len>.

> diff --git a/builtin/blame.c b/builtin/blame.c
> index bda1a78..d4472e9 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -488,7 +488,7 @@ static int read_ancestry(const char *graft_file)
>  		return -1;
>  	while (!strbuf_getwholeline(&buf, fp, '\n')) {
>  		/* The format is just "Commit Parent1 Parent2 ...\n" */
> -		struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
> +		struct commit_graft *graft = read_graft_line(&buf);
>  		if (graft)
>  			register_commit_graft(graft, 0);
>  	}
> diff --git a/commit.c b/commit.c
> index 8b28415..499fb14 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -134,15 +134,16 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
>  	return 0;
>  }
>  
> -struct commit_graft *read_graft_line(char *buf, int len)
> +struct commit_graft *read_graft_line(struct strbuf *line)
>  {
>  	/* The format is just "Commit Parent1 Parent2 ...\n" */
> -	int i;
> +	int i, len;
> +	char *buf = line->buf;
>  	struct commit_graft *graft = NULL;
>  	const int entry_size = GIT_SHA1_HEXSZ + 1;
>  
> -	while (len && isspace(buf[len-1]))
> -		buf[--len] = '\0';
> +	strbuf_rtrim(line);
> +	len = line->len;
>  	if (buf[0] == '#' || buf[0] == '\0')
>  		return NULL;
>  	if ((len + 1) % entry_size)
> @@ -174,7 +175,7 @@ static int read_graft_file(const char *graft_file)
>  		return -1;
>  	while (!strbuf_getwholeline(&buf, fp, '\n')) {
>  		/* The format is just "Commit Parent1 Parent2 ...\n" */
> -		struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
> +		struct commit_graft *graft = read_graft_line(&buf);
>  		if (!graft)
>  			continue;
>  		if (register_commit_graft(graft, 1))
> diff --git a/commit.h b/commit.h
> index 6d857f0..baecc0a 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -247,7 +247,7 @@ struct commit_graft {
>  };
>  typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
>  
> -struct commit_graft *read_graft_line(char *buf, int len);
> +struct commit_graft *read_graft_line(struct strbuf *line);
>  int register_commit_graft(struct commit_graft *, int);
>  struct commit_graft *lookup_commit_graft(const struct object_id *oid);

  parent reply	other threads:[~2017-08-15 18:25 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 11:49 [PATCH 0/5] Modernize read_graft_line implementation Patryk Obara
2017-08-15 11:49 ` [PATCH 1/5] cache: extend object_id size to sha3-256 Patryk Obara
2017-08-15 11:49 ` [PATCH 2/5] sha1_file: fix hardcoded size in null_sha1 Patryk Obara
2017-08-15 18:23   ` Junio C Hamano
2017-08-15 18:29     ` Stefan Beller
2017-08-15 19:02       ` Junio C Hamano
2017-08-16 12:11         ` Patryk Obara
2017-08-16 19:32           ` Junio C Hamano
2017-08-15 11:49 ` [PATCH 3/5] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-15 17:02   ` Stefan Beller
2017-08-16 12:24     ` Patryk Obara
2017-08-16 22:59       ` brian m. carlson
2017-08-17  5:55         ` Jeff King
2017-08-17 21:17           ` Junio C Hamano
2017-08-17 21:38             ` Patryk Obara
2017-08-15 18:25   ` Junio C Hamano [this message]
2017-08-15 11:49 ` [PATCH 4/5] commit: implement free_commit_graft Patryk Obara
2017-08-15 17:04   ` Stefan Beller
2017-08-15 18:26   ` Junio C Hamano
2017-08-16 12:28     ` Patryk Obara
2017-08-15 11:49 ` [PATCH 5/5] commit: rewrite read_graft_line Patryk Obara
2017-08-15 17:11   ` Stefan Beller
2017-08-15 18:30   ` Junio C Hamano
2017-08-16 13:07     ` Patryk Obara
2017-08-16 19:39       ` Junio C Hamano
2017-08-15 17:19 ` [PATCH 0/5] Modernize read_graft_line implementation Stefan Beller
2017-08-16 17:58 ` [PATCH v2 0/4] " Patryk Obara
2017-08-16 17:58   ` [PATCH v2 1/4] sha1_file: fix hardcoded size in null_sha1 Patryk Obara
2017-08-16 19:46     ` Junio C Hamano
2017-08-16 17:58   ` [PATCH v2 2/4] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-16 17:58   ` [PATCH v2 3/4] commit: implement free_commit_graft Patryk Obara
2017-08-16 17:58   ` [PATCH v2 4/4] commit: rewrite read_graft_line Patryk Obara
2017-08-17 21:20     ` Junio C Hamano
2017-08-17 21:42       ` Patryk Obara
2017-08-18  1:59   ` [PATCH v3 0/4] Modernize read_graft_line implementation Patryk Obara
2017-08-18  1:59     ` [PATCH v3 1/4] sha1_file: fix definition of null_sha1 Patryk Obara
2017-08-18  1:59     ` [PATCH v3 2/4] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-18  6:29       ` Jeff King
2017-08-18 10:12         ` Patryk Obara
2017-08-18 11:50           ` Jeff King
2017-08-18  1:59     ` [PATCH v3 3/4] commit: allocate array using object_id size Patryk Obara
2017-08-18  1:59     ` [PATCH v3 4/4] commit: rewrite read_graft_line Patryk Obara
2017-08-18  6:43       ` Jeff King
2017-08-18  7:44         ` Junio C Hamano
2017-08-18 11:30           ` Patryk Obara
2017-08-18 11:45             ` Jeff King
2017-08-18 16:44             ` Junio C Hamano
2017-08-18 17:05               ` Patryk Obara
2017-08-18 18:29                 ` Junio C Hamano
2017-08-18  2:20     ` [PATCH v3 0/4] Modernize read_graft_line implementation Junio C Hamano
2017-08-18 18:33     ` [PATCH v4 " Patryk Obara
2017-08-18 18:33       ` [PATCH v4 1/4] sha1_file: fix definition of null_sha1 Patryk Obara
2017-08-18 18:33       ` [PATCH v4 2/4] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-18 18:33       ` [PATCH v4 3/4] commit: allocate array using object_id size Patryk Obara
2017-08-18 18:33       ` [PATCH v4 4/4] commit: rewrite read_graft_line Patryk Obara
2017-08-18 18:38         ` Patryk Obara
2017-08-18 19:12           ` Junio C Hamano
2017-08-18 19:33             ` Patryk Obara
2017-08-18 19:47           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqwp64r8n0.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=patryk.obara@gmail$(echo .)com \
    --cc=sandals@crustytoothpaste$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox