All of lore.kernel.org
 help / color / mirror / Atom feed
From: "AreaZR via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	AreaZR <gfunni234@gmail.com>,
	Seija Kijin <doremylover123@gmail.com>
Subject: [PATCH v3] git: replace strbuf_addstr with strbuf_addch for all strings of length 2
Date: Wed, 18 Dec 2024 02:54:58 +0000	[thread overview]
Message-ID: <pull.1436.v3.git.git.1734490498710.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1436.v2.git.git.1734481897905.gitgitgadget@gmail.com>

From: Seija Kijin <doremylover123@gmail.com>

Adding the char directly instead of a string of length 2
is clearer and more efficient.

Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
    git: replace strbuf_addstr with strbuf_addch for all strings of length 2

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1436%2FAreaZR%2Fstrbuf-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1436/AreaZR/strbuf-v3
Pull-Request: https://github.com/git/git/pull/1436

Range-diff vs v2:

 1:  22c37ed6677 ! 1:  96a093dec36 git: replace strbuf_addstr with strbuf_addch for all strings of length 2
     @@ Metadata
       ## Commit message ##
          git: replace strbuf_addstr with strbuf_addch for all strings of length 2
      
     -    This helps reduce overhead of calculating the length
     +    Adding the char directly instead of a string of length 2
     +    is clearer and more efficient.
      
          Signed-off-by: Seija Kijin <doremylover123@gmail.com>
      
     @@ log-tree.c: void fmt_output_subject(struct strbuf *filename,
       	}
       	strbuf_addf(filename, "%04d-%s", nr, subject);
      
     - ## merge-ort.c ##
     -@@ merge-ort.c: static void path_msg(struct merge_options *opt,
     - 
     - 	va_start(ap, fmt);
     - 	if (opt->priv->call_depth) {
     --		strbuf_addchars(dest, ' ', 2);
     --		strbuf_addstr(dest, "From inner merge:");
     -+		strbuf_addstr(dest, "  From inner merge:");
     - 		strbuf_addchars(dest, ' ', opt->priv->call_depth * 2);
     - 	}
     - 	strbuf_vaddf(dest, fmt, ap);
     -
       ## path.c ##
      @@ path.c: const char *remove_leading_path(const char *in, const char *prefix)
       


 bisect.c                | 2 +-
 builtin/am.c            | 6 ++----
 builtin/blame.c         | 8 +++-----
 builtin/ls-tree.c       | 2 +-
 diff.c                  | 2 +-
 log-tree.c              | 2 +-
 path.c                  | 2 +-
 protocol-caps.c         | 2 +-
 setup.c                 | 2 +-
 trace2/tr2_tgt_normal.c | 2 +-
 10 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/bisect.c b/bisect.c
index d71c4e4b44b..94bb53c9bf6 100644
--- a/bisect.c
+++ b/bisect.c
@@ -454,7 +454,7 @@ static int register_ref(const char *refname, const char *referent UNUSED, const
 {
 	struct strbuf good_prefix = STRBUF_INIT;
 	strbuf_addstr(&good_prefix, term_good);
-	strbuf_addstr(&good_prefix, "-");
+	strbuf_addch(&good_prefix, '-');
 
 	if (!strcmp(refname, term_bad)) {
 		free(current_bad_oid);
diff --git a/builtin/am.c b/builtin/am.c
index bfa95147cf4..6cb9fd4f45f 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -341,13 +341,11 @@ static void write_author_script(const struct am_state *state)
 
 	strbuf_addstr(&sb, "GIT_AUTHOR_NAME=");
 	sq_quote_buf(&sb, state->author_name);
-	strbuf_addch(&sb, '\n');
 
-	strbuf_addstr(&sb, "GIT_AUTHOR_EMAIL=");
+	strbuf_addstr(&sb, "\nGIT_AUTHOR_EMAIL=");
 	sq_quote_buf(&sb, state->author_email);
-	strbuf_addch(&sb, '\n');
 
-	strbuf_addstr(&sb, "GIT_AUTHOR_DATE=");
+	strbuf_addstr(&sb, "\nGIT_AUTHOR_DATE=");
 	sq_quote_buf(&sb, state->author_date);
 	strbuf_addch(&sb, '\n');
 
diff --git a/builtin/blame.c b/builtin/blame.c
index 6a7bb3b0724..c1ee2585ee8 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -148,11 +148,9 @@ static void get_ac_line(const char *inbuf, const char *what,
 
 	if (split_ident_line(&ident, tmp, len)) {
 	error_out:
-		/* Ugh */
-		tmp = "(unknown)";
-		strbuf_addstr(name, tmp);
-		strbuf_addstr(mail, tmp);
-		strbuf_addstr(tz, tmp);
+		strbuf_addstr(name, "(unknown)");
+		strbuf_addstr(mail, "(unknown)");
+		strbuf_addstr(tz, "(unknown)");
 		*time = 0;
 		return;
 	}
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 8542b5d53e4..605ddb5a719 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -37,7 +37,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
 	} else if (padded) {
 		strbuf_addf(line, "%7s", "-");
 	} else {
-		strbuf_addstr(line, "-");
+		strbuf_addch(line, '-');
 	}
 }
 
diff --git a/diff.c b/diff.c
index 266ddf18e73..61434c6cb45 100644
--- a/diff.c
+++ b/diff.c
@@ -1763,7 +1763,7 @@ static void add_line_count(struct strbuf *out, int count)
 		strbuf_addstr(out, "0,0");
 		break;
 	case 1:
-		strbuf_addstr(out, "1");
+		strbuf_addch(out, '1');
 		break;
 	default:
 		strbuf_addf(out, "1,%d", count);
diff --git a/log-tree.c b/log-tree.c
index 83cc4b1cfb7..d0dc065e4f3 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -452,7 +452,7 @@ void fmt_output_subject(struct strbuf *filename,
 
 		strbuf_addf(&temp, "v%s", info->reroll_count);
 		format_sanitized_subject(filename, temp.buf, temp.len);
-		strbuf_addstr(filename, "-");
+		strbuf_addch(filename, '-');
 		strbuf_release(&temp);
 	}
 	strbuf_addf(filename, "%04d-%s", nr, subject);
diff --git a/path.c b/path.c
index 4dcf3c8d40d..04085c164d0 100644
--- a/path.c
+++ b/path.c
@@ -982,7 +982,7 @@ const char *remove_leading_path(const char *in, const char *prefix)
 
 	strbuf_reset(&buf);
 	if (!in[j])
-		strbuf_addstr(&buf, ".");
+		strbuf_addch(&buf, '.');
 	else
 		strbuf_addstr(&buf, in + j);
 	return buf.buf;
diff --git a/protocol-caps.c b/protocol-caps.c
index 855f279c2f7..a841a457bbd 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -65,7 +65,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
 
 		if (info->size) {
 			if (oid_object_info(r, &oid, &object_size) < 0) {
-				strbuf_addstr(&send_buffer, " ");
+				strbuf_addch(&send_buffer, ' ');
 			} else {
 				strbuf_addf(&send_buffer, " %lu", object_size);
 			}
diff --git a/setup.c b/setup.c
index 39ff48d9dc5..27535f9f9a2 100644
--- a/setup.c
+++ b/setup.c
@@ -1550,7 +1550,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
 				return GIT_DIR_DISALLOWED_BARE;
 			if (!ensure_valid_ownership(NULL, NULL, dir->buf, report))
 				return GIT_DIR_INVALID_OWNERSHIP;
-			strbuf_addstr(gitdir, ".");
+			strbuf_addch(gitdir, '.');
 			return GIT_DIR_BARE;
 		}
 
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index baef48aa698..8a05cf2109a 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -226,7 +226,7 @@ static void fn_child_start_fl(const char *file, int line,
 	if (cmd->dir) {
 		strbuf_addstr(&buf_payload, " cd ");
 		sq_quote_buf_pretty(&buf_payload, cmd->dir);
-		strbuf_addstr(&buf_payload, ";");
+		strbuf_addch(&buf_payload, ';');
 	}
 
 	/*

base-commit: d882f382b3d939d90cfa58d17b17802338f05d66
-- 
gitgitgadget

  reply	other threads:[~2024-12-18  2:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 21:54 [PATCH] git: replace strbuf_addstr with strbuf_addch for all strings of length 2 Rose via GitGitGadget
2023-01-18 16:04 ` Junio C Hamano
2023-01-18 18:53   ` Eric Sunshine
2024-12-18  0:31 ` [PATCH v2] " AreaZR via GitGitGadget
2024-12-18  2:54   ` AreaZR via GitGitGadget [this message]
2024-12-18  3:06     ` [PATCH v4] " AreaZR via GitGitGadget

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=pull.1436.v3.git.git.1734490498710.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=doremylover123@gmail.com \
    --cc=gfunni234@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.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.