[PATCH 4/4] Replace pointer arithmetic with strbuf
From: Vasyl' Vavrychuk <hidden>
Date: 2016-06-15 22:50:33
Subsystem:
the rest · Maintainer:
Linus Torvalds
Signed-off-by: Vasyl' Vavrychuk <redacted> --- 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(¬e, kind); + strbuf_addch(¬e, ' '); + } + strbuf_addf(¬e, "'%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(¬e); + 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(¬e); free(url); fclose(fp); if (rc & STORE_REF_ERROR_DF_CONFLICT)
--
1.7.1