All of lore.kernel.org
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] strbuf: use strbuf_addstr() for adding C strings
Date: Thu, 17 Jul 2014 01:38:18 +0200	[thread overview]
Message-ID: <53C70CEA.8000000@web.de> (raw)

Avoid code duplication and let strbuf_addstr() call strlen() for us.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/commit.c |  2 +-
 diff.c           | 12 ++++++------
 path.c           |  6 +++---
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 72eb3be..f2d7979 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -702,7 +702,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		char *buffer;
 		buffer = strstr(use_message_buffer, "\n\n");
 		if (buffer)
-			strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
+			strbuf_addstr(&sb, buffer + 2);
 		hook_arg1 = "commit";
 		hook_arg2 = use_message;
 	} else if (fixup_message) {
diff --git a/diff.c b/diff.c
index 06bdfb8..867f034 100644
--- a/diff.c
+++ b/diff.c
@@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
 	ep += 2; /* skip over @@ */
 
 	/* The hunk header in fraginfo color */
-	strbuf_add(&msgbuf, frag, strlen(frag));
+	strbuf_addstr(&msgbuf, frag);
 	strbuf_add(&msgbuf, line, ep - line);
-	strbuf_add(&msgbuf, reset, strlen(reset));
+	strbuf_addstr(&msgbuf, reset);
 
 	/*
 	 * trailing "\r\n"
@@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
 		if (*ep != ' ' && *ep != '\t')
 			break;
 	if (ep != cp) {
-		strbuf_add(&msgbuf, plain, strlen(plain));
+		strbuf_addstr(&msgbuf, plain);
 		strbuf_add(&msgbuf, cp, ep - cp);
-		strbuf_add(&msgbuf, reset, strlen(reset));
+		strbuf_addstr(&msgbuf, reset);
 	}
 
 	if (ep < line + len) {
-		strbuf_add(&msgbuf, func, strlen(func));
+		strbuf_addstr(&msgbuf, func);
 		strbuf_add(&msgbuf, ep, line + len - ep);
-		strbuf_add(&msgbuf, reset, strlen(reset));
+		strbuf_addstr(&msgbuf, reset);
 	}
 
 	strbuf_add(&msgbuf, line + len, org_len - len);
diff --git a/path.c b/path.c
index bc804a3..c3883d4 100644
--- a/path.c
+++ b/path.c
@@ -277,16 +277,16 @@ char *expand_user_path(const char *path)
 			const char *home = getenv("HOME");
 			if (!home)
 				goto return_null;
-			strbuf_add(&user_path, home, strlen(home));
+			strbuf_addstr(&user_path, home);
 		} else {
 			struct passwd *pw = getpw_str(username, username_len);
 			if (!pw)
 				goto return_null;
-			strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
+			strbuf_addstr(&user_path, pw->pw_dir);
 		}
 		to_copy = first_slash;
 	}
-	strbuf_add(&user_path, to_copy, strlen(to_copy));
+	strbuf_addstr(&user_path, to_copy);
 	return strbuf_detach(&user_path, NULL);
 return_null:
 	strbuf_release(&user_path);
-- 
2.0.2

             reply	other threads:[~2014-07-16 23:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 23:38 René Scharfe [this message]
2014-07-16 23:41 ` [PATCH] strbuf: use strbuf_addstr() for adding C strings Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53C70CEA.8000000@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.