From patchwork Thu Jun 13 20:25:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 13697442 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15CC182C67 for ; Thu, 13 Jun 2024 20:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310313; cv=none; b=A/jzK3J63wz/vju++yRS1h7UzgO3FTaOYHJXl0Dz9DlgH9zUHt6688IhyVim925ydQQyuEPdWeLsRwlRYmmGV9kUP4ozI7ZorvGsLBWz6lpn5VxLDmr4C4heUpFdConb6z3bosctSpvMuf6zcdG6qHXv7SaAoVb3OtukP7XvyK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310313; c=relaxed/simple; bh=OPi3b/GMulpBT0QV1VdSJlP0mGfS7ONhiG6/DdJUfJk=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Yh8mR1lqeENexuspY1K6KTT8NMtXqxyhr/yPvNbwp4qm9l3OfJDyd7F9YBHy53uyVAMr8dn6ibcjbKJeTt/wvbd1e0xqXePHOHtPu+z1xS0mGiEa0mIQKLFn35LeP77dUfmSq++ZN7Ckbgn2jDvMhED+tnRw8bRicEjnEixhdFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ddYtnuWg; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ddYtnuWg" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-421757d217aso16272915e9.3 for ; Thu, 13 Jun 2024 13:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310310; x=1718915110; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=WQB926BDScI7gAUE1hQ2OAdJAxYFLzHUV8FSZigHySU=; b=ddYtnuWgpRsxEwG5s1z4NOoHIXGsHOs68P8Q3f77/GXDpb9PRPVOTTHZOKSbkZx8uy dxfcU+EMgyqT7H7jHb42cwyMU84Cs+HhEVe0Az7ziTBEzJELTqeNFp2+MSEvbUMOqxL+ BUWK/6Z4/dB2yBGrYex0LkGHxOwpL2UNF91AvGlr0yu05cfeCv+zftSwkTxUvYlVJXSn XqB9OUu5bI273cP9guyhDPVZnNLuJ4mVp8MbmDtOypoD3YLCP8usw9WG/rQyDNpmtQea by6PnuMQy6TkK3z71nocg7SnvoOhr0KGYiKUoA+7nVACyx+rLlL/Nvmhp0Fl6rCd108x LNZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310310; x=1718915110; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WQB926BDScI7gAUE1hQ2OAdJAxYFLzHUV8FSZigHySU=; b=qss7+1xhTT0zGc3+N6NLoHMVnicicu0WzsIpQVyb5jqgC5iO6E/NzdBhQX2ZlOGEsg 8OmPb4sJ8qdBA5nbxgBKlCdJghcgaYl3WwtfMI2RLtw40QS4Bx4ei0AWiApluqumbTF3 ByUOcSyyr/y87a11Al2XRnSjv5/AUvwqVS6HWAUu/7FVcUzxgz0CdDMFhELEH8FB7rzS rUBASb05v1Mb2OsYmHsUTB0boluB/D1qTmx+6VzGxZ7VqFe33JfzMqaPI//zswGica9f nIqHMXYezQMCj2mwJ69tAQsx2dAP0Dswjo0oKTGM5+M9lzQFXfeV6nkrQo19NoA5FBTb nwxQ== X-Gm-Message-State: AOJu0YwHgm9cY/C4i8vg7+7ASme+wngDgviOxdUD6rOHW5zvIkPiJANo HajqMTezUgi1iD3SonyEoCMcbz4gRcGFlsxxup8ET5ei2iAOotK35q0sYg== X-Google-Smtp-Source: AGHT+IFy9a6VsEkbV730nIpos3DRBUwAj83fL7JEYtf97V2jEEHMfo8jiU/MpUsmDpHMY58vazUuhA== X-Received: by 2002:a05:600c:354f:b0:421:e7ae:955b with SMTP id 5b1f17b1804b1-42304825ca9mr7502285e9.21.1718310309999; Thu, 13 Jun 2024 13:25:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-423047e28b7sm9942485e9.44.2024.06.13.13.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:25:09 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 13 Jun 2024 20:25:01 +0000 Subject: [PATCH 1/7] merge-ort: extract handling of priv member into reusable function Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren In preparation for a subsequent commit which will ensure we do not forget to maintain our invariants for the priv member in error codepaths, extract the necessary functionality out into a separate function. This change is cosmetic at this point, and introduces no changes beyond an extra assertion sanity check. Signed-off-by: Elijah Newren --- merge-ort.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index eaede6cead9..10f5a655f29 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -5000,6 +5000,28 @@ static void merge_check_renames_reusable(struct merge_result *result, /*** Function Grouping: merge_incore_*() and their internal variants ***/ +static void move_opt_priv_to_result_priv(struct merge_options *opt, + struct merge_result *result) +{ + /* + * opt->priv and result->priv are a bit weird. opt->priv contains + * information that we can re-use in subsequent merge operations to + * enable our cached renames optimization. The best way to provide + * that to subsequent merges is putting it in result->priv. + * However, putting it directly there would mean retrofitting lots + * of functions in this file to also take a merge_result pointer, + * which is ugly and annoying. So, we just make sure at the end of + * the merge (the outer merge if there are internal recursive ones) + * to move it. + */ + assert(opt->priv && !result->priv); + if (!opt->priv->call_depth) { + result->priv = opt->priv; + result->_properly_initialized = RESULT_INITIALIZED; + opt->priv = NULL; + } +} + /* * Originally from merge_trees_internal(); heavily adapted, though. */ @@ -5060,11 +5082,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt, /* existence of conflicted entries implies unclean */ result->clean &= strmap_empty(&opt->priv->conflicted); } - if (!opt->priv->call_depth) { - result->priv = opt->priv; - result->_properly_initialized = RESULT_INITIALIZED; - opt->priv = NULL; - } + move_opt_priv_to_result_priv(opt, result); } /* From patchwork Thu Jun 13 20:25:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 13697443 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22A8D83A12 for ; Thu, 13 Jun 2024 20:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310314; cv=none; b=tZLI4T9JE2ec5IKkBMVyg/608smDA/Szq8BSiecXAn+ZxOPuwKQXCJlHcIR1gjEaujPMEimTFN9rMXvXzYHWsV0JNaIx+7K62X22a4+oaLkz2tzgsry5ET0AoMQ09W10xitcgSlJC+tpi9eSrOv4XhG7ILIUFfnp17jVQLX3JVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310314; c=relaxed/simple; bh=5ndp5kc1EkksktK0FqHk2q/UQlZ+VcDAkqqo4gh0kiA=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=cYJiSfPJDth5y0F7SqUbPvTPRl8JsHfp5cZxwx7LVOVtxqcOZzRJnYhXrlhs+q3SawstNOfJCXEm/xWZz8iLaBJi2rLG52KQK9/HchQHKLnN4nzJxtK0d+5Rx9sOdQSKRUHfwRiZwgBuTxB77D2qvT4AAxSsZQP0wMmnSBoRR9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UJWNh2fg; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UJWNh2fg" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-35f090093d8so1236356f8f.0 for ; Thu, 13 Jun 2024 13:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310311; x=1718915111; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=G4N2+McsKqskjMX3WjohnPbDfySDHNpuGo3pNeSOEAI=; b=UJWNh2fgy5l4o+QmIk0lBQBWxa60j0rJsC0BZmNMUP39PcpQ+SyCNwM5fpHSAvgOYG 2EM+mleuflDKOuwb1CY4Aox1oSb506CvvRetYs152axTXVKKnioqRJRQqcO6LevmeS4d 61EOBdBBw4+Rcx8iM7zeXFvfIKYUe3J3F6LNZc25T5JgktyUPFjKa6q0LyqyO+MeCXIQ nBf4TRi3T42X6TF57Id9Or82fyin4AEzka8gvVOu8HeTqBvlTFG++k6e6Vuhvy3rhrsB Sx378NbLcv846JV9Ozx8XlVdIdG35OC/ei1DNbDznZe7MlvR+hK38eNAFgaOCvqs6izy tyxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310311; x=1718915111; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G4N2+McsKqskjMX3WjohnPbDfySDHNpuGo3pNeSOEAI=; b=EA+9ldOKZjPEQYIxVaJD+Pbhd2aSd6U958oAdGmqrH2An/foTK6FxhVA22cNMAcA3c s9RE6uuCdSOi59zdm37HgSXMv9LNgelu3nnY5r7AcvTso4eVTK0xG0KvRvg2lvzIJ1yB le24e3vD6jGGYQDGkmIKFBTGMkMs4rrxm9oS9to8iu8MGVjU4p+eNJ91pSXBiNHeaz3T LWgzoTAi83lwqJjsvBSUvLrI9zCOGyEjTnpqhnXdPBT7mnPXywpmUvKYg7DqA1RzbXua A6nlh16KlAUYi4lTy+zQ4eEhcSoKpR+IzqwKSwLCKfd0OiSu4HJeY0I6Ml+gYWmkyWPW 3V9Q== X-Gm-Message-State: AOJu0YxvxidwJpPbPPRgOIHl2/OJ6ZpSUYBkA0XBpI/OffWSwPHD8Kcg FMvTx31L9rCgsv9WuSkxMkBHpj0v5sQLpkRtfvvwWAC+D9VvPWnTk4kdNA== X-Google-Smtp-Source: AGHT+IFqQC3pLeu9cOJIqv/K9y65wD1G3f3moVUf45cOA6XIeraF0FowFF+IutRxRSOghk3sR1xoig== X-Received: by 2002:adf:e802:0:b0:35f:1d13:c843 with SMTP id ffacd0b85a97d-3607a720704mr504615f8f.11.1718310311066; Thu, 13 Jun 2024 13:25:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509c911sm2583377f8f.33.2024.06.13.13.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:25:10 -0700 (PDT) Message-Id: <17c97301baa829a993cf8838deb9271add5bd1cd.1718310307.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Jun 2024 20:25:02 +0000 Subject: [PATCH 2/7] merge-ort: maintain expected invariant for priv member Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren The calling convention for the merge machinery is One call to init_merge_options() One or more calls to merge_incore_[non]recursive() One call to merge_finalize() (possibly indirectly via merge_switch_to_result()) Both merge_switch_to_result() and merge_finalize() expect opt->priv == NULL && result->priv != NULL which is supposed to be set up by our move_opt_priv_to_result_priv() function. However, two codepath dealing with error cases did not execute this necessary logic, which could result in assertion failures (or, if assertions were compiled out, could result in segfaults). Fix the oversight and add a test that would have caught one of these problems. While at it, also tighten an existing test for a non-recursive merge to verify that it fails correctly, i.e. with the expected exit code rather than with an assertion failure. Reported-by: Matt Cree Signed-off-by: Elijah Newren --- merge-ort.c | 3 ++- t/t6406-merge-attr.sh | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 10f5a655f29..6ca7b0f9be4 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -5015,7 +5015,7 @@ static void move_opt_priv_to_result_priv(struct merge_options *opt, * to move it. */ assert(opt->priv && !result->priv); - if (!opt->priv->call_depth) { + if (!opt->priv->call_depth || result->clean < 0) { result->priv = opt->priv; result->_properly_initialized = RESULT_INITIALIZED; opt->priv = NULL; @@ -5052,6 +5052,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt, oid_to_hex(&side1->object.oid), oid_to_hex(&side2->object.oid)); result->clean = -1; + move_opt_priv_to_result_priv(opt, result); return; } trace2_region_leave("merge", "collect_merge_info", opt->repo); diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index 156a1efacfe..b6db5c2cc36 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -185,7 +185,7 @@ test_expect_success !WINDOWS 'custom merge driver that is killed with a signal' >./please-abort && echo "* merge=custom" >.gitattributes && - test_must_fail git merge main 2>err && + test_expect_code 2 git merge main 2>err && grep "^error: failed to execute internal merge" err && git ls-files -u >output && git diff --name-only HEAD >>output && @@ -261,4 +261,44 @@ test_expect_success 'binary files with union attribute' ' grep -i "warning.*cannot merge.*HEAD vs. bin-main" output ' +test_expect_success !WINDOWS 'custom merge driver that is killed with a signal on recursive merge' ' + test_when_finished "rm -f output please-abort" && + test_when_finished "git checkout side" && + + git reset --hard anchor && + + git checkout -b base-a main^ && + echo base-a >text && + git commit -m base-a text && + + git checkout -b base-b main^ && + echo base-b >text && + git commit -m base-b text && + + git checkout -b recursive-a base-a && + test_must_fail git merge base-b && + echo recursive-a >text && + git add text && + git commit -m recursive-a && + + git checkout -b recursive-b base-b && + test_must_fail git merge base-a && + echo recursive-b >text && + git add text && + git commit -m recursive-b && + + git config --replace-all \ + merge.custom.driver "./custom-merge %O %A %B 0 %P %S %X %Y" && + git config --replace-all \ + merge.custom.name "custom merge driver for testing" && + + >./please-abort && + echo "* merge=custom" >.gitattributes && + test_expect_code 2 git merge recursive-a 2>err && + grep "^error: failed to execute internal merge" err && + git ls-files -u >output && + git diff --name-only HEAD >>output && + test_must_be_empty output +' + test_done From patchwork Thu Jun 13 20:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 13697444 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 875021386DD for ; Thu, 13 Jun 2024 20:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310316; cv=none; b=nyMCvMKWiBmBf251ktzt3sPNDeIDQfxLekRsU0S3GJrUbsPKZenNFum7czLzOQmzdyMclWpO7hIf7GeNKq4EmJCexPPTBDdzWWv7lTKsi6WkL7oHkEpOETIC7k0cIlnONRxYODdJrN9Q5cnn5mHgAM0N/4Gc78TbPWR1K+6i9OI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310316; c=relaxed/simple; bh=Kbu+OgFjaQd35bZDZ9rCMiDBvbVGdHR7B/qu6ymk3lk=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=lRD/D8DBrr/AotdCIlD/CH0hCk/eHjDFsZMvUrDImxWz6Ns1avs1oxNs2lwdeZCXevUP3MGKSYetvg+qtPLr+wqoy4U8UMUVDqMz66dOEd2FDQzf8P6LGT6W/G7FBhnGGi6SgWi6O6JwW7lyPEe4VPF0AGzfywnVmoV/olaFZ2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dmBz+8Io; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dmBz+8Io" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-421a1b834acso13203785e9.3 for ; Thu, 13 Jun 2024 13:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310312; x=1718915112; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=yVsU2Cl8ScZ/OmhDv+DolrqWnc9N2Y3WAlue34ePLFI=; b=dmBz+8IoPT6Zc5ep3QH7hPga9Gfd+Gyx9tHpgv1rRPgvUcbaRlkRmdWt7GhDJZs0ai MdQDz1VdF10/NjJdB+7W4rbkT4tKNx350/rJHEuCwz4FZhiHhHWbihADCv4EdzMfAztD Q73k/3NhrLo91i5PhCfLkbbRtp6esdZ33LLHUXTKh+djrTsdBQRDdBZH+RcSBQHB/Wh2 hHkL15RJbxgMHnv8b4wzun0Bk/qCNAm0/qNv+YAUENdVGFyY7tOJyyVnBzoXUsLGCZuV DO26Fzj+J1oLlfhG0Q3zybwrIFmIfWLhLcOAY5x69ns42Hj31jDJWNaENYstMjQqTlmi H0rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310312; x=1718915112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yVsU2Cl8ScZ/OmhDv+DolrqWnc9N2Y3WAlue34ePLFI=; b=O65xr5aHmXteSkRliX6WgVI86quTDd+eXvAC/vhtpoUrcl9/PKfvdiKzqM1/HBfKbr /GcTmFzCZUYdAdxeR24yKZQnvVwQxHUtMfWp3oEFgC+fkHkWYuXCFs7MmKXQwRS8htN1 uhSCSHnDXvuKowv0pfa81AG+r7hv5zIgE5F/DtGQUhvYKG7mS52xf0m3bWGpkqrUY7lc utW81oYYy9+O8ZSs4C+MJaGGjDunh8zrWy1flXrVnwBv8ZYogBnUM5U2SfHBk/O32H7O NbHrh/uvAVU3wfGsOhnYTWe/xoNAIc1l1C0nhMOKfOCNWtHTXRtreo7d20lo12G2DfUp 68fA== X-Gm-Message-State: AOJu0Yww0Icmnha3dse3Qqz/2uIf6JEGugGa5u/3vt1FjQywAPqs7L6s smZ8axgUvN2Vje0YDbHREBfw89uU1LzF2+T23WE/Te0Lv+61BZzpDPwDjQ== X-Google-Smtp-Source: AGHT+IGTvYtnqPuSqh02FmcmZwiUGsI6w7wNQiWa2AeS2uvuX9MThoQGkEVzbbOfIEILT1bsOyQ37A== X-Received: by 2002:a05:600c:4f84:b0:422:7037:54d7 with SMTP id 5b1f17b1804b1-4230484fa59mr7126175e9.28.1718310312276; Thu, 13 Jun 2024 13:25:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422870e9145sm73163875e9.22.2024.06.13.13.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:25:11 -0700 (PDT) Message-Id: <23bb3386114f3bb08de285e3d11e1029ca03850a.1718310307.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Jun 2024 20:25:03 +0000 Subject: [PATCH 3/7] merge-ort: fix type of local 'clean' var in handle_content_merge() Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren handle_content_merge() returns an int. Every caller of handle_content_merge() expects an int. However, we declare a local variable 'clean' that we use for the return value to be unsigned. To make matters worse, we also assign 'clean' the return value of merge_submodule() in one codepath, which is defined to return an int. It seems that the only reason to have 'clean' be unsigned was to allow a cutesy bit manipulation operation to be well-defined. Fix the type of the 'clean' local in handle_content_merge(). Signed-off-by: Elijah Newren --- merge-ort.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 6ca7b0f9be4..13b47d352fc 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2109,7 +2109,7 @@ static int handle_content_merge(struct merge_options *opt, * merges, which happens for example with rename/rename(2to1) and * rename/add conflicts. */ - unsigned clean = 1; + int clean = 1; /* * handle_content_merge() needs both files to be of the same type, i.e. @@ -2184,7 +2184,8 @@ static int handle_content_merge(struct merge_options *opt, free(result_buf.ptr); if (ret) return -1; - clean &= (merge_status == 0); + if (merge_status > 0) + clean = 0; path_msg(opt, INFO_AUTO_MERGING, 1, path, NULL, NULL, NULL, _("Auto-merging %s"), path); } else if (S_ISGITLINK(a->mode)) { From patchwork Thu Jun 13 20:25:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 13697445 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42F0113A240 for ; Thu, 13 Jun 2024 20:25:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310316; cv=none; b=ogtpD+KBJVYWYWsrURe8l582I2CSJee7qExt4IpmOJO0s8pGhvVVO648dSvBYzSXWbvl9dqh6CBsItPCH0bWPm+w7Zf8NLxIbo5/QmTld1fkjwHnLLSiJAnXjb89e+C4sMyx7QyKOzULKcYLAX2BpfzZD5cIoiL/vB72y+Al590= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310316; c=relaxed/simple; bh=rfddR9IyWKrBII454hny5+7nItNCo354Z/dpCnKX+ko=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Wb6qYZzRQAYZPHy9mXs9u5B1+/XtsUK3SQePdroTOAGSYRuAbFX/UYMX7APu/NnrLw/rZLoUEiKdAckZG501hAc6vHXRltm4qtSzDV0qwqWWtzYTnqInZEgeclTWlEMOb+Ui8UjNYSBfrtFCo/ItscHrjic7R7jp5Jj7yelk+O8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TjsK8wKo; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TjsK8wKo" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-42189d3c7efso16298675e9.2 for ; Thu, 13 Jun 2024 13:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310313; x=1718915113; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=TTvnjTA+Po5ea3tWbEUN6diN2UbWvIy0/eP5L9cBdDc=; b=TjsK8wKoWMNKxWQvrWwyJ//gB1F8sFyhZAGMQFl/QKOlcX85RmznObcdRmvYgmO7h8 3BZuwlhjLYo6ITagsDG6kK0TDhtQO8iS7Ci+MFQdA/RsKWF9o9kdeMLKESlHVbFhx6po AyQfMW3SJCdv1fIWDv0/KWZfTP9d6AFBhFMCss2SMAWemx4ivVbf90kcF2dnhGU45ac8 +ocY/+x+1Kwwci70tq3bnIeV1s5FkCC2OD4JM/ghS5w76f3UBxfKEfk+rMCsdchOCqmt fxQvP7vsHsX83knb41nqkOWAemAbpe6M9ck2tpXb4Bm8ca0+HGYAXZICQBcIbRaIGmlg dAuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310313; x=1718915113; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TTvnjTA+Po5ea3tWbEUN6diN2UbWvIy0/eP5L9cBdDc=; b=T5dT1LMEzG56zlTvHUYt6n8IFSZuFus4cFEE32+vM4HxM/HmV/a9+2dZaloYmyhsYB yQ9yyX0MN6xYE2lk9zuGT+v+eEduxYNngh3JOQOWEZ2Cher5W4fwmru5bMbWIVHUAzel krh5O6hMexGfKH4pHXy0Z75qfQ2OeS7LeS6d2quELCPwtTwhK+RvzOWx2I8dcDT3BZdB NxgA4vTUXKH0y9X959MdSAFd+qMxbukcZpTjux8wo/HfM/7ah6dBHQ8FK7xiOwJw5jO/ oZfvqXpzxrvwFCuQR+GHH83bK7eIFmIW7QXVE8uWwRpsq1RxWeR26cyeRUKhqAHqwzyR 5bUQ== X-Gm-Message-State: AOJu0YzTYzImrdGLbyw5khWTAm1ruHtDfrzBwryW3tV/9WH2xFHEeaoB AljQsjNGgmv7+p7MVQlcZ5AD+thdfYmg2K+BiW5jVO9g11S8XloQ4/cVMg== X-Google-Smtp-Source: AGHT+IFMPKBPChu3Q0pS9pR8HE8E+jvlgdzA9ORN7UCHQGlcxCWcBlyDhNli6QTgv/Ap2mXIYr3trw== X-Received: by 2002:a05:600c:3b06:b0:422:1705:7549 with SMTP id 5b1f17b1804b1-42304844acamr8268545e9.25.1718310312950; Thu, 13 Jun 2024 13:25:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42301a7c850sm29166365e9.6.2024.06.13.13.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:25:12 -0700 (PDT) Message-Id: <2789c58cd3f0691a32cbd0a5aa96a438b799b9f3.1718310307.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Jun 2024 20:25:04 +0000 Subject: [PATCH 4/7] merge-ort: clearer propagation of failure-to-function from merge_submodule Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren The 'clean' member variable is somewhat of a tri-state (1 = clean, 0 = conflicted, -1 = failure-to-determine), but we often like to think of it as binary (ignoring the possibility of a negative value) and use constructs like '!clean' to reflect this. However, these constructs can make codepaths more difficult to understand, unless we handle the negative case early and return pre-emptively; do that in handle_content_merge() to make the code a bit easier to read. Signed-off-by: Elijah Newren --- merge-ort.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/merge-ort.c b/merge-ort.c index 13b47d352fc..39799e65a36 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2193,6 +2193,8 @@ static int handle_content_merge(struct merge_options *opt, clean = merge_submodule(opt, pathnames[0], two_way ? null_oid() : &o->oid, &a->oid, &b->oid, &result->oid); + if (clean < 0) + return -1; if (opt->priv->call_depth && two_way && !clean) { result->mode = o->mode; oidcpy(&result->oid, &o->oid); From patchwork Thu Jun 13 20:25:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 13697447 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2C7B13A27E for ; Thu, 13 Jun 2024 20:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310318; cv=none; b=UgRGwx3TdBhzx5EphkOg2imrcbFyVVj60oAMTkfq36i0fGsZTL1ykTP0VZeiOoe9BYgk51rnn1IrZjNNBle5pMhMEG+BNk3DCMiKkhe1pKk2y12H4HBB3udH4faNurVzmCkaBbHdMszoE3WsogGBvNLT16jpEXCDGV4QRJxIbqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310318; c=relaxed/simple; bh=/U0obEsi5f14h0Xy6+/HcwRIbiQSQeWcG8Mtp0iLwbQ=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=MCPOz/3LaG/FaDgCw+rDT8br0qHcqWy4DySAwEp6yWYEda7TjMZXilO03bkhHvkle/BZt0Ul6pM0EVyql5XxoK8OI9Zw1GvlmE4LJMyaN8OOR8mid4iF/tL52DmsU8sdXu9Gje69XEwQc5q5cy/lVvAswx7db2lxWT581xcTzqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MgHCmTa3; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MgHCmTa3" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4210aa00c94so13327965e9.1 for ; Thu, 13 Jun 2024 13:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310314; x=1718915114; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=tAuGnwSbBnJA5elepqauAEZFpJHQJdEqOknjIGfEOcI=; b=MgHCmTa3DnxNta35Mqk78rnZtJ4qpmzAKzG4w6m13sZsYwTLMmzqU/4ehe7Uet3+0L bmMNY1iqN2nZg0Gkip9CIHlpiLzD2ixA9PypnT+mPOCuvzxzrvuxVK1y5cia6UWeoNXj KQnNl2EN5GQ/bM9ddcp7Adk/8a5HJnMjpiMkgnAWpqnN7pP8kC5qkhhmyLK7bT39dGCO E5POCbPd9OFNat26s21DU7pQsBfYUphOBGvzvWeX7kjB/WMjHFFqrMG3Cfkl98BcdboM x35D0qZIfboviMfinoogQw7jX7l31uibB2IvyjndOYW91dhD4osSV4A2I5wB2l1sC+jc l4dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310314; x=1718915114; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tAuGnwSbBnJA5elepqauAEZFpJHQJdEqOknjIGfEOcI=; b=ORT6t3u0QIHtFw+jAl2eB3YWQ7/7JOY4ZbJs03yPPmAKhkQajZX4XrrLegmEvLMDh9 jQyhztLh63dePOIkmqYt/54aVkMSZOql5UBukxk+SlZAVl9vc95cDAA57nVzWaeq6cLw qi0DyHXA+SzGRCHXeGP8bPqXWrCgjtScwxaBgGdmRUhktneDrvYMeoaAcB1qyI2+eBxq xK7Ee9SPdqT/U8ql6IRC9ltWUBKhsQhyKMW/ExgfYUN3Qon5+4o0ATb8EYEjCYUL7xsC WP9SIh9jEV72lkC0i+UI9hE3RXWi2EBjZQFeBOpSijUjR7Sz63TpdWGn4Caey8XNxcH8 lipw== X-Gm-Message-State: AOJu0YzcyW22OeYkwxyKndMO9+yh4YdQvDio2hVQK3mSku6bhJOhBkvQ V/4BYMATkOnuizLB2B/lHlbZWxySHfjPq1CqOvJ/1zbeDOKz4HcBXkLO6g== X-Google-Smtp-Source: AGHT+IEQ7Njn0QtFIdJJJjPliJsFy/txo+Ggle7Ok3hSEgAFmwJuA4zkv4KajpQW1O31ADZczJfycQ== X-Received: by 2002:a05:600c:1c9a:b0:422:6449:1307 with SMTP id 5b1f17b1804b1-4230484f994mr8704635e9.32.1718310314351; Thu, 13 Jun 2024 13:25:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422874e73b1sm74396945e9.45.2024.06.13.13.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:25:13 -0700 (PDT) Message-Id: <975fbddf3053d678df5cdfc75521b1be9e2533ce.1718310307.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Jun 2024 20:25:05 +0000 Subject: [PATCH 5/7] merge-ort: loosen commented requirements Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren The comment above type_short_descriptions claimed that the order had to match what was found in the conflict_info_and_types enum. Since type_short_descriptions uses designated initializers, the order should not actually matter; I am guessing that positional initializers may have been under consideration when that comment was added, but the comment was not updated when designated initializers were chosen. Signed-off-by: Elijah Newren --- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index 39799e65a36..462bc6fb6e1 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -553,7 +553,7 @@ enum conflict_and_info_types { * Short description of conflict type, relied upon by external tools. * * We can add more entries, but DO NOT change any of these strings. Also, - * Order MUST match conflict_info_and_types. + * please ensure the order matches what is used in conflict_info_and_types. */ static const char *type_short_descriptions[] = { /*** "Simple" conflicts and informational messages ***/ From patchwork Thu Jun 13 20:25:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 13697448 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED17513B2A8 for ; Thu, 13 Jun 2024 20:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310319; cv=none; b=tR2DYJlzLkn7ro2YoNKUZK9r/cSU3uGq1PfgysPHQxV9t5Nc8+Y7GN1g0a+zknhyhcjldiOC5gdnBkpDwIhImz5hzPb5HSnjALaxeyF91zsl5ZZsM0fBsKhoYc1nELQMWsZRoT91xlAFPKk5QJBxMu/+kspzKCn8d4g6kyrsk4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310319; c=relaxed/simple; bh=V2R1W56YQOOFHiKmSrR/5oGXKXtfIjztXxp4vLTOaoQ=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=JJidHOescUq9uKNWmRQMYvp5OyKdlqkcZFegJqhAAP8b6SrgHoQlhhsv4IWV5ysXJl2t0lWpkeJWg0+OcJQEWsELIeWdAluFlKr16dn3PfJot7uinIWJ9AJYX/4MSKL+eD7sGZwOrdrcUeSqlaDf756OYHostrezvl/z0Cfnfvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hSmnF3Qr; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hSmnF3Qr" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-35f225ac23bso1417194f8f.0 for ; Thu, 13 Jun 2024 13:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310316; x=1718915116; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=7q6K6UOmFxkhSBQjcEH3QUR/miq8F8IOpZkyX3XHOyg=; b=hSmnF3QrSS0y2egvZN/b/9PuaLlOLsKp89ilqclnBiNZi4fGNJLacIA59G4BFfJfdG RajO//q10xEkj3+UA1DX9nln+fHgN3bKeGrfRwZPwqr8covBiUTFSSPBaTw9nbPlrdzR fWkAqaBX1KLJrIaoAMysXbTaRdMsPutxM0k4F2bKb4fnA/l7Sk9EW9G+4i4Q2TXgNRTR 0edUPhM3YkjZEn08WBtyuM+im0AbxdSTkTjt32ulULvJ6h/Wo4m86T/w4iAKnQ2SBSFb Fm9zNYw+ZEbDEcFQkyw2sFWouHQyPjND3UIRIWvVtebb9zuTXhdyLmguwTPHokyKOOSU 99Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310316; x=1718915116; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7q6K6UOmFxkhSBQjcEH3QUR/miq8F8IOpZkyX3XHOyg=; b=VKeW/Y/HlzGo0Bs1yk8Wj3hFM2N+QP885ArELGXQvL1OWmyiFM08A8S55aogLChF+T 8vXSBcqsLKwLF79B9v73+W0yR55EAvPUCLtQq80OOdFR30UHUpNOdUFDeldY9Uoo1LrF 2PuVEW0Y4Y/1DzSMEmX40z2T9UCaJ4IfH47Q27vBAmXiw4MtFi15bkxk/gkccXikbM2G evmxGVHPgEe9aLQ9sR4rZp8jA7dV1IzuMrf/Fr/dSZ1ns3VklritcI3D+GQ46jlMQuZF k7gz9ILVdZjxHccMMQr2FhWwuq6gIXlEm1kb2aiPYOpe5Hdu/0iQiVxGKrYg0tWj/Clb XfYQ== X-Gm-Message-State: AOJu0Ywu5aRwwsfYyy4HvMsF2jIdKW5mdJ3WrbLEHNzdwTucpzrrXVBD rIfKxAdiNDN+40yqX8Skhmctq54+EanLco6klvjOGXChYik4ZF3gb0NsZQ== X-Google-Smtp-Source: AGHT+IE+qaRzYwwde2SIfNoCv3yR9y/QH3HnJryhzvfBEzVbIhGFgxyS/CA2hN77Yn5zmdkQ8JlP1g== X-Received: by 2002:a5d:4d08:0:b0:35f:2363:e4fc with SMTP id ffacd0b85a97d-3607a7606b3mr735274f8f.17.1718310315865; Thu, 13 Jun 2024 13:25:15 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509c86dsm2611169f8f.40.2024.06.13.13.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:25:14 -0700 (PDT) Message-Id: <71391b18c1a711fee1f5aff6eedbd3f631d37ded.1718310307.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Jun 2024 20:25:06 +0000 Subject: [PATCH 6/7] merge-ort: upon merge abort, only show messages causing the abort Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren When something goes wrong enough that we need to abort early and not even attempt merging the remaining files, it probably does not make sense to report conflicts messages for the subset of files we processed before hitting the fatal error. Instead, only show the messages associated with paths where we hit the fatal error. Also, print these messages to stderr rather than stdout. Signed-off-by: Elijah Newren --- merge-ort.c | 76 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 462bc6fb6e1..5410dec2b4f 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -543,10 +543,24 @@ enum conflict_and_info_types { CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE, CONFLICT_SUBMODULE_MAY_HAVE_REWINDS, CONFLICT_SUBMODULE_NULL_MERGE_BASE, - CONFLICT_SUBMODULE_CORRUPT, + + /* INSERT NEW ENTRIES HERE */ + + /* + * Keep this entry after all regular conflict and info types; only + * errors (failures causing immediate abort of the merge) should + * come after this. + */ + NB_REGULAR_CONFLICT_TYPES, + + /* + * Something is seriously wrong; cannot even perform merge; + * Keep this group _last_ other than NB_CONFLICT_TYPES + */ + ERROR_SUBMODULE_CORRUPT, /* Keep this entry _last_ in the list */ - NB_CONFLICT_TYPES, + NB_TOTAL_TYPES, }; /* @@ -597,8 +611,10 @@ static const char *type_short_descriptions[] = { "CONFLICT (submodule may have rewinds)", [CONFLICT_SUBMODULE_NULL_MERGE_BASE] = "CONFLICT (submodule lacks merge base)", - [CONFLICT_SUBMODULE_CORRUPT] = - "CONFLICT (submodule corrupt)" + + /* Something is seriously wrong; cannot even perform merge */ + [ERROR_SUBMODULE_CORRUPT] = + "ERROR (submodule corrupt)", }; struct logical_conflict_info { @@ -762,7 +778,8 @@ static void path_msg(struct merge_options *opt, /* Sanity checks */ assert(omittable_hint == - !starts_with(type_short_descriptions[type], "CONFLICT") || + (!starts_with(type_short_descriptions[type], "CONFLICT") && + !starts_with(type_short_descriptions[type], "ERROR")) || type == CONFLICT_DIR_RENAME_SUGGESTED); if (opt->record_conflict_msgs_as_headers && omittable_hint) return; /* Do not record mere hints in headers */ @@ -1817,9 +1834,9 @@ static int merge_submodule(struct merge_options *opt, /* check whether both changes are forward */ ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_a); if (ret2 < 0) { - path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0, path, NULL, NULL, NULL, - _("Failed to merge submodule %s " + _("error: failed to merge submodule %s " "(repository corrupt)"), path); ret = -1; @@ -1828,9 +1845,9 @@ static int merge_submodule(struct merge_options *opt, if (ret2 > 0) ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_b); if (ret2 < 0) { - path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0, path, NULL, NULL, NULL, - _("Failed to merge submodule %s " + _("error: failed to merge submodule %s " "(repository corrupt)"), path); ret = -1; @@ -1848,7 +1865,7 @@ static int merge_submodule(struct merge_options *opt, /* Case #1: a is contained in b or vice versa */ ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b); if (ret2 < 0) { - path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0, path, NULL, NULL, NULL, _("Failed to merge submodule %s " "(repository corrupt)"), @@ -1867,9 +1884,9 @@ static int merge_submodule(struct merge_options *opt, } ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a); if (ret2 < 0) { - path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0, path, NULL, NULL, NULL, - _("Failed to merge submodule %s " + _("error: failed to merge submodule %s " "(repository corrupt)"), path); ret = -1; @@ -1901,9 +1918,9 @@ static int merge_submodule(struct merge_options *opt, &merges); switch (parent_count) { case -1: - path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0, path, NULL, NULL, NULL, - _("Failed to merge submodule %s " + _("error: failed to merge submodule %s " "(repository corrupt)"), path); ret = -1; @@ -4646,6 +4663,7 @@ void merge_display_update_messages(struct merge_options *opt, struct hashmap_iter iter; struct strmap_entry *e; struct string_list olist = STRING_LIST_INIT_NODUP; + FILE *o = stdout; if (opt->record_conflict_msgs_as_headers) BUG("Either display conflict messages or record them as headers, not both"); @@ -4662,6 +4680,10 @@ void merge_display_update_messages(struct merge_options *opt, } string_list_sort(&olist); + /* Print to stderr if we hit errors rather than just conflicts */ + if (result->clean < 0) + o = stderr; + /* Iterate over the items, printing them */ for (int path_nr = 0; path_nr < olist.nr; ++path_nr) { struct string_list *conflicts = olist.items[path_nr].util; @@ -4669,25 +4691,31 @@ void merge_display_update_messages(struct merge_options *opt, struct logical_conflict_info *info = conflicts->items[i].util; + /* On failure, ignore regular conflict types */ + if (result->clean < 0 && + info->type < NB_REGULAR_CONFLICT_TYPES) + continue; + if (detailed) { - printf("%lu", (unsigned long)info->paths.nr); - putchar('\0'); + fprintf(o, "%lu", (unsigned long)info->paths.nr); + fputc('\0', o); for (int n = 0; n < info->paths.nr; n++) { - fputs(info->paths.v[n], stdout); - putchar('\0'); + fputs(info->paths.v[n], o); + fputc('\0', o); } - fputs(type_short_descriptions[info->type], - stdout); - putchar('\0'); + fputs(type_short_descriptions[info->type], o); + fputc('\0', o); } - puts(conflicts->items[i].string); + fputs(conflicts->items[i].string, o); + fputc('\n', o); if (detailed) - putchar('\0'); + fputc('\0', o); } } string_list_clear(&olist, 0); - print_submodule_conflict_suggestion(&opti->conflicted_submodules); + if (result->clean >= 0) + print_submodule_conflict_suggestion(&opti->conflicted_submodules); /* Also include needed rename limit adjustment now */ diff_warn_rename_limit("merge.renamelimit", From patchwork Thu Jun 13 20:25:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 13697449 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF54E13B580 for ; Thu, 13 Jun 2024 20:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310320; cv=none; b=eLJcHdxTCfVSM0WOOinyIkVJWuxPI2NHhhI7syZloTRRmsRZS7wQgOJbp/7ZxcAE8PyewP5wB6T4iwqsJavS4zTGP4lZqCTYZPY+e6IMlPpP9Fz3nnAvFucL1XQxseU6uf7RY/KudeVSpWeu1A5gQOiroo3uBFHxYSnAqZnCYwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310320; c=relaxed/simple; bh=lL0Uf6Yos/1qSOTLHQ6wEUlzmTScor++Nn3QKxQ1gYI=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=bE7Nf8sqHEhCS1Da6GA56nZlB5nsn7bbxcpNv985aP2Hogpytfkk5nZqI7M8nYtbGH61Awbe0oV7aJ1aqJ8yAeWbxd7L2M+pfa7jjy3FrqRACobl6+sIXI20g54lp6ULt2ySLQ/JJaekEqE3UM0ZGUHHIpXYrnwiSi/yB67aA88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HeWvsPuP; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HeWvsPuP" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-35f275c7286so1355600f8f.2 for ; Thu, 13 Jun 2024 13:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310317; x=1718915117; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=XLIF4q2ZHyh/Xh9xiDa55Q70fW1Ev/dNsms6su/hvVc=; b=HeWvsPuPR55VMZWYLLCSXDM0M4g2h5M4Cm3KhUpTMWPx8TUSOm9XtlVy+6Uh+Js88v wqeWzn8bqCDPKzGkz2JGQzy+vH4goXoQTORHpGkozlR5jPcrHABFkxB3fTZvRena+9Wq 7OgVquGKmYUdh2/Sklm1QtKpSW/hf3bTcAUwMgosLyn9Wt/ZBJdEl++j2HQ3EJfGGsq3 kRQyu1SsHrD2gVZHVvd6aWahymUUYdelFfAcLVr5qGnrPvYWHyJB4mwuo3UHTzCBMoAA zF6P+kb4yd18oDEyqo9kcp/wR5C/nPcdbym3dqz5AJGg4Mtd05rNKEgUz/KDnnCfGtUu Dlew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310317; x=1718915117; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XLIF4q2ZHyh/Xh9xiDa55Q70fW1Ev/dNsms6su/hvVc=; b=KUpjwxfPk8/pHokHm+2H0X3dTz+Eu6EBTGKR+OOXdmxr98GeAobpNdMTB3oKjmtVKG 4FTbgYyT89To7weDvXxicEA1yeiIgL20ilBjFR2WjsCmJrmQirIu61Xqk1BT+VEHP420 Ahtrf5kI/7iqCztPoy/vDyQxUySUCkhNfmzBs/RylNjiEaIBQ46JyIeWXnyu1k+Tlt4B KC4Df4qadYmwTVG6ZyZDO9sNs1OKAwlhVFZvUs3g2oMwDSwQt22zNxJx7Gzz4MFtvEEn fdJJogt7iQS79SCSVrth4KbaAVqwFpHzScG3WhvaHwvoiH73kY6/+H3r+U3/xLVr+kN/ 67oQ== X-Gm-Message-State: AOJu0YyypBBzr60vuRheCEX52qE8av6vlDseLTQR1JQtG9rSlTT18sZ8 Loq48sIyBQoyz3m/g5+mOPCDQaJ9HxwQNa4IRk4KhJt+yzGs3rtyPciSig== X-Google-Smtp-Source: AGHT+IHZSTqPg5VWVpPYNAPG2QQgyBZomN22xyMxTRaynH2GSav1JVrEmgulAQI7h7THzJbRYDV02Q== X-Received: by 2002:a05:6000:102:b0:360:6e1d:6c68 with SMTP id ffacd0b85a97d-3607a759bf8mr561795f8f.16.1718310316523; Thu, 13 Jun 2024 13:25:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509346asm2604148f8f.20.2024.06.13.13.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:25:16 -0700 (PDT) Message-Id: <32ae44b6260eea8dad7a428ed92e25b3891ddd9c.1718310307.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Jun 2024 20:25:07 +0000 Subject: [PATCH 7/7] merge-ort: convert more error() cases to path_msg() Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren merge_submodule() stores errors using path_msg(), whereas other call sites make use of the error() function. This is inconsistent, and moving towards path_msg() seems more friendly for libification efforts since it will allow the caller to determine whether the error messages need to be printed. Note that this deferred handling of error messages changes the error message in a recursive merge from error: failed to execute internal merge to From inner merge: error: failed to execute internal merge which provides a little more information about the error which may be useful. Since the recursive merge strategy still only shows the older error, we had to adjust the new testcase introduced a few commits ago to just search for the older message somewhere in the output. Signed-off-by: Elijah Newren --- merge-ort.c | 53 +++++++++++++++++++++++++++++++++---------- t/t6406-merge-attr.sh | 2 +- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 5410dec2b4f..493aa55aa80 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -558,6 +558,10 @@ enum conflict_and_info_types { * Keep this group _last_ other than NB_CONFLICT_TYPES */ ERROR_SUBMODULE_CORRUPT, + ERROR_THREEWAY_CONTENT_MERGE_FAILED, + ERROR_OBJECT_WRITE_FAILED, + ERROR_OBJECT_READ_FAILED, + ERROR_OBJECT_NOT_A_BLOB, /* Keep this entry _last_ in the list */ NB_TOTAL_TYPES, @@ -615,6 +619,14 @@ static const char *type_short_descriptions[] = { /* Something is seriously wrong; cannot even perform merge */ [ERROR_SUBMODULE_CORRUPT] = "ERROR (submodule corrupt)", + [ERROR_THREEWAY_CONTENT_MERGE_FAILED] = + "ERROR (three-way content merge failed)", + [ERROR_OBJECT_WRITE_FAILED] = + "ERROR (object write failed)", + [ERROR_OBJECT_READ_FAILED] = + "ERROR (object read failed)", + [ERROR_OBJECT_NOT_A_BLOB] = + "ERROR (object is not a blob)", }; struct logical_conflict_info { @@ -2190,15 +2202,24 @@ static int handle_content_merge(struct merge_options *opt, pathnames, extra_marker_size, &result_buf); - if ((merge_status < 0) || !result_buf.ptr) - ret = error(_("failed to execute internal merge")); + if ((merge_status < 0) || !result_buf.ptr) { + path_msg(opt, ERROR_THREEWAY_CONTENT_MERGE_FAILED, 0, + pathnames[0], pathnames[1], pathnames[2], NULL, + _("error: failed to execute internal merge for %s"), + path); + ret = -1; + } if (!ret && write_object_file(result_buf.ptr, result_buf.size, - OBJ_BLOB, &result->oid)) - ret = error(_("unable to add %s to database"), path); - + OBJ_BLOB, &result->oid)) { + path_msg(opt, ERROR_OBJECT_WRITE_FAILED, 0, + pathnames[0], pathnames[1], pathnames[2], NULL, + _("error: unable to add %s to database"), path); + ret = -1; + } free(result_buf.ptr); + if (ret) return -1; if (merge_status > 0) @@ -3577,18 +3598,26 @@ static int sort_dirs_next_to_their_children(const char *one, const char *two) return c1 - c2; } -static int read_oid_strbuf(const struct object_id *oid, - struct strbuf *dst) +static int read_oid_strbuf(struct merge_options *opt, + const struct object_id *oid, + struct strbuf *dst, + const char *path) { void *buf; enum object_type type; unsigned long size; buf = repo_read_object_file(the_repository, oid, &type, &size); - if (!buf) - return error(_("cannot read object %s"), oid_to_hex(oid)); + if (!buf) { + path_msg(opt, ERROR_OBJECT_READ_FAILED, 0, + path, NULL, NULL, NULL, + _("error: cannot read object %s"), oid_to_hex(oid)); + return -1; + } if (type != OBJ_BLOB) { free(buf); - return error(_("object %s is not a blob"), oid_to_hex(oid)); + path_msg(opt, ERROR_OBJECT_NOT_A_BLOB, 0, + path, NULL, NULL, NULL, + _("error: object %s is not a blob"), oid_to_hex(oid)); } strbuf_attach(dst, buf, size, size + 1); return 0; @@ -3612,8 +3641,8 @@ static int blob_unchanged(struct merge_options *opt, if (oideq(&base->oid, &side->oid)) return 1; - if (read_oid_strbuf(&base->oid, &basebuf) || - read_oid_strbuf(&side->oid, &sidebuf)) + if (read_oid_strbuf(opt, &base->oid, &basebuf, path) || + read_oid_strbuf(opt, &side->oid, &sidebuf, path)) goto error_return; /* * Note: binary | is used so that both renormalizations are diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index b6db5c2cc36..9bf95249347 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -295,7 +295,7 @@ test_expect_success !WINDOWS 'custom merge driver that is killed with a signal o >./please-abort && echo "* merge=custom" >.gitattributes && test_expect_code 2 git merge recursive-a 2>err && - grep "^error: failed to execute internal merge" err && + grep "error: failed to execute internal merge" err && git ls-files -u >output && git diff --name-only HEAD >>output && test_must_be_empty output