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

[PATCH] use strbuf_addstr() for adding strings to strbufs

From
René Scharfe <l.s.r@web.de>
Date
Oct 1, 2017, 14:44 UTC
Message-ID
<431a993c-fbd4-4bc6-0641-1a69b419cd7f@web.de>

Use strbuf_addstr() instead of strbuf_addf() for adding strings. That's simpler and makes the intent clearer.

Patch generated by Coccinelle and contrib/coccinelle/strbuf.cocci; adjusted indentation in refs/packed-backend.c manually.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/branch.c      | 2 +-
 refs/packed-backend.c | 4 ++--
 sequencer.c           | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 355f9ef5da..a2b7c55427 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -352,7 +352,7 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
 			strbuf_addf(&obname, "%%(objectname:short=%d)", filter->abbrev);
 
 		strbuf_addf(&local, "%%(align:%d,left)%%(refname:lstrip=2)%%(end)", maxwidth);
-		strbuf_addf(&local, "%s", branch_get_color(BRANCH_COLOR_RESET));
+		strbuf_addstr(&local, branch_get_color(BRANCH_COLOR_RESET));
 		strbuf_addf(&local, " %s ", obname.buf);
 
 		if (filter->verbose > 1)
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 3bc47ffd5e..2951514f25 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -729,8 +729,8 @@ static int write_with_updates(struct packed_ref_store *refs,
 	}
 
 	if (ok != ITER_DONE) {
-		strbuf_addf(err, "unable to write packed-refs file: "
-			    "error iterating over old contents");
+		strbuf_addstr(err, "unable to write packed-refs file: "
+			      "error iterating over old contents");
 		goto error;
 	}
 
diff --git a/sequencer.c b/sequencer.c
index 60636ce54b..ba95cefc7d 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -203,7 +203,7 @@ int sequencer_remove_state(struct replay_opts *opts)
 		free(opts->xopts[i]);
 	free(opts->xopts);
 
-	strbuf_addf(&dir, "%s", get_dir(opts));
+	strbuf_addstr(&dir, get_dir(opts));
 	remove_dir_recursively(&dir, 0);
 	strbuf_release(&dir);
 
-- 
2.14.2
Message 1 of 1 in “use strbuf_addstr() for adding strings to strbufs”
  1. use strbuf_addstr() for adding strings to strbufsRené Scharfe, Oct 1, 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.