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

[PATCH 4/4] Replace pointer arithmetic with strbuf

From
Vasyl' Vavrychuk <vvavrychuk@gmail.com>
Date
Feb 12, 2011, 22:38 UTC
Message-ID
<1297550311-17723-5-git-send-email-vvavrychuk@gmail.com>
In-Reply-To
<1297550311-17723-1-git-send-email-vvavrychuk@gmail.com>
Signed-off-by: Vasyl' Vavrychuk <vvavrychuk@gmail.com>
---
 builtin/fetch.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index ddb40c6..eaea475 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -342,8 +342,9 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 {
 	FILE *fp;
 	struct commit *commit;
-	int i, note_len, shown_url = 0, rc = 0;
-	char note[1024], display[1024];
+	int i, shown_url = 0, rc = 0;
+	struct strbuf note = STRBUF_INIT;
+	char display[1024];
 	const char *what, *kind;
 	struct ref *rm;
 	char *url, *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD");
@@ -394,19 +395,20 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 			what = rm->name;
 		}
 
-		note_len = 0;
 		if (*what) {
-			if (*kind)
-				note_len += sprintf(note + note_len, "%s ",
-						    kind);
-			note_len += sprintf(note + note_len, "'%s' of ", what);
+			if (*kind) {
+				strbuf_addstr(&note, kind);
+				strbuf_addch(&note, ' ');
+			}
+			strbuf_addf(&note, "'%s' of ", what);
 		}
-		note[note_len] = '\0';
 		fprintf(fp, "%s\t%s\t%s",
 			sha1_to_hex(commit ? commit->object.sha1 :
 				    rm->old_sha1),
 			rm->merge ? "" : "not-for-merge",
-			note);
+			note.buf);
+		strbuf_reset(&note);
+
 		for (i = 0; url[i]; ++i)
 			if ('\n' == url[i])
 				fputs("\\n", fp);
@@ -431,6 +433,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				fprintf(stderr, " %s\n", display);
 		}
 	}
+	strbuf_release(&note);
 	free(url);
 	fclose(fp);
 	if (rc & STORE_REF_ERROR_DF_CONFLICT)
-- 
1.7.1
Previous: João P. SampaioNext: Sverre Rabbelier
Message 9 of 12 in “clean-up store_updated_refs”
  1. 0/4 clean-up store_updated_refsVasyl' Vavrychuk, Feb 12, 2011
  2. 1/4 Reduce url_len variable scopeVasyl' Vavrychuk, Feb 12, 2011
  3. Junio C HamanoFeb 17, 2011
  4. 2/4 Extract function trim_url and optimize calls of it.Vasyl' Vavrychuk, Feb 12, 2011
  5. Junio C HamanoFeb 17, 2011
  6. 3/4 Dont use the same variable for different thingsVasyl' Vavrychuk, Feb 12, 2011
  7. Junio C HamanoFeb 17, 2011
  8. João P. SampaioFeb 17, 2011
  9. 4/4 Replace pointer arithmetic with strbufVasyl' Vavrychuk, Feb 12, 2011
  10. Sverre RabbelierFeb 13, 2011
  11. Vasyl'Feb 13, 2011
  12. Sverre RabbelierFeb 13, 2011

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.