From patchwork Sat Apr 6 14:31:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13619843 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A98CA1CFB9 for ; Sat, 6 Apr 2024 14:32:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413923; cv=none; b=kUIp/IHr9ua8vh8BxTLM5+fQTRtSkH3hOfZIg7npTujfIqAli4IBZmJhmT35GvylNwVt60h666d9sD2XNaAA4Dsj1bHx4xH/e7uvWDJUxgHMnhxGiRSD00fouV9bVyX0e2k5320UWL109vU0LvmMM/wKf/mqThuT6sqnUei6YtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413923; c=relaxed/simple; bh=Jj5scjrZuibs6OABZKZ6ZO3ePEPtibyNDL/iszNowKc=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=fBdlycHb0P1SEuHkh52dmlapuuXXtTkN5m/rx/lmMGGdeuJJpzYPFp48wDD+2utnZEYTYqJCsAEVHkOGkwI/SHWD1zbIcMuTOd/6+Xbj1rNkrFMgxGZPGSx0tbxIKC8HzHEWFPlk06PIeWqr1YrGVSOB3XOxKMrUdTggmVexmSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=e0Xhxf+R; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e0Xhxf+R" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-345600106d3so139930f8f.0 for ; Sat, 06 Apr 2024 07:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712413920; x=1713018720; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=PJ+P6qKQDdXYIqfy9/BwKhPifK2njnWDt/UHuaDhigs=; b=e0Xhxf+RkH7YTGLGPlk6nu2yXi8SRG6gQCoZboXTQiZx5YzhzuXX0JaJiRPAH+1v+c g6DYmkJbWDU+h9tPaiV9Cqo9jsCeIP5PVVYqNsp9JFbU+HJsxnF8IBjQbVmQbHkxnymW 1iHVyWAaD64FgGV4mMBbPGVTdiBpVK5StEOR0JNWY//bWgSYljvY9aTjk9nsLwwHZIsM Hw1n3K6QbyNE4NkMycPcFh1RQpB3M60kco/XXXSTmbbRGuwhSvFz2K4Yi3sicC4MjdYk jzJWzhzgd39GxYuOIGIj2gBADl24NL65TiduldHb+y8ROaIOJ/E75HgShjQVJgxpy8Yu zw1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712413920; x=1713018720; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PJ+P6qKQDdXYIqfy9/BwKhPifK2njnWDt/UHuaDhigs=; b=F2ZPQCGc9kEdMcgxYUfhkPktj4bNiRBVqeBGFjUxY9uRTtiwBo0t8HkPu0+/UAVjTY VllGbkuTDo/GgNGm2877Iy6rhylqmzBcNxgtvmfUPvnKfPqbiTGfq6ljQmsrJdGezcjg NfHX8g9jfzFI8TDyJSSouK/AilY+RTdqWQ0DBXWqV7IoMHDJi7DmzgadbKLycZsRCVxH aHsDyyi7XciIWCUTdh2gGIKEkHWXHG7/KNKEk/gNiFros2FOmMNXk70UkT05S9YgKN9P FO5zW3QxOAcJBSyN3WuxcKo8IKELyNozVi5ngDAPmbpRUh/k+j2U5nus1eDdVBtiafaK WnkQ== X-Gm-Message-State: AOJu0Yx6izBGLGc3tPhgGzq7sI9kJW39r9GRv6I+z15fDU6bv159/XVP i/g+yfK2G9a3RXq2t9EdX+sRAWP3aCzXD+ZULTANOLu4vFInKn7pAvV4y8vp X-Google-Smtp-Source: AGHT+IF8B1FC1jz85G4vRnjhpi68aA4ND8+sPac1xtj8pkdy+7IWvBesya6PHiQelGO758uHEPFqZg== X-Received: by 2002:a05:6000:cc:b0:343:7c16:34df with SMTP id q12-20020a05600000cc00b003437c1634dfmr3040438wrx.49.1712413919818; Sat, 06 Apr 2024 07:31:59 -0700 (PDT) Received: from gmail.com (4.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.4]) by smtp.gmail.com with ESMTPSA id r10-20020a05600c35ca00b0041622c88852sm10263353wmq.16.2024.04.06.07.31.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Apr 2024 07:31:59 -0700 (PDT) Message-ID: Date: Sat, 6 Apr 2024 16:31:56 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/4] path.c: introduce strbuf_interpolate_path From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: Content-Language: en-US In-Reply-To: Factorize interpolate_path to have a similar function that uses a strbuf, instead of allocating a new string, to return the interpolated path. It will allow us to avoid some allocs and also some frees, which we will take advantage of in the next commits. Signed-off-by: Rubén Justo --- path.c | 20 ++++++++++++++------ path.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/path.c b/path.c index 8bb223c92c..7a1a1a9bc0 100644 --- a/path.c +++ b/path.c @@ -737,8 +737,16 @@ static struct passwd *getpw_str(const char *username, size_t len) char *interpolate_path(const char *path, int real_home) { struct strbuf user_path = STRBUF_INIT; + + return strbuf_interpolate_path(path, real_home, &user_path); +} + +char *strbuf_interpolate_path(const char *path, int real_home, struct strbuf* dst) +{ const char *to_copy = path; + strbuf_reset(dst); + if (!path) goto return_null; @@ -754,9 +762,9 @@ char *interpolate_path(const char *path, int real_home) if (!home) goto return_null; if (real_home) - strbuf_add_real_path(&user_path, home); + strbuf_add_real_path(dst, home); else - strbuf_addstr(&user_path, home); + strbuf_addstr(dst, home); #ifdef GIT_WINDOWS_NATIVE convert_slashes(user_path.buf); #endif @@ -764,14 +772,14 @@ char *interpolate_path(const char *path, int real_home) struct passwd *pw = getpw_str(username, username_len); if (!pw) goto return_null; - strbuf_addstr(&user_path, pw->pw_dir); + strbuf_addstr(dst, pw->pw_dir); } to_copy = first_slash; } - strbuf_addstr(&user_path, to_copy); - return strbuf_detach(&user_path, NULL); + strbuf_addstr(dst, to_copy); + return dst->buf; return_null: - strbuf_release(&user_path); + strbuf_release(dst); return NULL; } diff --git a/path.h b/path.h index e053effef2..da7e5384a3 100644 --- a/path.h +++ b/path.h @@ -185,6 +185,7 @@ int calc_shared_perm(int mode); int adjust_shared_perm(const char *path); char *interpolate_path(const char *path, int real_home); +char *strbuf_interpolate_path(const char *path, int real_home, struct strbuf *dst); const char *enter_repo(const char *path, int strict); const char *remove_leading_path(const char *in, const char *prefix); const char *relative_path(const char *in, const char *prefix, struct strbuf *sb); From patchwork Sat Apr 6 14:32:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13619844 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B0B61CFB9 for ; Sat, 6 Apr 2024 14:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413954; cv=none; b=E7T3C1xHAbs9Qo5H26bTMrY0po7hUnFR8wVUmhMS7XOfsR5KoW8YgBufZi7afyjVJZG2hAG0QWT6yh440rWYZSHGZNBk//D1jiVGg3cOj6vjJxuMZ0VNKfVCDoNrkWr8ARQCQBz87oFrAb9GRe3wNTyacjtJHU5IrYTn2S48slc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413954; c=relaxed/simple; bh=Og23LSkc0Mr94v7KfXLW2IIuIM2RqejPy/yHfmJZqyA=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=q6mWzCr0dL1YWHEThRjLcqSaf16xUs/8Gd7mEacS05OEEJgAXLj7Cs8mhrq9BLbWP9iWk3ikSoYIT2IsSQqXODi2xfRgsZivX/EMpoWHepKvqUxLcMFdpTfpuvAHCbCPWiWS3sDkuGpITJoKhCuRg29XUIY/3IfuqD5tc1CJN88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GIVQU+CF; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GIVQU+CF" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4164a19aaf5so417675e9.1 for ; Sat, 06 Apr 2024 07:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712413951; x=1713018751; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=3U+U7nw5R6vsgRPJruyEZSyzrtmViEZeQRRexO5wiKc=; b=GIVQU+CFRvJ6rfvNfhoH78vuMdwGCYXHBtXP8oHhjGROWX3mC5R7wB2hCI0gIiVHcC 12VFXLZ5te3/1yVe2+xF70tLFoJ2trgkt1M+MGuG4AEBtm82hHJPxrF2WoVK+N23/nST 2QQs1us/oDG0ruII4wfVQxc8iDT+6qetizhJ3BujVK3xzWbpSfwkYMKySCixmEGwarvV +NsUSMB6KmNUKB4/HaDDbCzHEx6mrGXgv0Zl17vpZbKoP2vRJ49o6TgWXe7+kMJVZ06q gxwKH0O2aaUT3TOOIOR4g20D3TdZM6z6SO3tuZlf9v5erEcNlPkxpX6FGfaSVbsejqCP FpVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712413951; x=1713018751; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3U+U7nw5R6vsgRPJruyEZSyzrtmViEZeQRRexO5wiKc=; b=Ot7LNlkR73WxC72pGLL0JIuIpv/cM7FUY+3cZPEKyPqSOS3LS9tFgVfaRM4aQxiV1x fEfwZOppT4Hj3271e/KEwuStQireSjzCjRAleknhYBQ7AWHZ6EeF9vmW5iqixmt45Z1V OtFm283nrCC+wsQU2uTqIlgNEKNpaO6FVNSDYfrHN0QUr88E4qCollhICUVBYEEeAMO9 A0axzrRsDpt+Sy4D9UJo6SX3yfzVI4tuEAZHL1jnMPsGIs1hvc8peuvRvYTGYTK4L7cT GQ7KONL/Z9XQcKDpTZ2AHVxS8dri/SOOx0e2F5KG3Cd6b6mBLGsXPdpc56SKegqev+oc TVIQ== X-Gm-Message-State: AOJu0Yz30IMxRG9JTQiFkTSX5+IA3qs+rFJZ79BwhFr+U0+qi66Ir4Oi 2wSfk5OHjV+l8DDGgc+wqUq2ZsGZWrf7wM7JaW++S61NsIGyjEXFKEGx9Hij X-Google-Smtp-Source: AGHT+IGNk6Aa5G8WPCkdslptH0fL1hZ5Qmkvq+RlICVh1pKxQCTLXf9gcUAppUCVG0QAIf5k14M5cA== X-Received: by 2002:a05:600c:3ba7:b0:416:2abe:b886 with SMTP id n39-20020a05600c3ba700b004162abeb886mr4237215wms.0.1712413951579; Sat, 06 Apr 2024 07:32:31 -0700 (PDT) Received: from gmail.com (4.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.4]) by smtp.gmail.com with ESMTPSA id fc9-20020a05600c524900b004162d0676cdsm6671002wmb.29.2024.04.06.07.32.30 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Apr 2024 07:32:31 -0700 (PDT) Message-ID: Date: Sat, 6 Apr 2024 16:32:17 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/4] config.c: introduce git_config_strbuf_pathname From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: Content-Language: en-US In-Reply-To: Add a new git_config_strbuf_pathname function, similar to git_config_pathname, that works with a strbuf relying on the recently introduced strbuf_interpolate_path. Signed-off-by: Rubén Justo --- config.c | 10 ++++++++++ config.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/config.c b/config.c index eebce8c7e0..9beeb63b50 100644 --- a/config.c +++ b/config.c @@ -1355,6 +1355,16 @@ int git_config_pathname(const char **dest, const char *var, const char *value) return 0; } +int git_config_strbuf_pathname(struct strbuf *dest, const char *var, const char *value) +{ + if (!value) + return config_error_nonbool(var); + strbuf_interpolate_path(value, 0, dest); + if (!dest->len) + die(_("failed to expand user dir in: '%s'"), value); + return 0; +} + int git_config_expiry_date(timestamp_t *timestamp, const char *var, const char *value) { if (!value) diff --git a/config.h b/config.h index f4966e3749..e405f1c140 100644 --- a/config.h +++ b/config.h @@ -22,6 +22,7 @@ */ struct object_id; +struct strbuf; /* git_config_parse_key() returns these negated: */ #define CONFIG_INVALID_KEY 1 @@ -287,6 +288,7 @@ int git_config_string(const char **, const char *, const char *); * user's home directory when found at the beginning of the path. */ int git_config_pathname(const char **, const char *, const char *); +int git_config_strbuf_pathname(struct strbuf *, const char *, const char *); int git_config_expiry_date(timestamp_t *, const char *, const char *); int git_config_color(char *, const char *, const char *); From patchwork Sat Apr 6 14:32:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13619845 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39ECA1E4B1 for ; Sat, 6 Apr 2024 14:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413965; cv=none; b=UTy0mbkUgYy3wh7qqgTqFykCqDknYjmIKZGMN7uEH6FoQXVyIi3XrBEzbWlqUrkBN5LdxrXoHvJxeZrxCwCHWMXzonnVuCo3zgtg/WoBdUCwrzcuklrKBn1kNJh2N3pf52oFcQ7C8sRrxHvNgCkmn4EgZe2wptwocV+pzJV0mBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413965; c=relaxed/simple; bh=49frcw5IDHGfK4G/3LL9tS0IUWjmD02Rx1qAdGsNxlM=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=UpGWBoHL4iB8l1uGiu9cbO4qYXwG3rP82/gEWW7o5NdyiaZsCSDGhLjM2vqI6PEG2SlIKTai7GMYc6iydPShYz5E/j+k0ZZfIN9sfFOdXpGG7oUSlzZ3blKYYBYsRRAEgopPtMzJ9Bk7OoNaNqF4lPEQr+8uBE3GykzynsKYyw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YfTaz99p; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YfTaz99p" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-343cfe8cae1so1555652f8f.3 for ; Sat, 06 Apr 2024 07:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712413962; x=1713018762; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=gyMqb/pFDKZUufmMOMIKmtN83in2NOvovepYr9ptN3o=; b=YfTaz99pLZCCw5pM0FJMh3l80Wc4nAA2lEAqQHb0YsDG8mdCWButu0sNjyIdJuXSqz xE4kiKi0VqY1c+xReHjd1BaobgMdxtoxMFmUxqqhdJ/EacVShyWBYx2b9sfaoyPELxId qetl148fJyvaV2cNf0Tmwu1/U0lxh4HjdorftZ+P0a1DCVQGJAwsC6pCKtLkLhKGvbr9 jhhcQy/KnuTScWjfoJ7JqIueePoYLuj5HY+qIKrbiwP+RRI7b1oNuY8/lpNJ5RwUyOrC /T87l8AOa3/NCl1PAhUe0pZ3PzpLM1CPGsQfgu8mWi0B9/2SSlpjle9EU3RV7Z9ro1+f Yj6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712413962; x=1713018762; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gyMqb/pFDKZUufmMOMIKmtN83in2NOvovepYr9ptN3o=; b=dXH+LzP4FQdR0jDOSeGTdSEpUNWq+7k9wNgZgYWPWgD3O/rThbiF76aAOI6EyVPUnN jTKiBNAZ1bioJKGBG9sLzii1jaPy6342KyYS05Fcs8Tuzp19+ZAt4+FEIK6O9OHOBfmq H31q2RuqLbs1r3/BRB9aeVOFihlmDrCyLKa0sAK/KbRWg+4u6Dyt/leAIugM4Rlw/ChK a5FnXmqBErjcsE5ShDmDiZtqpRJkrKdSamHkschq7u8e2NrReoMavmw5QiX9CdbW/8hr EvrbX2rWSU02tmf4ZbsQoCbpeW0fMqT8f+CLJGTgGCyHevcAjIOf0eC3F2VPRP0mikMd QKiQ== X-Gm-Message-State: AOJu0YxI9FypcOr7jJJNR3IB+8zkh8jKgI6osguMfaXMAgODukf2EN+S uMpmm6x30hkZrJC2IbghrsBaxM4phg6Tm1Et26jVTh5tlacXwpFasMLhadNG X-Google-Smtp-Source: AGHT+IFW7KoSS71bOXX3klFWrU8HsFy3l2z4JP7fYaTNCinv5WrjZvdZnDoRN8E1zaMy4oDVvnaSbQ== X-Received: by 2002:a05:6000:1864:b0:33e:48f9:169d with SMTP id d4-20020a056000186400b0033e48f9169dmr4659624wri.31.1712413962426; Sat, 06 Apr 2024 07:32:42 -0700 (PDT) Received: from gmail.com (4.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.4]) by smtp.gmail.com with ESMTPSA id j11-20020adff54b000000b003433bf6651dsm3789296wrp.75.2024.04.06.07.32.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Apr 2024 07:32:42 -0700 (PDT) Message-ID: <657f1780-c813-459d-aecc-94a10f7a3b4f@gmail.com> Date: Sat, 6 Apr 2024 16:32:39 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 3/4] environment.c: convert excludes_file to struct strbuf From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: Content-Language: en-US In-Reply-To: Make excludes_file a strbuf, so that we don't have to worry about freeing it if it is set multiple times. Signed-off-by: Rubén Justo --- config.c | 2 +- dir.c | 13 +++++++++---- environment.c | 2 +- environment.h | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config.c b/config.c index 9beeb63b50..bc64af8efa 100644 --- a/config.c +++ b/config.c @@ -1595,7 +1595,7 @@ static int git_default_core_config(const char *var, const char *value, return git_config_string(&askpass_program, var, value); if (!strcmp(var, "core.excludesfile")) - return git_config_pathname(&excludes_file, var, value); + return git_config_strbuf_pathname(&excludes_file, var, value); if (!strcmp(var, "core.whitespace")) { if (!value) diff --git a/dir.c b/dir.c index 20ebe4cba2..e31ccd8e48 100644 --- a/dir.c +++ b/dir.c @@ -3386,10 +3386,15 @@ void setup_standard_excludes(struct dir_struct *dir) dir->exclude_per_dir = ".gitignore"; /* core.excludesfile defaulting to $XDG_CONFIG_HOME/git/ignore */ - if (!excludes_file) - excludes_file = xdg_config_home("ignore"); - if (excludes_file && !access_or_warn(excludes_file, R_OK, 0)) - add_patterns_from_file_1(dir, excludes_file, + if (!excludes_file.len) { + char *str = xdg_config_home("ignore"); + if (str) { + strbuf_addstr(&excludes_file, str); + free(str); + } + } + if (excludes_file.len && !access_or_warn(excludes_file.buf, R_OK, 0)) + add_patterns_from_file_1(dir, excludes_file.buf, dir->untracked ? &dir->internal.ss_excludes_file : NULL); /* per repository user preference */ diff --git a/environment.c b/environment.c index a73ba9c12c..b4c66e7153 100644 --- a/environment.c +++ b/environment.c @@ -60,7 +60,7 @@ size_t delta_base_cache_limit = 96 * 1024 * 1024; unsigned long big_file_threshold = 512 * 1024 * 1024; const char *editor_program; const char *askpass_program; -const char *excludes_file; +struct strbuf excludes_file = STRBUF_INIT; enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; enum eol core_eol = EOL_UNSET; int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; diff --git a/environment.h b/environment.h index 05fd94d7be..114e3dde99 100644 --- a/environment.h +++ b/environment.h @@ -222,7 +222,7 @@ extern const char *git_log_output_encoding; extern const char *editor_program; extern const char *askpass_program; -extern const char *excludes_file; +extern struct strbuf excludes_file; /* * Should we print an ellipsis after an abbreviated SHA-1 value From patchwork Sat Apr 6 14:32:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13619846 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9E6A1CFB9 for ; Sat, 6 Apr 2024 14:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413981; cv=none; b=eDY4BuLtsAMhlv0LYzmuyfIPUa8/uHJNtbl2QuMzuz285Ydiz+qPI4z0lZ33Y6smYuGbtsp4luJdvj/OU8nwsj21IKXGflSMcW+MeqklVwMKARPCjB3KLujD4fpSM6daFJc1Ge2ON1EADMtQazhZT+NMqBHJSapd+nyqXf2vzxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712413981; c=relaxed/simple; bh=aQNaT/KZZgTupuJKHEjNeWIPEKvUisMwuqkvuA8dR/w=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=DBYEwWe8beZ/HFhC9n7/R+1Qj7BWfwNqe2sTA6eQHjULcEuJrxZzUzf0tPavdsYiMAis/Gx2UsYI5/wzvQn2yWoc+Zg8nzypX7Km3s5T4gz0eTuO5wE7wyy14wYAk2oH0piC3YK9dHx9/MuK8TMJUIC5SJBiVm+Y2X89WR6AxP8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YWV1UPE7; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YWV1UPE7" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-343cfe8cae1so1555756f8f.3 for ; Sat, 06 Apr 2024 07:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712413978; x=1713018778; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=w/igucRLj4B1C+6BQp1nIsOKQYN7Mcng25kDVNBj6do=; b=YWV1UPE79Ax+vpngCOhxKQDxERvCGVKkTM1VWifnks7Dzs/T+eTOE4YjrKGRS37nAE /Qzz77NFGglacqSQG/kyzlJ8YSjug+nWyEXXevbmgYodYplLOBqozY62GD3Iq2fm1KNS Br070H9ETUiyoWArokaKT2KDnAspXkIe6EbTQcd706nH+WL6EM2IAauvjfWm+uQi+syX saWKFVx6/tzZF3C5SwEEoma3Pqkq9HK3Zu7pFOduNg2vsC6LFQsT8FclE/9onPm8RHkV J8Xtr2RQoty0rCLOGLwhMO6vZsZI8tOnjloETPt3SMI+6nVTUCcUQp/AQHVrVOC5o5Pp N00w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712413978; x=1713018778; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w/igucRLj4B1C+6BQp1nIsOKQYN7Mcng25kDVNBj6do=; b=Y19n3w0RK5U6tAO4AJY6VgDDnE3AaHOLSjGpI1vtXL8B37SJDlVn+HtFmrMX5hl5bX jma3L1GM2oQyOI7O6Mdw++Ws1C05WsqyV4ifZDi8RxDPYHnp5XBLTIZ5Hy0uWgX/oggE 4YssIp0jyEgYOaN3dgUYJcFmQHO1Qoxj//LZL0DEIYJnvTJeNA03rpVvgXSnBAHwPGwf mo5spE4mZ2d/xUHd93VKz341vJuXNTeZfQ7aT/f9QhrFRthlSclIBeKdTqKohaJJFee0 ZnGN8XX5x5exRjWOhiCuj6FeEhVKXvd0gN/o6E9CiqTe2VrBSjpVadvX8wzPznDrPyU1 ym+w== X-Gm-Message-State: AOJu0YwkY4Rm0bVnfRYlXI7mZX+B/mS/7nTse1txPDUGEjGSooSHSnvG mGptYKOVAxYuIxABCQwR98KQnKP0/3Rn49XG8Vzud/GZhdU+ekMCaGsgeb5J X-Google-Smtp-Source: AGHT+IFe9yi+t7u1AmBSSwfk2ONpJd+MfnsF7pzKNBVlRsDTbUF6XAUdPIzE7rAY7HsvEZNrbcgFJg== X-Received: by 2002:a5d:6348:0:b0:343:ab10:f31e with SMTP id b8-20020a5d6348000000b00343ab10f31emr3060305wrw.42.1712413977973; Sat, 06 Apr 2024 07:32:57 -0700 (PDT) Received: from gmail.com (4.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.4]) by smtp.gmail.com with ESMTPSA id s7-20020adfea87000000b0033e7de97214sm4592137wrm.40.2024.04.06.07.32.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Apr 2024 07:32:57 -0700 (PDT) Message-ID: <7f759a5a-ae25-4f2b-a38e-4d0d786ca3bc@gmail.com> Date: Sat, 6 Apr 2024 16:32:54 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 4/4] t7300: mark as leak-free Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: In-Reply-To: Since the previous commit this test does not leak. Mark it with TEST_PASSES_SANITIZE_LEAK=true so to make the leak checkers happy. Signed-off-by: Rubén Justo --- t/t7300-clean.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 1f7201eb60..0aae0dee67 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -5,6 +5,7 @@ test_description='git clean basic tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh git config clean.requireForce no