From patchwork Wed Oct 18 20:28:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13427846 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C85B13DFE6 for ; Wed, 18 Oct 2023 20:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b="TbXpmV/j"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cWxalzYx" Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2E601B9 for ; Wed, 18 Oct 2023 13:29:19 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id E02735C01F7; Wed, 18 Oct 2023 16:29:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 18 Oct 2023 16:29:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1697660958; x= 1697747358; bh=62aWoPylZCqih6z4kx4qnentc7+P/sN58F7+grESGnU=; b=T bXpmV/jsjvr5/+hoDYhVgfNIZM+7zbQ9Zmelfk0fDgv16PYbDhIxzPvjBdzAjlBH xOnV0q8Ke/LElGh/lAv+2dkMhYDFLFbv0AK7NOeR/sXZzmpMY5kYVNVbEwLqmw7D 9uJYXnTMVxm83ogIygIliMGvIjM1h+qFRdk9YV3FjWo6GI7DCPqYhddrj3v1xKlb hsnkn1LX8BMdLkgX5zl4Sve8Bv+pRFGG64KvL5mdb79RLB6Eo0Us1BMS+eDfUptT IezTKk8wCgSNtNOgj4aKt9lIVlpsmxecvZDphL/lQ/2DZg7OyeM/fYP2p776df7E 4jEIk7UbbA74do9/LOlHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1697660958; x= 1697747358; bh=62aWoPylZCqih6z4kx4qnentc7+P/sN58F7+grESGnU=; b=c WxalzYxVHe817g5hRX9a/ZD4BYREohDUMIpAl+pQ6vauIQOP+nQvxolODWIhvgLC 2Xbnq5I0qFbetXJBovBTEs9dVotS7LAMs0zzhUoXjW6wjA4IjyC54AUu9AFq6c2O 4pBPay37A5dB9RXoOvVw1G+hw+MehV9gbbDqltwR5FLT5+nXDC+E9l3uhQN3TWaH ud4fob4yVlbXH7+kgdk7Do8+f3jDtEUjsmg+FcDfuiVlqFsdL5pJuw1Y5nTqUbpY BKJiTxTWeBmyLS76mkLRyOIKYtV5MDaUUKpxV28K+G1puaIjz2poXs++w/jo8ao1 rdKQytelwc5l0CW9QA4wA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjeeggddugeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefmrhhishhtohhffhgvrhcujfgruhhgshgsrghkkhcuoegt ohguvgeskhhhrghughhssggrkhhkrdhnrghmvgeqnecuggftrfgrthhtvghrnhepteduie ehgedutdfgudevkefhveduieeiteejhfffteeitdegjeeihedthfejgfetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheptghouggvsehkhhgruh hgshgsrghkkhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 18 Oct 2023 16:29:17 -0400 (EDT) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , ps@pks.im, stolee@gmail.com Subject: [PATCH v1 1/4] config: format newlines Date: Wed, 18 Oct 2023 22:28:38 +0200 Message-ID: <39934cb7e50ad0a5b287b13d0cdcf2f87a96d6f6.1697660181.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.42.0.2.g879ad04204 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove unneeded newlines according to `clang-format`. Signed-off-by: Kristoffer Haugsbakk --- Notes (series): Honestly the formatter changing these lines over and over again was just annoying. And we're visiting the file anyway. builtin/config.c | 1 - config.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 11a4d4ef141..87d0dc92d99 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -760,7 +760,6 @@ int cmd_config(int argc, const char **argv, const char *prefix) given_config_source.scope = CONFIG_SCOPE_COMMAND; } - if (respect_includes_opt == -1) config_options.respect_includes = !given_config_source.file; else diff --git a/config.c b/config.c index 3846a37be97..19f832818f1 100644 --- a/config.c +++ b/config.c @@ -96,7 +96,6 @@ static long config_file_ftell(struct config_source *conf) return ftell(conf->u.file); } - static int config_buf_fgetc(struct config_source *conf) { if (conf->u.buf.pos < conf->u.buf.len) @@ -3564,7 +3563,6 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, write_err_out: ret = write_error(get_lock_file_path(&lock)); goto out_free; - } void git_config_set_multivar_in_file(const char *config_filename, From patchwork Wed Oct 18 20:28:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13427847 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B43FD3DFF6 for ; Wed, 18 Oct 2023 20:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b="OzmRJK1F"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="vIWQbOHR" Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ADC21BF for ; Wed, 18 Oct 2023 13:29:20 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3DF715C01A0; Wed, 18 Oct 2023 16:29:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 18 Oct 2023 16:29:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1697660960; x= 1697747360; bh=IVZe7LcBH7kIXFvwUiHdiyKp3CvN+hIRwcElAV/sG3k=; b=O zmRJK1FgGzMtVgbSnh7LC1ek7A0gd09sZwrmZTCj85J4OrJQVGE/YKtB6bfswNCe 7rifAPlV7rEwMwGh3XF6qcPLziGlxDyWlpqZhZaUoYXI3ZEpYUM6gRDi0DZHqDdg 3YDTaBDuihQD5WeTKH31ONQcRf5oaJQs2zLo+luL32FvvEPUpV0KN5xK56UdSisz 0RjlBYhYhgr+lkMxKStpdKHLjC726f0yuP7Cxb97AzwtCq37qPJR9VBY6AguOX2x UabbXNcmr8sLv4lgh5cuIv2sA7yHVb4lAG0C/0RNfWyXacHhYW6G0bDF9ViT0F+Z TiEo/WW7XPb5nkRMDAprQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1697660960; x= 1697747360; bh=IVZe7LcBH7kIXFvwUiHdiyKp3CvN+hIRwcElAV/sG3k=; b=v IWQbOHRLlpb9Tbyzd1l6C1mofzd95XvcpxMLgo4c3wD0eqJpRpzyWTXJwuLL0MPt Wj8VdbFgXCkDV7Qgj5IM7PTt+WSEvxD96tYD4qBmkxOf4MomE4Hw5NqF60kfVPaI B6teDniO9Y0w8Mv+/nVJoQGIqJx0YLsOpGk3vHAKODn7kgMnCuYlOYkiL5oX15NM R19Jezko2Lt/qTAKCBOlIDmuhxxbGmRhxkzVUr5hSf7M+oL+W0EhMTiHkj7rE12y +xIOqmGFZwFOFvaHgRyad0XeCoKYWZ8wYd+gQ7P0A6KMKoWzi/PNI0GAbCVva04a yVXI3Zfm5EUavNyrDXDlg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjeeggddugeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefmrhhishhtohhffhgvrhcujfgruhhgshgsrghkkhcuoegt ohguvgeskhhhrghughhssggrkhhkrdhnrghmvgeqnecuggftrfgrthhtvghrnhepteduie ehgedutdfgudevkefhveduieeiteejhfffteeitdegjeeihedthfejgfetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheptghouggvsehkhhgruh hgshgsrghkkhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 18 Oct 2023 16:29:19 -0400 (EDT) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , ps@pks.im, stolee@gmail.com Subject: [PATCH v1 2/4] config: rename global config function Date: Wed, 18 Oct 2023 22:28:39 +0200 Message-ID: <48a5357f97cec2c5babc6512e0b30bcb8f7d201f.1697660181.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.42.0.2.g879ad04204 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename this function to a more descriptive name since we want to use the existing name for a new function. Signed-off-by: Kristoffer Haugsbakk --- builtin/config.c | 2 +- builtin/gc.c | 4 ++-- builtin/var.c | 2 +- config.c | 4 ++-- config.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 87d0dc92d99..6fff2655816 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -710,7 +710,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) if (use_global_config) { char *user_config, *xdg_config; - git_global_config(&user_config, &xdg_config); + git_global_config_paths(&user_config, &xdg_config); if (!user_config) /* * It is unknown if HOME/.gitconfig exists, so diff --git a/builtin/gc.c b/builtin/gc.c index 5c4315f0d81..17fc031f63a 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1529,7 +1529,7 @@ static int maintenance_register(int argc, const char **argv, const char *prefix) char *user_config = NULL, *xdg_config = NULL; if (!config_file) { - git_global_config(&user_config, &xdg_config); + git_global_config_paths(&user_config, &xdg_config); config_file = user_config; if (!user_config) die(_("$HOME not set")); @@ -1597,7 +1597,7 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi int rc; char *user_config = NULL, *xdg_config = NULL; if (!config_file) { - git_global_config(&user_config, &xdg_config); + git_global_config_paths(&user_config, &xdg_config); config_file = user_config; if (!user_config) die(_("$HOME not set")); diff --git a/builtin/var.c b/builtin/var.c index 74161bdf1c6..8e18b50b1e5 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -90,7 +90,7 @@ static char *git_config_val_global(int ident_flag UNUSED) char *user, *xdg; size_t unused; - git_global_config(&user, &xdg); + git_global_config_paths(&user, &xdg); if (xdg && *xdg) { normalize_path_copy(xdg, xdg); strbuf_addf(&buf, "%s\n", xdg); diff --git a/config.c b/config.c index 19f832818f1..d2cdda96edd 100644 --- a/config.c +++ b/config.c @@ -2111,7 +2111,7 @@ char *git_system_config(void) return system_config; } -void git_global_config(char **user_out, char **xdg_out) +void git_global_config_paths(char **user_out, char **xdg_out) { char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL")); char *xdg_config = NULL; @@ -2186,7 +2186,7 @@ static int do_git_config_sequence(const struct config_options *opts, data, CONFIG_SCOPE_SYSTEM, NULL); - git_global_config(&user_config, &xdg_config); + git_global_config_paths(&user_config, &xdg_config); if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK)) ret += git_config_from_file_with_options(fn, xdg_config, data, diff --git a/config.h b/config.h index 6332d749047..9f04de8ee3e 100644 --- a/config.h +++ b/config.h @@ -394,7 +394,7 @@ int config_error_nonbool(const char *); #endif char *git_system_config(void); -void git_global_config(char **user, char **xdg); +void git_global_config_paths(char **user, char **xdg); int git_config_parse_parameter(const char *, config_fn_t fn, void *data); From patchwork Wed Oct 18 20:28:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13427848 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEA6A3E007 for ; Wed, 18 Oct 2023 20:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b="nsTxC3sn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="olgxaf6A" Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B4D10DD for ; Wed, 18 Oct 2023 13:29:22 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 858E05C0267; Wed, 18 Oct 2023 16:29:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 18 Oct 2023 16:29:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm2; t=1697660961; x=1697747361; bh=OKuqjneD8+v87x9+Y+Iv3A4XU 462/xfToiSeUDirN1k=; b=nsTxC3snRlaK1rzDgKVFRyZwDQj7jM08e5RdibRGc z0L/Kry5bBeMqEm6gHvonfxGNE3RUgYhKU1E1GpqGRRo+yu7cg8fEyL/kaN4fcAu Vx3XxMb0BgMTn64/5mzMgcEQiay3FrOZrlbbj5ngsZzZe9yRLuzWjS48wA3W9yAZ INcvzBPvr7WaO/DdeCLxsGspPDbN+CVoyxMuyPiW+Gj3LJ8Ty9AdVxQ4c9GqSuE8 wMyp3D3jcVyzxoDQFl0wLd4TSoeo72F98l30sVBGF5loA1KfruiJjalQsXrSwK0D l5FGRuxQj+y4/cLfhkwxhzfDVyz/jlDGAWyKUnJQMAcqQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1697660961; x=1697747361; bh=OKuqjneD8+v87x9+Y+Iv3A4XU462/xfToiS eUDirN1k=; b=olgxaf6AygB46blulGacNn/5Fg+Q/p2Numki6z4KTH5PlJiciep 7+UULQXOSt3qnakwR/OGsvsko+oAziYfPP8Q0SYOviXgBPsZwgsvY1fBphW+MXbB jMXf5BY0fJxBbk9Dxu84x1AXYCdeXw7js/sSw36LibOt7moR0XCujiFYesz2KaR/ aIk1WvRsGnG30x9I/jKAL5xV/RHcKrG2OF6ZCfBijjJeURVIvPBvhPMTRFHoHIiX oqJv/CC/rMsRhnKpIaaAxD5IDBZH8SqzWWrRT7P4sr2lMWGPrUo3+pQVqXpIIEXK 5lMUnBOqZ9Q/JXHCD5icfw2hgv3yaCR8gyQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjeeggddugeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfgggtgfesth ekredtredtjeenucfhrhhomhepmfhrihhsthhofhhfvghrucfjrghughhssggrkhhkuceo tghouggvsehkhhgruhhgshgsrghkkhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpeevgf elveeikeegjeeikeeuvefhleeiuddvleegfeekjedtkeevtdetgfffveettdenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegtohguvgeskhhhrg hughhssggrkhhkrdhnrghmvg X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 18 Oct 2023 16:29:20 -0400 (EDT) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , ps@pks.im, stolee@gmail.com Subject: [PATCH v1 3/4] config: factor out global config file retrieval Date: Wed, 18 Oct 2023 22:28:40 +0200 Message-ID: <147c767443c35b3b4a5516bf40557f41bb201078.1697660181.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.42.0.2.g879ad04204 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Factor out code that retrieves the global config file so that we can use it in `gc.c` as well. Use the old name from the previous commit since this function acts functionally the same as `git_system_config` but for “global”. Signed-off-by: Kristoffer Haugsbakk --- builtin/config.c | 25 ++----------------------- config.c | 24 ++++++++++++++++++++++++ config.h | 1 + 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 6fff2655816..df06b766fad 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -708,30 +708,9 @@ int cmd_config(int argc, const char **argv, const char *prefix) } if (use_global_config) { - char *user_config, *xdg_config; - - git_global_config_paths(&user_config, &xdg_config); - if (!user_config) - /* - * It is unknown if HOME/.gitconfig exists, so - * we do not know if we should write to XDG - * location; error out even if XDG_CONFIG_HOME - * is set and points at a sane location. - */ - die(_("$HOME not set")); - + given_config_source.file = git_global_config(); given_config_source.scope = CONFIG_SCOPE_GLOBAL; - - if (access_or_warn(user_config, R_OK, 0) && - xdg_config && !access_or_warn(xdg_config, R_OK, 0)) { - given_config_source.file = xdg_config; - free(user_config); - } else { - given_config_source.file = user_config; - free(xdg_config); - } - } - else if (use_system_config) { + } else if (use_system_config) { given_config_source.file = git_system_config(); given_config_source.scope = CONFIG_SCOPE_SYSTEM; } else if (use_local_config) { diff --git a/config.c b/config.c index d2cdda96edd..2ff766c56ff 100644 --- a/config.c +++ b/config.c @@ -2111,6 +2111,30 @@ char *git_system_config(void) return system_config; } +char *git_global_config(void) +{ + char *user_config, *xdg_config; + + git_global_config_paths(&user_config, &xdg_config); + if (!user_config) + /* + * It is unknown if HOME/.gitconfig exists, so + * we do not know if we should write to XDG + * location; error out even if XDG_CONFIG_HOME + * is set and points at a sane location. + */ + die(_("$HOME not set")); + + if (access_or_warn(user_config, R_OK, 0) && xdg_config && + !access_or_warn(xdg_config, R_OK, 0)) { + free(user_config); + return xdg_config; + } else { + free(xdg_config); + return user_config; + } +} + void git_global_config_paths(char **user_out, char **xdg_out) { char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL")); diff --git a/config.h b/config.h index 9f04de8ee3e..5cf961b548d 100644 --- a/config.h +++ b/config.h @@ -394,6 +394,7 @@ int config_error_nonbool(const char *); #endif char *git_system_config(void); +char *git_global_config(void); void git_global_config_paths(char **user, char **xdg); int git_config_parse_parameter(const char *, config_fn_t fn, void *data); From patchwork Wed Oct 18 20:28:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13427849 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE9293E010 for ; Wed, 18 Oct 2023 20:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=khaugsbakk.name header.i=@khaugsbakk.name header.b="m5EYduWB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LfrDQY23" Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 350D110E6 for ; Wed, 18 Oct 2023 13:29:24 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 2E1A95C0116; Wed, 18 Oct 2023 16:29:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 18 Oct 2023 16:29:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1697660963; x= 1697747363; bh=CvDfaddkbFav4E/axthUtVquSo78BG12GBoUBh5Nh7g=; b=m 5EYduWBynE7mggd2LmrTUJLh6eG9vKK8RPI8EL3hQM/YaZWZ9QoSk48llz5keP5L WuazxNWDoEP9btKcWp44SWiK+8sgc1eOIWaKY/SF8R7uoy2xGi0YgLueUQC9QHLI 1NsEGqF8Ez6VxqNsXNEqgGcO2OsDYF6u07x6bAP1/8r2tH0i0rrt5IqUp5SIhEma IFu7BBSXPBdg/Z6K9seVhThOTzSg1aykf30NNV4sqJBVSKXHe/55jWYy8OTl8mCB p8/cdPnaTj+SNFeha4EY/xvWCUknYoy7g2NT0jRIBfhxU41HODrzzK5TUzEO3hVe kT4JekqacHEE37Fd9mm4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1697660963; x= 1697747363; bh=CvDfaddkbFav4E/axthUtVquSo78BG12GBoUBh5Nh7g=; b=L frDQY23qjK3VMUQOf6GeKGp00moTN/uzXqhw1KQgAYFFiKk+7+8JNkWzLAntJ7ja CHSY++f1admiRqwtR0qs82u4rutz7PTMbJdIxlor5zgOX69/Wc9zIYIqZ61/R3/I 4xmrI1eveFhElmPMvGVj6BQX1yY+YJrMUjqSUHubPZZRC2O5dkcqQEya21fuH5ez 8WcATXwmKDglrilNrlqxTw7RGvp+WUYknb4Dg5uNHDQOi51qbQWYHRvLh+8X0GKs Kw8AiQM4t/n3eI/adfObNkWHNRpXumd3QMFovWNGkRUlmVjtDo62XGBI1ykWknkG l+a+m3UmfeXY/Hx+RuVIQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjeeggddugeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefmrhhishhtohhffhgvrhcujfgruhhgshgsrghkkhcuoegt ohguvgeskhhhrghughhssggrkhhkrdhnrghmvgeqnecuggftrfgrthhtvghrnhepteduie ehgedutdfgudevkefhveduieeiteejhfffteeitdegjeeihedthfejgfetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheptghouggvsehkhhgruh hgshgsrghkkhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 18 Oct 2023 16:29:21 -0400 (EDT) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , ps@pks.im, stolee@gmail.com Subject: [PATCH v1 4/4] maintenance: use XDG config if it exists Date: Wed, 18 Oct 2023 22:28:41 +0200 Message-ID: <1e2376a4b998b5b182cc5f72afc7282134bcdf2c.1697660181.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.42.0.2.g879ad04204 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 `git maintenance register` registers the repository in the user's global config. `$XDG_CONFIG_HOME/git/config` is supposed to be used if `~/.gitconfig` does not exist. However, this command creates a `~/.gitconfig` file and writes to that one even though the XDG variant exists. This used to work correctly until 50a044f1e4 (gc: replace config subprocesses with API calls, 2022-09-27), when the command started calling the config API instead of git-config(1). Also change `unregister` accordingly. Signed-off-by: Kristoffer Haugsbakk --- builtin/gc.c | 23 +++++------------------ t/t7900-maintenance.sh | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 17fc031f63a..7b780f2ab38 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1526,19 +1526,12 @@ static int maintenance_register(int argc, const char **argv, const char *prefix) if (!found) { int rc; - char *user_config = NULL, *xdg_config = NULL; - if (!config_file) { - git_global_config_paths(&user_config, &xdg_config); - config_file = user_config; - if (!user_config) - die(_("$HOME not set")); - } + if (!config_file) + config_file = git_global_config(); rc = git_config_set_multivar_in_file_gently( config_file, "maintenance.repo", maintpath, CONFIG_REGEX_NONE, 0); - free(user_config); - free(xdg_config); if (rc) die(_("unable to add '%s' value of '%s'"), @@ -1595,18 +1588,12 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi if (found) { int rc; - char *user_config = NULL, *xdg_config = NULL; - if (!config_file) { - git_global_config_paths(&user_config, &xdg_config); - config_file = user_config; - if (!user_config) - die(_("$HOME not set")); - } + + if (!config_file) + config_file = git_global_config(); rc = git_config_set_multivar_in_file_gently( config_file, key, NULL, maintpath, CONFIG_FLAGS_MULTI_REPLACE | CONFIG_FLAGS_FIXED_VALUE); - free(user_config); - free(xdg_config); if (rc && (!force || rc == CONFIG_NOTHING_SET)) diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 487e326b3fa..a11e6c61520 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -67,6 +67,27 @@ test_expect_success 'maintenance.auto config option' ' test_subcommand ! git maintenance run --auto --quiet actual && + pwd >expect && + test_cmp expect actual +' + +test_expect_success 'register does not need XDG_CONFIG_HOME config to exist' ' + test_when_finished git maintenance unregister && + test_path_is_missing "$XDG_CONFIG_HOME"/git/config && + git maintenance register && + git config --global --get maintenance.repo >actual && + pwd >expect && + test_cmp expect actual +' + test_expect_success 'maintenance..enabled' ' git config maintenance.gc.enabled false && git config maintenance.commit-graph.enabled true &&