git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/5] commit: replace the raw buffer with strbuf in read_graft_line

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 15, 2017, 18:25 UTC
Message-ID
<xmqqwp64r8n0.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<b5633a5425c623f3d2204325e99332b5bb511582.1502796628.git.patryk.obara@gmail.com>
Patryk Obara <patryk.obara@gmail.com> writes:
Show 9 quoted lines
> 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>.

Show 59 quoted lines
> 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);
Previous: Patryk ObaraNext: Patryk Obara
Message 20 of 59 in “Modernize read_graft_line implementation”
  1. 0/5 Modernize read_graft_line implementationPatryk Obara, Aug 15, 2017
  2. 1/5 cache: extend object_id size to sha3-256Patryk Obara, Aug 15, 2017
  3. 2/5 sha1_file: fix hardcoded size in null_sha1Patryk Obara, Aug 15, 2017
  4. Junio C HamanoAug 15, 2017
  5. Stefan BellerAug 15, 2017
  6. Junio C HamanoAug 15, 2017
  7. Patryk ObaraAug 16, 2017
  8. Junio C HamanoAug 16, 2017
  9. 4/5 commit: implement free_commit_graftPatryk Obara, Aug 15, 2017
  10. Stefan BellerAug 15, 2017
  11. Junio C HamanoAug 15, 2017
  12. Patryk ObaraAug 16, 2017
  13. 3/5 commit: replace the raw buffer with strbuf in read_graft_linePatryk Obara, Aug 15, 2017
  14. Stefan BellerAug 15, 2017
  15. Patryk ObaraAug 16, 2017
  16. brian m. carlsonAug 16, 2017
  17. Jeff KingAug 17, 2017
  18. Junio C HamanoAug 17, 2017
  19. Patryk ObaraAug 17, 2017
  20. Junio C HamanoAug 15, 2017
  21. 5/5 commit: rewrite read_graft_linePatryk Obara, Aug 15, 2017
  22. Stefan BellerAug 15, 2017
  23. Junio C HamanoAug 15, 2017
  24. Patryk ObaraAug 16, 2017
  25. Junio C HamanoAug 16, 2017
  26. Stefan BellerAug 15, 2017
  27. 0/4 Modernize read_graft_line implementationPatryk Obara, Aug 16, 2017
  28. 1/4 sha1_file: fix hardcoded size in null_sha1Patryk Obara, Aug 16, 2017
  29. Junio C HamanoAug 16, 2017
  30. 3/4 commit: implement free_commit_graftPatryk Obara, Aug 16, 2017
  31. 2/4 commit: replace the raw buffer with strbuf in read_graft_linePatryk Obara, Aug 16, 2017
  32. 4/4 commit: rewrite read_graft_linePatryk Obara, Aug 16, 2017
  33. Junio C HamanoAug 17, 2017
  34. Patryk ObaraAug 17, 2017
  35. 0/4 Modernize read_graft_line implementationPatryk Obara, Aug 18, 2017
  36. 2/4 commit: replace the raw buffer with strbuf in read_graft_linePatryk Obara, Aug 18, 2017
  37. Jeff KingAug 18, 2017
  38. Patryk ObaraAug 18, 2017
  39. Jeff KingAug 18, 2017
  40. 1/4 sha1_file: fix definition of null_sha1Patryk Obara, Aug 18, 2017
  41. 4/4 commit: rewrite read_graft_linePatryk Obara, Aug 18, 2017
  42. Jeff KingAug 18, 2017
  43. Junio C HamanoAug 18, 2017
  44. Patryk ObaraAug 18, 2017
  45. Jeff KingAug 18, 2017
  46. Junio C HamanoAug 18, 2017
  47. Patryk ObaraAug 18, 2017
  48. Junio C HamanoAug 18, 2017
  49. 3/4 commit: allocate array using object_id sizePatryk Obara, Aug 18, 2017
  50. Junio C HamanoAug 18, 2017
  51. 0/4 Modernize read_graft_line implementationPatryk Obara, Aug 18, 2017
  52. 2/4 commit: replace the raw buffer with strbuf in read_graft_linePatryk Obara, Aug 18, 2017
  53. 4/4 commit: rewrite read_graft_linePatryk Obara, Aug 18, 2017
  54. Patryk ObaraAug 18, 2017
  55. Junio C HamanoAug 18, 2017
  56. Patryk ObaraAug 18, 2017
  57. Junio C HamanoAug 18, 2017
  58. 1/4 sha1_file: fix definition of null_sha1Patryk Obara, Aug 18, 2017
  59. 3/4 commit: allocate array using object_id sizePatryk Obara, Aug 18, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.