From patchwork Mon May 8 16:59:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13234766 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C705C77B75 for ; Mon, 8 May 2023 16:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233551AbjEHQ7n (ORCPT ); Mon, 8 May 2023 12:59:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbjEHQ7l (ORCPT ); Mon, 8 May 2023 12:59:41 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 016554EFB for ; Mon, 8 May 2023 09:59:41 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1aafa03f55aso26070695ad.2 for ; Mon, 08 May 2023 09:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683565180; x=1686157180; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+dLUhuF6uOKYAoZSfwaPr08LEFMr3AKQHlQqMsgFWks=; b=2rCdO1PKDUJ94pjVJ2JPq5gDocNNQW2gL+05bdbKzp1CaoXN0TQA4fWs/uxxChsPYp 8DuPgFqA595QjX271Dx1ud9MENH7ZKWJuq7aGZIhTaDh3WKdd2Tj79J2kKlA0UyC+PSS CP8JefNJg/w0OV7aAdu13heeD/6yf5iuW3Ne5s+j12t7iXP8ZlxEHdIMUXgU/jTzRP0Z JCCc7+RXqwoCtYnkJ+HMaPtydBoN/ANWWtXgianed44zP6tMJq/tRhMkJMnAzV+mPOql 2JIrlDzfOGdKhVwGbEOzh2UYpgr7tP4J6cmZJxcRVJHGxlbQ/CeHmubj67px9uiFagFt DCaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683565180; x=1686157180; 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=+dLUhuF6uOKYAoZSfwaPr08LEFMr3AKQHlQqMsgFWks=; b=Bk5TBwvvUF6JzCBC46y8lZPOmqvvg/4wolKHGY6Ekit8H/XWnReuIkj6eDrBEPRQDA X2/4Rvd9BTqfIIDAWTmnuJ5Ms6tZYN2LYlYFmeMbLV2GDwJkJ0l95zSYUviNOYH9Nyy4 FgO8Al/qv+cA8L6LmwW6AMFaF6GrZTBTeDdObihsnrufTxi/9t3FRniXEclj8G4YZVY0 uBW73U77ysTQTpK7eu9MnfdN7JDlKkoaodaJ+FRjedFwcKwCB4EfD8dYfzTqbe8sc+gJ L6zW/hETr/VM8AA0VC0YdvvhXaGX7mF3goWuTQISmeSH8HKyAkOZ2R/vD+D+xuHBpVX2 ggwg== X-Gm-Message-State: AC+VfDzZaOFGwDHRBy+Ms5gishSPp1liy4PvqdDpdrRuMcEPw2eB/fxB RSBP9W+Xksy/xi5H9rBHKHt/FKUfpNEncMA++YGAQS9kkclNKpCwXbocZDCjUUZkS5g9uNztgyi 4p54AKh9nEvzRfJuR5oQM9Omr0fDWA1vgz0MgkyGpQexpa5CgL8clafsP5zUrPZ94qw== X-Google-Smtp-Source: ACHHUZ4hRz2icClf3P7VOpkgNNF1rmdD1ShUwoG1NFs/yWd94ADT1S719vgrr1RaWsJKcnEEldytMKq3ptfK8XQ= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:902:bf4c:b0:1ac:6b92:6609 with SMTP id u12-20020a170902bf4c00b001ac6b926609mr2091755pls.1.1683565180319; Mon, 08 May 2023 09:59:40 -0700 (PDT) Date: Mon, 8 May 2023 16:59:02 +0000 In-Reply-To: <20230508165728.525603-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230508165728.525603-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508165908.526247-1-calvinwan@google.com> Subject: [PATCH v4 1/7] strbuf: clarify API boundary From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , newren@gmail.com, peff@peff.net Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org strbuf, as a generic and widely used structure across the codebase, should be limited as a libary to only interact with primitives. Add documentation so future functions can be appropriately be placed. Older functions that do not follow this boundary should eventually be moved or refactored. Signed-off-by: Calvin Wan --- strbuf.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/strbuf.h b/strbuf.h index 3dfeadb44c..c856253216 100644 --- a/strbuf.h +++ b/strbuf.h @@ -5,7 +5,11 @@ struct string_list; /** * strbuf's are meant to be used with all the usual C string and memory - * APIs. Given that the length of the buffer is known, it's often better to + * APIs. The objects that this API interacts with in this file should be + * limited to other primitives, however, there are older functions in here + * that should eventually be moved out or refactored. + * + * Given that the length of the buffer is known, it's often better to * use the mem* functions than a str* one (memchr vs. strchr e.g.). * Though, one has to be careful about the fact that str* functions often * stop on NULs and that strbufs may have embedded NULs. From patchwork Mon May 8 16:59:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13234769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACC84C77B7F for ; Mon, 8 May 2023 16:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234285AbjEHQ7z (ORCPT ); Mon, 8 May 2023 12:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234297AbjEHQ7o (ORCPT ); Mon, 8 May 2023 12:59:44 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B11B2524D for ; Mon, 8 May 2023 09:59:42 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-643fdfb437aso10514238b3a.0 for ; Mon, 08 May 2023 09:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683565182; x=1686157182; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=a3nA1Gf6EnaLJwm6AKTzmrj6aA+OW6tp9MViR7k3kZI=; b=jmN6lIupUOwzhgE0OaN56owYXSiXK7Fp6dYQl4qveNOxd/thAzgjvyzGIjRDxuJzVF WH739g9c+wC0W0oWBb7o1gE0HzGc22wa9WFi2Thqt3XfKY2w85js5RcdIn+E/GSOqB1N lceGRo5XoI8eDa5EEJI5XbLfCSTnYtWxV1nwV3XzxBkcSN+deg4uDvGHnmC5wEanZ0fQ oPeh1BjyTAYX9lgemqxBRKIQFd2NvqiTnkgMNixnEM7vplEgyMQCnHShC8vZETJMCKyX LrRgLXI+jc9blNDwgiQH85o8nHmpPdC8cWc/VSxGZMqF56Q9AlfOzjtrcsURqhkJRdyZ Wrig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683565182; x=1686157182; 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=a3nA1Gf6EnaLJwm6AKTzmrj6aA+OW6tp9MViR7k3kZI=; b=cJg0m/0eyUt8p+nigh7B8twGQiaAuSzsI76MJlM7T5/lZLNZgk++TltvEovr+PitI1 PoaC298DKlmvl0niZTMLkc/Y6RjP7MsmBS+VjkWm3S9goLLlOLwG/91b3LXcfZnKOTns 3gZH5mQ9FwDvdCwyRNTijavKjGtlrOzsmlpiTBxkePeRaDwsRXnVLqU+xVxdaLqgXEqI nxXCooaO3zt+Jf7tblnd8V+Rpd03Qod5JBichG5oppvJuiUZ8IW69T8402eS+rw9FYOj QGLYVAnPo+UGbBjetA91KcMKDzd3I0EhmGqn+zTeoKacaYvmvG4onPQyEDkg4emOpIlU NzHA== X-Gm-Message-State: AC+VfDw2pjTS126ayILOAENRUd0wgycqdHBswzzZS4VDBEwBJCbaNymk lFN81vwovfQJz9DZvfA57ngc9lHLGWzOvPK2uEYV79NLqg4bYB/Sm6JKaHElbGE9OWWT0XHQeX9 GBxyCWDaKzZ+hthIkWIpa1zQkti5P/XPHafyTaglwJ/Y9L9NrvaoENIuDXuzyjJYRdQ== X-Google-Smtp-Source: ACHHUZ6bqHMdUzh2iOgbWaj9rO2jqdGv55r+lnP74EA0nJEVMube+WcGa+uO69UWws/XGQovmW5bGW0rQ4uyqWc= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a05:6a00:478a:b0:643:b8b1:b3f5 with SMTP id dh10-20020a056a00478a00b00643b8b1b3f5mr2686002pfb.3.1683565182162; Mon, 08 May 2023 09:59:42 -0700 (PDT) Date: Mon, 8 May 2023 16:59:03 +0000 In-Reply-To: <20230508165728.525603-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230508165728.525603-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508165908.526247-2-calvinwan@google.com> Subject: [PATCH v4 2/7] abspath: move related functions to abspath From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , newren@gmail.com, peff@peff.net Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move abspath-related functions from strbuf.[ch] to abspath.[ch] so that strbuf is focused on string manipulation routines with minimal dependencies. Signed-off-by: Calvin Wan --- abspath.c | 36 ++++++++++++++++++++++++++++++++++++ abspath.h | 21 +++++++++++++++++++++ hook.c | 1 + strbuf.c | 37 ------------------------------------- strbuf.h | 22 ---------------------- tempfile.c | 1 + 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/abspath.c b/abspath.c index d032f5dce5..1202cde23d 100644 --- a/abspath.c +++ b/abspath.c @@ -289,3 +289,39 @@ char *prefix_filename_except_for_dash(const char *pfx, const char *arg) return xstrdup(arg); return prefix_filename(pfx, arg); } + +void strbuf_add_absolute_path(struct strbuf *sb, const char *path) +{ + if (!*path) + die("The empty string is not a valid path"); + if (!is_absolute_path(path)) { + struct stat cwd_stat, pwd_stat; + size_t orig_len = sb->len; + char *cwd = xgetcwd(); + char *pwd = getenv("PWD"); + if (pwd && strcmp(pwd, cwd) && + !stat(cwd, &cwd_stat) && + (cwd_stat.st_dev || cwd_stat.st_ino) && + !stat(pwd, &pwd_stat) && + pwd_stat.st_dev == cwd_stat.st_dev && + pwd_stat.st_ino == cwd_stat.st_ino) + strbuf_addstr(sb, pwd); + else + strbuf_addstr(sb, cwd); + if (sb->len > orig_len && !is_dir_sep(sb->buf[sb->len - 1])) + strbuf_addch(sb, '/'); + free(cwd); + } + strbuf_addstr(sb, path); +} + +void strbuf_add_real_path(struct strbuf *sb, const char *path) +{ + if (sb->len) { + struct strbuf resolved = STRBUF_INIT; + strbuf_realpath(&resolved, path, 1); + strbuf_addbuf(sb, &resolved); + strbuf_release(&resolved); + } else + strbuf_realpath(sb, path, 1); +} diff --git a/abspath.h b/abspath.h index 7cd3de5e9d..4653080d5e 100644 --- a/abspath.h +++ b/abspath.h @@ -30,4 +30,25 @@ static inline int is_absolute_path(const char *path) return is_dir_sep(path[0]) || has_dos_drive_prefix(path); } +/** + * Add a path to a buffer, converting a relative path to an + * absolute one in the process. Symbolic links are not + * resolved. + */ +void strbuf_add_absolute_path(struct strbuf *sb, const char *path); + +/** + * Canonize `path` (make it absolute, resolve symlinks, remove extra + * slashes) and append it to `sb`. Die with an informative error + * message if there is a problem. + * + * The directory part of `path` (i.e., everything up to the last + * dir_sep) must denote a valid, existing directory, but the last + * component need not exist. + * + * Callers that don't mind links should use the more lightweight + * strbuf_add_absolute_path() instead. + */ +void strbuf_add_real_path(struct strbuf *sb, const char *path); + #endif /* ABSPATH_H */ diff --git a/hook.c b/hook.c index 76e322f580..2d8706371e 100644 --- a/hook.c +++ b/hook.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "abspath.h" #include "advice.h" #include "gettext.h" #include "hook.h" diff --git a/strbuf.c b/strbuf.c index 729378ec82..c3b6d48797 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,5 +1,4 @@ #include "git-compat-util.h" -#include "abspath.h" #include "alloc.h" #include "environment.h" #include "gettext.h" @@ -899,42 +898,6 @@ void strbuf_humanise_rate(struct strbuf *buf, off_t bytes) strbuf_humanise(buf, bytes, 1); } -void strbuf_add_absolute_path(struct strbuf *sb, const char *path) -{ - if (!*path) - die("The empty string is not a valid path"); - if (!is_absolute_path(path)) { - struct stat cwd_stat, pwd_stat; - size_t orig_len = sb->len; - char *cwd = xgetcwd(); - char *pwd = getenv("PWD"); - if (pwd && strcmp(pwd, cwd) && - !stat(cwd, &cwd_stat) && - (cwd_stat.st_dev || cwd_stat.st_ino) && - !stat(pwd, &pwd_stat) && - pwd_stat.st_dev == cwd_stat.st_dev && - pwd_stat.st_ino == cwd_stat.st_ino) - strbuf_addstr(sb, pwd); - else - strbuf_addstr(sb, cwd); - if (sb->len > orig_len && !is_dir_sep(sb->buf[sb->len - 1])) - strbuf_addch(sb, '/'); - free(cwd); - } - strbuf_addstr(sb, path); -} - -void strbuf_add_real_path(struct strbuf *sb, const char *path) -{ - if (sb->len) { - struct strbuf resolved = STRBUF_INIT; - strbuf_realpath(&resolved, path, 1); - strbuf_addbuf(sb, &resolved); - strbuf_release(&resolved); - } else - strbuf_realpath(sb, path, 1); -} - int printf_ln(const char *fmt, ...) { int ret; diff --git a/strbuf.h b/strbuf.h index c856253216..20d0e37d9c 100644 --- a/strbuf.h +++ b/strbuf.h @@ -531,28 +531,6 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term); */ int strbuf_getcwd(struct strbuf *sb); -/** - * Add a path to a buffer, converting a relative path to an - * absolute one in the process. Symbolic links are not - * resolved. - */ -void strbuf_add_absolute_path(struct strbuf *sb, const char *path); - -/** - * Canonize `path` (make it absolute, resolve symlinks, remove extra - * slashes) and append it to `sb`. Die with an informative error - * message if there is a problem. - * - * The directory part of `path` (i.e., everything up to the last - * dir_sep) must denote a valid, existing directory, but the last - * component need not exist. - * - * Callers that don't mind links should use the more lightweight - * strbuf_add_absolute_path() instead. - */ -void strbuf_add_real_path(struct strbuf *sb, const char *path); - - /** * Normalize in-place the path contained in the strbuf. See * normalize_path_copy() for details. If an error occurs, the contents of "sb" diff --git a/tempfile.c b/tempfile.c index 50c377134c..6c88a63b42 100644 --- a/tempfile.c +++ b/tempfile.c @@ -43,6 +43,7 @@ */ #include "git-compat-util.h" +#include "abspath.h" #include "path.h" #include "tempfile.h" #include "sigchain.h" From patchwork Mon May 8 16:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13234767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DF7FC77B75 for ; Mon, 8 May 2023 16:59:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233771AbjEHQ7x (ORCPT ); Mon, 8 May 2023 12:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234341AbjEHQ7p (ORCPT ); Mon, 8 May 2023 12:59:45 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F0F5261 for ; Mon, 8 May 2023 09:59:44 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-645538f6101so8724702b3a.1 for ; Mon, 08 May 2023 09:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683565184; x=1686157184; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/R0a/kHnyx4o9/HChG7nHUd642uhvmHNwkgsegQmtY8=; b=qxMJZHHe+qGOTEBO88Jf8C1D1fIbyvpK4W7+hpdvp13nju3gqV70UKra4umJRc/DSC HLmTcFgcuf+AyjvoXhLoQrjrJ2DcH6/KvIapDeLyhyHuhtBVImI37ECdwxsHq9sQ6sS5 95AzFPN2mi5NfI4+WWOY1ej3iq/b/uU29eyA/hAzpuNLpuu+SSfKcpvfwSNkUmnYaEaq 8t//82oMHEKBIZsT6T7Z65WVuLAX4xE7GFH1luxRhur5e1A1mXhQ3u+I/qVcWd0DGpYH MS98XULDT9qelkSweSxzEvzh7iLOx4s7qVHnSblfYGz+Qbtm89C7vFt/C9hJo9Yfxljr TbLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683565184; x=1686157184; 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=/R0a/kHnyx4o9/HChG7nHUd642uhvmHNwkgsegQmtY8=; b=PbOAws4WHmiO3z/bhI9fiobYTn6/XI7fsiqtZFErcpWE8eH0f4qJogEI/eHxzg/sAt 1iKiIH23h+DhTY/yFkwW+n0i7HI7k9YfPPrY6UmBaAKuFTBS8rEJ1RdPhPDfRteRbM7s kfZbHvBc+S6N0KC8SVr96SBfOemSqpMVtAXwKTjkhHtMJ5g6hpYtehtagQjY0sZf+8lO l5IaU7pN2hsfg5+p4d2Lzpn5FfH8y3q0LscPB/SNTKV5NKwtsqmJj4ovG0/PV/WifyJP ua0X6TpPkORWqvlmDecwt0mbLlSpz5IrDiKvlwpC6Hiqqy+kU0NnyU9EKqxiRy7T7QnV mfxg== X-Gm-Message-State: AC+VfDyR3m9z2XsjzibPiNh1sqQizUA54WuMHjiC9658hNR4FA6T/OCz q7AHjZ2qjW8+JCL08pgBH7YxoV0Pj5In7xwGn8z8xzf16zGsg42hIcm5ZcM0ykC2F18Fwv8dQ+D haXzyp31E5eMqpRPi/uyNed1qQMxT6dW/CrkU2KcZplVbGpOk/8tXJduPqUUkk1SeRQ== X-Google-Smtp-Source: ACHHUZ7s4EB3BeiXTA5R+mXa0KfwLq8XQFGBqBuKx0g6FRN88Pxzn9LbjDRZxhrsw6Usb6603vNHORDLSMZbuB0= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:90b:885:b0:24e:403d:4882 with SMTP id bj5-20020a17090b088500b0024e403d4882mr4023050pjb.3.1683565183757; Mon, 08 May 2023 09:59:43 -0700 (PDT) Date: Mon, 8 May 2023 16:59:04 +0000 In-Reply-To: <20230508165728.525603-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230508165728.525603-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508165908.526247-3-calvinwan@google.com> Subject: [PATCH v4 3/7] credential-store: move related functions to credential-store file From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , newren@gmail.com, peff@peff.net Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org is_rfc3986_unreserved() and is_rfc3986_reserved_or_unreserved() are only called from builtin/credential-store.c and they are only relevant to that file so move those functions and make them static. Signed-off-by: Calvin Wan --- builtin/credential-store.c | 19 +++++++++++++++++++ strbuf.c | 19 ------------------- strbuf.h | 3 --- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/builtin/credential-store.c b/builtin/credential-store.c index 8977604eb9..4776118331 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -73,6 +73,25 @@ static void rewrite_credential_file(const char *fn, struct credential *c, die_errno("unable to write credential store"); } +static int is_rfc3986_unreserved(char ch) +{ + return isalnum(ch) || + ch == '-' || ch == '_' || ch == '.' || ch == '~'; +} + +static int is_rfc3986_reserved_or_unreserved(char ch) +{ + if (is_rfc3986_unreserved(ch)) + return 1; + switch (ch) { + case '!': case '*': case '\'': case '(': case ')': case ';': + case ':': case '@': case '&': case '=': case '+': case '$': + case ',': case '/': case '?': case '#': case '[': case ']': + return 1; + } + return 0; +} + static void store_credential_file(const char *fn, struct credential *c) { struct strbuf buf = STRBUF_INIT; diff --git a/strbuf.c b/strbuf.c index c3b6d48797..da2693b21f 100644 --- a/strbuf.c +++ b/strbuf.c @@ -809,25 +809,6 @@ void strbuf_addstr_xml_quoted(struct strbuf *buf, const char *s) } } -int is_rfc3986_reserved_or_unreserved(char ch) -{ - if (is_rfc3986_unreserved(ch)) - return 1; - switch (ch) { - case '!': case '*': case '\'': case '(': case ')': case ';': - case ':': case '@': case '&': case '=': case '+': case '$': - case ',': case '/': case '?': case '#': case '[': case ']': - return 1; - } - return 0; -} - -int is_rfc3986_unreserved(char ch) -{ - return isalnum(ch) || - ch == '-' || ch == '_' || ch == '.' || ch == '~'; -} - static void strbuf_add_urlencode(struct strbuf *sb, const char *s, size_t len, char_predicate allow_unencoded_fn) { diff --git a/strbuf.h b/strbuf.h index 20d0e37d9c..9e52fe7706 100644 --- a/strbuf.h +++ b/strbuf.h @@ -686,9 +686,6 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name); typedef int (*char_predicate)(char ch); -int is_rfc3986_unreserved(char ch); -int is_rfc3986_reserved_or_unreserved(char ch); - void strbuf_addstr_urlencode(struct strbuf *sb, const char *name, char_predicate allow_unencoded_fn); From patchwork Mon May 8 16:59:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13234770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A4D3C7EE24 for ; Mon, 8 May 2023 16:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234351AbjEHQ75 (ORCPT ); Mon, 8 May 2023 12:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234372AbjEHQ7r (ORCPT ); Mon, 8 May 2023 12:59:47 -0400 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 3B30E524D for ; Mon, 8 May 2023 09:59:46 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-552f2f940edso87884437b3.0 for ; Mon, 08 May 2023 09:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683565185; x=1686157185; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zkqwa7L1/kR0+Cc4PcW8itO6Z+BruXGvlxCg7pCNvQI=; b=fIZ8WlrjsN7QNAVzzFjq7r83q39Z4fNXo2XBYB4ohtZPwDu/x/reV8OUbGAE659pwJ 28Hh8RY0pifRkOpvDtDJ1mtIM3bM3MfESsLU2LlmsBg3GskSqy+uSvuGcF7v3nprL32D qboVZR4ymjYI60TJMJWcXxEe3yQD6v0E1szglzZRP9xBQFR0byGY5gxBkLLgt9gmaOrD H872bM3MoVu1sNEmGPBdBVOsyyycWR8cSwKTX9wQVCzbq+v1oiRn898XLo5s3yomr/Tk GYCAGmC/UWhV4QFBOO3cY+kQrleyMvxZEtkwmLAwO6nZxPpBp9QYVTTV7yr0i78jdXg7 zixw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683565185; x=1686157185; 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=zkqwa7L1/kR0+Cc4PcW8itO6Z+BruXGvlxCg7pCNvQI=; b=NPBUneiVFZCo81FI5YCWZj339xouCZ7LIxNZ6yLmxtWKONzTG4REH6V/ISoLV0KZUn S/rzAVHqp/KeD071Hl32cnF1RSVZJES3wx6JjgFF68cW718RsFICrrNQZefgW0tDSDJO iRKozdNKpMZlKGrrn8Sn7GTWgJZc1TDVYrMSb0T2icbkD0gE8M3c//siMk9OLGHPfmE5 hR16iTZ4FsmIYcN6Ljp0qEEnFQ+6GGUBLX1Yo504eMPSjUKAScX9+I/adoA4jSPSFIN+ mNDkuly9aJnI9in+CyIyteZ9+6mMZmn8RTSMAl1CNkAlOHmaEN33VZghCDmNaIHydW4g f2rA== X-Gm-Message-State: AC+VfDzzym+QcHvrtSMAAavEWZ7oJMwaloy2b0H8Shn59xrGJ5wB0TEn 8A9x7/IKuuHSpTG72a0Rc9nggyqm/AzMZCGn3V4jawTVQqDncHLDWcgWTce0DElD3lQTs8KJ3mc uojzI8sQFsGM8/Xw1g1dmBVa+Tg/lFBHGHuiMuzz2oZ9EtUdGA9LJx2bIc+jDK/WB8w== X-Google-Smtp-Source: ACHHUZ5VaZ0wYpxOJG8u6GqbzenojDjXCG3kcyg85fTEYwl8NDnhgahDmMQ/kRM6QwblJSVSFyJX9gfUADv4U7w= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a81:ca49:0:b0:55d:9484:f153 with SMTP id y9-20020a81ca49000000b0055d9484f153mr6604807ywk.7.1683565185369; Mon, 08 May 2023 09:59:45 -0700 (PDT) Date: Mon, 8 May 2023 16:59:05 +0000 In-Reply-To: <20230508165728.525603-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230508165728.525603-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508165908.526247-4-calvinwan@google.com> Subject: [PATCH v4 4/7] object-name: move related functions to object-name From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , newren@gmail.com, peff@peff.net Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move object-name-related functions from strbuf.[ch] to object-name.[ch] so that strbuf is focused on string manipulation routines with minimal dependencies. Signed-off-by: Calvin Wan --- object-name.c | 15 +++++++++++++++ object-name.h | 9 +++++++++ pretty.c | 1 + strbuf.c | 16 ---------------- strbuf.h | 10 ---------- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/object-name.c b/object-name.c index 538e8a8f62..c2e82aceea 100644 --- a/object-name.c +++ b/object-name.c @@ -766,6 +766,21 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad) find_abbrev_len_for_pack(p, mad); } +void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo, + const struct object_id *oid, int abbrev_len) +{ + int r; + strbuf_grow(sb, GIT_MAX_HEXSZ + 1); + r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len); + strbuf_setlen(sb, sb->len + r); +} + +void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, + int abbrev_len) +{ + strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len); +} + int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len) { diff --git a/object-name.h b/object-name.h index 1d63698f42..9ae5223071 100644 --- a/object-name.h +++ b/object-name.h @@ -40,6 +40,15 @@ struct object_context { const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len); int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); +/** + * Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to + * the strbuf `sb`. + */ +void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo, + const struct object_id *oid, int abbrev_len); +void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, + int abbrev_len); + int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); __attribute__((format (printf, 2, 3))) int get_oidf(struct object_id *oid, const char *fmt, ...); diff --git a/pretty.c b/pretty.c index 0bb938021b..78bac2d818 100644 --- a/pretty.c +++ b/pretty.c @@ -18,6 +18,7 @@ #include "gpg-interface.h" #include "trailer.h" #include "run-command.h" +#include "object-name.h" /* * The limit for formatting directives, which enable the caller to append diff --git a/strbuf.c b/strbuf.c index da2693b21f..6533559e95 100644 --- a/strbuf.c +++ b/strbuf.c @@ -3,7 +3,6 @@ #include "environment.h" #include "gettext.h" #include "hex.h" -#include "object-name.h" #include "refs.h" #include "string-list.h" #include "utf8.h" @@ -1023,21 +1022,6 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm, strbuf_setlen(sb, sb->len + len); } -void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo, - const struct object_id *oid, int abbrev_len) -{ - int r; - strbuf_grow(sb, GIT_MAX_HEXSZ + 1); - r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len); - strbuf_setlen(sb, sb->len + r); -} - -void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, - int abbrev_len) -{ - strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len); -} - /* * Returns the length of a line, without trailing spaces. * diff --git a/strbuf.h b/strbuf.h index 9e52fe7706..1bae7e0f47 100644 --- a/strbuf.h +++ b/strbuf.h @@ -612,16 +612,6 @@ void strbuf_add_separated_string_list(struct strbuf *str, */ void strbuf_list_free(struct strbuf **list); -/** - * Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to - * the strbuf `sb`. - */ -struct repository; -void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo, - const struct object_id *oid, int abbrev_len); -void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, - int abbrev_len); - /* * Remove the filename from the provided path string. If the path * contains a trailing separator, then the path is considered a directory From patchwork Mon May 8 16:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13234768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4BA5C7EE24 for ; Mon, 8 May 2023 16:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234278AbjEHQ7y (ORCPT ); Mon, 8 May 2023 12:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233648AbjEHQ7u (ORCPT ); Mon, 8 May 2023 12:59:50 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE7D75FE2 for ; Mon, 8 May 2023 09:59:48 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba2b9ecf90aso3012328276.1 for ; Mon, 08 May 2023 09:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683565188; x=1686157188; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MEQNl5dMg2xRh6C9SxOl+it4k4XCRhsP1yoUSnxmOcI=; b=FBn4rILQqlvGsc/n6x+6o/L/PBiC35XE1BCwY2PDYd5vWhItRrcIKuHfqcqsS4R/pp qXQn73Pp7p6GHfoIrtpqa2Z/Q3uji80P8DPdUo8M/Re1Pq02rpqr4j3PgB5jOH3rI9EW QlIGljjIq9WYeRLBSn20g8+0ei6QYMQy3WAuajs2isyWJvPx/tuC8brCMrrUxHp89hXY VoKSfthMJpmu5ePJa5FiliEYnU17R05KUmeyKjILIE1dz/k9J11fvmbWFUUUJRvZDjnS MWOGvho1W7BtmXjnwyZGb3IWf+3bmAcDJFxWyweQC6dXres8LjygOFvRplZxrQSTTSBU kJ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683565188; x=1686157188; 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=MEQNl5dMg2xRh6C9SxOl+it4k4XCRhsP1yoUSnxmOcI=; b=Wzy6qHgi6VRIYWDMMh3lDaxf6oH8jiY5gWcJTA9SFDcFh1O25Toeq+mEcEnWXWroZb 4Bt3XRzXbXneuvGs1ZO47W9cUg9ejYSJneshjlwCW/vLmnJaQmHfoUEn7Cy9x4LtVx9T f3/7Ng1CByqrZYVDZW/WQqnZXwcNdNH6PmNG8kSTKWswRI3t+fhNFleFaUKCH0Ec7+pl V7DBNYW5Oc73rUxOw+iSQewLw2wltg6J8btvAlKtM8NZOKtjdA6XkxuePO963+1MVp0P yMhhk35Sgws8YDgNqHTJc52pGlemVdGgUtPfGZaoLxJMW0iFf2kO8f0QOwOLoN291Ajz LsHQ== X-Gm-Message-State: AC+VfDyWXIhPApcIzMOAmv/w94bOCt6zFPj4AIqx7ZaNUIbE9vipecc+ Wd/c9qKHxsCAev9A8hO2XZjHGwh5ClaK0RQ5rvqNOwUOW8Z0ejlUc5G1SvM3O0mIH1XFZh/qBMG mY8Ovmip2YF+ai4f/oE1gv/8msj41rP4Y7rSNQ/xtGQoskE82onBKIGzj2ugycR4gbw== X-Google-Smtp-Source: ACHHUZ6pwzAP1rfYT1I3boOB0He43Q5tqc7OoGtoNJtP/QnpMcdOre3vixhAd/QyuRVMIsFH6lSAkwyuOvJc9yA= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a25:9bc1:0:b0:b9d:b399:64b0 with SMTP id w1-20020a259bc1000000b00b9db39964b0mr6806250ybo.10.1683565188152; Mon, 08 May 2023 09:59:48 -0700 (PDT) Date: Mon, 8 May 2023 16:59:06 +0000 In-Reply-To: <20230508165728.525603-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230508165728.525603-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508165908.526247-5-calvinwan@google.com> Subject: [PATCH v4 5/7] path: move related function to path From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , newren@gmail.com, peff@peff.net Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move path-related function from strbuf.[ch] to path.[ch] so that strbuf is focused on string manipulation routines with minimal dependencies. Signed-off-by: Calvin Wan --- path.c | 20 ++++++++++++++++++++ path.h | 5 +++++ strbuf.c | 20 -------------------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/path.c b/path.c index 7c1cd8182a..e17a2613c5 100644 --- a/path.c +++ b/path.c @@ -1213,6 +1213,26 @@ int normalize_path_copy(char *dst, const char *src) return normalize_path_copy_len(dst, src, NULL); } +int strbuf_normalize_path(struct strbuf *src) +{ + struct strbuf dst = STRBUF_INIT; + + strbuf_grow(&dst, src->len); + if (normalize_path_copy(dst.buf, src->buf) < 0) { + strbuf_release(&dst); + return -1; + } + + /* + * normalize_path does not tell us the new length, so we have to + * compute it by looking for the new NUL it placed + */ + strbuf_setlen(&dst, strlen(dst.buf)); + strbuf_swap(src, &dst); + strbuf_release(&dst); + return 0; +} + /* * path = Canonical absolute path * prefixes = string_list containing normalized, absolute paths without diff --git a/path.h b/path.h index 60e83a49a9..639372edd9 100644 --- a/path.h +++ b/path.h @@ -191,6 +191,11 @@ const char *remove_leading_path(const char *in, const char *prefix); const char *relative_path(const char *in, const char *prefix, struct strbuf *sb); int normalize_path_copy_len(char *dst, const char *src, int *prefix_len); int normalize_path_copy(char *dst, const char *src); +/** + * Normalize in-place the path contained in the strbuf. If an error occurs, + * the contents of "sb" are left untouched, and -1 is returned. + */ +int strbuf_normalize_path(struct strbuf *src); int longest_ancestor_length(const char *path, struct string_list *prefixes); char *strip_path_suffix(const char *path, const char *suffix); int daemon_avoid_alias(const char *path); diff --git a/strbuf.c b/strbuf.c index 6533559e95..178d75f250 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1088,26 +1088,6 @@ void strbuf_stripspace(struct strbuf *sb, int skip_comments) strbuf_setlen(sb, j); } -int strbuf_normalize_path(struct strbuf *src) -{ - struct strbuf dst = STRBUF_INIT; - - strbuf_grow(&dst, src->len); - if (normalize_path_copy(dst.buf, src->buf) < 0) { - strbuf_release(&dst); - return -1; - } - - /* - * normalize_path does not tell us the new length, so we have to - * compute it by looking for the new NUL it placed - */ - strbuf_setlen(&dst, strlen(dst.buf)); - strbuf_swap(src, &dst); - strbuf_release(&dst); - return 0; -} - void strbuf_strip_file_from_path(struct strbuf *sb) { char *path_sep = find_last_dir_sep(sb->buf); From patchwork Mon May 8 16:59:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13234771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37018C77B7F for ; Mon, 8 May 2023 17:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234380AbjEHQ77 (ORCPT ); Mon, 8 May 2023 12:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234320AbjEHQ7w (ORCPT ); Mon, 8 May 2023 12:59:52 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E10659E2 for ; Mon, 8 May 2023 09:59:50 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9a25f6aa0eso9115458276.1 for ; Mon, 08 May 2023 09:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683565189; x=1686157189; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mWG/+S0pEkG9Rcz9k61ni3HDuVyEZnHiCAyEi7lI+0Q=; b=UNTOGk+yiueZ0RsSvzmqrw/CqjE2FBjhrYBvG+T/RiK0gauWTNnCemPgcvFYXn4B+d P9j8dRkqyK5lYenO5UwSvl2g9uHAVGbukhQhl5FJYD2CSAS4rpzftAYl+hoFuB+VKkQd OCLXzREqSkwlpUAj7KiZzqTasfsnUnT7lBBHW5blLNLxi9YWlEGL5YN7O7v8A4cTBzBk QqXytE/0obvxspQIwwjNLL7SKqSeDD3eAzZr7M6NLvzA1n6jdkb+SEGvjCmB8NlnrE30 Fou/oip8zD96402VXsznlSavwGsf69PlY7Sk1FxFwFHkHKSQ4fkTi6Rq+E1MLwJTQ41v fUsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683565189; x=1686157189; 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=mWG/+S0pEkG9Rcz9k61ni3HDuVyEZnHiCAyEi7lI+0Q=; b=eFZUll2Y6DHNukjaDfLFxS0mGbkzcp0Q5I1EfwiCPZ9qyb7rhkLS8svak1F6IIVM1D Kb3GWoe8QIaB6HAxNtaLVPw9Nzdk8BMi1o7FawZ/oB1eq1hTB6ls0XOf/m9NlWo2S4KQ NNt7tlOuqnJylehXx5jifdLoidusCvMomCAowoK6Z1xPzLzFXFNPR6m6c8h2dtyAFuVE uBarvYPS3fnkAg4eOCiwkJjRwJsLEE19hJun0WK9KwldzgfWe7QsjbELkaVh+zPzRjfg lv9PoBRJgpSkmnZ8iTLCrESMNECIIXbnPXfJbD07OqXu0RJzGBRgtJdT5QhJvykqlOd1 bCLw== X-Gm-Message-State: AC+VfDyZs5djB5Tun5osljbvITQStNRgu3dFyybhD5UstHgQA2z354Dk d2f4H9Vl/vcmT1HP2gApXqIL6p+kbHXjlKuhR77awR04Ye8w/iclI8Sk8/J8TQN4E28hYhyo8ui Ddb59CUyfpgbPEYq7nIcxtScET9HhgESiODvsWmBGvCZtaI7JYKqtWfoKy2MuEW03kA== X-Google-Smtp-Source: ACHHUZ6HpI0mWb7nz2agd//yTYH5OP7MqZrWl7rr8arWTkx/5UmLjWRQgnsbUoqNdbV3yUXgSkiNBrNFBdhYsfs= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a25:1bd4:0:b0:997:c919:4484 with SMTP id b203-20020a251bd4000000b00997c9194484mr4745571ybb.6.1683565189650; Mon, 08 May 2023 09:59:49 -0700 (PDT) Date: Mon, 8 May 2023 16:59:07 +0000 In-Reply-To: <20230508165728.525603-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230508165728.525603-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508165908.526247-6-calvinwan@google.com> Subject: [PATCH v4 6/7] strbuf: clarify dependency From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , newren@gmail.com, peff@peff.net Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org refs.h was once needed but is no longer so as of 6bab74e7fb8 ("strbuf: move strbuf_branchname to sha1_name.c", 2010-11-06). strbuf.h was included thru refs.h, so removing refs.h requires strbuf.h to be added back. Signed-off-by: Calvin Wan --- strbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strbuf.c b/strbuf.c index 178d75f250..d5978fee4e 100644 --- a/strbuf.c +++ b/strbuf.c @@ -3,7 +3,7 @@ #include "environment.h" #include "gettext.h" #include "hex.h" -#include "refs.h" +#include "strbuf.h" #include "string-list.h" #include "utf8.h" #include "date.h" From patchwork Mon May 8 16:59:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13234772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1B65C7EE24 for ; Mon, 8 May 2023 17:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234301AbjEHRAD (ORCPT ); Mon, 8 May 2023 13:00:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234338AbjEHQ74 (ORCPT ); Mon, 8 May 2023 12:59:56 -0400 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 8E60E5262 for ; Mon, 8 May 2023 09:59:53 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-55a37bf6fd0so84450187b3.2 for ; Mon, 08 May 2023 09:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683565193; x=1686157193; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yJePqKOh+yzC/KOjjx/+VVX0dcON5kd5U5cVUztbGos=; b=nijR3yZ1vURhZBVRr+HTWJMYyIXnaJiHnNaCRQ1nnoBOBIY5PF3brjqmO53yKKVks0 Uwz6YR32BaT4NVckSavVJHfzLOnoYX9UcEdXZG/n+n1m3BNGEh8zVMvddUCGq1ljqgmU wzCm5JwEDy5ipspRs5lL6mcotRejC0b1VcIWCyvZ1csQx27pGVbONDRA4Flk2lpvhEep DeBSvVr7WAvZTpssMOXf+pqOQOQrzgzEw5eJoRmbWJsQKrGGC0DR/lM15kwF67yP6nX9 WfurkjQnNwN6aR2y4TYnnDDOhjRg2LS3x8yoNI2uZBgh8YuSv20oLw31mHEZTwVoQ0t/ Y/Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683565193; x=1686157193; 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=yJePqKOh+yzC/KOjjx/+VVX0dcON5kd5U5cVUztbGos=; b=OqWHIVFK3JBaTU9clVMsVCIkGk2uRs+3fZJVbl03fq5GVFiR9UcnNiKHVXXEU4mj5H /BSNRQEDxKZFZPOLyE3t5JVRVmiuxl/UkKEO4KaEYLIOAudtiYkCkRlj9hM8d4rbnV7e nTWl+wx3hCnE+Zci17ypV86Fc+Yhvdwd8/NIIkrs/kZE2bcTZbwghTLNId/DM9Cm324u GzWu4Fi0w5m8LxnbepkDhcvGiRYSAuBiQAAnl9h/tkN3NGkMUgYkQE3LpP2B7VLnpnyN ldxgWnJ+qDRPUrJpjlP6N5FbkWbxcpH8Q2IFDwDcMxsMvvXvPjsEYqE33wUaa7XROei5 iM3Q== X-Gm-Message-State: AC+VfDwBTYVYNM1uPvQU3gYNGEXdew49XiLUBhW25x4yEIe+zgWSv+8n n3R6UCrkBAnSfGw1KUy61UOdnqMSh1xgyTTO3cm2EiITGVdDTe8ogHXh4HgWNPGnP5zs5R4vkBY uUuZvi1dOOkBMC48uf6DoPv7X5yD25NMnz6FP92oqFfy8hgRKjzl5doSnN510c2/dbA== X-Google-Smtp-Source: ACHHUZ4Yx0QJDrMyCI4Xy4yUGDpMrt4lnjdJKZM9sWNjQ+isFs+xav/o132w2AnkFWgqeMTeCOQY6IsLyicxtrI= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a81:c402:0:b0:55d:ea61:d8e9 with SMTP id j2-20020a81c402000000b0055dea61d8e9mr3173688ywi.7.1683565191502; Mon, 08 May 2023 09:59:51 -0700 (PDT) Date: Mon, 8 May 2023 16:59:08 +0000 In-Reply-To: <20230508165728.525603-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230508165728.525603-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508165908.526247-7-calvinwan@google.com> Subject: [PATCH v4 7/7] strbuf: remove global variable From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , newren@gmail.com, peff@peff.net Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As a library that only interacts with other primitives, strbuf should not utilize the comment_line_char global variable within its functions. Therefore, add an additional parameter for functions that use comment_line_char and refactor callers to pass it in instead. Signed-off-by: Calvin Wan --- add-patch.c | 12 +++++++----- builtin/am.c | 2 +- builtin/branch.c | 4 ++-- builtin/commit.c | 2 +- builtin/merge.c | 10 ++++++---- builtin/notes.c | 16 +++++++++------- builtin/rebase.c | 2 +- builtin/stripspace.c | 6 ++++-- builtin/tag.c | 9 ++++++--- fmt-merge-msg.c | 9 ++++++--- gpg-interface.c | 5 +++-- rebase-interactive.c | 15 ++++++++------- sequencer.c | 24 +++++++++++++++--------- strbuf.c | 12 +++++++----- strbuf.h | 12 +++++++----- wt-status.c | 6 +++--- 16 files changed, 86 insertions(+), 60 deletions(-) diff --git a/add-patch.c b/add-patch.c index 8d770d203f..9702c1aabd 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1105,10 +1105,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, _("Manual hunk edit mode -- see bottom for " - "a quick guide.\n")); + strbuf_commented_addf(&s->buf, comment_line_char, + _("Manual hunk edit mode -- see bottom for " + "a quick guide.\n")); render_hunk(s, hunk, 0, 0, &s->buf); - strbuf_commented_addf(&s->buf, + strbuf_commented_addf(&s->buf, comment_line_char, _("---\n" "To remove '%c' lines, make them ' ' lines " "(context).\n" @@ -1117,12 +1118,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, "%s", _(s->mode->edit_hunk_hint)); + strbuf_commented_addf(&s->buf, comment_line_char, "%s", + _(s->mode->edit_hunk_hint)); /* * TRANSLATORS: 'it' refers to the patch mentioned in the previous * messages. */ - strbuf_commented_addf(&s->buf, + strbuf_commented_addf(&s->buf, comment_line_char, _("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/am.c b/builtin/am.c index 5c83f2e003..306489db13 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1283,7 +1283,7 @@ static int parse_mail(struct am_state *state, const char *mail) strbuf_addstr(&msg, "\n\n"); strbuf_addbuf(&msg, &mi.log_message); - strbuf_stripspace(&msg, 0); + strbuf_stripspace(&msg, 0, comment_line_char); assert(!state->author_name); state->author_name = strbuf_detach(&author_name, NULL); diff --git a/builtin/branch.c b/builtin/branch.c index 501c47657c..e52afcf4d7 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -629,7 +629,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, + strbuf_commented_addf(&buf, comment_line_char, _("Please edit the description for the branch\n" " %s\n" "Lines starting with '%c' will be stripped.\n"), @@ -640,7 +640,7 @@ static int edit_branch_description(const char *branch_name) strbuf_release(&buf); return -1; } - strbuf_stripspace(&buf, 1); + strbuf_stripspace(&buf, 1, comment_line_char); strbuf_addf(&name, "branch.%s.description", branch_name); if (buf.len || exists) diff --git a/builtin/commit.c b/builtin/commit.c index e67c4be221..6d3cc4d9fe 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -893,7 +893,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, s->hints = 0; if (clean_message_contents) - strbuf_stripspace(&sb, 0); + strbuf_stripspace(&sb, 0, comment_line_char); if (signoff) append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0); diff --git a/builtin/merge.c b/builtin/merge.c index 8da3e46abb..1d14767c0c 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -879,13 +879,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, "\n"); + strbuf_commented_addf(&msg, comment_line_char, "\n"); } - strbuf_commented_addf(&msg, _(merge_editor_comment)); + strbuf_commented_addf(&msg, comment_line_char, + _(merge_editor_comment)); if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) - strbuf_commented_addf(&msg, _(scissors_editor_comment)); + strbuf_commented_addf(&msg, comment_line_char, + _(scissors_editor_comment)); else - strbuf_commented_addf(&msg, + strbuf_commented_addf(&msg, comment_line_char, _(no_scissors_editor_comment), comment_line_char); } if (signoff) diff --git a/builtin/notes.c b/builtin/notes.c index d5788352b6..0918b92752 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -11,6 +11,7 @@ #include "config.h" #include "builtin.h" #include "editor.h" +#include "environment.h" #include "gettext.h" #include "hex.h" #include "notes.h" @@ -157,7 +158,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); + strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_char); write_or_die(fd, cbuf.buf, cbuf.len); strbuf_release(&cbuf); @@ -185,9 +186,10 @@ 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")); - strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template))); - strbuf_add_commented_lines(&buf, "\n", strlen("\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); write_or_die(fd, buf.buf, buf.len); write_commented_object(fd, object); @@ -199,7 +201,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data * if (launch_editor(d->edit_path, &d->buf, NULL)) { die(_("please supply the note contents using either -m or -F option")); } - strbuf_stripspace(&d->buf, 1); + strbuf_stripspace(&d->buf, 1, comment_line_char); } } @@ -225,7 +227,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset) if (d->buf.len) strbuf_addch(&d->buf, '\n'); strbuf_addstr(&d->buf, arg); - strbuf_stripspace(&d->buf, 0); + strbuf_stripspace(&d->buf, 0, comment_line_char); d->given = 1; return 0; @@ -244,7 +246,7 @@ static int parse_file_arg(const struct option *opt, const char *arg, int unset) die_errno(_("cannot read '%s'"), arg); } else if (strbuf_read_file(&d->buf, arg, 1024) < 0) die_errno(_("could not open or read '%s'"), arg); - strbuf_stripspace(&d->buf, 0); + strbuf_stripspace(&d->buf, 0, comment_line_char); d->given = 1; return 0; diff --git a/builtin/rebase.c b/builtin/rebase.c index ace1d5e8d1..d092e06dc7 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -209,7 +209,7 @@ static int edit_todo_file(unsigned flags) if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); - strbuf_stripspace(&todo_list.buf, 1); + strbuf_stripspace(&todo_list.buf, 1, comment_line_char); res = edit_todo_list(the_repository, &todo_list, &new_todo, NULL, NULL, flags); if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file, NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 9451eb69ff..e182c2a14e 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "environment.h" #include "gettext.h" #include "parse-options.h" #include "setup.h" @@ -13,7 +14,7 @@ static void comment_lines(struct strbuf *buf) size_t len; msg = strbuf_detach(buf, &len); - strbuf_add_commented_lines(buf, msg, len); + strbuf_add_commented_lines(buf, msg, len, comment_line_char); free(msg); } @@ -58,7 +59,8 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix) die_errno("could not read the input"); if (mode == STRIP_DEFAULT || mode == STRIP_COMMENTS) - strbuf_stripspace(&buf, mode == STRIP_COMMENTS); + strbuf_stripspace(&buf, mode == STRIP_COMMENTS, + comment_line_char); else comment_lines(&buf); diff --git a/builtin/tag.c b/builtin/tag.c index 1850a6a6fd..e7e2511f0c 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -311,9 +311,11 @@ 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, _(tag_template), tag, comment_line_char); + strbuf_commented_addf(&buf, comment_line_char, + _(tag_template), tag, comment_line_char); else - strbuf_commented_addf(&buf, _(tag_template_nocleanup), tag, comment_line_char); + strbuf_commented_addf(&buf, comment_line_char, + _(tag_template_nocleanup), tag, comment_line_char); write_or_die(fd, buf.buf, buf.len); strbuf_release(&buf); } @@ -327,7 +329,8 @@ static void create_tag(const struct object_id *object, const char *object_ref, } if (opt->cleanup_mode != CLEANUP_NONE) - strbuf_stripspace(buf, opt->cleanup_mode == CLEANUP_ALL); + strbuf_stripspace(buf, opt->cleanup_mode == CLEANUP_ALL, + comment_line_char); if (!opt->message_given && !buf->len) die(_("no tag message?")); diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index 5af0d4715b..5d15e2387d 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -508,7 +508,8 @@ 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); + strbuf_add_commented_lines(tagbuf, sig->buf, sig->len, + comment_line_char); } } @@ -554,7 +555,8 @@ 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)); + strlen(origins.items[first_tag].string), + comment_line_char); strbuf_insert(&tagbuf, 0, tagline.buf, tagline.len); strbuf_release(&tagline); @@ -562,7 +564,8 @@ 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)); + strlen(origins.items[i].string), + comment_line_char); fmt_tag_signature(&tagbuf, &sig, buf, len); } strbuf_release(&payload); diff --git a/gpg-interface.c b/gpg-interface.c index f3ac5acdd9..b625f17460 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -11,6 +11,7 @@ #include "tempfile.h" #include "alias.h" #include "wrapper.h" +#include "environment.h" static int git_gpg_config(const char *, const char *, void *); @@ -584,8 +585,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, } } - strbuf_stripspace(&ssh_keygen_out, 0); - strbuf_stripspace(&ssh_keygen_err, 0); + strbuf_stripspace(&ssh_keygen_out, 0, comment_line_char); + strbuf_stripspace(&ssh_keygen_err, 0, comment_line_char); /* Add stderr outputs to show the user actual ssh-keygen errors */ strbuf_add(&ssh_keygen_out, ssh_principals_err.buf, ssh_principals_err.len); strbuf_add(&ssh_keygen_out, ssh_keygen_err.buf, ssh_keygen_err.len); diff --git a/rebase-interactive.c b/rebase-interactive.c index 789f407361..c6027e73c1 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -71,13 +71,14 @@ void append_todo_help(int command_count, if (!edit_todo) { strbuf_addch(buf, '\n'); - strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)", - "Rebase %s onto %s (%d commands)", - command_count), + strbuf_commented_addf(buf, comment_line_char, + Q_("Rebase %s onto %s (%d command)", + "Rebase %s onto %s (%d commands)", + command_count), shortrevisions, shortonto, command_count); } - strbuf_add_commented_lines(buf, msg, strlen(msg)); + strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char); if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR) msg = _("\nDo not remove any line. Use 'drop' " @@ -86,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)); + strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char); if (edit_todo) msg = _("\nYou are editing the todo file " @@ -97,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)); + strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char); } int edit_todo_list(struct repository *r, struct todo_list *todo_list, @@ -129,7 +130,7 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list, if (launch_sequence_editor(todo_file, &new_todo->buf, NULL)) return -2; - strbuf_stripspace(&new_todo->buf, 1); + strbuf_stripspace(&new_todo->buf, 1, comment_line_char); if (initial && new_todo->buf.len == 0) return -3; diff --git a/sequencer.c b/sequencer.c index c88d1d9553..9675b62bcb 100644 --- a/sequencer.c +++ b/sequencer.c @@ -659,11 +659,12 @@ void append_conflicts_hint(struct index_state *istate, } strbuf_addch(msgbuf, '\n'); - strbuf_commented_addf(msgbuf, "Conflicts:\n"); + strbuf_commented_addf(msgbuf, comment_line_char, "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, "\t%s\n", ce->name); + strbuf_commented_addf(msgbuf, comment_line_char, + "\t%s\n", ce->name); while (i < istate->cache_nr && !strcmp(ce->name, istate->cache[i]->name)) i++; @@ -1142,7 +1143,8 @@ void cleanup_message(struct strbuf *msgbuf, cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) strbuf_setlen(msgbuf, wt_status_locate_end(msgbuf->buf, msgbuf->len)); if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE) - strbuf_stripspace(msgbuf, cleanup_mode == COMMIT_MSG_CLEANUP_ALL); + strbuf_stripspace(msgbuf, cleanup_mode == COMMIT_MSG_CLEANUP_ALL, + comment_line_char); } /* @@ -1173,7 +1175,8 @@ int template_untouched(const struct strbuf *sb, const char *template_file, if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0) return 0; - strbuf_stripspace(&tmpl, cleanup_mode == COMMIT_MSG_CLEANUP_ALL); + strbuf_stripspace(&tmpl, cleanup_mode == COMMIT_MSG_CLEANUP_ALL, + comment_line_char); if (!skip_prefix(sb->buf, tmpl.buf, &start)) start = sb->buf; strbuf_release(&tmpl); @@ -1545,7 +1548,8 @@ static int try_to_commit(struct repository *r, cleanup = opts->default_msg_cleanup; if (cleanup != COMMIT_MSG_CLEANUP_NONE) - strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL); + strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL, + comment_line_char); if ((flags & EDIT_MSG) && message_is_empty(msg, cleanup)) { res = 1; /* run 'git commit' to display error message */ goto out; @@ -1839,7 +1843,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); + strbuf_add_commented_lines(buf, s, len, comment_line_char); } /* Does the current fixup chain contain a squash command? */ @@ -1938,7 +1942,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); + strbuf_add_commented_lines(buf, body, commented_len, comment_line_char); /* buf->buf may be reallocated so store an offset into the buffer */ fixup_off = buf->len; strbuf_addstr(buf, body + commented_len); @@ -2028,7 +2032,8 @@ 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)); + strbuf_add_commented_lines(&buf, body, strlen(body), + comment_line_char); else strbuf_addstr(&buf, body); @@ -2047,7 +2052,8 @@ 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)); + strbuf_add_commented_lines(&buf, body, strlen(body), + comment_line_char); } else return error(_("unknown command: %d"), command); repo_unuse_commit_buffer(r, commit, message); diff --git a/strbuf.c b/strbuf.c index d5978fee4e..eba65ca421 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,6 +1,5 @@ #include "git-compat-util.h" #include "alloc.h" -#include "environment.h" #include "gettext.h" #include "hex.h" #include "strbuf.h" @@ -362,7 +361,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) +void strbuf_add_commented_lines(struct strbuf *out, const char *buf, + size_t size, char comment_line_char) { static char prefix1[3]; static char prefix2[2]; @@ -374,7 +374,8 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size add_lines(out, prefix1, prefix2, buf, size); } -void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...) +void strbuf_commented_addf(struct strbuf *sb, char comment_line_char, + const char *fmt, ...) { va_list params; struct strbuf buf = STRBUF_INIT; @@ -384,7 +385,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...) strbuf_vaddf(&buf, fmt, params); va_end(params); - strbuf_add_commented_lines(sb, buf.buf, buf.len); + strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_line_char); if (incomplete_line) sb->buf[--sb->len] = '\0'; @@ -1054,7 +1055,8 @@ static size_t cleanup(char *line, size_t len) * Enable skip_comments to skip every line starting with comment * character. */ -void strbuf_stripspace(struct strbuf *sb, int skip_comments) +void strbuf_stripspace(struct strbuf *sb, int skip_comments, + char comment_line_char) { size_t empties = 0; size_t i, j, len, newlen; diff --git a/strbuf.h b/strbuf.h index 1bae7e0f47..bc16fa4ef9 100644 --- a/strbuf.h +++ b/strbuf.h @@ -287,7 +287,8 @@ 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); + const char *buf, size_t size, + char comment_line_char); /** @@ -416,8 +417,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, 2, 3))) -void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...); +__attribute__((format (printf, 3, 4))) +void strbuf_commented_addf(struct strbuf *sb, char comment_line_char, const char *fmt, ...); __attribute__((format (printf,2,0))) void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); @@ -540,9 +541,10 @@ int strbuf_normalize_path(struct strbuf *sb); /** * Strip whitespace from a buffer. The second parameter controls if - * comments are considered contents to be removed or not. + * comments are considered contents to be removed or not. The third parameter + * is the comment character that determines whether a line is a comment or not. */ -void strbuf_stripspace(struct strbuf *buf, int skip_comments); +void strbuf_stripspace(struct strbuf *buf, int skip_comments, char comment_line_char); static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix) { diff --git a/wt-status.c b/wt-status.c index 97b9c1c035..da7734866f 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1023,7 +1023,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); + strbuf_add_commented_lines(&summary, summary_content, len, comment_line_char); free(summary_content); } @@ -1098,8 +1098,8 @@ 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)); + strbuf_commented_addf(buf, comment_line_char, "%s", cut_line); + strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char); } void wt_status_add_cut_line(FILE *fp)