From patchwork Tue Oct 31 22:28:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 13442299 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70858249E6 for ; Tue, 31 Oct 2023 22:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fjSwdxKr" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C78EDF5 for ; Tue, 31 Oct 2023 15:28:40 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5af9ad9341fso61562187b3.2 for ; Tue, 31 Oct 2023 15:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698791320; x=1699396120; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jFqlmzfjxaj3ax6Zx1Dr5dQxFI87VmUXJOTDutnTjGc=; b=fjSwdxKr1dykMScPPZo7flbORh5qUqceAGulTGon6JmU/N/k27PwcaMl09O1JQLpls G6sjtRI/rl3j8+sfZjvbyJlUIaFR9sY5Eg6ak2dM+8iQhkgKmBX9gcjmVUACkgPmr8Ti I7CESOQ92tNoxPYBCmLoWgTNoBPxBoAk2uumVXLb6ELZVw0MYa+YAZutpdvGDu33Lefp qRKXVWo2Gt22IKxgeAbkY3ZhA7n5jnCWMG/EBbQDYxyClB8QRaxGqHlQgEIxPjyCY5oX xj6n+41AL/2cXeeKLlAKbfPoi+Y0tqY42/icohCyqOen9d+WSpWy/H0uKXOuTBfTudvs ck1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698791320; x=1699396120; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jFqlmzfjxaj3ax6Zx1Dr5dQxFI87VmUXJOTDutnTjGc=; b=OFE0U8nQgcTBxlwrYOByxjkCWHEkUxxE2NtTQwapQzop1+oleyWaMG66KqVxfb5pAG 53KG5CJMTLu7COvKD/e6wzXn/RpkWb5LbCCaWPjN8krTPMBHIYAZZKECMgOlFBk5HMCU lRGec5AjxromajFCNVhhej+334OGyfcSbdPY6sJTBcYLLQ6VOQIjeZC8tLsjolPgWhfx ra1PeuUWEjWTxbVpYeOy2g+RNqkVNLACv0fi/X83Q400zB6qaWJ9e4QUXBVpTdRaRWVz RIW4bxoytxKvggIP1TR6/JflMekNZE015Qe/ApkYRkFr2DzoyYhsd8PIdAGyJD7USUqF dK1A== X-Gm-Message-State: AOJu0YwqLb0isd4Vot6VrMVjEYEkh+CcKgWG+kjyxoQ5OAp4cBVy0Sef 2Pasywsn85zPfFKvC4cr2EnsxahoEd+vCjr2V6A9bplZxjVto5OSqix/s7kUR4GzJjwXz3cbxAM Nc9xg8qEglmIK3njP7PSCD5eoN2YeQdfew1xG2oqCA1pmsLR6p1KR3MspF2nB3KdjnV62Q7rS+g c5 X-Google-Smtp-Source: AGHT+IFtanXTk960IJYAgk2ipYruDMJHes2PGeDq9vhF0j1viOJaxt2SbmOYngP34BIq1m4jZVwZeu7N1jkJFshJG2CY X-Received: from jonathantanmy0.svl.corp.google.com ([2620:15c:2d3:204:70a1:f59a:2e01:c62e]) (user=jonathantanmy job=sendgmr) by 2002:a0d:df82:0:b0:586:a8ab:f8fe with SMTP id i124-20020a0ddf82000000b00586a8abf8femr293476ywe.10.1698791319963; Tue, 31 Oct 2023 15:28:39 -0700 (PDT) Date: Tue, 31 Oct 2023 15:28:30 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <98c9f70608d7b6f7bee49a89634de100b2dd5ecf.1698791220.git.jonathantanmy@google.com> Subject: [PATCH v2 1/4] strbuf_commented_addf(): drop the comment_line_char parameter From: Jonathan Tan To: git@vger.kernel.org Cc: Junio C Hamano , Dragan Simic , Phillip Wood , Jonathan Tan From: Junio C Hamano All the callers of this function supply the global variable comment_line_char as an argument to its second parameter. Remove the parameter to allow us in the future to change the reference to the global variable with something else, like a function call. Signed-off-by: Junio C Hamano --- add-patch.c | 8 ++++---- builtin/branch.c | 2 +- builtin/merge.c | 8 ++++---- builtin/tag.c | 4 ++-- rebase-interactive.c | 2 +- sequencer.c | 4 ++-- strbuf.c | 3 ++- strbuf.h | 4 ++-- wt-status.c | 2 +- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/add-patch.c b/add-patch.c index bfe19876cd..471a0037be 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1106,11 +1106,11 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk) size_t i; strbuf_reset(&s->buf); - strbuf_commented_addf(&s->buf, comment_line_char, + strbuf_commented_addf(&s->buf, _("Manual hunk edit mode -- see bottom for " "a quick guide.\n")); render_hunk(s, hunk, 0, 0, &s->buf); - strbuf_commented_addf(&s->buf, comment_line_char, + strbuf_commented_addf(&s->buf, _("---\n" "To remove '%c' lines, make them ' ' lines " "(context).\n" @@ -1119,13 +1119,13 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk) s->mode->is_reverse ? '+' : '-', s->mode->is_reverse ? '-' : '+', comment_line_char); - strbuf_commented_addf(&s->buf, comment_line_char, "%s", + strbuf_commented_addf(&s->buf, "%s", _(s->mode->edit_hunk_hint)); /* * TRANSLATORS: 'it' refers to the patch mentioned in the previous * messages. */ - strbuf_commented_addf(&s->buf, comment_line_char, + strbuf_commented_addf(&s->buf, _("If it does not apply cleanly, you will be " "given an opportunity to\n" "edit again. If all lines of the hunk are " diff --git a/builtin/branch.c b/builtin/branch.c index 2ec190b14a..b2f171e10b 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -668,7 +668,7 @@ static int edit_branch_description(const char *branch_name) exists = !read_branch_desc(&buf, branch_name); if (!buf.len || buf.buf[buf.len-1] != '\n') strbuf_addch(&buf, '\n'); - strbuf_commented_addf(&buf, comment_line_char, + strbuf_commented_addf(&buf, _("Please edit the description for the branch\n" " %s\n" "Lines starting with '%c' will be stripped.\n"), diff --git a/builtin/merge.c b/builtin/merge.c index d748d46e13..8f0e8be7c3 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -857,15 +857,15 @@ static void prepare_to_commit(struct commit_list *remoteheads) strbuf_addch(&msg, '\n'); if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) { wt_status_append_cut_line(&msg); - strbuf_commented_addf(&msg, comment_line_char, "\n"); + strbuf_commented_addf(&msg, "\n"); } - strbuf_commented_addf(&msg, comment_line_char, + strbuf_commented_addf(&msg, _(merge_editor_comment)); if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) - strbuf_commented_addf(&msg, comment_line_char, + strbuf_commented_addf(&msg, _(scissors_editor_comment)); else - strbuf_commented_addf(&msg, comment_line_char, + strbuf_commented_addf(&msg, _(no_scissors_editor_comment), comment_line_char); } if (signoff) diff --git a/builtin/tag.c b/builtin/tag.c index 3918eacbb5..a85a0d8def 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -314,10 +314,10 @@ static void create_tag(const struct object_id *object, const char *object_ref, struct strbuf buf = STRBUF_INIT; strbuf_addch(&buf, '\n'); if (opt->cleanup_mode == CLEANUP_ALL) - strbuf_commented_addf(&buf, comment_line_char, + strbuf_commented_addf(&buf, _(tag_template), tag, comment_line_char); else - strbuf_commented_addf(&buf, comment_line_char, + strbuf_commented_addf(&buf, _(tag_template_nocleanup), tag, comment_line_char); write_or_die(fd, buf.buf, buf.len); strbuf_release(&buf); diff --git a/rebase-interactive.c b/rebase-interactive.c index d9718409b3..3f33da7f03 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -71,7 +71,7 @@ void append_todo_help(int command_count, if (!edit_todo) { strbuf_addch(buf, '\n'); - strbuf_commented_addf(buf, comment_line_char, + strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)", "Rebase %s onto %s (%d commands)", command_count), diff --git a/sequencer.c b/sequencer.c index d584cac8ed..5d348a3f12 100644 --- a/sequencer.c +++ b/sequencer.c @@ -675,11 +675,11 @@ void append_conflicts_hint(struct index_state *istate, } strbuf_addch(msgbuf, '\n'); - strbuf_commented_addf(msgbuf, comment_line_char, "Conflicts:\n"); + strbuf_commented_addf(msgbuf, "Conflicts:\n"); for (i = 0; i < istate->cache_nr;) { const struct cache_entry *ce = istate->cache[i++]; if (ce_stage(ce)) { - strbuf_commented_addf(msgbuf, comment_line_char, + strbuf_commented_addf(msgbuf, "\t%s\n", ce->name); while (i < istate->cache_nr && !strcmp(ce->name, istate->cache[i]->name)) diff --git a/strbuf.c b/strbuf.c index 7827178d8e..15550b2619 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "environment.h" #include "gettext.h" #include "hex-ll.h" #include "strbuf.h" @@ -372,7 +373,7 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf, add_lines(out, prefix1, prefix2, buf, size); } -void strbuf_commented_addf(struct strbuf *sb, char comment_line_char, +void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...) { va_list params; diff --git a/strbuf.h b/strbuf.h index e959caca87..981617dc77 100644 --- a/strbuf.h +++ b/strbuf.h @@ -378,8 +378,8 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...); * Add a formatted string prepended by a comment character and a * blank to the buffer. */ -__attribute__((format (printf, 3, 4))) -void strbuf_commented_addf(struct strbuf *sb, char comment_line_char, const char *fmt, ...); +__attribute__((format (printf, 2, 3))) +void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...); __attribute__((format (printf,2,0))) void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); diff --git a/wt-status.c b/wt-status.c index 9f45bf6949..54b2775730 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1102,7 +1102,7 @@ void wt_status_append_cut_line(struct strbuf *buf) { const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored."); - strbuf_commented_addf(buf, comment_line_char, "%s", cut_line); + strbuf_commented_addf(buf, "%s", cut_line); strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char); } From patchwork Tue Oct 31 22:28:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 13442300 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 693BA2745D for ; Tue, 31 Oct 2023 22:28:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3rsmGqTa" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5474F3 for ; Tue, 31 Oct 2023 15:28:42 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7b9e83b70so2829467b3.0 for ; Tue, 31 Oct 2023 15:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698791322; x=1699396122; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=O9pvSQ4uIAfJHCTHvc6jewH23WsYYLZIzyZ0484t/nM=; b=3rsmGqTa2xfKyApuTxhlGuOZfA89wHg4YWdAAZFCYupWZp+q5+Lp2WpfTTH2Ywy4W7 2Rty+rI28bvd1FSJxiIicDU0qwBH/vLewcdiQR2aJBkx5rnIZq9FUaCvikerku4XJ498 ATcSG/YdXaya9tM51UuKo9e819pvrXjIOvpHCS7xOfIbo3K19JbL1pbuvKW01i7gJw0R fuqbh19N+XToMzBkDvjb/KiK7Fb9h5WF2gyGSKzJ1/vhlznLnVOYR2caQE86zACKePnM 5/d6Nh4LBeHobgGwugE/IYBWm/URlr/fGEqHusTDVS6lV037qjoZGwEJvq5QV07gGRd0 ZK6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698791322; x=1699396122; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O9pvSQ4uIAfJHCTHvc6jewH23WsYYLZIzyZ0484t/nM=; b=EuIksg7SiD9HjZ2CVdITbXrGGa95tiLqxvgKslfz2asu5Xgm373aPoD3K10U9VIMvg KIrRPjEs86VnWAwLftjwtGXDuO3ciZaZccY6sJ13e412pham62RFupg255P/GGAaf65C 2iQjhBQ1gFUHN5fLiTZBZPMiqUakceEdWXFJ9vACGKYfrQR1+7++tqBYE5MiMO9zuFxg 6cg9smfogJyxiU3qOv3MCXsY1RIAQ0QAsMFHnbTmJ8gHGkC/t5q/aUjCEoJhprbD5Vk/ OkvfSz8cwOkq+PBVhZw3zDpoltPCQmykplPZcBgJ5F9j1jmXtJmE9duzTFcs0wSwnQnA Nyzg== X-Gm-Message-State: AOJu0YxVFLJV2RumZ4qii4NNrFsODTyj2MjaMzeqb2mM4r99Aq5QPIe7 m97xRUKH+zJRl30R+WMLJivp9bkjjt5fmzkThOJcUpDV5HMLrUnJUDpJdj4G05zWZe3tR7cORWb kwmvhfeqGtZvA6ci+OlWKRVXE16bQUmNjnj3HzPBsIutoN50UNUDbHer2JkHtD4iU6HJ8Q4NGoC rT X-Google-Smtp-Source: AGHT+IFUF4dpQHjCd8ETD1rJjRiB75V2PapqtiZmv65/iHvIBTSUebhQixJLVoe/g5Ri9jrELPdMmHu3I+5pCIFWG2Ke X-Received: from jonathantanmy0.svl.corp.google.com ([2620:15c:2d3:204:70a1:f59a:2e01:c62e]) (user=jonathantanmy job=sendgmr) by 2002:a0d:c001:0:b0:5a4:fd03:2516 with SMTP id b1-20020a0dc001000000b005a4fd032516mr102639ywd.1.1698791322009; Tue, 31 Oct 2023 15:28:42 -0700 (PDT) Date: Tue, 31 Oct 2023 15:28:31 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <22e96f5ba1a36e96d9577ba279711f7c61308441.1698791220.git.jonathantanmy@google.com> Subject: [PATCH v2 2/4] strbuf_add_commented_lines(): drop the comment_line_char parameter From: Jonathan Tan To: git@vger.kernel.org Cc: Junio C Hamano , Dragan Simic , Phillip Wood , Jonathan Tan From: Junio C Hamano All the callers of this function supply the global variable comment_line_char as an argument to its last parameter. Remove the parameter to allow us in the future to change the reference to the global variable with something else, like a function call. Signed-off-by: Junio C Hamano --- builtin/notes.c | 9 ++++----- builtin/stripspace.c | 2 +- fmt-merge-msg.c | 9 +++------ rebase-interactive.c | 6 +++--- sequencer.c | 10 ++++------ strbuf.c | 6 +++--- strbuf.h | 3 +-- wt-status.c | 4 ++-- 8 files changed, 21 insertions(+), 28 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index 9f38863dd5..355ecce07a 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -181,7 +181,7 @@ static void write_commented_object(int fd, const struct object_id *object) if (strbuf_read(&buf, show.out, 0) < 0) die_errno(_("could not read 'show' output")); - strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_char); + strbuf_add_commented_lines(&cbuf, buf.buf, buf.len); write_or_die(fd, cbuf.buf, cbuf.len); strbuf_release(&cbuf); @@ -209,10 +209,9 @@ static void prepare_note_data(const struct object_id *object, struct note_data * copy_obj_to_fd(fd, old_note); strbuf_addch(&buf, '\n'); - strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char); - strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)), - comment_line_char); - strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char); + strbuf_add_commented_lines(&buf, "\n", strlen("\n")); + strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template))); + strbuf_add_commented_lines(&buf, "\n", strlen("\n")); write_or_die(fd, buf.buf, buf.len); write_commented_object(fd, object); diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 7b700a9fb1..11e475760c 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -13,7 +13,7 @@ static void comment_lines(struct strbuf *buf) size_t len; msg = strbuf_detach(buf, &len); - strbuf_add_commented_lines(buf, msg, len, comment_line_char); + strbuf_add_commented_lines(buf, msg, len); free(msg); } diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index 66e47449a0..adc85d2a72 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -509,8 +509,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf, strbuf_complete_line(tagbuf); if (sig->len) { strbuf_addch(tagbuf, '\n'); - strbuf_add_commented_lines(tagbuf, sig->buf, sig->len, - comment_line_char); + strbuf_add_commented_lines(tagbuf, sig->buf, sig->len); } } @@ -556,8 +555,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out) strbuf_addch(&tagline, '\n'); strbuf_add_commented_lines(&tagline, origins.items[first_tag].string, - strlen(origins.items[first_tag].string), - comment_line_char); + strlen(origins.items[first_tag].string)); strbuf_insert(&tagbuf, 0, tagline.buf, tagline.len); strbuf_release(&tagline); @@ -565,8 +563,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out) strbuf_addch(&tagbuf, '\n'); strbuf_add_commented_lines(&tagbuf, origins.items[i].string, - strlen(origins.items[i].string), - comment_line_char); + strlen(origins.items[i].string)); fmt_tag_signature(&tagbuf, &sig, buf, len); } strbuf_release(&payload); diff --git a/rebase-interactive.c b/rebase-interactive.c index 3f33da7f03..1138bd37ba 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -78,7 +78,7 @@ void append_todo_help(int command_count, shortrevisions, shortonto, command_count); } - strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char); + strbuf_add_commented_lines(buf, msg, strlen(msg)); if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR) msg = _("\nDo not remove any line. Use 'drop' " @@ -87,7 +87,7 @@ void append_todo_help(int command_count, msg = _("\nIf you remove a line here " "THAT COMMIT WILL BE LOST.\n"); - strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char); + strbuf_add_commented_lines(buf, msg, strlen(msg)); if (edit_todo) msg = _("\nYou are editing the todo file " @@ -98,7 +98,7 @@ void append_todo_help(int command_count, msg = _("\nHowever, if you remove everything, " "the rebase will be aborted.\n\n"); - strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char); + strbuf_add_commented_lines(buf, msg, strlen(msg)); } int edit_todo_list(struct repository *r, struct todo_list *todo_list, diff --git a/sequencer.c b/sequencer.c index 5d348a3f12..29c8b5e32b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1859,7 +1859,7 @@ static void add_commented_lines(struct strbuf *buf, const void *str, size_t len) s += count; len -= count; } - strbuf_add_commented_lines(buf, s, len, comment_line_char); + strbuf_add_commented_lines(buf, s, len); } /* Does the current fixup chain contain a squash command? */ @@ -1958,7 +1958,7 @@ static int append_squash_message(struct strbuf *buf, const char *body, strbuf_addf(buf, _(nth_commit_msg_fmt), ++opts->current_fixup_count + 1); strbuf_addstr(buf, "\n\n"); - strbuf_add_commented_lines(buf, body, commented_len, comment_line_char); + strbuf_add_commented_lines(buf, body, commented_len); /* buf->buf may be reallocated so store an offset into the buffer */ fixup_off = buf->len; strbuf_addstr(buf, body + commented_len); @@ -2048,8 +2048,7 @@ static int update_squash_messages(struct repository *r, _(first_commit_msg_str)); strbuf_addstr(&buf, "\n\n"); if (is_fixup_flag(command, flag)) - strbuf_add_commented_lines(&buf, body, strlen(body), - comment_line_char); + strbuf_add_commented_lines(&buf, body, strlen(body)); else strbuf_addstr(&buf, body); @@ -2068,8 +2067,7 @@ static int update_squash_messages(struct repository *r, strbuf_addf(&buf, _(skip_nth_commit_msg_fmt), ++opts->current_fixup_count + 1); strbuf_addstr(&buf, "\n\n"); - strbuf_add_commented_lines(&buf, body, strlen(body), - comment_line_char); + strbuf_add_commented_lines(&buf, body, strlen(body)); } else return error(_("unknown command: %d"), command); repo_unuse_commit_buffer(r, commit, message); diff --git a/strbuf.c b/strbuf.c index 15550b2619..2088f7800a 100644 --- a/strbuf.c +++ b/strbuf.c @@ -360,8 +360,8 @@ static void add_lines(struct strbuf *out, strbuf_complete_line(out); } -void strbuf_add_commented_lines(struct strbuf *out, const char *buf, - size_t size, char comment_line_char) +void strbuf_add_commented_lines(struct strbuf *out, + const char *buf, size_t size) { static char prefix1[3]; static char prefix2[2]; @@ -384,7 +384,7 @@ void strbuf_commented_addf(struct strbuf *sb, strbuf_vaddf(&buf, fmt, params); va_end(params); - strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_line_char); + strbuf_add_commented_lines(sb, buf.buf, buf.len); if (incomplete_line) sb->buf[--sb->len] = '\0'; diff --git a/strbuf.h b/strbuf.h index 981617dc77..4547efa62e 100644 --- a/strbuf.h +++ b/strbuf.h @@ -287,8 +287,7 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, * by a comment character and a blank. */ void strbuf_add_commented_lines(struct strbuf *out, - const char *buf, size_t size, - char comment_line_char); + const char *buf, size_t size); /** diff --git a/wt-status.c b/wt-status.c index 54b2775730..b390c77334 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1027,7 +1027,7 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom if (s->display_comment_prefix) { size_t len; summary_content = strbuf_detach(&summary, &len); - strbuf_add_commented_lines(&summary, summary_content, len, comment_line_char); + strbuf_add_commented_lines(&summary, summary_content, len); free(summary_content); } @@ -1103,7 +1103,7 @@ void wt_status_append_cut_line(struct strbuf *buf) const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored."); strbuf_commented_addf(buf, "%s", cut_line); - strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char); + strbuf_add_commented_lines(buf, explanation, strlen(explanation)); } void wt_status_add_cut_line(FILE *fp) From patchwork Tue Oct 31 22:28:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 13442301 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B95C4249E6 for ; Tue, 31 Oct 2023 22:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tbyRKbVE" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84303F4 for ; Tue, 31 Oct 2023 15:28:44 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7c97d5d5aso73537427b3.3 for ; Tue, 31 Oct 2023 15:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698791323; x=1699396123; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=C9v1lTJ6NFAvI1XXmHsVjYLk3AmaHfm3B6E6Cgepk4o=; b=tbyRKbVE0jEeSgl1udXI5uCm64ncGPOVdH4Ys9qTn9gjX+lBQ9PKb/zZRJ+rriKtzP Zp1t1zTqiiZjYVKHkkSrqbYgfmL5uY0jjziMvPFkVin3XK+yqjf/oDeEIUlyo7/q9d3k 4wrjPUUgnZkC6H4SGDUQbMQZt4Rky3KQpagxqVkc/xHGZXiyPb2+0vZY9mPIEB2W61mZ 8UZEOtuyMiBqxfGK+wE9fTqQSXMz07FZwkvu5CCEqA3/VED0o2XgzVi6kBoaH3e4Qud0 h3JWw26n64jjeTIXu2/kgjCeV7f/wK4RwKabR6xxId9bNT/3qHCoMqV69HZUSylgjgjg gncA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698791323; x=1699396123; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=C9v1lTJ6NFAvI1XXmHsVjYLk3AmaHfm3B6E6Cgepk4o=; b=cLyVA2lz71nZOuONCpFsL329/XQvJ7+Z26U73yMYk2/QLx93Xc8XCPAeNALMTRfmKc woN+4+jjXX7NPCw6+JO7xxYwU9ggG8EZHm0pj/PSkU+ItgWWOOzxnpB+XIYm/uH1V1h5 TmO1E1Rpw998vSsIr7cVe/2kEE3iFCmKhOcbCyyRUuf3vBFeLXYXgYtqrDsJgpq+Itg+ xYPunm3XRbuSpyaHyE+Uxvx8ML7B3sEgJJxlX3XzATgtGm7+ZiBs/mxU4n7plWFNkeqt VSc/kxKVRBtX+6N8RfooHBUMmMWPvlVx83qmYQoeABT3bveRkESUXSEZ6+aBU61oePSv Cglw== X-Gm-Message-State: AOJu0YxQk0Ejf/lCsS/jeCzQe/guQswTkm4yNAF8U/pREg6F+IM69dJi gRJn/x79XBRlfPbUNCGBCXcHNLgM4FivnDEF5rm5LMjQ2l2QOoRFpS5XBVPQu5QaiVkyVs0KYM6 j0Cke+AT7ZWvZjYpyR4Bg+aZJkH1vhC2vtHec5hzK5RMSo2szeR56ySdvH0YNvGCs6Txz7mazdi zg X-Google-Smtp-Source: AGHT+IGGLC4P4M/RBztoO17EtwYisZU2EXiw6bhzjR2bm7QPLum91y0uEe1hoj5aST5TFiNUzlM1vweb1o+KVBIp25cf X-Received: from jonathantanmy0.svl.corp.google.com ([2620:15c:2d3:204:70a1:f59a:2e01:c62e]) (user=jonathantanmy job=sendgmr) by 2002:a0d:d716:0:b0:5a7:fc19:a060 with SMTP id z22-20020a0dd716000000b005a7fc19a060mr274923ywd.8.1698791323732; Tue, 31 Oct 2023 15:28:43 -0700 (PDT) Date: Tue, 31 Oct 2023 15:28:32 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <283f502acb68910cb43d6077eef99d6345aaea4b.1698791220.git.jonathantanmy@google.com> Subject: [PATCH v2 3/4] strbuf: make add_lines() public From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , Dragan Simic , Phillip Wood , Junio C Hamano A subsequent patch will require the ability to add different prefixes to different lines (depending on their contents), so make this functionality available from outside strbuf.c. The function name is chosen to avoid a conflict with the existing function named strbuf_add_lines(). Signed-off-by: Jonathan Tan --- strbuf.c | 22 +++++++++++----------- strbuf.h | 4 ++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/strbuf.c b/strbuf.c index 2088f7800a..d5ee8874f8 100644 --- a/strbuf.c +++ b/strbuf.c @@ -340,24 +340,24 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) va_end(ap); } -static void add_lines(struct strbuf *out, - const char *prefix1, - const char *prefix2, - const char *buf, size_t size) +void strbuf_add_lines_varied_prefix(struct strbuf *sb, + const char *default_prefix, + const char *tab_nl_prefix, + const char *buf, size_t size) { while (size) { const char *prefix; const char *next = memchr(buf, '\n', size); next = next ? (next + 1) : (buf + size); - prefix = ((prefix2 && (buf[0] == '\n' || buf[0] == '\t')) - ? prefix2 : prefix1); - strbuf_addstr(out, prefix); - strbuf_add(out, buf, next - buf); + prefix = (buf[0] == '\n' || buf[0] == '\t') + ? tab_nl_prefix : default_prefix; + strbuf_addstr(sb, prefix); + strbuf_add(sb, buf, next - buf); size -= next - buf; buf = next; } - strbuf_complete_line(out); + strbuf_complete_line(sb); } void strbuf_add_commented_lines(struct strbuf *out, @@ -370,7 +370,7 @@ void strbuf_add_commented_lines(struct strbuf *out, xsnprintf(prefix1, sizeof(prefix1), "%c ", comment_line_char); xsnprintf(prefix2, sizeof(prefix2), "%c", comment_line_char); } - add_lines(out, prefix1, prefix2, buf, size); + strbuf_add_lines_varied_prefix(out, prefix1, prefix2, buf, size); } void strbuf_commented_addf(struct strbuf *sb, @@ -751,7 +751,7 @@ ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint) void strbuf_add_lines(struct strbuf *out, const char *prefix, const char *buf, size_t size) { - add_lines(out, prefix, NULL, buf, size); + strbuf_add_lines_varied_prefix(out, prefix, prefix, buf, size); } void strbuf_addstr_xml_quoted(struct strbuf *buf, const char *s) diff --git a/strbuf.h b/strbuf.h index 4547efa62e..a9333ac1ad 100644 --- a/strbuf.h +++ b/strbuf.h @@ -601,6 +601,10 @@ void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size); +void strbuf_add_lines_varied_prefix(struct strbuf *sb, + const char *default_prefix, + const char *tab_nl_prefix, + const char *buf, size_t size); /** * Append s to sb, with the characters '<', '>', '&' and '"' converted From patchwork Tue Oct 31 22:28:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 13442302 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 926E627476 for ; Tue, 31 Oct 2023 22:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ye2jeXWT" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61420ED for ; Tue, 31 Oct 2023 15:28:46 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5afc00161daso47952727b3.1 for ; Tue, 31 Oct 2023 15:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698791325; x=1699396125; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=t9HBWOCEKUxSXkT1IcU5St6aM3a2nN0UYhwsakuLLKc=; b=Ye2jeXWTSgRnGSZVj6s58qe9kHYBpuDedhh/uFiUw+JGNt7Azo+QjUUXo44Sp/S6Dp FFn39skPC23s3dxZb1UK+Wmo9qGMKnI7Rp9bt7jpYc9fvvTASOCkFdxdoswJASFIs5st ERgNNadvNhvU25QUmr4qH8mPJKf5OrEm60ipzMc5YeFGHkLTK/zLFfFs8vsG53n99eeY uITg2ISucpYZKulpZs5+bGGByD7WLOkrTCID97jmY8eIOz2jbpzDvlPzQiCkyXQ8V6nB 4JSCEYJFMW8Le+ujZIvdreqCZeE6/Ij20ejVkTY3m+RtnFyIUEUYAF14VB4zwSt7zJUK iJXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698791325; x=1699396125; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t9HBWOCEKUxSXkT1IcU5St6aM3a2nN0UYhwsakuLLKc=; b=qIFed7nXRcMOxoRn9YukOSaU+wHtL/mNKuADP1BkPGf4fqy3A1IT3mwu/0NHNBx6uy cJT86iV+F1uCImWapWlIA1Rh/IVOJEVHRS+ICMfdqlcS4OVpUG+aB1OkSW7LkvyQrHeZ WFbc2Feur7o/7fgQg314Qa9Z8snYYupUnsVJ5RYta7fdG+wacZk5qyNwjFeW6684KkGA 01wMUFKAp2eHhN/zYVErbzY0jZyHScmzwXlVGR5DVZToLNVUUf4tYyiQ9Z46kSsoN0Fe G0SftRCESVgURFZZrN1MkrGfzjhJugHZ0yc5Pztlx+BZo07VHPwYPXnVYN04oFQsQUd+ TzwA== X-Gm-Message-State: AOJu0YwW3DO72KzM6umHEgMSRmkhbkAtX1Zz+ansPexEgLHrlNRF35GE 2dS0qA+N0lb1YfNPf3+m80I5WHzgEBSAn408oeD0hlamcbq724PLi+iuIiu6RRpGy6V/YDmyOAc lQKYebJdXmTg0x2kfTk6054lr5etShXpIwCJlRinpFG/hvZZgbMabeNNUCvoA7NiLmHIZyHFM+r Qe X-Google-Smtp-Source: AGHT+IHOeg1McY/IVugcAzTSZLHINozbF4NWIrtRfq2PjDioKBNS0WB0NpFeTi6iPofhkgj7XDtAexuvEAvN+aTv3C3Q X-Received: from jonathantanmy0.svl.corp.google.com ([2620:15c:2d3:204:70a1:f59a:2e01:c62e]) (user=jonathantanmy job=sendgmr) by 2002:a0d:d54b:0:b0:59b:e684:3c7a with SMTP id x72-20020a0dd54b000000b0059be6843c7amr270488ywd.4.1698791325550; Tue, 31 Oct 2023 15:28:45 -0700 (PDT) Date: Tue, 31 Oct 2023 15:28:33 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <4097385820973b30a78f2e45741444a3f6eee98d.1698791220.git.jonathantanmy@google.com> Subject: [PATCH v2 4/4] strbuf: move env-using functions to environment.c From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , Dragan Simic , Phillip Wood , Junio C Hamano This eliminates the dependency from strbuf to environment. Signed-off-by: Jonathan Tan --- environment.c | 32 ++++++++++++++++++++++++++++++++ environment.h | 14 ++++++++++++++ strbuf.c | 32 -------------------------------- strbuf.h | 15 --------------- 4 files changed, 46 insertions(+), 47 deletions(-) diff --git a/environment.c b/environment.c index bb3c2a96a3..942c5b8dd3 100644 --- a/environment.c +++ b/environment.c @@ -18,6 +18,7 @@ #include "refs.h" #include "fmt-merge-msg.h" #include "commit.h" +#include "strbuf.h" #include "strvec.h" #include "object-file.h" #include "object-store-ll.h" @@ -416,3 +417,34 @@ int print_sha1_ellipsis(void) } return cached_result; } + +void strbuf_commented_addf(struct strbuf *sb, + const char *fmt, ...) +{ + va_list params; + struct strbuf buf = STRBUF_INIT; + int incomplete_line = sb->len && sb->buf[sb->len - 1] != '\n'; + + va_start(params, fmt); + strbuf_vaddf(&buf, fmt, params); + va_end(params); + + strbuf_add_commented_lines(sb, buf.buf, buf.len); + if (incomplete_line) + sb->buf[--sb->len] = '\0'; + + strbuf_release(&buf); +} + +void strbuf_add_commented_lines(struct strbuf *out, + const char *buf, size_t size) +{ + static char prefix1[3]; + static char prefix2[2]; + + if (prefix1[0] != comment_line_char) { + xsnprintf(prefix1, sizeof(prefix1), "%c ", comment_line_char); + xsnprintf(prefix2, sizeof(prefix2), "%c", comment_line_char); + } + strbuf_add_lines_varied_prefix(out, prefix1, prefix2, buf, size); +} diff --git a/environment.h b/environment.h index e5351c9dd9..f801dbe36e 100644 --- a/environment.h +++ b/environment.h @@ -229,4 +229,18 @@ extern const char *excludes_file; */ int print_sha1_ellipsis(void); +/** + * Add a formatted string prepended by a comment character and a + * blank to the buffer. + */ +__attribute__((format (printf, 2, 3))) +void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...); + +/** + * Add a NUL-terminated string to the buffer. Each line will be prepended + * by a comment character and a blank. + */ +void strbuf_add_commented_lines(struct strbuf *out, + const char *buf, size_t size); + #endif diff --git a/strbuf.c b/strbuf.c index d5ee8874f8..f6c1978ecf 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,5 +1,4 @@ #include "git-compat-util.h" -#include "environment.h" #include "gettext.h" #include "hex-ll.h" #include "strbuf.h" @@ -360,37 +359,6 @@ void strbuf_add_lines_varied_prefix(struct strbuf *sb, strbuf_complete_line(sb); } -void strbuf_add_commented_lines(struct strbuf *out, - const char *buf, size_t size) -{ - static char prefix1[3]; - static char prefix2[2]; - - if (prefix1[0] != comment_line_char) { - xsnprintf(prefix1, sizeof(prefix1), "%c ", comment_line_char); - xsnprintf(prefix2, sizeof(prefix2), "%c", comment_line_char); - } - strbuf_add_lines_varied_prefix(out, prefix1, prefix2, buf, size); -} - -void strbuf_commented_addf(struct strbuf *sb, - const char *fmt, ...) -{ - va_list params; - struct strbuf buf = STRBUF_INIT; - int incomplete_line = sb->len && sb->buf[sb->len - 1] != '\n'; - - va_start(params, fmt); - strbuf_vaddf(&buf, fmt, params); - va_end(params); - - strbuf_add_commented_lines(sb, buf.buf, buf.len); - if (incomplete_line) - sb->buf[--sb->len] = '\0'; - - strbuf_release(&buf); -} - void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap) { int len; diff --git a/strbuf.h b/strbuf.h index a9333ac1ad..d5f0d4c579 100644 --- a/strbuf.h +++ b/strbuf.h @@ -282,14 +282,6 @@ void strbuf_remove(struct strbuf *sb, size_t pos, size_t len); void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, const void *data, size_t data_len); -/** - * Add a NUL-terminated string to the buffer. Each line will be prepended - * by a comment character and a blank. - */ -void strbuf_add_commented_lines(struct strbuf *out, - const char *buf, size_t size); - - /** * Add data of given length to the buffer. */ @@ -373,13 +365,6 @@ void strbuf_humanise_rate(struct strbuf *buf, off_t bytes); __attribute__((format (printf,2,3))) void strbuf_addf(struct strbuf *sb, const char *fmt, ...); -/** - * Add a formatted string prepended by a comment character and a - * blank to the buffer. - */ -__attribute__((format (printf, 2, 3))) -void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...); - __attribute__((format (printf,2,0))) void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);