From patchwork Tue May 21 19:56:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669695 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (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 6F7731494D7 for ; Tue, 21 May 2024 19:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321434; cv=none; b=Levys6rkaQMYK+XhGOYIdfQ9U5htHM+3hVGT0qBMBXo1sLjCYuH/vulty19uxKOfrM+R0CEkDiHinaYgKEstEmXm4Vzkw+ovQSXAjjBTVVhBDgAzKzcvWZDaXp6DW3OpkYK5Kl8IxIGUCZ42vVPSkItWJjUUBmM/3bFkxBokH/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321434; c=relaxed/simple; bh=ZhbH0MPwzTFAR59Tj+UDaG91WA/um6x0qH6BdHgMgrM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lp+ORBaVw8A5WwZrxcTmwdnhNWyJJ+DUG0tdYkZW+lIq2W+azsP7ALURCbyYJkIy42KPK9NV5bJuAhYo5JVKvMgQ+XO7HyvIqitdnsWfe78cARy44/EStXh1teO9r/BIOAK2UQZZpI269rb8BABA7U3k60L4Yur1wKCpmtMR1ho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=caUC4JH9; arc=none smtp.client-ip=173.228.157.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="caUC4JH9" Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id D3E3031236; Tue, 21 May 2024 15:57:07 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=ZhbH0MPwzTFAR59Tj+UDaG91W A/um6x0qH6BdHgMgrM=; b=caUC4JH9CQ9XjPAHQt2+yM+QczeQJtTeObW4D+AMU n16UsuWKwoR2oAREKtfjmOkU9qn8sTcH1oBliN9Nz/UD3EjINK34lA9NF3wkbjeK lzfgMA81qEyWNESXmEPpNrbD4Fr2kuoFak2r+haxxNtS7SeLPsm8L3lpCU/Yj3cU nA= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id CBC7F31235; Tue, 21 May 2024 15:57:07 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id C3E8031234; Tue, 21 May 2024 15:57:04 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King , Taylor Blau Subject: [PATCH 01/12] send-email: drop FakeTerm hack Date: Tue, 21 May 2024 12:56:47 -0700 Message-ID: <20240521195659.870714-2-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 4BF8A4C6-17AC-11EF-BC39-A19503B9AAD1-77302942!pb-smtp21.pobox.com From: Jeff King Back in 280242d1cc (send-email: do not barf when Term::ReadLine does not like your terminal, 2006-07-02), we added a fallback for when Term::ReadLine's constructor failed: we'd have a FakeTerm object instead, which would then die if anybody actually tried to call readline() on it. Since we instantiated the $term variable at program startup, we needed this workaround to let the program run in modes when we did not prompt the user. But later, in f4dc9432fd (send-email: lazily load modules for a big speedup, 2021-05-28), we started loading Term::ReadLine lazily only when ask() is called. So at that point we know we're trying to prompt the user, and we can just die if ReadLine instantiation fails, rather than making this fake object to lazily delay showing the error. This should be OK even if there is no tty (e.g., we're in a cron job), because Term::ReadLine will return a stub object in that case whose "IN" and "OUT" functions return undef. And since 5906f54e47 (send-email: don't attempt to prompt if tty is closed, 2009-03-31), we check for that case and skip prompting. And we can be sure that FakeTerm was not kicking in for such a situation, because it has actually been broken since that commit! It does not define "IN" or "OUT" methods, so perl would barf with an error. If FakeTerm was in use, we were neither honoring what 5906f54e47 tried to do, nor producing the readable message that 280242d1cc intended. So we're better off just dropping FakeTerm entirely, and letting the error reported by constructing Term::ReadLine through. [jc: cherry-picked from v2.42.0-rc2~6^2~1] Signed-off-by: Jeff King Acked-by: Taylor Blau Signed-off-by: Junio C Hamano Reviewed-by: Dragan Simic --- git-send-email.perl | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 5861e99a6e..72d876f0a0 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -26,18 +26,6 @@ Getopt::Long::Configure qw/ pass_through /; -package FakeTerm; -sub new { - my ($class, $reason) = @_; - return bless \$reason, shift; -} -sub readline { - my $self = shift; - die "Cannot use readline on FakeTerm: $$self"; -} -package main; - - sub usage { print <] @@ -930,16 +918,10 @@ sub get_patch_subject { } sub term { - my $term = eval { - require Term::ReadLine; - $ENV{"GIT_SEND_EMAIL_NOTTY"} + require Term::ReadLine; + return $ENV{"GIT_SEND_EMAIL_NOTTY"} ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT) : Term::ReadLine->new('git-send-email'); - }; - if ($@) { - $term = FakeTerm->new("$@: going non-interactive"); - } - return $term; } sub ask { From patchwork Tue May 21 19:56:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669693 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (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 49B7D1482E7 for ; Tue, 21 May 2024 19:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321432; cv=none; b=Xv3znCExierJVV+8G+kCLcH1Mt030Wgt+K09xKNkxnoK5HPNaFy7EbrmXnfXYkgU0ywvLv0wQX7GtCJlH3S0Z6Ycvyxl+tk98aDNUEiBFVuwLFhnV5SC7fDVdAM5eH/NzTwhrYFmf9pJGL/zuoYZr6dTfxpOus3g8yDhIF8T1Yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321432; c=relaxed/simple; bh=iW/LSqSO4Kn2BU87K7kzFrZ7HnQ3V0sqDKqd7PZtJd4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W/GYoJNng7npoiP5Uo6sT5wxpy/tkfI0Mbg0QB4dnoDwpuWw/RAubREMdHtp1f1PQuDKDoGPpBODO18xv3lZujG/S0Nmz3ofcyqvHF7mHGmS5mgmxmJ/ls9QdCxe7lSTSqmndk0xXSj76NZH6llHy9qSXyPaBT1MfsukuFk3InM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=QS6WDEEb; arc=none smtp.client-ip=64.147.108.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="QS6WDEEb" Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id CB18831203; Tue, 21 May 2024 15:57:08 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=iW/LSqSO4Kn2BU87K7kzFrZ7H nQ3V0sqDKqd7PZtJd4=; b=QS6WDEEbeEqVcnH4NPRgWYN3zzea1RbtVWN9tIzBF MU03v11dQZ8VF09FbcA3Ntpdp1aEUZppVybXZ+9Vtu8GBy2CdDoPngd9kDtAsKAr hPTVsASsWdr3TI6QPPB2OqX//g3xcyqOCLKgPOXQsN+YQyHj9BDWkXGrCfQ4gtE0 ts= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id C11EC31202; Tue, 21 May 2024 15:57:08 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 1BAF331201; Tue, 21 May 2024 15:57:08 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King , Taylor Blau Subject: [PATCH 02/12] send-email: avoid creating more than one Term::ReadLine object Date: Tue, 21 May 2024 12:56:48 -0700 Message-ID: <20240521195659.870714-3-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 4DF28512-17AC-11EF-BEB2-78DCEB2EC81B-77302942!pb-smtp1.pobox.com From: Jeff King Every time git-send-email calls its ask() function to prompt the user, we call term(), which instantiates a new Term::ReadLine object. But in v1.46 of Term::ReadLine::Gnu (which provides the Term::ReadLine interface on some platforms), its constructor refuses to create a second instance[1]. So on systems with that version of the module, most git-send-email instances will fail (as we usually prompt for both "to" and "in-reply-to" unless the user provided them on the command line). We can fix this by keeping a single instance variable and returning it for each call to term(). In perl 5.10 and up, we could do that with a "state" variable. But since we only require 5.008, we'll do it the old-fashioned way, with a lexical "my" in its own scope. Note that the tests in t9001 detect this problem as-is, since the failure mode is for the program to die. But let's also beef up the "Prompting works" test to check that it correctly handles multiple inputs (if we had chosen to keep our FakeTerm hack in the previous commit, then the failure mode would be incorrectly ignoring prompts after the first). [1] For discussion of why multiple instances are forbidden, see: https://github.com/hirooih/perl-trg/issues/16 [jc: cherry-picked from v2.42.0-rc2~6^2] Signed-off-by: Jeff King Acked-by: Taylor Blau Signed-off-by: Junio C Hamano Reviewed-by: Dragan Simic --- git-send-email.perl | 18 +++++++++++++----- t/t9001-send-email.sh | 5 +++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 72d876f0a0..ad51508790 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -917,11 +917,19 @@ sub get_patch_subject { do_edit(@files); } -sub term { - require Term::ReadLine; - return $ENV{"GIT_SEND_EMAIL_NOTTY"} - ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT) - : Term::ReadLine->new('git-send-email'); +{ + # Only instantiate one $term per program run, since some + # Term::ReadLine providers refuse to create a second instance. + my $term; + sub term { + require Term::ReadLine; + if (!defined $term) { + $term = $ENV{"GIT_SEND_EMAIL_NOTTY"} + ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT) + : Term::ReadLine->new('git-send-email'); + } + return $term; + } } sub ask { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 1130ef21b3..0f08a9542b 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -337,13 +337,14 @@ test_expect_success $PREREQ 'Show all headers' ' test_expect_success $PREREQ 'Prompting works' ' clean_fake_sendmail && (echo "to@example.com" && - echo "" + echo "my-message-id@example.com" ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ --smtp-server="$(pwd)/fake.sendmail" \ $patches \ 2>errors && grep "^From: A U Thor \$" msgtxt1 && - grep "^To: to@example.com\$" msgtxt1 + grep "^To: to@example.com\$" msgtxt1 && + grep "^In-Reply-To: " msgtxt1 ' test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' ' From patchwork Tue May 21 19:56:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669694 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) (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 052C21494CC for ; Tue, 21 May 2024 19:57:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321434; cv=none; b=Bo9gKxHI7RiRPI9itAzlTdi5jTr1QfNUSvKq1P0rXtWEd6e8F4LAShYqioxs+n2sM2nYQNcdyk95oHohFlIXjQRsXyG1h698dGpwKwnCTWaGUaNGS7I8Qb+90/3y408KEOskgqjUKq069qCK2lN1DyjQ44XCdSjLJa7Kt5CDZNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321434; c=relaxed/simple; bh=rZY3pMl4hK9nUeE62D6/4fN+l7AxSxUvjTp2jSDMnQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Aj4vTCF42W+lQ8u4CdrtiWaPPICWpquyg0rbEO3WH3OK1BLf3UCqR2TnXGbwK+VM6S1YPdMT+R1ctl+zSMdrWmxJeWuZwsrx/U9ygRTCmuFS/JWltM18HR3yLZZey3FHOhKS8n+C/bZWS9mbBNJ22GJrD9ZKnATQqkv+RGoYZ8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=cNz6F8U3; arc=none smtp.client-ip=64.147.108.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="cNz6F8U3" Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id ABF7E2228A; Tue, 21 May 2024 15:57:11 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=rZY3pMl4hK9nUeE62D6/4fN+l 7AxSxUvjTp2jSDMnQI=; b=cNz6F8U3sPaDc0vA7Wg58bY4AvYxRqiUp7vufQ7wc X6luUHhTOSuz/6Yyd0NVDYwkzeuBQTDgonfnPpyIo7mIOatrIVJO3Au3N7ulK5Xh lZZ/MLZGEGnks7SLRZF0q0LbnhYLMcCE4aAq7cApZAQdGSyQWJ4GB66g8WAtqRyy T0= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id A2ED822287; Tue, 21 May 2024 15:57:11 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id DCD3722286; Tue, 21 May 2024 15:57:09 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 03/12] ci: drop mention of BREW_INSTALL_PACKAGES variable Date: Tue, 21 May 2024 12:56:49 -0700 Message-ID: <20240521195659.870714-4-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 4F03AF08-17AC-11EF-8E02-25B3960A682E-77302942!pb-smtp2.pobox.com From: Jeff King The last user of this variable went away in 4a6e4b9602 (CI: remove Travis CI support, 2021-11-23), so it's doing nothing except making it more confusing to find out which packages _are_ installed. [jc: cherry-picked from v2.45.0-1-g9d4453e8d6] Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- ci/install-dependencies.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh index 4f407530d3..33039d516b 100755 --- a/ci/install-dependencies.sh +++ b/ci/install-dependencies.sh @@ -34,8 +34,6 @@ macos-*) export HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 # Uncomment this if you want to run perf tests: # brew install gnu-time - test -z "$BREW_INSTALL_PACKAGES" || - brew install $BREW_INSTALL_PACKAGES brew link --force gettext mkdir -p $HOME/bin ( From patchwork Tue May 21 19:56:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669696 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) (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 184E3149019 for ; Tue, 21 May 2024 19:57:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321438; cv=none; b=FhbcAvXgeGKerQcND3t4nyt/G0MMI7FOYQg8Aexl1tTypuYiMjfcGNj61PajSarnZ98y5Eym9CpyB2iN++zHozgL4Kom5XNz40rSWOkS0Dln3KghNFMFGz6CtrdnzUV/idtF/wKz8eaSt4AOSmqksge2MDLD9JNWmrDLxuNVbf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321438; c=relaxed/simple; bh=7PFmRwx+Lng41DVj1knKkE4I7Ga+gV8zAlMAceBRVXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hzsLMnLd66k2SoAfoyPOsVbCRU1WSRdcvsKYslP40s9Z2SJSk0e+J787guO+x4p9kv6UgKu+yN4XXx3dGNLE8UC1Ryl5AYrTpn6GsxnrpFHt8fbwCJ7KAszQzKbgZsupU0hzsIaimKmdKf1D0A9gddOjBH9VytnAk0tmkozMYIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=JqSlcVOx; arc=none smtp.client-ip=173.228.157.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="JqSlcVOx" Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 8803A2DBE4; Tue, 21 May 2024 15:57:16 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=7PFmRwx+Lng41DVj1knKkE4I7 Ga+gV8zAlMAceBRVXw=; b=JqSlcVOxVZAQWNHoi4K7/x3R0gtc8Ylgkkku/jWK5 tYmzVXNfRL/2PQ4BZFSXyRiZpUqGjTEhEV3b5/351dRgtggfbCBt5FLqvPJP/T1o nTI2eeofwZiQELqnAWAuC6+FnbJj+c/dNOG+oHgSDLWS6Ni9qaXTgoueC/yDcKiA +Q= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 80BF32DBE3; Tue, 21 May 2024 15:57:16 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 0733D2DBE1; Tue, 21 May 2024 15:57:12 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 04/12] ci: avoid bare "gcc" for osx-gcc job Date: Tue, 21 May 2024 12:56:50 -0700 Message-ID: <20240521195659.870714-5-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 50E02BB2-17AC-11EF-839D-F515D2CDFF5E-77302942!pb-smtp20.pobox.com From: Jeff King On macOS, a bare "gcc" (without a version) will invoke a wrapper for clang, not actual gcc. Even when gcc is installed via homebrew, that only provides version-specific links in /usr/local/bin (like "gcc-13"), and never a version-agnostic "gcc" wrapper. As far as I can tell, this has been the case for a long time, and this osx-gcc job has largely been doing nothing. We can point it at "gcc-13", which will pick up the homebrew-installed version. The fix here is specific to the github workflow file, as the gitlab one does not have a matching job. It's a little unfortunate that we cannot just ask for the latest version of gcc which homebrew provides, but as far as I can tell there is no easy alias (you'd have to find the highest number gcc-* in /usr/local/bin yourself). [jc: cherry-picked from v2.45.0-2-g11c7001e3d] Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2dc0221f7f..583e7cd5f0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -264,7 +264,7 @@ jobs: cc: clang pool: macos-13 - jobname: osx-gcc - cc: gcc + cc: gcc-13 cc_package: gcc-13 pool: macos-13 - jobname: linux-gcc-default From patchwork Tue May 21 19:56:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669697 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (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 80A08149019 for ; Tue, 21 May 2024 19:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321442; cv=none; b=rNY9Jh/SpDUvmo6SMdDq0oMPzaZADJ9jmuUFkOSD0qWUStnhtzqvlQtxh/1i0a6Gp4i3ldPLSdRVIPPf9pi1Nojf+i55JZUXedI04Moa1iDne/HeZ9YBKMEYqN6AlB6NUStX3V9OPoCmnjbW64B3dpGnH+ogtX3ifQDNxIJFz8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321442; c=relaxed/simple; bh=NqtsZEw5rRD3wqADGXQuaBM5sAJ7oiBuxod5LHb6P6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P2Y7J3Wh9LeDjTMw7ggSBxPpiTcvimxSuiTkT1nFAPcvr+UJUk9a1/av8gYgDSfS0mJQD0ZVS/jRjCE0U01D+ApH0I7MEVmUBOKTw+Ss6m1SDq4OuR4AW7E+UiOMvyvk5pxg4OjWySvbOS9J8A8UFL/2jx54gyigXd6yCc5xBQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=rcCHMylq; arc=none smtp.client-ip=173.228.157.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="rcCHMylq" Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 07D7C31239; Tue, 21 May 2024 15:57:20 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=NqtsZEw5rRD3wqADGXQuaBM5s AJ7oiBuxod5LHb6P6k=; b=rcCHMylq+/han8NkGhngP2JG9x3XoZbNckvtaRfkW 9EUiU5ZDV5CtMRvrwJmECeqNUY4AxuVcvodGbIaxpSUK7JQlQzww7jrigSRX8dt+ CraOXmqRp/uOGWyHY3y8PJcPbqIcJRbLyHoVpPqKwy7YdRC68i4zkfziZSGq8Ljz ys= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 00B3C31238; Tue, 21 May 2024 15:57:20 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 126E731237; Tue, 21 May 2024 15:57:17 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 05/12] ci: stop installing "gcc-13" for osx-gcc Date: Tue, 21 May 2024 12:56:51 -0700 Message-ID: <20240521195659.870714-6-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 534969E0-17AC-11EF-B374-A19503B9AAD1-77302942!pb-smtp21.pobox.com From: Jeff King Our osx-gcc job explicitly asks to install gcc-13. But since the GitHub runner image already comes with gcc-13 installed, this is mostly doing nothing (or in some cases it may install an incremental update over the runner image). But worse, it recently started causing errors like: ==> Fetching gcc@13 ==> Downloading https://ghcr.io/v2/homebrew/core/gcc/13/blobs/sha256:fb2403d97e2ce67eb441b54557cfb61980830f3ba26d4c5a1fe5ecd0c9730d1a ==> Pouring gcc@13--13.2.0.ventura.bottle.tar.gz Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/c++-13 Target /usr/local/bin/c++-13 is a symlink belonging to gcc. You can unlink it: brew unlink gcc which cause the whole CI job to bail. I didn't track down the root cause, but I suspect it may be related to homebrew recently switching the "gcc" default to gcc-14. And it may even be fixed when a new runner image is released. But if we don't need to run brew at all, it's one less thing for us to worry about. [jc: cherry-picked from v2.45.0-3-g7df2405b38] Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 583e7cd5f0..76e3f1e768 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -265,7 +265,6 @@ jobs: pool: macos-13 - jobname: osx-gcc cc: gcc-13 - cc_package: gcc-13 pool: macos-13 - jobname: linux-gcc-default cc: gcc From patchwork Tue May 21 19:56:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669698 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (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 AB8771494C4 for ; Tue, 21 May 2024 19:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321443; cv=none; b=PWhS1TdmTGW2DUbOWFcSTag4svBX5DvIE8bREeFGIwENMvhcnVENxv2nyoJ1NpINmMvmYbMTwzQ/qcDGdmpuRm5u39Ibn2aY6trO+BZDMCvtl2ciUhTH4/oZhrkt6TC3+hhJsWqlgUVsTKSdrm/9kqbjRsBeHRmwHVy4+u1vSS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321443; c=relaxed/simple; bh=tsBzMn6ZzXQDtyrDg97INTCA8rJBYuiSH2QIGRY5oZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J6T1uju1++r+pXKZ1C+GbHGSZBhGj7kBKLsARnxOPcjI/spDBh5QSShWXza4TJzFeJ9cT6iSjA8OBP+Re5XczSbRa5YXEON9NJ4CdKqrqJLWUbQcSqRfvVteVJxTNwePQRuUXuqHQCdYUGJ4hqgcZtVdSDMwnTxdzCGIeEkBHhs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=BvMW9Vm0; arc=none smtp.client-ip=64.147.108.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="BvMW9Vm0" Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id BAF3E31206; Tue, 21 May 2024 15:57:20 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=tsBzMn6ZzXQDtyrDg97INTCA8 rJBYuiSH2QIGRY5oZ4=; b=BvMW9Vm0FxCJ7EACat+/ZUSlJs8Er9GnLN3yasZQr bbOO4/F9dTg1DGVELStshCfQF8zCaH9qzG2Te8+pod5yIc/h1Gxg7Wxsg6v7GJ/9 7IhwctCwOxyr4zQVbhZOTKN5DifEdqeWG6DW6vmwYxIPdVTRdDm/gKOF8FTWro2p BQ= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id B392331205; Tue, 21 May 2024 15:57:20 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 1FA1131204; Tue, 21 May 2024 15:57:20 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Johannes Schindelin Subject: [PATCH 06/12] hook: plug a new memory leak Date: Tue, 21 May 2024 12:56:52 -0700 Message-ID: <20240521195659.870714-7-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 551B3C9E-17AC-11EF-9060-78DCEB2EC81B-77302942!pb-smtp1.pobox.com From: Johannes Schindelin In 8db1e8743c0 (clone: prevent hooks from running during a clone, 2024-03-28), I introduced an inadvertent memory leak that was unfortunately not caught before v2.45.1 was released. Here is a fix. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- hook.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hook.c b/hook.c index 632b537b99..fc974cee1d 100644 --- a/hook.c +++ b/hook.c @@ -18,8 +18,10 @@ static int identical_to_template_hook(const char *name, const char *path) found_template_hook = access(template_path.buf, X_OK) >= 0; } #endif - if (!found_template_hook) + if (!found_template_hook) { + strbuf_release(&template_path); return 0; + } ret = do_files_match(template_path.buf, path); From patchwork Tue May 21 19:56:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669699 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) (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 330151494CD for ; Tue, 21 May 2024 19:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321444; cv=none; b=SWooktWgY10ixOCFVhbLQmWSKp2chW7/oEXfZrVt5a/nJfehlBQoXvkkIb8nfH/gMP9bwCbek1GdxrSgU4tgZa4IA4h5dzxkodqsXMEK4/IzdWuqCJXatKtMmP/897w9VKT9n/KT6voU84jLfY50gltTzdHY3jMzViDvFHH1udY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321444; c=relaxed/simple; bh=uCQM9Zlksy6MiYttstcPV+nkDsX8WJYmtLCG8s2WkYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MV/HRFnLqRa1chtJKzB3fcn6qYRkysH/yGcikKCqHFNM1h8Gov6AA6wUBxb+SI6uaRm8AssqkZXZla5apAJAmwfjqSBJNEOAJNi/vtqAhGh4PAwWvEiWz1DXrbQPAcN0UJJSvmFVx/bHCDFGHkwhMPqCoE53gcXrUWsVrd3Zd5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=uQKyYkDx; arc=none smtp.client-ip=64.147.108.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="uQKyYkDx" Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 4DA752228D; Tue, 21 May 2024 15:57:22 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=uCQM9Zlksy6MiYttstcPV+nkD sX8WJYmtLCG8s2WkYs=; b=uQKyYkDx39gWtvo86S/bUjQwA87Lb4xs4Lqsf3UPQ nBTZNAsQxXI6gvKXFeltg2iqadp4sqiko32XepQzrbWXSttG1H8h8ONOB6W+Nx1K 6D0ty2N/mcMRwIIuCFH5b+FeZQCWs8VEfciT3muqG5ls1xDQjf7z03ZAZlWIwmmY oA= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 458322228C; Tue, 21 May 2024 15:57:22 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id A73272228B; Tue, 21 May 2024 15:57:21 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Johannes Schindelin Subject: [PATCH 07/12] init: use the correct path of the templates directory again Date: Tue, 21 May 2024 12:56:53 -0700 Message-ID: <20240521195659.870714-8-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 5608D4EA-17AC-11EF-8A22-25B3960A682E-77302942!pb-smtp2.pobox.com From: Johannes Schindelin In df93e407f06 (init: refactor the template directory discovery into its own function, 2024-03-29), I refactored the way the templates directory is discovered. The refactoring was faithful, but missed a reference in the `Makefile` where the `DEFAULT_GIT_TEMPLATE_DIR` constant is defined. As a consequence, Git v2.45.1 and friends will always use the hard-coded path `/usr/share/git-core/templates`. Let's fix that by defining the `DEFAULT_GIT_TEMPLATE_DIR` when building `setup.o`, where that constant is actually used. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 093829ae28..4b1502ba2c 100644 --- a/Makefile +++ b/Makefile @@ -2751,7 +2751,7 @@ exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \ '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX -builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ +setup.sp setup.s setup.o: EXTRA_CPPFLAGS = \ -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' config.sp config.s config.o: GIT-PREFIX From patchwork Tue May 21 19:56:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669700 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) (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 D76741494DD for ; Tue, 21 May 2024 19:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321448; cv=none; b=TcLFhs9DOWKd2sA3n9u91/PtaRDDeR2UojHP4lXVTwmC/UXtDdgoBDZMnwA9AoE77GRNNgs1k7dwpBLjJILCuLTnSwrNeV//AcHvoMgUckWM9RCt1XWOJBXFdxTFcMN7jAc82nfp+hBvwS+N6hs4NOlMj0aUHs+HTXVY8zZjCq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321448; c=relaxed/simple; bh=/hXamjjLZaQHWfa6ICRbgFEnZW63j+p2W3spaxjKUdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZGjIt1tPKu5TJOK2I2PRGtmzyTEgFznCwx8mjF/uEEztaApcADhKTDj8oMXKY42ClAGahe2EIE/NzceuOr4eqUCgU9qchaXAVh62AvDf7Gg4jJPX6b7vNWGq+AjqPdahQr51fLH1w9KACu2l/E1OnOH+tJYvBCKoHU50mz1wPF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=xaQKmErX; arc=none smtp.client-ip=173.228.157.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="xaQKmErX" Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 7C6C62DBEF; Tue, 21 May 2024 15:57:26 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=/hXamjjLZaQHWfa6ICRbgFEnZ W63j+p2W3spaxjKUdU=; b=xaQKmErXtDd6/t5LJIuIOHGA64lbUopAA8NvVuQSV uyIU+g63ntgwYlROc4Lb09Ho5aSwU70YogDnuTnTxEMFVHsFlDYEWwDuhNzVp2ax Fck8ScNo9J1UpxZqtEKQbrvvCNfVa20Y7IeycbsJwN+oi2Hk5S8LToBr+VexbhU0 rU= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 75F892DBEE; Tue, 21 May 2024 15:57:26 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 85BCA2DBED; Tue, 21 May 2024 15:57:23 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Johannes Schindelin Subject: [PATCH 08/12] Revert "core.hooksPath: add some protection while cloning" Date: Tue, 21 May 2024 12:56:54 -0700 Message-ID: <20240521195659.870714-9-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 57250506-17AC-11EF-8AB9-F515D2CDFF5E-77302942!pb-smtp20.pobox.com From: Johannes Schindelin This defense-in-depth was intended to protect the clone operation against future escalations where bugs in `git clone` would allow attackers to write arbitrary files in the `.git/` directory would allow for Remote Code Execution attacks via maliciously-placed hooks. However, it turns out that the `core.hooksPath` protection has unintentional side effects so severe that they do not justify the benefit of the protections. For example, it has been reported in https://lore.kernel.org/git/FAFA34CB-9732-4A0A-87FB-BDB272E6AEE8@alchemists.io/ that the following invocation, which is intended to make `git clone` safer, is itself broken by that protective measure: git clone --config core.hooksPath=/dev/null Since it turns out that the benefit does not justify the cost, let's revert 20f3588efc6 (core.hooksPath: add some protection while cloning, 2024-03-30). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- config.c | 13 +------------ t/t1800-hook.sh | 15 --------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/config.c b/config.c index 85b37f2ee0..8c1c4071f0 100644 --- a/config.c +++ b/config.c @@ -1525,19 +1525,8 @@ static int git_default_core_config(const char *var, const char *value, void *cb) if (!strcmp(var, "core.attributesfile")) return git_config_pathname(&git_attributes_file, var, value); - if (!strcmp(var, "core.hookspath")) { - if (current_config_scope() == CONFIG_SCOPE_LOCAL && - git_env_bool("GIT_CLONE_PROTECTION_ACTIVE", 0)) - die(_("active `core.hooksPath` found in the local " - "repository config:\n\t%s\nFor security " - "reasons, this is disallowed by default.\nIf " - "this is intentional and the hook should " - "actually be run, please\nrun the command " - "again with " - "`GIT_CLONE_PROTECTION_ACTIVE=false`"), - value); + if (!strcmp(var, "core.hookspath")) return git_config_pathname(&git_hooks_path, var, value); - } if (!strcmp(var, "core.bare")) { is_bare_repository_cfg = git_config_bool(var, value); diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 7ee12e6f48..2ef3579fa7 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -177,19 +177,4 @@ test_expect_success 'git hook run a hook with a bad shebang' ' test_cmp expect actual ' -test_expect_success 'clone protections' ' - test_config core.hooksPath "$(pwd)/my-hooks" && - mkdir -p my-hooks && - write_script my-hooks/test-hook <<-\EOF && - echo Hook ran $1 - EOF - - git hook run test-hook 2>err && - grep "Hook ran" err && - test_must_fail env GIT_CLONE_PROTECTION_ACTIVE=true \ - git hook run test-hook 2>err && - grep "active .core.hooksPath" err && - ! grep "Hook ran" err -' - test_done From patchwork Tue May 21 19:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669701 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (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 28C111494DD for ; Tue, 21 May 2024 19:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321451; cv=none; b=aPZ14+C9oShvUWiTGXOKwvAmg4pPl80Gfn0Gut/Zh+awUFtgR79vCqnykCkPN0AOTcLZGYDIdYi10PE9X1H/cUd1o/Hf6ZBosrWAD+JhWCJ5t7uhPslHyPBKrNmIBpNH+kpl3hehMMd4goT3vTM13KEgQPi47htnPWjqW8D1iJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321451; c=relaxed/simple; bh=RF1htK79hEhaPg2EN1SMbIx/fjbxT7dL9fOAa6ajORg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aFE9PPD2ub1oetx7wwFgsVh7WTeg2+WE/RySbbd6PJp9pHgfxbHfTvn2sIeWGlx7ZIC5SUD0mBma38vZxiMtpUtMYCjBflIX3o3rN4xlSfRyoZb5AX1KvcVcH/vyyN1anVN+dtcMt1Hcvy+JzaozPJOqNmJ1mCluM6j3LeLokp8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=xklYn4Ob; arc=none smtp.client-ip=173.228.157.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="xklYn4Ob" Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id CAB1D3123C; Tue, 21 May 2024 15:57:29 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=RF1htK79hEhaPg2EN1SMbIx/f jbxT7dL9fOAa6ajORg=; b=xklYn4ObYWIV5FxcXE9gQv/Cg0yrqx0gUU6rcatat fsfDkTpqr7HGswYMVk56p5aSm4K9jr8LT+9TxyTeLjy92xo+Ns0oAww/hmgyxSTf lhiX0EtUcA6QkZEQNM1VWAJntsaPR8AyHf/5yeezbjwEPduopqWUmV+K+XZCl3La dM= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id C2BB53123B; Tue, 21 May 2024 15:57:29 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id D2C793123A; Tue, 21 May 2024 15:57:26 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Johannes Schindelin , Brooke Kuhlmann Subject: [PATCH 09/12] tests: verify that `clone -c core.hooksPath=/dev/null` works again Date: Tue, 21 May 2024 12:56:55 -0700 Message-ID: <20240521195659.870714-10-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 591EF1AA-17AC-11EF-9D7A-A19503B9AAD1-77302942!pb-smtp21.pobox.com From: Johannes Schindelin As part of the protections added in Git v2.45.1 and friends, repository-local `core.hooksPath` settings are no longer allowed, as a defense-in-depth mechanism to prevent future Git vulnerabilities to raise to critical level if those vulnerabilities inadvertently allow the repository-local config to be written. What the added protection did not anticipate is that such a repository-local `core.hooksPath` can not only be used to point to maliciously-placed scripts in the current worktree, but also to _prevent_ hooks from being called altogether. We just reverted the `core.hooksPath` protections, based on the Git maintainer's recommendation in https://lore.kernel.org/git/xmqq4jaxvm8z.fsf@gitster.g/ to address this concern as well as related ones. Let's make sure that we won't regress while trying to protect the clone operation further. Reported-by: Brooke Kuhlmann Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t1350-config-hooks-path.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh index f6dc83e2aa..45a0492917 100755 --- a/t/t1350-config-hooks-path.sh +++ b/t/t1350-config-hooks-path.sh @@ -41,4 +41,11 @@ test_expect_success 'git rev-parse --git-path hooks' ' test .git/custom-hooks/abc = "$(cat actual)" ' +test_expect_success 'core.hooksPath=/dev/null' ' + git clone -c core.hooksPath=/dev/null . no-templates && + value="$(git -C no-templates config --local core.hooksPath)" && + # The Bash used by Git for Windows rewrites `/dev/null` to `nul` + { test /dev/null = "$value" || test nul = "$value"; } +' + test_done From patchwork Tue May 21 19:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669702 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (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 3A486149C46 for ; Tue, 21 May 2024 19:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321452; cv=none; b=GAa971qXGcCzXb7IhTasfEC1+K4SyHKE+rnXvFO8s/gSf7Z3p5TRyQLDA7McoYeuO6o3XE0NqlWOekRplI5oT4rO2n+3reFLLNwt8mB4rp+jItfYQREALv00p8qlZ9FPE5H4J6SsXF7dHMmb4S+64b6XePGa2Eck3Yz3AfsKYs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321452; c=relaxed/simple; bh=mOhWb+byk2NBFPl43kKXjDnKvXRcP1aXsZZT91qb8KY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qKOCpzv8uO0htwGnMrGLyCmWIeis+ogcX93ZlabKJlR42OnaGE+pnk8zMrOOT57q/lReXcnbcXWv2Vh2aCfwWN1aSkMcELvQNTpZIDz3UD74OlL2fkwEIzsKLBVJ1tp7q8Cqhkq7i59NGxpQhrhYm2GFqGnb1hxD9BAWgL9eOwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=WCaVV4DJ; arc=none smtp.client-ip=64.147.108.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="WCaVV4DJ" Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 6BFEF31209; Tue, 21 May 2024 15:57:30 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=mOhWb+byk2NBFPl43kKXjDnKv XRcP1aXsZZT91qb8KY=; b=WCaVV4DJ45pnbuvM8U1DIOUlUG4zNUZC13DQCf/Wg ARd7TI4Q4a7pOOuC6FlXOa5ZpSJYZu4KrPx5YvZF9SQ6VrO6MDaId/3aJXGdchkY GZd8g+Tl7qW8fak4Cmk6KkRq+E5FMmItj+wqGeDP/2ikXdTc/USAiPCbEsqVdRwD Ag= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 64E1631208; Tue, 21 May 2024 15:57:30 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id D06F131207; Tue, 21 May 2024 15:57:29 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Johannes Schindelin Subject: [PATCH 10/12] clone: drop the protections where hooks aren't run Date: Tue, 21 May 2024 12:56:56 -0700 Message-ID: <20240521195659.870714-11-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 5AE6D962-17AC-11EF-9FE2-78DCEB2EC81B-77302942!pb-smtp1.pobox.com From: Johannes Schindelin As part of the security bug-fix releases v2.39.4, ..., v2.45.1, I introduced logic to safeguard `git clone` from running hooks that were installed _during_ the clone operation. The rationale was that Git's CVE-2024-32002, CVE-2021-21300, CVE-2019-1354, CVE-2019-1353, CVE-2019-1352, and CVE-2019-1349 should have been low-severity vulnerabilities but were elevated to critical/high severity by the attack vector that allows a weakness where files inside `.git/` can be inadvertently written during a `git clone` to escalate to a Remote Code Execution attack by virtue of installing a malicious `post-checkout` hook that Git will then run at the end of the operation without giving the user a chance to see what code is executed. Unfortunately, Git LFS uses a similar strategy to install its own `post-checkout` hook during a `git clone`; In fact, Git LFS is installing four separate hooks while running the `smudge` filter. While this pattern is probably in want of being improved by introducing better support in Git for Git LFS and other tools wishing to register hooks to be run at various stages of Git's commands, let's undo the clone protections to unbreak Git LFS-enabled clones. This reverts commit 8db1e8743c0 (clone: prevent hooks from running during a clone, 2024-03-28). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin/clone.c | 12 +----------- hook.c | 34 -------------------------------- t/t5601-clone.sh | 51 ------------------------------------------------ 3 files changed, 1 insertion(+), 96 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index e7721f5c22..9ec500d427 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -937,8 +937,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int err = 0, complete_refs_before_fetch = 1; int submodule_progress; int filter_submodules = 0; - const char *template_dir; - char *template_dir_dup = NULL; struct transport_ls_refs_options transport_ls_refs_options = TRANSPORT_LS_REFS_OPTIONS_INIT; @@ -958,13 +956,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) usage_msg_opt(_("You must specify a repository to clone."), builtin_clone_usage, builtin_clone_options); - xsetenv("GIT_CLONE_PROTECTION_ACTIVE", "true", 0 /* allow user override */); - template_dir = get_template_dir(option_template); - if (*template_dir && !is_absolute_path(template_dir)) - template_dir = template_dir_dup = - absolute_pathdup(template_dir); - xsetenv("GIT_CLONE_TEMPLATE_DIR", template_dir, 1); - if (option_depth || option_since || option_not.nr) deepen = 1; if (option_single_branch == -1) @@ -1112,7 +1103,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } } - init_db(git_dir, real_git_dir, template_dir, GIT_HASH_UNKNOWN, NULL, + init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL, INIT_DB_QUIET); if (real_git_dir) { @@ -1430,7 +1421,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) free(unborn_head); free(dir); free(path); - free(template_dir_dup); UNLEAK(repo); junk_mode = JUNK_LEAVE_ALL; diff --git a/hook.c b/hook.c index fc974cee1d..22b274b60b 100644 --- a/hook.c +++ b/hook.c @@ -3,32 +3,6 @@ #include "run-command.h" #include "config.h" -static int identical_to_template_hook(const char *name, const char *path) -{ - const char *env = getenv("GIT_CLONE_TEMPLATE_DIR"); - const char *template_dir = get_template_dir(env && *env ? env : NULL); - struct strbuf template_path = STRBUF_INIT; - int found_template_hook, ret; - - strbuf_addf(&template_path, "%s/hooks/%s", template_dir, name); - found_template_hook = access(template_path.buf, X_OK) >= 0; -#ifdef STRIP_EXTENSION - if (!found_template_hook) { - strbuf_addstr(&template_path, STRIP_EXTENSION); - found_template_hook = access(template_path.buf, X_OK) >= 0; - } -#endif - if (!found_template_hook) { - strbuf_release(&template_path); - return 0; - } - - ret = do_files_match(template_path.buf, path); - - strbuf_release(&template_path); - return ret; -} - const char *find_hook(const char *name) { static struct strbuf path = STRBUF_INIT; @@ -64,14 +38,6 @@ const char *find_hook(const char *name) } return NULL; } - if (!git_hooks_path && git_env_bool("GIT_CLONE_PROTECTION_ACTIVE", 0) && - !identical_to_template_hook(name, path.buf)) - die(_("active `%s` hook found during `git clone`:\n\t%s\n" - "For security reasons, this is disallowed by default.\n" - "If this is intentional and the hook should actually " - "be run, please\nrun the command again with " - "`GIT_CLONE_PROTECTION_ACTIVE=false`"), - name, path.buf); return path.buf; } diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 20deca0231..fd02984330 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -771,57 +771,6 @@ test_expect_success 'batch missing blob request does not inadvertently try to fe git clone --filter=blob:limit=0 "file://$(pwd)/server" client ' -test_expect_success 'clone with init.templatedir runs hooks' ' - git init tmpl/hooks && - write_script tmpl/hooks/post-checkout <<-EOF && - echo HOOK-RUN >&2 - echo I was here >hook.run - EOF - git -C tmpl/hooks add . && - test_tick && - git -C tmpl/hooks commit -m post-checkout && - - test_when_finished "git config --global --unset init.templateDir || :" && - test_when_finished "git config --unset init.templateDir || :" && - ( - sane_unset GIT_TEMPLATE_DIR && - NO_SET_GIT_TEMPLATE_DIR=t && - export NO_SET_GIT_TEMPLATE_DIR && - - git -c core.hooksPath="$(pwd)/tmpl/hooks" \ - clone tmpl/hooks hook-run-hookspath 2>err && - ! grep "active .* hook found" err && - test_path_is_file hook-run-hookspath/hook.run && - - git -c init.templateDir="$(pwd)/tmpl" \ - clone tmpl/hooks hook-run-config 2>err && - ! grep "active .* hook found" err && - test_path_is_file hook-run-config/hook.run && - - git clone --template=tmpl tmpl/hooks hook-run-option 2>err && - ! grep "active .* hook found" err && - test_path_is_file hook-run-option/hook.run && - - git config --global init.templateDir "$(pwd)/tmpl" && - git clone tmpl/hooks hook-run-global-config 2>err && - git config --global --unset init.templateDir && - ! grep "active .* hook found" err && - test_path_is_file hook-run-global-config/hook.run && - - # clone ignores local `init.templateDir`; need to create - # a new repository because we deleted `.git/` in the - # `setup` test case above - git init local-clone && - cd local-clone && - - git config init.templateDir "$(pwd)/../tmpl" && - git clone ../tmpl/hooks hook-run-local-config 2>err && - git config --unset init.templateDir && - ! grep "active .* hook found" err && - test_path_is_missing hook-run-local-config/hook.run - ) -' - . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd From patchwork Tue May 21 19:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669703 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) (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 F0D2F149C54 for ; Tue, 21 May 2024 19:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321454; cv=none; b=jCOr/mcDdNm+JjTuMUjdRyz+/QaB9au42yzbvCLtmLbVS+Tlybq+70J/MouFh42qw7j0LADLoMkent+C3oCGlQtWOYeQGtS3qxh479wofK5Hjh1H/eyaNNDCmLGces9rDAYkUZz2/5TmKvVZR4PsAi3U8LQvom+KFtzNonWoOqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321454; c=relaxed/simple; bh=bT9U6JZaSx5HPrksYCIgmRPWw2qdVvhiv+QJenj9zjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DXGcm/wfpQYDzXgBWr5t0ifqpfyKHBmesuOag+vphIkpkDG7h1r0nPkGYtPf+wGSR89gQSlZrSxj1KGsqbdSm8AD+nVTDX8udVzxtTjm/729zpR76rL46aWNpMDHn6hM0qspUOMd3Mxs+bArOet6xDSKdnwtgPAiPuzSUC5qmtc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=NIZHdT7V; arc=none smtp.client-ip=64.147.108.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="NIZHdT7V" Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 0AA8522290; Tue, 21 May 2024 15:57:32 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=bT9U6JZaSx5HPrksYCIgmRPWw 2qdVvhiv+QJenj9zjQ=; b=NIZHdT7V9YSXnu1U9rafT/R39dpnk1MvX1hybLHGt W85gYpUe6rhfjnrsej/25WjkeJy0aA9XAbuMMyWxchjlikGh/Gr3CM2qIOeU0E0s 9i+uhGB43/fanoEyntXrlz/jKnrWjbOMGdMezkSmMYGqSw4tvhBTYbWTYuRgGsGo 8k= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 023C22228F; Tue, 21 May 2024 15:57:32 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 5D9F72228E; Tue, 21 May 2024 15:57:31 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Johannes Schindelin Subject: [PATCH 11/12] Revert "Add a helper function to compare file contents" Date: Tue, 21 May 2024 12:56:57 -0700 Message-ID: <20240521195659.870714-12-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 5BD0C3D8-17AC-11EF-832F-25B3960A682E-77302942!pb-smtp2.pobox.com From: Johannes Schindelin Now that during a `git clone`, the hooks' contents are no longer compared to the templates' files', the caller for which the `do_files_match()` function was introduced is gone, and therefore this function can be retired, too. This reverts commit 584de0b4c23 (Add a helper function to compare file contents, 2024-03-30). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 14 --------- copy.c | 58 -------------------------------------- t/helper/test-path-utils.c | 10 ------- t/t0060-path-utils.sh | 41 --------------------------- 4 files changed, 123 deletions(-) diff --git a/cache.h b/cache.h index 16b34799bf..8c5fb1e1ba 100644 --- a/cache.h +++ b/cache.h @@ -1785,20 +1785,6 @@ int copy_fd(int ifd, int ofd); int copy_file(const char *dst, const char *src, int mode); int copy_file_with_time(const char *dst, const char *src, int mode); -/* - * Compare the file mode and contents of two given files. - * - * If both files are actually symbolic links, the function returns 1 if the link - * targets are identical or 0 if they are not. - * - * If any of the two files cannot be accessed or in case of read failures, this - * function returns 0. - * - * If the file modes and contents are identical, the function returns 1, - * otherwise it returns 0. - */ -int do_files_match(const char *path1, const char *path2); - void write_or_die(int fd, const void *buf, size_t count); void fsync_or_die(int fd, const char *); int fsync_component(enum fsync_component component, int fd); diff --git a/copy.c b/copy.c index 8492f6fc83..4de6a110f0 100644 --- a/copy.c +++ b/copy.c @@ -65,61 +65,3 @@ int copy_file_with_time(const char *dst, const char *src, int mode) return copy_times(dst, src); return status; } - -static int do_symlinks_match(const char *path1, const char *path2) -{ - struct strbuf buf1 = STRBUF_INIT, buf2 = STRBUF_INIT; - int ret = 0; - - if (!strbuf_readlink(&buf1, path1, 0) && - !strbuf_readlink(&buf2, path2, 0)) - ret = !strcmp(buf1.buf, buf2.buf); - - strbuf_release(&buf1); - strbuf_release(&buf2); - return ret; -} - -int do_files_match(const char *path1, const char *path2) -{ - struct stat st1, st2; - int fd1 = -1, fd2 = -1, ret = 1; - char buf1[8192], buf2[8192]; - - if ((fd1 = open_nofollow(path1, O_RDONLY)) < 0 || - fstat(fd1, &st1) || !S_ISREG(st1.st_mode)) { - if (fd1 < 0 && errno == ELOOP) - /* maybe this is a symbolic link? */ - return do_symlinks_match(path1, path2); - ret = 0; - } else if ((fd2 = open_nofollow(path2, O_RDONLY)) < 0 || - fstat(fd2, &st2) || !S_ISREG(st2.st_mode)) { - ret = 0; - } - - if (ret) - /* to match, neither must be executable, or both */ - ret = !(st1.st_mode & 0111) == !(st2.st_mode & 0111); - - if (ret) - ret = st1.st_size == st2.st_size; - - while (ret) { - ssize_t len1 = read_in_full(fd1, buf1, sizeof(buf1)); - ssize_t len2 = read_in_full(fd2, buf2, sizeof(buf2)); - - if (len1 < 0 || len2 < 0 || len1 != len2) - ret = 0; /* read error or different file size */ - else if (!len1) /* len2 is also 0; hit EOF on both */ - break; /* ret is still true */ - else - ret = !memcmp(buf1, buf2, len1); - } - - if (fd1 >= 0) - close(fd1); - if (fd2 >= 0) - close(fd2); - - return ret; -} diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 0e0de21807..f69709d674 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -495,16 +495,6 @@ int cmd__path_utils(int argc, const char **argv) return !!res; } - if (argc == 4 && !strcmp(argv[1], "do_files_match")) { - int ret = do_files_match(argv[2], argv[3]); - - if (ret) - printf("equal\n"); - else - printf("different\n"); - return !ret; - } - fprintf(stderr, "%s: unknown function name: %s\n", argv[0], argv[1] ? argv[1] : "(there was none)"); return 1; diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 73d0e1a7f1..68e29c904a 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -560,45 +560,4 @@ test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' test_cmp expect actual ' -test_expect_success 'do_files_match()' ' - test_seq 0 10 >0-10.txt && - test_seq -1 10 >-1-10.txt && - test_seq 1 10 >1-10.txt && - test_seq 1 9 >1-9.txt && - test_seq 0 8 >0-8.txt && - - test-tool path-utils do_files_match 0-10.txt 0-10.txt >out && - - assert_fails() { - test_must_fail \ - test-tool path-utils do_files_match "$1" "$2" >out && - grep different out - } && - - assert_fails 0-8.txt 1-9.txt && - assert_fails -1-10.txt 0-10.txt && - assert_fails 1-10.txt 1-9.txt && - assert_fails 1-10.txt .git && - assert_fails does-not-exist 1-10.txt && - - if test_have_prereq FILEMODE - then - cp 0-10.txt 0-10.x && - chmod a+x 0-10.x && - assert_fails 0-10.txt 0-10.x - fi && - - if test_have_prereq SYMLINKS - then - ln -sf 0-10.txt symlink && - ln -s 0-10.txt another-symlink && - ln -s over-the-ocean yet-another-symlink && - ln -s "$PWD/0-10.txt" absolute-symlink && - assert_fails 0-10.txt symlink && - test-tool path-utils do_files_match symlink another-symlink && - assert_fails symlink yet-another-symlink && - assert_fails symlink absolute-symlink - fi -' - test_done From patchwork Tue May 21 19:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669704 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) (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 96EC21494A2 for ; Tue, 21 May 2024 19:57:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321457; cv=none; b=s8cxch/wzfStUbn/HYDwOmjwcw4WPTHMIWdzyoI+YPrAVOi/qaGeRBx6JBEOYZXjiUAuBYcjPMKx3QIv9kF0ai2r1Xw3WOsFjvuBZ0VaUSOJId1fUIsJT8v0/4j9ZwFvmPUrhWEN18gPgg2ueVmBG65R4xe60Ndcl3NaBBkO8rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716321457; c=relaxed/simple; bh=sGt4fckFb6a1hc82xeYVNXay/KtR5awbOaVQNzV3dmA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NHq5QBU9U5S+ZQGFQrwheGsMbtPSoBMoPGDdu9KF3UUtEZ9KWxFM11/udH0rXjwQb8U6eh11qtXXRS3m1ACB8lCopaFpRvSCsOnFtQg707pKEc69NqFnFsMtHKhVU9jESkv+/ZMDaZCYX9S3uIwuoeTqojUHQhHfAJHCuLaaxZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=czSSnJWZ; arc=none smtp.client-ip=173.228.157.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="czSSnJWZ" Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 3B73E2DBF2; Tue, 21 May 2024 15:57:36 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=sGt4fckFb6a1hc82xeYVNXay/ KtR5awbOaVQNzV3dmA=; b=czSSnJWZc/aiKQC1LlWlPsydWFhTR/Ri2SLSOGG8X WDlsEaxxyZfeBjtaQ6NvvwoQvVPpja5Aw6llqO0bxczBj3gjCAOJfnWiBVdbSmaw rWxGteaFkH4yAbhVcGUN6hYlb8iAxhzFl28KDX4QdMNxBpUS8Ru/VB1VFLHJ8YgN Ms= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 3368B2DBF1; Tue, 21 May 2024 15:57:36 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 413192DBF0; Tue, 21 May 2024 15:57:33 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 12/12] Revert "fetch/clone: detect dubious ownership of local repositories" Date: Tue, 21 May 2024 12:56:58 -0700 Message-ID: <20240521195659.870714-13-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 5CEFA9D2-17AC-11EF-81CE-F515D2CDFF5E-77302942!pb-smtp20.pobox.com This partially reverts f4aa8c8b (fetch/clone: detect dubious ownership of local repositories, 2024-04-10) that broke typical read-only use cases (e.g. by git-daemon serving fetches and clones) where "nobody" who has no write permission serves repositories owned by others. The function to die upon seeing dubious ownership is still kept, as there are other users of it, but calls to it from the generic repository discovery code path, which triggered in cases far wider than originally intended (i.e. to stop local clones), have been removed. Signed-off-by: Junio C Hamano --- path.c | 2 -- t/t0411-clone-from-partial.sh | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/path.c b/path.c index d61f70e87d..492e17ad12 100644 --- a/path.c +++ b/path.c @@ -840,7 +840,6 @@ const char *enter_repo(const char *path, int strict) if (!suffix[i]) return NULL; gitfile = read_gitfile(used_path.buf); - die_upon_dubious_ownership(gitfile, NULL, used_path.buf); if (gitfile) { strbuf_reset(&used_path); strbuf_addstr(&used_path, gitfile); @@ -851,7 +850,6 @@ const char *enter_repo(const char *path, int strict) } else { const char *gitfile = read_gitfile(path); - die_upon_dubious_ownership(gitfile, NULL, path); if (gitfile) path = gitfile; if (chdir(path)) diff --git a/t/t0411-clone-from-partial.sh b/t/t0411-clone-from-partial.sh index b3d6ddc4bc..a481ed97b7 100755 --- a/t/t0411-clone-from-partial.sh +++ b/t/t0411-clone-from-partial.sh @@ -23,7 +23,7 @@ test_expect_success 'create evil repo' ' >evil/.git/shallow ' -test_expect_success 'local clone must not fetch from promisor remote and execute script' ' +test_expect_failure 'local clone must not fetch from promisor remote and execute script' ' rm -f script-executed && test_must_fail git clone \ --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \ @@ -33,7 +33,7 @@ test_expect_success 'local clone must not fetch from promisor remote and execute test_path_is_missing script-executed ' -test_expect_success 'clone from file://... must not fetch from promisor remote and execute script' ' +test_expect_failure 'clone from file://... must not fetch from promisor remote and execute script' ' rm -f script-executed && test_must_fail git clone \ --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \ @@ -43,7 +43,7 @@ test_expect_success 'clone from file://... must not fetch from promisor remote a test_path_is_missing script-executed ' -test_expect_success 'fetch from file://... must not fetch from promisor remote and execute script' ' +test_expect_failure 'fetch from file://... must not fetch from promisor remote and execute script' ' rm -f script-executed && test_must_fail git fetch \ --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \ From patchwork Tue May 21 20:45:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669725 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (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 B06A551C27 for ; Tue, 21 May 2024 20:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324312; cv=none; b=NdDk93nlww2crKppEqtGcAP7ds6JWk7rE+qOgu6t0AtGh7x70HO2lSJJHIFcILP3YNMRRYN+ciycu4kV1AvY5lz1bAdSyyHo6cWIAr2aAlyfa2j+zVxCIgkaOUTaGm6aL6D2ouqzY/+YgdVMSFWsbWrlwRdxG4uHacDkhOqvuKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324312; c=relaxed/simple; bh=DIv4DhJ6/tv/xw5azVW2PBHi82q80nyDHI+i4fWaCBA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kSYBeX2CjCnymgEnrv5hihBlgy1WmpmLy8zxXqvh8+xfVdjhiwHPuq0hAQsrWsqydMondYnsA6H68ybzvew7JCp7hSe62jiYeuFHsfOoqWDOsjRRgEL4O6B8kpjhYbXXYIlmLwirBwZRalNBAjWCuG2+xfiqIwd3IMMcm2yOhz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=lq9efm1W; arc=none smtp.client-ip=64.147.108.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="lq9efm1W" Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 80266315ED; Tue, 21 May 2024 16:45:09 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=DIv4DhJ6/tv/xw5azVW2PBHi8 2q80nyDHI+i4fWaCBA=; b=lq9efm1Wigc0ZmUn/k3DKMA5ueC38/xUp4wotpoZm rh6Qllhhrq+leEdKVfjPj6TsPaxOTcfZ+MFmX58LrZ1ltq6g+UBrqRfXA0jSTsAP j0eEvq+Fu++haTgbuQNJ9a3/Rpi8+nw2/4nlNiNZDV4nBO0b/j+YOFVC+lvJSyie +o= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 6EEE1315EC; Tue, 21 May 2024 16:45:09 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 726F9315EA; Tue, 21 May 2024 16:45:08 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [rPATCH 13/12] Merge branch 'jc/fix-aggressive-protection-2.39' Date: Tue, 21 May 2024 13:45:06 -0700 Message-ID: <20240521204507.1288528-1-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 02C57AF2-17B3-11EF-9AB3-78DCEB2EC81B-77302942!pb-smtp1.pobox.com This is "git show --remerge-diff" of the result of adjusting the jc/fix-aggressive-protection-2.39 topic (which you just saw) into maint-2.40 track. The result is called jc/fix-aggressive-protection-2.40. It is not for direct consumption by "git am". If this format looks reasonable to folks as a way to review the result of merging up fixes, I'll follow up with "patches" for more recent maintenance tracks. diff --git a/builtin/clone.c b/builtin/clone.c remerge CONFLICT (content): Merge conflict in builtin/clone.c index 17d34efebd..399b2d3f42 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1447,15 +1447,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) free(unborn_head); free(dir); free(path); -<<<<<<< b9b439e0e3 (Git 2.40.2) free(repo_to_free); - free(template_dir_dup); -||||||| 47b6d90e91 - free(template_dir_dup); UNLEAK(repo); -======= - UNLEAK(repo); ->>>>>>> 9074ec92e7 (Revert "fetch/clone: detect dubious ownership of local repositories") junk_mode = JUNK_LEAVE_ALL; transport_ls_refs_options_release(&transport_ls_refs_options); diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh remerge CONFLICT (content): Merge conflict in t/t1800-hook.sh index edf0fa1334..3506f627b6 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -177,7 +177,6 @@ test_expect_success 'git hook run a hook with a bad shebang' ' test_cmp expect actual ' -<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< b9b439e0e3 (Git 2.40.2) test_expect_success 'stdin to hooks' ' write_script .git/hooks/test-hook <<-\EOF && echo BEGIN stdin @@ -196,37 +195,4 @@ test_expect_success 'stdin to hooks' ' test_cmp expect actual ' -test_expect_success 'clone protections' ' - test_config core.hooksPath "$(pwd)/my-hooks" && - mkdir -p my-hooks && - write_script my-hooks/test-hook <<-\EOF && - echo Hook ran $1 - EOF - - git hook run test-hook 2>err && - grep "Hook ran" err && - test_must_fail env GIT_CLONE_PROTECTION_ACTIVE=true \ - git hook run test-hook 2>err && - grep "active .core.hooksPath" err && - ! grep "Hook ran" err -' - -|||||||||||||||||||||||||||||||| 47b6d90e91 -test_expect_success 'clone protections' ' - test_config core.hooksPath "$(pwd)/my-hooks" && - mkdir -p my-hooks && - write_script my-hooks/test-hook <<-\EOF && - echo Hook ran $1 - EOF - - git hook run test-hook 2>err && - grep "Hook ran" err && - test_must_fail env GIT_CLONE_PROTECTION_ACTIVE=true \ - git hook run test-hook 2>err && - grep "active .core.hooksPath" err && - ! grep "Hook ran" err -' - -================================ ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 9074ec92e7 (Revert "fetch/clone: detect dubious ownership of local repositories") test_done From patchwork Tue May 21 20:45:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13669726 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (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 6611451C27 for ; Tue, 21 May 2024 20:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324317; cv=none; b=QHK7muePRqYLmtTakxGXbeZ5sq66SrUbldlYO504WTO1Kj7hviB2cq54RqItHdvarkqNFm6Ve4eO2fOIYfJc23z2JUY6Ov3Qxo+bXyKGPO5ZOY5eWu5rXKcvj/swcdqXArmuasDXlWCcGqwbW4I5Wh8RVfrSXOsSSNuy5yzDS58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324317; c=relaxed/simple; bh=5euu4+mRtFbThnSLb1M0Wgkt+KGJY5gNtaCJzWWSoDE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZPB2iASacwkkQ0FC67JTKCn6G9hiLkgi8tvS4/D97anoi4XDWfQVJgA7aE9BechQL5qTPtjn7fmTT+6khl2LnsgnoxKDKwHIcyIMuTGjFBiOyP22jDufusbdxhKG8Txc1833TpA6u29cpPl8LxwOwXnyWo1ElXey6OQNZaQftZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=NQm+OBki; arc=none smtp.client-ip=173.228.157.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="NQm+OBki" Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 0F7D431617; Tue, 21 May 2024 16:45:14 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=5euu4+mRtFbThnSLb1M0Wgkt+ KGJY5gNtaCJzWWSoDE=; b=NQm+OBkiZP67N4SCF8Tgt8NaPNW6nwLhyRYVyN0V3 GOifpNr99WyIrLZlT3Dc0xrUVS9LYDo2VJScwfKMetoiz6K1MDiD8GwqaBMcPqTC /Z/V6YToj8UIJk94HfPgn8grUqZx9Uur/k19p/5zq0FbSCkqX4XzV7FR46Oy06XI /E= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 06F6E31616; Tue, 21 May 2024 16:45:14 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.173.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 79D1D31613; Tue, 21 May 2024 16:45:10 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [rPATCH 14/12] Merge branch 'jc/fix-aggressive-protection-2.40' Date: Tue, 21 May 2024 13:45:07 -0700 Message-ID: <20240521204507.1288528-2-gitster@pobox.com> X-Mailer: git-send-email 2.45.1-216-g4365c6fcf9 In-Reply-To: <20240521195659.870714-1-gitster@pobox.com> References: <20240521195659.870714-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: 03FAAB18-17B3-11EF-997A-A19503B9AAD1-77302942!pb-smtp21.pobox.com With patches 01/12 - 12/12 applied on top of maint-2.39 (the result of which is called jc/fix-aggressive-protection-2.39), and then the result merged to maint-2.40 with conflict resolutions shown in 13/12, I've prepared jc/fix-aggressive-protection-2.40. This is "git show --remerge-diff" of the result of adjusting the jc/fix-aggressive-protection-2.40 topic to maint-2.41 track. The result is called jc/fix-aggressive-protection-2.41. It is not for direct consumption by "git am". The only tricky part is an evil merge to copy.h that was made necessarily due to recent header file shuffling. diff --git a/builtin/clone.c b/builtin/clone.c remerge CONFLICT (content): Merge conflict in builtin/clone.c index 85ecda8e6f..b7db074b7e 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -958,15 +958,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int err = 0, complete_refs_before_fetch = 1; int submodule_progress; int filter_submodules = 0; -<<<<<<< 0f15832059 (Git 2.41.1) int hash_algo; - const char *template_dir; - char *template_dir_dup = NULL; -||||||| b9b439e0e3 - const char *template_dir; - char *template_dir_dup = NULL; -======= ->>>>>>> 1b2b92753e (Merge branch 'jc/fix-aggressive-protection-2.39' into HEAD) struct transport_ls_refs_options transport_ls_refs_options = TRANSPORT_LS_REFS_OPTIONS_INIT; diff --git a/cache.h b/cache.h remerge CONFLICT (content): Merge conflict in cache.h index 534e983b90..bdedb87e83 100644 --- a/cache.h +++ b/cache.h @@ -555,1301 +555,7 @@ extern int verify_ce_order; #define DATA_CHANGED 0x0020 #define TYPE_CHANGED 0x0040 -<<<<<<< 0f15832059 (Git 2.41.1) int cmp_cache_name_compare(const void *a_, const void *b_); -||||||| b9b439e0e3 -/* - * Return an abbreviated sha1 unique within this repository's object database. - * The result will be at least `len` characters long, and will be NUL - * terminated. - * - * The non-`_r` version returns a static buffer which remains valid until 4 - * more calls to find_unique_abbrev are made. - * - * The `_r` variant writes to a buffer supplied by the caller, which must be at - * least `GIT_MAX_HEXSZ + 1` bytes. The return value is the number of bytes - * written (excluding the NUL terminator). - * - * Note that while this version avoids the static buffer, it is not fully - * reentrant, as it calls into other non-reentrant git code. - */ -const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len); -#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len) -int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); -#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len) - -/* set default permissions by passing mode arguments to open(2) */ -int git_mkstemps_mode(char *pattern, int suffix_len, int mode); -int git_mkstemp_mode(char *pattern, int mode); - -/* - * NOTE NOTE NOTE!! - * - * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must - * not be changed. Old repositories have core.sharedrepository written in - * numeric format, and therefore these values are preserved for compatibility - * reasons. - */ -enum sharedrepo { - PERM_UMASK = 0, - OLD_PERM_GROUP = 1, - OLD_PERM_EVERYBODY = 2, - PERM_GROUP = 0660, - PERM_EVERYBODY = 0664 -}; -int git_config_perm(const char *var, const char *value); -int adjust_shared_perm(const char *path); - -/* - * Create the directory containing the named path, using care to be - * somewhat safe against races. Return one of the scld_error values to - * indicate success/failure. On error, set errno to describe the - * problem. - * - * SCLD_VANISHED indicates that one of the ancestor directories of the - * path existed at one point during the function call and then - * suddenly vanished, probably because another process pruned the - * directory while we were working. To be robust against this kind of - * race, callers might want to try invoking the function again when it - * returns SCLD_VANISHED. - * - * safe_create_leading_directories() temporarily changes path while it - * is working but restores it before returning. - * safe_create_leading_directories_const() doesn't modify path, even - * temporarily. Both these variants adjust the permissions of the - * created directories to honor core.sharedRepository, so they are best - * suited for files inside the git dir. For working tree files, use - * safe_create_leading_directories_no_share() instead, as it ignores - * the core.sharedRepository setting. - */ -enum scld_error { - SCLD_OK = 0, - SCLD_FAILED = -1, - SCLD_PERMS = -2, - SCLD_EXISTS = -3, - SCLD_VANISHED = -4 -}; -enum scld_error safe_create_leading_directories(char *path); -enum scld_error safe_create_leading_directories_const(const char *path); -enum scld_error safe_create_leading_directories_no_share(char *path); - -int mkdir_in_gitdir(const char *path); -char *interpolate_path(const char *path, int real_home); -/* NEEDSWORK: remove this synonym once in-flight topics have migrated */ -#define expand_user_path interpolate_path -const char *enter_repo(const char *path, int strict); -static inline int is_absolute_path(const char *path) -{ - return is_dir_sep(path[0]) || has_dos_drive_prefix(path); -} -int is_directory(const char *); -char *strbuf_realpath(struct strbuf *resolved, const char *path, - int die_on_error); -char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, - int die_on_error); -char *real_pathdup(const char *path, int die_on_error); -const char *absolute_path(const char *path); -char *absolute_pathdup(const char *path); -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); -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); - -/* - * These functions match their is_hfs_dotgit() counterparts; see utf8.h for - * details. - */ -int is_ntfs_dotgit(const char *name); -int is_ntfs_dotgitmodules(const char *name); -int is_ntfs_dotgitignore(const char *name); -int is_ntfs_dotgitattributes(const char *name); -int is_ntfs_dotmailmap(const char *name); - -/* - * Returns true iff "str" could be confused as a command-line option when - * passed to a sub-program like "ssh". Note that this has nothing to do with - * shell-quoting, which should be handled separately; we're assuming here that - * the string makes it verbatim to the sub-program. - */ -int looks_like_command_line_option(const char *str); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise - * "$HOME/.config/$subdir/$filename". Return NULL upon error. - */ -char *xdg_config_home_for(const char *subdir, const char *filename); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise - * "$HOME/.config/git/$filename". Return NULL upon error. - */ -char *xdg_config_home(const char *filename); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise - * "$HOME/.cache/git/$filename". Return NULL upon error. - */ -char *xdg_cache_home(const char *filename); - -int git_open_cloexec(const char *name, int flags); -#define git_open(name) git_open_cloexec(name, O_RDONLY) - -/** - * unpack_loose_header() initializes the data stream needed to unpack - * a loose object header. - * - * Returns: - * - * - ULHR_OK on success - * - ULHR_BAD on error - * - ULHR_TOO_LONG if the header was too long - * - * It will only parse up to MAX_HEADER_LEN bytes unless an optional - * "hdrbuf" argument is non-NULL. This is intended for use with - * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error) - * reporting. The full header will be extracted to "hdrbuf" for use - * with parse_loose_header(), ULHR_TOO_LONG will still be returned - * from this function to indicate that the header was too long. - */ -enum unpack_loose_header_result { - ULHR_OK, - ULHR_BAD, - ULHR_TOO_LONG, -}; -enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, - unsigned char *map, - unsigned long mapsize, - void *buffer, - unsigned long bufsiz, - struct strbuf *hdrbuf); - -/** - * parse_loose_header() parses the starting " \0" of an - * object. If it doesn't follow that format -1 is returned. To check - * the validity of the populate the "typep" in the "struct - * object_info". It will be OBJ_BAD if the object type is unknown. The - * parsed can be retrieved via "oi->sizep", and from there - * passed to unpack_loose_rest(). - */ -struct object_info; -int parse_loose_header(const char *hdr, struct object_info *oi); - -/** - * With in-core object data in "buf", rehash it to make sure the - * object name actually matches "oid" to detect object corruption. - * - * A negative value indicates an error, usually that the OID is not - * what we expected, but it might also indicate another error. - */ -int check_object_signature(struct repository *r, const struct object_id *oid, - void *map, unsigned long size, - enum object_type type); - -/** - * A streaming version of check_object_signature(). - * Try reading the object named with "oid" using - * the streaming interface and rehash it to do the same. - */ -int stream_object_signature(struct repository *r, const struct object_id *oid); - -int finalize_object_file(const char *tmpfile, const char *filename); - -/* Helper to check and "touch" a file */ -int check_and_freshen_file(const char *fn, int freshen); - -extern const signed char hexval_table[256]; -static inline unsigned int hexval(unsigned char c) -{ - return hexval_table[c]; -} - -/* - * Convert two consecutive hexadecimal digits into a char. Return a - * negative value on error. Don't run over the end of short strings. - */ -static inline int hex2chr(const char *s) -{ - unsigned int val = hexval(s[0]); - return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); -} - -/* Convert to/from hex/sha1 representation */ -#define MINIMUM_ABBREV minimum_abbrev -#define DEFAULT_ABBREV default_abbrev - -/* used when the code does not know or care what the default abbrev is */ -#define FALLBACK_DEFAULT_ABBREV 7 - -struct object_context { - unsigned short mode; - /* - * symlink_path is only used by get_tree_entry_follow_symlinks, - * and only for symlinks that point outside the repository. - */ - struct strbuf symlink_path; - /* - * If GET_OID_RECORD_PATH is set, this will record path (if any) - * found when resolving the name. The caller is responsible for - * releasing the memory. - */ - char *path; -}; - -#define GET_OID_QUIETLY 01 -#define GET_OID_COMMIT 02 -#define GET_OID_COMMITTISH 04 -#define GET_OID_TREE 010 -#define GET_OID_TREEISH 020 -#define GET_OID_BLOB 040 -#define GET_OID_FOLLOW_SYMLINKS 0100 -#define GET_OID_RECORD_PATH 0200 -#define GET_OID_ONLY_TO_DIE 04000 -#define GET_OID_REQUIRE_PATH 010000 - -#define GET_OID_DISAMBIGUATORS \ - (GET_OID_COMMIT | GET_OID_COMMITTISH | \ - GET_OID_TREE | GET_OID_TREEISH | \ - GET_OID_BLOB) - -enum get_oid_result { - FOUND = 0, - MISSING_OBJECT = -1, /* The requested object is missing */ - SHORT_NAME_AMBIGUOUS = -2, - /* The following only apply when symlinks are followed */ - DANGLING_SYMLINK = -4, /* - * The initial symlink is there, but - * (transitively) points to a missing - * in-tree file - */ - SYMLINK_LOOP = -5, - NOT_DIR = -6, /* - * Somewhere along the symlink chain, a path is - * requested which contains a file as a - * non-final element. - */ -}; - -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, ...); -int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid); -void maybe_die_on_misspelt_object_name(struct repository *repo, - const char *name, - const char *prefix); -enum get_oid_result get_oid_with_context(struct repository *repo, const char *str, - unsigned flags, struct object_id *oid, - struct object_context *oc); - -#define get_oid(str, oid) repo_get_oid(the_repository, str, oid) -#define get_oid_commit(str, oid) repo_get_oid_commit(the_repository, str, oid) -#define get_oid_committish(str, oid) repo_get_oid_committish(the_repository, str, oid) -#define get_oid_tree(str, oid) repo_get_oid_tree(the_repository, str, oid) -#define get_oid_treeish(str, oid) repo_get_oid_treeish(the_repository, str, oid) -#define get_oid_blob(str, oid) repo_get_oid_blob(the_repository, str, oid) -#define get_oid_mb(str, oid) repo_get_oid_mb(the_repository, str, oid) - -typedef int each_abbrev_fn(const struct object_id *oid, void *); -int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *); -#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data) - -int set_disambiguate_hint_config(const char *var, const char *value); - -/* - * Try to read a SHA1 in hexadecimal format from the 40 characters - * starting at hex. Write the 20-byte result to sha1 in binary form. - * Return 0 on success. Reading stops if a NUL is encountered in the - * input, so it is safe to pass this function an arbitrary - * null-terminated string. - */ -int get_sha1_hex(const char *hex, unsigned char *sha1); -int get_oid_hex(const char *hex, struct object_id *sha1); - -/* Like get_oid_hex, but for an arbitrary hash algorithm. */ -int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop); - -/* - * Read `len` pairs of hexadecimal digits from `hex` and write the - * values to `binary` as `len` bytes. Return 0 on success, or -1 if - * the input does not consist of hex digits). - */ -int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); - -/* - * Convert a binary hash in "unsigned char []" or an object name in - * "struct object_id *" to its hex equivalent. The `_r` variant is reentrant, - * and writes the NUL-terminated output to the buffer `out`, which must be at - * least `GIT_MAX_HEXSZ + 1` bytes, and returns a pointer to out for - * convenience. - * - * The non-`_r` variant returns a static buffer, but uses a ring of 4 - * buffers, making it safe to make multiple calls for a single statement, like: - * - * printf("%s -> %s", hash_to_hex(one), hash_to_hex(two)); - * printf("%s -> %s", oid_to_hex(one), oid_to_hex(two)); - */ -char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *); -char *oid_to_hex_r(char *out, const struct object_id *oid); -char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */ -char *hash_to_hex(const unsigned char *hash); /* same static buffer */ -char *oid_to_hex(const struct object_id *oid); /* same static buffer */ - -/* - * Parse a 40-character hexadecimal object ID starting from hex, updating the - * pointer specified by end when parsing stops. The resulting object ID is - * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or - * other invalid character. end is only updated on success; otherwise, it is - * unmodified. - */ -int parse_oid_hex(const char *hex, struct object_id *oid, const char **end); - -/* Like parse_oid_hex, but for an arbitrary hash algorithm. */ -int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end, - const struct git_hash_algo *algo); - - -/* - * These functions work like get_oid_hex and parse_oid_hex, but they will parse - * a hex value for any algorithm. The algorithm is detected based on the length - * and the algorithm in use is returned. If this is not a hex object ID in any - * algorithm, returns GIT_HASH_UNKNOWN. - */ -int get_oid_hex_any(const char *hex, struct object_id *oid); -int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end); - -/* - * This reads short-hand syntax that not only evaluates to a commit - * object name, but also can act as if the end user spelled the name - * of the branch from the command line. - * - * - "@{-N}" finds the name of the Nth previous branch we were on, and - * places the name of the branch in the given buf and returns the - * number of characters parsed if successful. - * - * - "@{upstream}" finds the name of the other ref that - * is configured to merge with (missing defaults - * to the current branch), and places the name of the branch in the - * given buf and returns the number of characters parsed if - * successful. - * - * If the input is not of the accepted format, it returns a negative - * number to signal an error. - * - * If the input was ok but there are not N branch switches in the - * reflog, it returns 0. - */ -#define INTERPRET_BRANCH_LOCAL (1<<0) -#define INTERPRET_BRANCH_REMOTE (1<<1) -#define INTERPRET_BRANCH_HEAD (1<<2) -struct interpret_branch_name_options { - /* - * If "allowed" is non-zero, it is a treated as a bitfield of allowable - * expansions: local branches ("refs/heads/"), remote branches - * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is - * allowed, even ones to refs outside of those namespaces. - */ - unsigned allowed; - - /* - * If ^{upstream} or ^{push} (or equivalent) is requested, and the - * branch in question does not have such a reference, return -1 instead - * of die()-ing. - */ - unsigned nonfatal_dangling_mark : 1; -}; -int repo_interpret_branch_name(struct repository *r, - const char *str, int len, - struct strbuf *buf, - const struct interpret_branch_name_options *options); -#define interpret_branch_name(str, len, buf, options) \ - repo_interpret_branch_name(the_repository, str, len, buf, options) - -int validate_headref(const char *ref); - -int base_name_compare(const char *name1, size_t len1, int mode1, - const char *name2, size_t len2, int mode2); -int df_name_compare(const char *name1, size_t len1, int mode1, - const char *name2, size_t len2, int mode2); -int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); -int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); - -void *read_object_with_reference(struct repository *r, - const struct object_id *oid, - enum object_type required_type, - unsigned long *size, - struct object_id *oid_ret); - -struct object *repo_peel_to_type(struct repository *r, - const char *name, int namelen, - struct object *o, enum object_type); -#define peel_to_type(name, namelen, obj, type) \ - repo_peel_to_type(the_repository, name, namelen, obj, type) - -#define IDENT_STRICT 1 -#define IDENT_NO_DATE 2 -#define IDENT_NO_NAME 4 - -enum want_ident { - WANT_BLANK_IDENT, - WANT_AUTHOR_IDENT, - WANT_COMMITTER_IDENT -}; - -const char *git_author_info(int); -const char *git_committer_info(int); -const char *fmt_ident(const char *name, const char *email, - enum want_ident whose_ident, - const char *date_str, int); -const char *fmt_name(enum want_ident); -const char *ident_default_name(void); -const char *ident_default_email(void); -const char *git_editor(void); -const char *git_sequence_editor(void); -const char *git_pager(int stdout_is_tty); -int is_terminal_dumb(void); -int git_ident_config(const char *, const char *, void *); -/* - * Prepare an ident to fall back on if the user didn't configure it. - */ -void prepare_fallback_ident(const char *name, const char *email); -void reset_ident_date(void); - -struct ident_split { - const char *name_begin; - const char *name_end; - const char *mail_begin; - const char *mail_end; - const char *date_begin; - const char *date_end; - const char *tz_begin; - const char *tz_end; -}; -/* - * Signals an success with 0, but time part of the result may be NULL - * if the input lacks timestamp and zone - */ -int split_ident_line(struct ident_split *, const char *, int); - -/* - * Given a commit or tag object buffer and the commit or tag headers, replaces - * the idents in the headers with their canonical versions using the mailmap mechanism. - */ -void apply_mailmap_to_header(struct strbuf *, const char **, struct string_list *); - -/* - * Compare split idents for equality or strict ordering. Note that we - * compare only the ident part of the line, ignoring any timestamp. - * - * Because there are two fields, we must choose one as the primary key; we - * currently arbitrarily pick the email. - */ -int ident_cmp(const struct ident_split *, const struct ident_split *); - -struct cache_def { - struct strbuf path; - int flags; - int track_flags; - int prefix_len_stat_func; -}; -#define CACHE_DEF_INIT { \ - .path = STRBUF_INIT, \ -} -static inline void cache_def_clear(struct cache_def *cache) -{ - strbuf_release(&cache->path); -} - -int has_symlink_leading_path(const char *name, int len); -int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); -int check_leading_path(const char *name, int len, int warn_on_lstat_err); -int has_dirs_only_path(const char *name, int len, int prefix_len); -void invalidate_lstat_cache(void); -void schedule_dir_for_removal(const char *name, int len); -void remove_scheduled_dirs(void); - -struct pack_window { - struct pack_window *next; - unsigned char *base; - off_t offset; - size_t len; - unsigned int last_used; - unsigned int inuse_cnt; -}; - -struct pack_entry { - off_t offset; - struct packed_git *p; -}; - -/* - * Create a temporary file rooted in the object database directory, or - * die on failure. The filename is taken from "pattern", which should have the - * usual "XXXXXX" trailer, and the resulting filename is written into the - * "template" buffer. Returns the open descriptor. - */ -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); - -/* - * Create a pack .keep file named "name" (which should generally be the output - * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on - * error. - */ -int odb_pack_keep(const char *name); - -/* - * Set this to 0 to prevent oid_object_info_extended() from fetching missing - * blobs. This has a difference only if extensions.partialClone is set. - * - * Its default value is 1. - */ -extern int fetch_if_missing; - -/* Dumb servers support */ -int update_server_info(int); - -const char *get_log_output_encoding(void); -const char *get_commit_output_encoding(void); - -int committer_ident_sufficiently_given(void); -int author_ident_sufficiently_given(void); - -extern const char *git_commit_encoding; -extern const char *git_log_output_encoding; -extern const char *git_mailmap_file; -extern const char *git_mailmap_blob; - -/* IO helper functions */ -void maybe_flush_or_die(FILE *, const char *); -__attribute__((format (printf, 2, 3))) -void fprintf_or_die(FILE *, const char *fmt, ...); -void fwrite_or_die(FILE *f, const void *buf, size_t count); -void fflush_or_die(FILE *f); - -#define COPY_READ_ERROR (-2) -#define COPY_WRITE_ERROR (-3) -int copy_fd(int ifd, int ofd); -int copy_file(const char *dst, const char *src, int mode); -int copy_file_with_time(const char *dst, const char *src, int mode); - -/* - * Compare the file mode and contents of two given files. - * - * If both files are actually symbolic links, the function returns 1 if the link - * targets are identical or 0 if they are not. - * - * If any of the two files cannot be accessed or in case of read failures, this - * function returns 0. - * - * If the file modes and contents are identical, the function returns 1, - * otherwise it returns 0. - */ -int do_files_match(const char *path1, const char *path2); - -void write_or_die(int fd, const void *buf, size_t count); -void fsync_or_die(int fd, const char *); -int fsync_component(enum fsync_component component, int fd); -void fsync_component_or_die(enum fsync_component component, int fd, const char *msg); - -static inline int batch_fsync_enabled(enum fsync_component component) -{ - return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); -} - -ssize_t read_in_full(int fd, void *buf, size_t count); -ssize_t write_in_full(int fd, const void *buf, size_t count); -ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset); - -static inline ssize_t write_str_in_full(int fd, const char *str) -{ - return write_in_full(fd, str, strlen(str)); -} - -/** - * Open (and truncate) the file at path, write the contents of buf to it, - * and close it. Dies if any errors are encountered. - */ -void write_file_buf(const char *path, const char *buf, size_t len); - -/** - * Like write_file_buf(), but format the contents into a buffer first. - * Additionally, write_file() will append a newline if one is not already - * present, making it convenient to write text files: - * - * write_file(path, "counter: %d", ctr); - */ -__attribute__((format (printf, 2, 3))) -void write_file(const char *path, const char *fmt, ...); - -/* pager.c */ -void setup_pager(void); -int pager_in_use(void); -extern int pager_use_color; -int term_columns(void); -void term_clear_line(void); -int decimal_width(uintmax_t); -int check_pager_config(const char *cmd); -void prepare_pager_args(struct child_process *, const char *pager); - -extern const char *editor_program; -extern const char *askpass_program; -extern const char *excludes_file; - -/* base85 */ -int decode_85(char *dst, const char *line, int linelen); -void encode_85(char *buf, const unsigned char *data, int bytes); - -/* pkt-line.c */ -void packet_trace_identity(const char *prog); -======= -/* - * Return an abbreviated sha1 unique within this repository's object database. - * The result will be at least `len` characters long, and will be NUL - * terminated. - * - * The non-`_r` version returns a static buffer which remains valid until 4 - * more calls to find_unique_abbrev are made. - * - * The `_r` variant writes to a buffer supplied by the caller, which must be at - * least `GIT_MAX_HEXSZ + 1` bytes. The return value is the number of bytes - * written (excluding the NUL terminator). - * - * Note that while this version avoids the static buffer, it is not fully - * reentrant, as it calls into other non-reentrant git code. - */ -const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len); -#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len) -int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); -#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len) - -/* set default permissions by passing mode arguments to open(2) */ -int git_mkstemps_mode(char *pattern, int suffix_len, int mode); -int git_mkstemp_mode(char *pattern, int mode); - -/* - * NOTE NOTE NOTE!! - * - * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must - * not be changed. Old repositories have core.sharedrepository written in - * numeric format, and therefore these values are preserved for compatibility - * reasons. - */ -enum sharedrepo { - PERM_UMASK = 0, - OLD_PERM_GROUP = 1, - OLD_PERM_EVERYBODY = 2, - PERM_GROUP = 0660, - PERM_EVERYBODY = 0664 -}; -int git_config_perm(const char *var, const char *value); -int adjust_shared_perm(const char *path); - -/* - * Create the directory containing the named path, using care to be - * somewhat safe against races. Return one of the scld_error values to - * indicate success/failure. On error, set errno to describe the - * problem. - * - * SCLD_VANISHED indicates that one of the ancestor directories of the - * path existed at one point during the function call and then - * suddenly vanished, probably because another process pruned the - * directory while we were working. To be robust against this kind of - * race, callers might want to try invoking the function again when it - * returns SCLD_VANISHED. - * - * safe_create_leading_directories() temporarily changes path while it - * is working but restores it before returning. - * safe_create_leading_directories_const() doesn't modify path, even - * temporarily. Both these variants adjust the permissions of the - * created directories to honor core.sharedRepository, so they are best - * suited for files inside the git dir. For working tree files, use - * safe_create_leading_directories_no_share() instead, as it ignores - * the core.sharedRepository setting. - */ -enum scld_error { - SCLD_OK = 0, - SCLD_FAILED = -1, - SCLD_PERMS = -2, - SCLD_EXISTS = -3, - SCLD_VANISHED = -4 -}; -enum scld_error safe_create_leading_directories(char *path); -enum scld_error safe_create_leading_directories_const(const char *path); -enum scld_error safe_create_leading_directories_no_share(char *path); - -int mkdir_in_gitdir(const char *path); -char *interpolate_path(const char *path, int real_home); -/* NEEDSWORK: remove this synonym once in-flight topics have migrated */ -#define expand_user_path interpolate_path -const char *enter_repo(const char *path, int strict); -static inline int is_absolute_path(const char *path) -{ - return is_dir_sep(path[0]) || has_dos_drive_prefix(path); -} -int is_directory(const char *); -char *strbuf_realpath(struct strbuf *resolved, const char *path, - int die_on_error); -char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, - int die_on_error); -char *real_pathdup(const char *path, int die_on_error); -const char *absolute_path(const char *path); -char *absolute_pathdup(const char *path); -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); -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); - -/* - * These functions match their is_hfs_dotgit() counterparts; see utf8.h for - * details. - */ -int is_ntfs_dotgit(const char *name); -int is_ntfs_dotgitmodules(const char *name); -int is_ntfs_dotgitignore(const char *name); -int is_ntfs_dotgitattributes(const char *name); -int is_ntfs_dotmailmap(const char *name); - -/* - * Returns true iff "str" could be confused as a command-line option when - * passed to a sub-program like "ssh". Note that this has nothing to do with - * shell-quoting, which should be handled separately; we're assuming here that - * the string makes it verbatim to the sub-program. - */ -int looks_like_command_line_option(const char *str); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise - * "$HOME/.config/$subdir/$filename". Return NULL upon error. - */ -char *xdg_config_home_for(const char *subdir, const char *filename); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise - * "$HOME/.config/git/$filename". Return NULL upon error. - */ -char *xdg_config_home(const char *filename); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise - * "$HOME/.cache/git/$filename". Return NULL upon error. - */ -char *xdg_cache_home(const char *filename); - -int git_open_cloexec(const char *name, int flags); -#define git_open(name) git_open_cloexec(name, O_RDONLY) - -/** - * unpack_loose_header() initializes the data stream needed to unpack - * a loose object header. - * - * Returns: - * - * - ULHR_OK on success - * - ULHR_BAD on error - * - ULHR_TOO_LONG if the header was too long - * - * It will only parse up to MAX_HEADER_LEN bytes unless an optional - * "hdrbuf" argument is non-NULL. This is intended for use with - * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error) - * reporting. The full header will be extracted to "hdrbuf" for use - * with parse_loose_header(), ULHR_TOO_LONG will still be returned - * from this function to indicate that the header was too long. - */ -enum unpack_loose_header_result { - ULHR_OK, - ULHR_BAD, - ULHR_TOO_LONG, -}; -enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, - unsigned char *map, - unsigned long mapsize, - void *buffer, - unsigned long bufsiz, - struct strbuf *hdrbuf); - -/** - * parse_loose_header() parses the starting " \0" of an - * object. If it doesn't follow that format -1 is returned. To check - * the validity of the populate the "typep" in the "struct - * object_info". It will be OBJ_BAD if the object type is unknown. The - * parsed can be retrieved via "oi->sizep", and from there - * passed to unpack_loose_rest(). - */ -struct object_info; -int parse_loose_header(const char *hdr, struct object_info *oi); - -/** - * With in-core object data in "buf", rehash it to make sure the - * object name actually matches "oid" to detect object corruption. - * - * A negative value indicates an error, usually that the OID is not - * what we expected, but it might also indicate another error. - */ -int check_object_signature(struct repository *r, const struct object_id *oid, - void *map, unsigned long size, - enum object_type type); - -/** - * A streaming version of check_object_signature(). - * Try reading the object named with "oid" using - * the streaming interface and rehash it to do the same. - */ -int stream_object_signature(struct repository *r, const struct object_id *oid); - -int finalize_object_file(const char *tmpfile, const char *filename); - -/* Helper to check and "touch" a file */ -int check_and_freshen_file(const char *fn, int freshen); - -extern const signed char hexval_table[256]; -static inline unsigned int hexval(unsigned char c) -{ - return hexval_table[c]; -} - -/* - * Convert two consecutive hexadecimal digits into a char. Return a - * negative value on error. Don't run over the end of short strings. - */ -static inline int hex2chr(const char *s) -{ - unsigned int val = hexval(s[0]); - return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); -} - -/* Convert to/from hex/sha1 representation */ -#define MINIMUM_ABBREV minimum_abbrev -#define DEFAULT_ABBREV default_abbrev - -/* used when the code does not know or care what the default abbrev is */ -#define FALLBACK_DEFAULT_ABBREV 7 - -struct object_context { - unsigned short mode; - /* - * symlink_path is only used by get_tree_entry_follow_symlinks, - * and only for symlinks that point outside the repository. - */ - struct strbuf symlink_path; - /* - * If GET_OID_RECORD_PATH is set, this will record path (if any) - * found when resolving the name. The caller is responsible for - * releasing the memory. - */ - char *path; -}; - -#define GET_OID_QUIETLY 01 -#define GET_OID_COMMIT 02 -#define GET_OID_COMMITTISH 04 -#define GET_OID_TREE 010 -#define GET_OID_TREEISH 020 -#define GET_OID_BLOB 040 -#define GET_OID_FOLLOW_SYMLINKS 0100 -#define GET_OID_RECORD_PATH 0200 -#define GET_OID_ONLY_TO_DIE 04000 -#define GET_OID_REQUIRE_PATH 010000 - -#define GET_OID_DISAMBIGUATORS \ - (GET_OID_COMMIT | GET_OID_COMMITTISH | \ - GET_OID_TREE | GET_OID_TREEISH | \ - GET_OID_BLOB) - -enum get_oid_result { - FOUND = 0, - MISSING_OBJECT = -1, /* The requested object is missing */ - SHORT_NAME_AMBIGUOUS = -2, - /* The following only apply when symlinks are followed */ - DANGLING_SYMLINK = -4, /* - * The initial symlink is there, but - * (transitively) points to a missing - * in-tree file - */ - SYMLINK_LOOP = -5, - NOT_DIR = -6, /* - * Somewhere along the symlink chain, a path is - * requested which contains a file as a - * non-final element. - */ -}; - -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, ...); -int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid); -int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid); -void maybe_die_on_misspelt_object_name(struct repository *repo, - const char *name, - const char *prefix); -enum get_oid_result get_oid_with_context(struct repository *repo, const char *str, - unsigned flags, struct object_id *oid, - struct object_context *oc); - -#define get_oid(str, oid) repo_get_oid(the_repository, str, oid) -#define get_oid_commit(str, oid) repo_get_oid_commit(the_repository, str, oid) -#define get_oid_committish(str, oid) repo_get_oid_committish(the_repository, str, oid) -#define get_oid_tree(str, oid) repo_get_oid_tree(the_repository, str, oid) -#define get_oid_treeish(str, oid) repo_get_oid_treeish(the_repository, str, oid) -#define get_oid_blob(str, oid) repo_get_oid_blob(the_repository, str, oid) -#define get_oid_mb(str, oid) repo_get_oid_mb(the_repository, str, oid) - -typedef int each_abbrev_fn(const struct object_id *oid, void *); -int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *); -#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data) - -int set_disambiguate_hint_config(const char *var, const char *value); - -/* - * Try to read a SHA1 in hexadecimal format from the 40 characters - * starting at hex. Write the 20-byte result to sha1 in binary form. - * Return 0 on success. Reading stops if a NUL is encountered in the - * input, so it is safe to pass this function an arbitrary - * null-terminated string. - */ -int get_sha1_hex(const char *hex, unsigned char *sha1); -int get_oid_hex(const char *hex, struct object_id *sha1); - -/* Like get_oid_hex, but for an arbitrary hash algorithm. */ -int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop); - -/* - * Read `len` pairs of hexadecimal digits from `hex` and write the - * values to `binary` as `len` bytes. Return 0 on success, or -1 if - * the input does not consist of hex digits). - */ -int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); - -/* - * Convert a binary hash in "unsigned char []" or an object name in - * "struct object_id *" to its hex equivalent. The `_r` variant is reentrant, - * and writes the NUL-terminated output to the buffer `out`, which must be at - * least `GIT_MAX_HEXSZ + 1` bytes, and returns a pointer to out for - * convenience. - * - * The non-`_r` variant returns a static buffer, but uses a ring of 4 - * buffers, making it safe to make multiple calls for a single statement, like: - * - * printf("%s -> %s", hash_to_hex(one), hash_to_hex(two)); - * printf("%s -> %s", oid_to_hex(one), oid_to_hex(two)); - */ -char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *); -char *oid_to_hex_r(char *out, const struct object_id *oid); -char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */ -char *hash_to_hex(const unsigned char *hash); /* same static buffer */ -char *oid_to_hex(const struct object_id *oid); /* same static buffer */ - -/* - * Parse a 40-character hexadecimal object ID starting from hex, updating the - * pointer specified by end when parsing stops. The resulting object ID is - * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or - * other invalid character. end is only updated on success; otherwise, it is - * unmodified. - */ -int parse_oid_hex(const char *hex, struct object_id *oid, const char **end); - -/* Like parse_oid_hex, but for an arbitrary hash algorithm. */ -int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end, - const struct git_hash_algo *algo); - - -/* - * These functions work like get_oid_hex and parse_oid_hex, but they will parse - * a hex value for any algorithm. The algorithm is detected based on the length - * and the algorithm in use is returned. If this is not a hex object ID in any - * algorithm, returns GIT_HASH_UNKNOWN. - */ -int get_oid_hex_any(const char *hex, struct object_id *oid); -int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end); - -/* - * This reads short-hand syntax that not only evaluates to a commit - * object name, but also can act as if the end user spelled the name - * of the branch from the command line. - * - * - "@{-N}" finds the name of the Nth previous branch we were on, and - * places the name of the branch in the given buf and returns the - * number of characters parsed if successful. - * - * - "@{upstream}" finds the name of the other ref that - * is configured to merge with (missing defaults - * to the current branch), and places the name of the branch in the - * given buf and returns the number of characters parsed if - * successful. - * - * If the input is not of the accepted format, it returns a negative - * number to signal an error. - * - * If the input was ok but there are not N branch switches in the - * reflog, it returns 0. - */ -#define INTERPRET_BRANCH_LOCAL (1<<0) -#define INTERPRET_BRANCH_REMOTE (1<<1) -#define INTERPRET_BRANCH_HEAD (1<<2) -struct interpret_branch_name_options { - /* - * If "allowed" is non-zero, it is a treated as a bitfield of allowable - * expansions: local branches ("refs/heads/"), remote branches - * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is - * allowed, even ones to refs outside of those namespaces. - */ - unsigned allowed; - - /* - * If ^{upstream} or ^{push} (or equivalent) is requested, and the - * branch in question does not have such a reference, return -1 instead - * of die()-ing. - */ - unsigned nonfatal_dangling_mark : 1; -}; -int repo_interpret_branch_name(struct repository *r, - const char *str, int len, - struct strbuf *buf, - const struct interpret_branch_name_options *options); -#define interpret_branch_name(str, len, buf, options) \ - repo_interpret_branch_name(the_repository, str, len, buf, options) - -int validate_headref(const char *ref); - -int base_name_compare(const char *name1, size_t len1, int mode1, - const char *name2, size_t len2, int mode2); -int df_name_compare(const char *name1, size_t len1, int mode1, - const char *name2, size_t len2, int mode2); -int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); -int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); - -void *read_object_with_reference(struct repository *r, - const struct object_id *oid, - enum object_type required_type, - unsigned long *size, - struct object_id *oid_ret); - -struct object *repo_peel_to_type(struct repository *r, - const char *name, int namelen, - struct object *o, enum object_type); -#define peel_to_type(name, namelen, obj, type) \ - repo_peel_to_type(the_repository, name, namelen, obj, type) - -#define IDENT_STRICT 1 -#define IDENT_NO_DATE 2 -#define IDENT_NO_NAME 4 - -enum want_ident { - WANT_BLANK_IDENT, - WANT_AUTHOR_IDENT, - WANT_COMMITTER_IDENT -}; - -const char *git_author_info(int); -const char *git_committer_info(int); -const char *fmt_ident(const char *name, const char *email, - enum want_ident whose_ident, - const char *date_str, int); -const char *fmt_name(enum want_ident); -const char *ident_default_name(void); -const char *ident_default_email(void); -const char *git_editor(void); -const char *git_sequence_editor(void); -const char *git_pager(int stdout_is_tty); -int is_terminal_dumb(void); -int git_ident_config(const char *, const char *, void *); -/* - * Prepare an ident to fall back on if the user didn't configure it. - */ -void prepare_fallback_ident(const char *name, const char *email); -void reset_ident_date(void); - -struct ident_split { - const char *name_begin; - const char *name_end; - const char *mail_begin; - const char *mail_end; - const char *date_begin; - const char *date_end; - const char *tz_begin; - const char *tz_end; -}; -/* - * Signals an success with 0, but time part of the result may be NULL - * if the input lacks timestamp and zone - */ -int split_ident_line(struct ident_split *, const char *, int); - -/* - * Given a commit or tag object buffer and the commit or tag headers, replaces - * the idents in the headers with their canonical versions using the mailmap mechanism. - */ -void apply_mailmap_to_header(struct strbuf *, const char **, struct string_list *); - -/* - * Compare split idents for equality or strict ordering. Note that we - * compare only the ident part of the line, ignoring any timestamp. - * - * Because there are two fields, we must choose one as the primary key; we - * currently arbitrarily pick the email. - */ -int ident_cmp(const struct ident_split *, const struct ident_split *); - -struct cache_def { - struct strbuf path; - int flags; - int track_flags; - int prefix_len_stat_func; -}; -#define CACHE_DEF_INIT { \ - .path = STRBUF_INIT, \ -} -static inline void cache_def_clear(struct cache_def *cache) -{ - strbuf_release(&cache->path); -} - -int has_symlink_leading_path(const char *name, int len); -int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); -int check_leading_path(const char *name, int len, int warn_on_lstat_err); -int has_dirs_only_path(const char *name, int len, int prefix_len); -void invalidate_lstat_cache(void); -void schedule_dir_for_removal(const char *name, int len); -void remove_scheduled_dirs(void); - -struct pack_window { - struct pack_window *next; - unsigned char *base; - off_t offset; - size_t len; - unsigned int last_used; - unsigned int inuse_cnt; -}; - -struct pack_entry { - off_t offset; - struct packed_git *p; -}; - -/* - * Create a temporary file rooted in the object database directory, or - * die on failure. The filename is taken from "pattern", which should have the - * usual "XXXXXX" trailer, and the resulting filename is written into the - * "template" buffer. Returns the open descriptor. - */ -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); - -/* - * Create a pack .keep file named "name" (which should generally be the output - * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on - * error. - */ -int odb_pack_keep(const char *name); - -/* - * Set this to 0 to prevent oid_object_info_extended() from fetching missing - * blobs. This has a difference only if extensions.partialClone is set. - * - * Its default value is 1. - */ -extern int fetch_if_missing; - -/* Dumb servers support */ -int update_server_info(int); - -const char *get_log_output_encoding(void); -const char *get_commit_output_encoding(void); - -int committer_ident_sufficiently_given(void); -int author_ident_sufficiently_given(void); - -extern const char *git_commit_encoding; -extern const char *git_log_output_encoding; -extern const char *git_mailmap_file; -extern const char *git_mailmap_blob; - -/* IO helper functions */ -void maybe_flush_or_die(FILE *, const char *); -__attribute__((format (printf, 2, 3))) -void fprintf_or_die(FILE *, const char *fmt, ...); -void fwrite_or_die(FILE *f, const void *buf, size_t count); -void fflush_or_die(FILE *f); - -#define COPY_READ_ERROR (-2) -#define COPY_WRITE_ERROR (-3) -int copy_fd(int ifd, int ofd); -int copy_file(const char *dst, const char *src, int mode); -int copy_file_with_time(const char *dst, const char *src, int mode); - -void write_or_die(int fd, const void *buf, size_t count); -void fsync_or_die(int fd, const char *); -int fsync_component(enum fsync_component component, int fd); -void fsync_component_or_die(enum fsync_component component, int fd, const char *msg); - -static inline int batch_fsync_enabled(enum fsync_component component) -{ - return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); -} - -ssize_t read_in_full(int fd, void *buf, size_t count); -ssize_t write_in_full(int fd, const void *buf, size_t count); -ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset); - -static inline ssize_t write_str_in_full(int fd, const char *str) -{ - return write_in_full(fd, str, strlen(str)); -} - -/** - * Open (and truncate) the file at path, write the contents of buf to it, - * and close it. Dies if any errors are encountered. - */ -void write_file_buf(const char *path, const char *buf, size_t len); - -/** - * Like write_file_buf(), but format the contents into a buffer first. - * Additionally, write_file() will append a newline if one is not already - * present, making it convenient to write text files: - * - * write_file(path, "counter: %d", ctr); - */ -__attribute__((format (printf, 2, 3))) -void write_file(const char *path, const char *fmt, ...); - -/* pager.c */ -void setup_pager(void); -int pager_in_use(void); -extern int pager_use_color; -int term_columns(void); -void term_clear_line(void); -int decimal_width(uintmax_t); -int check_pager_config(const char *cmd); -void prepare_pager_args(struct child_process *, const char *pager); - -extern const char *editor_program; -extern const char *askpass_program; -extern const char *excludes_file; - -/* base85 */ -int decode_85(char *dst, const char *line, int linelen); -void encode_85(char *buf, const unsigned char *data, int bytes); - -/* pkt-line.c */ -void packet_trace_identity(const char *prog); ->>>>>>> 1b2b92753e (Merge branch 'jc/fix-aggressive-protection-2.39' into HEAD) /* add */ /* diff --git a/copy.h b/copy.h index 057259a3a7..2af77cba86 100644 --- a/copy.h +++ b/copy.h @@ -7,18 +7,4 @@ int copy_fd(int ifd, int ofd); int copy_file(const char *dst, const char *src, int mode); int copy_file_with_time(const char *dst, const char *src, int mode); -/* - * Compare the file mode and contents of two given files. - * - * If both files are actually symbolic links, the function returns 1 if the link - * targets are identical or 0 if they are not. - * - * If any of the two files cannot be accessed or in case of read failures, this - * function returns 0. - * - * If the file modes and contents are identical, the function returns 1, - * otherwise it returns 0. - */ -int do_files_match(const char *path1, const char *path2); - #endif /* COPY_H */