From patchwork Wed May 3 18:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13230514 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 3C812C77B78 for ; Wed, 3 May 2023 18:51:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230004AbjECSvG (ORCPT ); Wed, 3 May 2023 14:51:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjECSuv (ORCPT ); Wed, 3 May 2023 14:50:51 -0400 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 95BDF59F9 for ; Wed, 3 May 2023 11:50:38 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54f8a3f1961so58965957b3.0 for ; Wed, 03 May 2023 11:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683139837; x=1685731837; 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=DrHSgOIj0Be9dpzC/5DWSd4PBqFtIVDyDH2MEbKeOnGlu8R6YfEJAT2fP3wcjuZOr8 7ELAGcAnk8RJ5x8OMnd/kPCuCBVr6VnKHpi9/oTylc67JVZdGQHTE0jegTePf9aVI59m Jqb/fAn5s5jxN9+qsCV1DzoPGZBeBkNrHBZN2fUGXIRLgJFgweM0+31HflPcPAyfHm3P 08erTMSKvt7fnmwI4Sgx873G5Ssf293H9GXiLkByfxaZ6aeT+hxZAs0cz4tPpaHMcEMO 44dk1+f4plSqDBlLdNxR/QifsYDlJkKQpzbVvOQ9PAxsdI/zUisL2NhTSJu3hldmva0E RSDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683139837; x=1685731837; 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=W1B+lZBB7DiitYQrbQ4nfZ4EZPvg4z4fp/dVki9xHfqpYUvvK5zkEVNov9QwoEvQ45 53eFbXUK/Zc/hoUWaHQbptuylIjWwIT98tvTeeWeNppuVRzUJVOgVweGD59XJx10zcvS 2mkdkg8njvczsw/kIjrZ3dYe5Fh22ZrrCULGYcKfZdC+gKrOM1/vxGK3/YVKmfJ0twtq gnM7erv6jrAmFIxqkCh5O/wokeUoqnnTg1FbF/YEGRGumVItvfilFMWMjYAeFb/Jrlr/ yyMCjwykZShWPubpD7WIALeOLvwwwMODE0TQMAldXLDX0oml0kxs/957ejW+0qFQuzDU UN4w== X-Gm-Message-State: AC+VfDxuSFJQ00jg8HoLNtQRJgS6kb/LQ6lX8xWyhx2YNEJOiKp00DOn eZInE3jx4MidfPKB8rMIUKbV2luAZJW1g6+6K9iezzuEfQrHOp4BVZdZRUq5oFwiS9eOqIea145 8Vznt7q7FdxW6MKwHaJWbs/CAZKlGhUDNgRf0+/UFsoRukils5GhrcJKFi0gf0NRljg== X-Google-Smtp-Source: ACHHUZ47JXOUwrc31FUbgpu+v1TH63WJTPMuOXoFgmB4AFCayJ5c1Ubtvwwez+2h2NTZ6eGa1ZfY8Rjeqls1EYY= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a81:ca4a:0:b0:555:cce6:1bd2 with SMTP id y10-20020a81ca4a000000b00555cce61bd2mr13478492ywk.0.1683139837608; Wed, 03 May 2023 11:50:37 -0700 (PDT) Date: Wed, 3 May 2023 18:50:25 +0000 In-Reply-To: <20230503184849.1809304-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230503184849.1809304-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230503185031.1810078-1-calvinwan@google.com> Subject: [PATCH v2 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 Wed May 3 18:50:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13230515 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 AC1EDC77B7F for ; Wed, 3 May 2023 18:51:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjECSvH (ORCPT ); Wed, 3 May 2023 14:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbjECSuw (ORCPT ); Wed, 3 May 2023 14:50:52 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F41A19A8 for ; Wed, 3 May 2023 11:50:39 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5144902c15eso2745759a12.2 for ; Wed, 03 May 2023 11:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683139839; x=1685731839; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9BI8GcA1W0eLnfWvRtV9iJbidfJEUTlErMxT+mrnnqM=; b=u+qNoYYn0nQNlEaluR55OD5MCaRtxvPUAn0TxGhyBBFJYyRbSXzWWYEUumzrRdBZpL iH8Ez6ne2hTOZPBp4CiVROL1gZ4VkpTPbM1xAXn1nBU68iK8GN5jf4OmwZiL82JVVEh1 MCFGcq9YEytGCnriQL4S3QJiogXfDAgfcFZ4JAKbxI6JcNCNCu8bRqtyBQT2WPHwYCd8 HwJdso50NUtPyv638+oisXuKB4lz7+DM0geuVDy2+g+mu8Dct/paImTnve21rJp2tgIU hyhLCEvC80mH9vc+F6w9OhbfFQ0i+J5PDn5DxCH2RA/dM6f0vyqfjSMIDFQhY00E2w9l 6nCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683139839; x=1685731839; 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=9BI8GcA1W0eLnfWvRtV9iJbidfJEUTlErMxT+mrnnqM=; b=hPP4FzyiGfMpI0EutzTr9c/6SDDbgLPdiFpC2QuyiLZp0V4zzYDoR/Crd+Bk7ITqf4 5Gdd6y1ETcjDzGT4oHgVbCWlDzpKqs9YnqeuKdiedgJ8wt0CLtbTjoj/6A2YcLwXmU7G xwgo3DGJ7Jy+pOVwMT7vSy4syeaWP8zmI7PZFEW5Qv45LUqhePoEo+IrTyLFIY/Z8mhf LCmSmY/qk4K+uB+AB3l4qy96evij+fKnmjnxidJn0JjDuDyjBhGeUzOgpvejZbjMLhOL v5aQZkBSxTW1t8BslmZE+HpsffTbGAUAwggAt/LIC6b5bE+7nqyHY+RDe9Cbh2rp4WaT H8Kw== X-Gm-Message-State: AC+VfDzxgNPp9//jZtQi2AvST2WP8o3TIGl8f3ckBNLgJLHmIVL5iX9D GsCB++1HVXckf2JGO3AnX9IeNjHrsZCYtjb/DZBNPZeXwK/+6ox9OxX2rTEVVIWKRMKepBzodFK qB2b6Xp4kBnfGzkZmCpYR0JGcBJ7fo2OHMYqSf96EZXaTq23g6PEZzOmV0qnfgonBNw== X-Google-Smtp-Source: ACHHUZ7E/L4aerBnU/hY5tdPMa0Swg/MbJIW8Fu+B7YX3YM2b4abLj/6wO34CC/lQ6LtfqqtOVv6nueaKGJ3f50= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a63:8841:0:b0:513:290b:7516 with SMTP id l62-20020a638841000000b00513290b7516mr780726pgd.3.1683139839072; Wed, 03 May 2023 11:50:39 -0700 (PDT) Date: Wed, 3 May 2023 18:50:26 +0000 In-Reply-To: <20230503184849.1809304-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230503184849.1809304-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230503185031.1810078-2-calvinwan@google.com> Subject: [PATCH v2 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] since paths are not primitive objects and therefore strbuf should not interact with them. 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 Wed May 3 18:50:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13230516 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 323BEC7EE21 for ; Wed, 3 May 2023 18:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229752AbjECSvJ (ORCPT ); Wed, 3 May 2023 14:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjECSux (ORCPT ); Wed, 3 May 2023 14:50:53 -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 6112D7EF0 for ; Wed, 3 May 2023 11:50:41 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-63b68f53f0dso6030371b3a.1 for ; Wed, 03 May 2023 11:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683139841; x=1685731841; 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=Os0Q/C/UD0pEyAAMv/RQhMXmxWj1Mzuw2TFjbySPpTD5V/NtfEQk6v0PJWyHZG8Uvs D2neVt1puVirgcpAEgAKuCFnbrrWrfn2U+08QKsI+TBb60XUG8HRtHlErvSg7TtYifAF 1wxjzOysjxDYtQA+vfb5SzGj9DAzlrH0HNImdh7EEkPGKJFZNWKhF2szds3hC42yNRly pY8RkkM6PdeRBGDMlbim66rD6Lg7xyBmCo0qQKrDqn9BXAL/WpOrFBPtZSq6+VpeKAWM Dge2AiK4kUvEbE3K7Y972Tdhc0MisQ1Q06ik7Hb7PG4x3/VtGaCHy02iUKxEM0MyXWwN azrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683139841; x=1685731841; 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=X/i+gz5p9roiYGKbys6S86MzWPuZQ45pXHwSTNjLADmV0MsK0KnY5lWDm4Itt8wqXO IXdNthV1cgnbXq1GzvgE33mgpkfNeb/nmQMl1SuI2WbxG8yzaFnFJbUis3fws9xj5tKo FF4zc7NQ5fVJ21yWa8oVUcTvvj9tPnIum4Q4a/VWq4X3kKZksIR/6OlP83uYpA8Yy2ON wpw0B6dwl/AGpYhmoI1Jp/z58A3Nmg1/IWvsSqt8qnVmVJgXVgMWqMRd6uQfokfzyX3o eUH68hbX5g5QZIpXjbfjhe5fTP2JWlLvUWoSik9TIUY17c87rKM15T24+ut/vaoMCVXM RxXA== X-Gm-Message-State: AC+VfDywMIDqLFCQOJLLSMKg0Z6kFIBuC+nlDAnXU2nRu+2m3DaE2b6h f0J4HW3mc1dtDM3lDk0qyRPxOG1RnR14E/qco6rscxiArbns47sXlNQA/FZV6TxS5jXsXrF3PdE MKsG4wiTqaQ9AiUhFi7JgAYHhHSH8Gi4UzIfUT1iO2uNuHF0HUNT9AXFwPcSLdhggMw== X-Google-Smtp-Source: ACHHUZ4X46d5IKbHhbKsXn7stpUkw+eYPxwPTvyj2/K49JFbXqh9sB5/1tJgKUiGEDM7VBJPWq9xKNmU+Cpor3s= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a05:6a00:26ec:b0:63b:7b21:3560 with SMTP id p44-20020a056a0026ec00b0063b7b213560mr5312191pfw.3.1683139840732; Wed, 03 May 2023 11:50:40 -0700 (PDT) Date: Wed, 3 May 2023 18:50:27 +0000 In-Reply-To: <20230503184849.1809304-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230503184849.1809304-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230503185031.1810078-3-calvinwan@google.com> Subject: [PATCH v2 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 Wed May 3 18:50:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13230518 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 C24A1C77B78 for ; Wed, 3 May 2023 18:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbjECSvN (ORCPT ); Wed, 3 May 2023 14:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbjECSuz (ORCPT ); Wed, 3 May 2023 14:50:55 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D92107EEB for ; Wed, 3 May 2023 11:50:42 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-24deb9c5f8dso2356690a91.0 for ; Wed, 03 May 2023 11:50:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683139842; x=1685731842; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+oOGiD8U1KFR4q9LXq3E9WQQJhTRM2nr/T7plEyJs5k=; b=dawnDHgA4NpA5R1DO1jEkIP4uut/GzAhTvOWNEQhAOVcFSq0U8PmyUGxnJlrfhRgVP PQ5Zobq3Hc6CVqYBagsvuACIIdSTraD9RRLd2jew2bl/NzYscD9SnvieBc1O1bryR1++ vaqpujFHO/UkhbeI3pwS31mH7kLLcGas2CX9FN2OLVK9Wnxf8MLgd5tQn3/IoTkPSF0n wnW/LWVtpn0MGmK4QqBkMc/AqiNcw/HYgEvw0Fwj7oa8KhqJg9biG+SrZRhi+JtC38pl aLHcQy7YPalAOnOGrwXYY5YJG7NN3FfjO64efHS+iJadUe9uMO3APISD9N8r90owqmwJ w+tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683139842; x=1685731842; 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=+oOGiD8U1KFR4q9LXq3E9WQQJhTRM2nr/T7plEyJs5k=; b=diQyuu682Lepwt/zq7nbKjHvrpMzSIv6UvKjPIYWRoNY0jjn9xCzEFxYfiK+Z4Yag4 VVVhWz8A4XnyCxi1sHDGXNuXHzhDCre+djylu4CZEozVE8YDrpHEB7PPMCwYpMvuvhMK QylTg2i5mKOHcwLGoEtN2rgDpVwVPKuSKbXPGxQPCMkkdoeuegBRWmihDQADX3lKZqK+ y0hZHaFGnBygaW/29bFxcwt7IeJZQn40yv8a5y9oua8LTaSqMhsA1zQ8kpTo9CSMzV+B BOJFB3pp+cLYtfRGicirWV1jnEcTfGumcNlxBL54RAavJBPKKNHaVcDRTOdjP9CJ2WEQ fmtw== X-Gm-Message-State: AC+VfDyBNHFbFzVVBTwEeqo5Qhid6sL5rCfbG6RA/hY+m1QZ/6uvtt2L FFkw8Amb5pdkSl3i6rlaxxvBVc225hyxkjlQ/Njvh3P7WQmuAuiRNY6FwiTHDq6W98wBbbDCuQM s6/+asIAUnPBUSOYhCZWF/YyWPl0nbURNCUWRHitYCSHlH1naoyOUweVyvnN59KIUTg== X-Google-Smtp-Source: ACHHUZ5+wiavG5hctp5m46Fcb4xV90GVoNICXdfHLPADKjDRWpFYJxNB7xvE22j9GdUCZ8MGzMVf/7TkeOXdOyc= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:90a:1c0f:b0:24d:e392:75ce with SMTP id s15-20020a17090a1c0f00b0024de39275cemr3678929pjs.2.1683139842048; Wed, 03 May 2023 11:50:42 -0700 (PDT) Date: Wed, 3 May 2023 18:50:28 +0000 In-Reply-To: <20230503184849.1809304-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230503184849.1809304-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230503185031.1810078-4-calvinwan@google.com> Subject: [PATCH v2 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] since paths are not a primitive object that strbuf should directly interact with. 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 Wed May 3 18:50:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13230517 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 27E20C77B7F for ; Wed, 3 May 2023 18:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbjECSvL (ORCPT ); Wed, 3 May 2023 14:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230019AbjECSuz (ORCPT ); Wed, 3 May 2023 14:50:55 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6242683F6 for ; Wed, 3 May 2023 11:50:44 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b9a7c45b8e1so9558796276.3 for ; Wed, 03 May 2023 11:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683139843; x=1685731843; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yMaY1aOrv7ibUhJTA50l5NAg8VCQzw7tODpfdgEpx6A=; b=ubQtfuuAuSBy9od3/FhtZzadU5kun9tOI/a4tQ4m3LLX6WVGfw31Qk5J3DALPWk8k9 w9ZIY0bUsPrdaJ5aRhDRSlsK1mid86ACGcJ6gjqFpfYQdxbbudPgoupnN4zqMZ3J/2+S RjEFvAIpqtrMFP+kd8CdHolF+H4TyqNceBQRHbch20b6Gc+qSrbe4OAfejCq1UZo/6LJ NMHzyJHouArq3DOxdWUJx699H1PcI7pGDNH0HSCDPmZuzKCXW0jcibMRT+hy5l+FzUJs lJisT1/Hgu8UUHSAZQjc0UoKFEnENcqdNEXXvyEn58Gtb8Bj35W+kg8zkgUOGvZMLCCU V6cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683139843; x=1685731843; 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=yMaY1aOrv7ibUhJTA50l5NAg8VCQzw7tODpfdgEpx6A=; b=eJ7mZTbYcvrm7Vv25B2GE8rtcNF1RhevS5K+9GdQxqjcyoomEVgBluJmZ2CvGyBhLv jxKnOSGgT1PveVa+UUTyvPhnTbKtCn7cCVR6vwOaInt1bhyboubldI26DXnQ8QJhRJR1 DggSSgj10O4+wzQwblasj9KIx2SONB500YqeaTrXKPUY/DJVxE0ZeJV9kp2WxyKtb5q/ WjgCLQ2J8S4yGY3FxpS6FhU3s/BHg2eXrzxvH6l45z/0qohWtTtMujWbsEFwvZL3O7hT R/wkTU2VQtuTVvBSoqT8fsNK3GBRMT0CSQJ1WBbm5FE5Yemj39UcDf+KRx2COSd/bZnK Ck5g== X-Gm-Message-State: AC+VfDxLz5300PF5YZQYOCFS6hFTBqB7eQ6mzUVwxqGmCBat2CJ4eGEt qILlAJYp01CXOjzCsKzmH9Mg1KlS4pNC2erM+4hypXqBKxgGSOJGVF7vabFum4+kWo7sRIKsAay 9CzNYeciKre2aOyzIm2j9xg2+sOD9c97l443aSE4cASsn3r53ayECtT08f3b8mnm1+A== X-Google-Smtp-Source: ACHHUZ5rg3llsQI2LqKDCxI/cLTTPaYqrFAl2QkKmopFUbOcLHj8hsPMgk897aV4ryoGEaOXmR3V1Gc6FlNz2S4= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a25:c0ca:0:b0:b9a:7cd6:ba7a with SMTP id c193-20020a25c0ca000000b00b9a7cd6ba7amr8729685ybf.12.1683139843623; Wed, 03 May 2023 11:50:43 -0700 (PDT) Date: Wed, 3 May 2023 18:50:29 +0000 In-Reply-To: <20230503184849.1809304-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230503184849.1809304-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230503185031.1810078-5-calvinwan@google.com> Subject: [PATCH v2 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] since path is not a primitive object and therefore strbuf should not directly interact with it. 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 Wed May 3 18:50:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13230519 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 36C0DC77B78 for ; Wed, 3 May 2023 18:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbjECSvV (ORCPT ); Wed, 3 May 2023 14:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjECSu4 (ORCPT ); Wed, 3 May 2023 14:50:56 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2254B8684 for ; Wed, 3 May 2023 11:50:46 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-52c219bf675so2029603a12.1 for ; Wed, 03 May 2023 11:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683139845; x=1685731845; 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=OQuy++4GO4vllfti/INtb+YDm1PXM+lBbDYxmJALJCZMxJqhOdnR6ECgPpd/3bBwra PV6Rf98gNRywA4hQVhCoTQHDa44lLA2eX8+gH6NQBvFOj3wM2umZGq9Tud4Z7juZFfti aaG1MmfXnKcr16PVjIqkNT5M8rIND2F5t3dVCEKxOOsNS8KwyJxDWTd0823BM8AbBv6n uw4Q7ApjQkrGstUqnX8AFy0MuhP4hQX2PTQrj63ZDun0s7pHerCBJS4uTMiDfsApoELQ LMmSTWURXH9jmvlskO5Qm4PJ/n5xLj9M8LbQTKFDrSPaQfYkuCiaSPf8Rscv6jjKi4q9 O3BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683139845; x=1685731845; 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=YjWDg9ZGOpc+8rJ6L4ZdroUE9tsiGD1T876an4csi0LlQmOJxLoL/Sn4sjh3rkd4xY rQFVCX2dg42uN93gV0QmPiFVGE4zXzuB2DsG0GcHUzaFoE0uoFHAVnOOfpff4d/om31T 5aS5YrTvBi4l760idBRdsgVqj+ZjDsXsSwqO8IEUhk0/SWROjQCVC6NXoLasCcx/l0WH JoitxzPiYGjJFoOX952x/oR2WxvUK29YDbxzezQC7X+p45wzQHq82ZQ1Eoj5flxCSR5u 5M3AE8GQ1dRQCp1OfVPW/0YB0lJrgAclHLaOeFJOJO0ptA7O3JrUk8tWScY67cHL+Egu 038g== X-Gm-Message-State: AC+VfDwewyeYsuigsFk5ykk5HboG1aRA4x0IjHEZaZdngiB0P73q3rdo S9jEurlPC+irvnT5/855SJy7G29IEsR+cuW7LdA0v3n48yYXp2Y7/Q7OGkIbDMhGEoFQ7424bC6 NJgavU+H5BoSAbv2nhHveI5Ie9ym2ZWXnt9x4sTrKrwmcyAKpYbMnDqVSKy8Lta916w== X-Google-Smtp-Source: ACHHUZ4B2tieYszX3seCCnLoZ39HG9gOPO32ZNmwCZJ9qoljWQiOBDTRKVsYAKs/KOBUj2UWv/uJcirnxR/HRwc= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a63:2ac8:0:b0:52c:6149:f6c8 with SMTP id q191-20020a632ac8000000b0052c6149f6c8mr714870pgq.4.1683139845384; Wed, 03 May 2023 11:50:45 -0700 (PDT) Date: Wed, 3 May 2023 18:50:30 +0000 In-Reply-To: <20230503184849.1809304-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230503184849.1809304-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230503185031.1810078-6-calvinwan@google.com> Subject: [PATCH v2 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 Wed May 3 18:50:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13230520 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 CDB37C77B78 for ; Wed, 3 May 2023 18:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbjECSvY (ORCPT ); Wed, 3 May 2023 14:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbjECSu7 (ORCPT ); Wed, 3 May 2023 14:50:59 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F2FF83DD for ; Wed, 3 May 2023 11:50:47 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-52883b4d2c9so2764159a12.1 for ; Wed, 03 May 2023 11:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683139847; x=1685731847; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=doCS6yTMF1SkxtJ0zdaItO+EFaPvxl5SoMOzAG7qxCw=; b=RWEfuC2FA1YHNdCjvfRJvyQ9pHyAAmFdrdafaxLDFSxGJXilYLWqjA/uyYLnyHWYDI KARG5xDkbO48mr/FtNwCk7d+IT5hrtWGchlARiiciOIhQqmcr4sOtnROwsLArweB3lNO XPgrs1E2t8diCUnYVSMctiSilZwcQoRuxfNAWcSrV+fdxDGlgst27BaEOQMVl8GcMISk zEdCC7ppzk/ViOTsiaWposzRdQp59rDRvCTDDjnTx3nIw2hxw/M3WJ8S3LWuDrh2fO/d nQDnuyFM7ozRplEV8FIVNAA99rRry7+QcsL94u8352n1NtOsz14v3s9noInm+JpN2onF LdXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683139847; x=1685731847; 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=doCS6yTMF1SkxtJ0zdaItO+EFaPvxl5SoMOzAG7qxCw=; b=a2F+7f4sbaetAQ05s8qy8vQCElIkEv0WtjG5w50h9UGgJwgovE1fIkBD8f1bqkIiir XXPBzR7s9QlKYtVvapVMVSdu/qRX6nAJbkgR5lb/Qtc+Jm5CxYgAg6P3PzvNQzTXSnGm LA9fSgAj9jX/RIzNWgW/CP/yYzzROUyuj4T9Aw42L8uQXsRJ5MO/oq44NXtozHW14SQW fXkcTSBOylCCjyCy1giVpWsiUQ5llvmhh1i0OHm3rAwZVrqUAiV5jyQlY7bCmmCipZ3F 9RePzooETyf8H7dckZH/Hpm2mKSapwCbRJ3bEKkAfKsHN/UXhEHiuhtWKKO8GVxWPtMn ZYbg== X-Gm-Message-State: AC+VfDytS+OzgZZLRf0AJhRMwm+qN1HsFavrFrCqfkw+yuuUoOjfypah 2RfhwgQchzo6rUrYb6udS3FtibpkspjTiRfr5Bhy6RCBKYevAjWzZZ/boIzmRyszasMc5rEfJfQ AVjywDSXMYuF88pk0uDxhLCRiMR7om0NUKusT7Ry+GiedyUrhRN/ggpquyely1sW0Uw== X-Google-Smtp-Source: ACHHUZ5GcyBwTpISeMA9NkxG9VF5mRhyi6pHwjWF1J8SaMWEMQQ0omWwHg+MFxnI3CLM7mcTbAO3IUeBFCdteh8= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:902:a715:b0:1a6:42dc:9137 with SMTP id w21-20020a170902a71500b001a642dc9137mr284051plq.10.1683139846973; Wed, 03 May 2023 11:50:46 -0700 (PDT) Date: Wed, 3 May 2023 18:50:31 +0000 In-Reply-To: <20230503184849.1809304-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230503184849.1809304-1-calvinwan@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230503185031.1810078-7-calvinwan@google.com> Subject: [PATCH v2 7/7] strbuf: remove environment variables 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 directly access environment variables within its functions. Therefore, add an additional variable to function signatures for functions that use an environment variable and refactor callers to pass in the environment variable. 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..c713d14489 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)