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

[PATCH/RFC v1 3/5] sha1_name.c: cleanup using strbuf_set operations

From
Jeremiah Mahler <jmmahler@gmail.com>
Date
Jun 9, 2014, 08:36 UTC
Message-ID
<d98e710757df0ad7465e074f283f3bf3781f7652.1402301816.git.jmmahler@gmail.com>
In-Reply-To
<cover.1402301815.git.jmmahler@gmail.com>

Simplified cases where a strbuf_reset was immediately followed by a strbuf_add using the new strbuf_set operations.

Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
 sha1_name.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 2b6322f..f88b66c 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -920,8 +920,7 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
 		return 0;
 	if (--(cb->remaining) == 0) {
 		len = target - match;
-		strbuf_reset(&cb->buf);
-		strbuf_add(&cb->buf, match, len);
+		strbuf_set(&cb->buf, match, len);
 		return 1; /* we are done */
 	}
 	return 0;
@@ -957,8 +956,7 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
 
 	retval = 0;
 	if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
-		strbuf_reset(buf);
-		strbuf_add(buf, cb.buf.buf, cb.buf.len);
+		strbuf_set(buf, cb.buf.buf, cb.buf.len);
 		retval = brace - name + 1;
 	}
 
@@ -1025,8 +1023,7 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
 	if (next != name + 1)
 		return -1;
 
-	strbuf_reset(buf);
-	strbuf_add(buf, "HEAD", 4);
+	strbuf_set(buf, "HEAD", 4);
 	return 1;
 }
 
@@ -1044,8 +1041,7 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
 		strbuf_setlen(buf, used);
 		return len;
 	}
-	strbuf_reset(buf);
-	strbuf_addbuf(buf, &tmp);
+	strbuf_setbuf(buf, &tmp);
 	strbuf_release(&tmp);
 	/* tweak for size of {-N} versus expanded ref name */
 	return ret - used + len;
@@ -1054,8 +1050,7 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
 static void set_shortened_ref(struct strbuf *buf, const char *ref)
 {
 	char *s = shorten_unambiguous_ref(ref, 0);
-	strbuf_reset(buf);
-	strbuf_addstr(buf, s);
+	strbuf_setstr(buf, s);
 	free(s);
 }
 
-- 
2.0.0.573.ged771ce.dirty
Previous: Jeremiah MahlerNext: Jeremiah Mahler
Message 6 of 12 in “add strbuf_set operations”
  1. 0/5 add strbuf_set operationsJeremiah Mahler, Jun 9, 2014
  2. 1/5 add strbuf_set operationsJeremiah Mahler, Jun 9, 2014
  3. 2/5 add strbuf_set operations documentationJeremiah Mahler, Jun 9, 2014
  4. Eric SunshineJun 9, 2014
  5. Jeremiah MahlerJun 9, 2014
  6. 3/5 sha1_name.c: cleanup using strbuf_set operationsJeremiah Mahler, Jun 9, 2014
  7. 4/5 fast-import.c: cleanup using strbuf_set operationsJeremiah Mahler, Jun 9, 2014
  8. Eric SunshineJun 9, 2014
  9. Jeremiah MahlerJun 9, 2014
  10. 5/5 builtin/remote.c: cleanup using strbuf_set operationsJeremiah Mahler, Jun 9, 2014
  11. Duy NguyenJun 9, 2014
  12. Jeremiah MahlerJun 9, 2014

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.