From patchwork Tue Mar 18 11:00:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14020778 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5ABE209673 for ; Tue, 18 Mar 2025 11:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295629; cv=none; b=Y/UL2m7X1Iqif8bWGfu2NpXIgdqg+hsYVwo2R3PlYCxAQPHDwElGf5g/X4IgDsQfalnH5Ln2lb8vhybHYxDjpD4t4M5bRRuTZFGNSARXTAXgD5uuG9yWx2MeUcgWUmTIxsWcILVy8LsojNBjvglzkm++pNFYzip++Z5sO5vgVoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295629; c=relaxed/simple; bh=x+4ITheMFV15srN/DNeCL8OOej5Cz/3Iokphcl0qfFE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u2/C4d6eXlO2ukhK+wB3jj6EnoAuJDPs5aW4FDck430sh3+nQgagsWQSVe03PnT1KPdDLEnnia3YAkdNlayakj4+lcNrM/cIJ9qb5YbWwH8mLKO7gZkYDyu/FWoSgZXE00ngLWTRUuBmKr2qQdI6bdC2HrvaXSfsuoRVHjZX7CM= 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=XaN/p3C4; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XaN/p3C4" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4393dc02b78so20182345e9.3 for ; Tue, 18 Mar 2025 04:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742295625; x=1742900425; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wO3y36G9A/pjzGu/899mnIFGDJqjSV8cLgeTdoBqFkc=; b=XaN/p3C4uViedWqKpJJriCoZhEYah4vyBV5KtqU0jI/yvla1rJONqZ1hUSXvdKA+qE YegvRoOQumZSv1NHqyYDkG9IteF731Y+xf7WqlaXiVt3w7lqhfNzzzr7IgUx/vRw+KK2 EqIEUksCL2EBcdy5898CUQ1A4sLRNJ5xrVJDeiUQzZfisHdvEh0TgSOrkaBhxa38YSBE HXctimHo0451JRrs0bncaBa+I/Fnddqy7P4Ew3yYqT02RL4y+Zy7yIZkRstTz5pa9CHX nY3RemfJaoMtY2u8mV65SM8xoEdwFmgvH5Gx8Ib2aC227RrMiEDhAZtw8eyhbpO4sM/a q6vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742295625; x=1742900425; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wO3y36G9A/pjzGu/899mnIFGDJqjSV8cLgeTdoBqFkc=; b=prDpf+lBEljMc99Wm1351twisvxlWh13T5d7X3YXyKgwiir5/48jTQrDMz8NmkreHW chnRc8znfK+L6TZp/GUpX0bR98RUg6Hvfhg8xYbWl+LIzFhCIBZk/LcMJhKcxF7s3pfN 6HPkmb7SIZparDLBjyIQsy1eGDzfDYM3k+Q2aWcb3Y97UC8ZDXMBA6IoHzHdnFSyJmVi S0nAr+s5oioJL3Dj342m4kXHtKf50sLE8iAqh1pPqsL7ofTvDyFY5RkmJndmC09nWoch kIkkdm6epp/sZZp11MKRy2I5vr27kABp1Fqm/6QXqDqD7MKXojodBKIMZpR349X3XhwH ak1Q== X-Gm-Message-State: AOJu0YxZV0HncQlU+Kpg+J5W2kjPAO5FTbAFKchbpnB8zVL7ktyvhLqJ kudgU0n7VI8unx98N6D7zJVGz1ZM3Fzf4tc7W45ciUe9bHA0WW6m0B+wpw== X-Gm-Gg: ASbGncvysf4cGF0nhPj3Xd8zSLPizh/aaKAlPQjDIFZAf8P8qSGYtAUl97107Jcb6HD rgFwA4VSTMpsWtyVhhSN7lUt8lE9j3MJNP8FHz/8KsHsRbHcJLjrJWZesu6G3AI0i3atnlHEgP7 YYon351nMSCDf4sDBTO1213QMksFUZFhyItXuvq1M/WNskors2Vvp3LTQW0bo/AzsIsJPSLfUZs YFQBeWTA1jtIO2cgEz25ebkefypUh4ltqe1I3DRMw/FNl0P7jkWbMtYJyQ9uMQZy1WQTmdpEnX2 FJaUXmmNcY70q4Ypt3x/W4BO/TpciB5ACtu/wgdd7p0349KpOieoGTpyMiqSo8wYSRIbHBxPLdI VXQ== X-Google-Smtp-Source: AGHT+IG/S68QlVbYrBCsM3+UQsHZcNRPQRr/LXh2bu8fzllVQizHTMtkq4/MIRWz4mrumHIb4jOyyA== X-Received: by 2002:a05:600c:1d8d:b0:43c:f81d:34 with SMTP id 5b1f17b1804b1-43d3ca66b80mr14577705e9.9.1742295625034; Tue, 18 Mar 2025 04:00:25 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:f066:6e28:cef1:9d6a:ca5b:64d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fe60951sm131169515e9.26.2025.03.18.04.00.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 04:00:22 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Patrick Steinhardt , Taylor Blau , Eric Sunshine , Karthik Nayak , Kristoffer Haugsbakk , "brian m . carlson" , "Randall S . Becker" , Christian Couder , Christian Couder Subject: [PATCH v6 1/4] t5710: arrange to delete the client before cloning Date: Tue, 18 Mar 2025 12:00:05 +0100 Message-ID: <20250318110008.656695-2-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.4.g81387f61c3 In-Reply-To: <20250318110008.656695-1-christian.couder@gmail.com> References: <20250314141203.2548803-1-christian.couder@gmail.com> <20250318110008.656695-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If `test_when_finished "rm -rf client"` is run after we clone, it will not run if the clone failed, so the "client" directory might not be removed at the end of the test. `git clone` does try to remove the directory when it fails, but let's be safe and try to protect against possibly weird clone failures by moving `test_when_finished "rm -rf client"` before the clone. It just makes more sense this way around. Signed-off-by: Christian Couder --- t/t5710-promisor-remote-capability.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh index d2cc69a17e..e26a97f588 100755 --- a/t/t5710-promisor-remote-capability.sh +++ b/t/t5710-promisor-remote-capability.sh @@ -93,6 +93,7 @@ test_expect_success "setup for testing promisor remote advertisement" ' test_expect_success "clone with promisor.advertise set to 'true'" ' git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ @@ -100,7 +101,6 @@ test_expect_success "clone with promisor.advertise set to 'true'" ' -c remote.lop.url="file://$(pwd)/lop" \ -c promisor.acceptfromserver=All \ --no-local --filter="blob:limit=5k" server client && - test_when_finished "rm -rf client" && # Check that the largest object is still missing on the server check_missing_objects server 1 "$oid" @@ -108,6 +108,7 @@ test_expect_success "clone with promisor.advertise set to 'true'" ' test_expect_success "clone with promisor.advertise set to 'false'" ' git -C server config promisor.advertise false && + test_when_finished "rm -rf client" && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ @@ -115,7 +116,6 @@ test_expect_success "clone with promisor.advertise set to 'false'" ' -c remote.lop.url="file://$(pwd)/lop" \ -c promisor.acceptfromserver=All \ --no-local --filter="blob:limit=5k" server client && - test_when_finished "rm -rf client" && # Check that the largest object is not missing on the server check_missing_objects server 0 "" && @@ -126,6 +126,7 @@ test_expect_success "clone with promisor.advertise set to 'false'" ' test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ @@ -133,7 +134,6 @@ test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' -c remote.lop.url="file://$(pwd)/lop" \ -c promisor.acceptfromserver=None \ --no-local --filter="blob:limit=5k" server client && - test_when_finished "rm -rf client" && # Check that the largest object is not missing on the server check_missing_objects server 0 "" && @@ -144,8 +144,8 @@ test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' test_expect_success "init + fetch with promisor.advertise set to 'true'" ' git -C server config promisor.advertise true && - test_when_finished "rm -rf client" && + mkdir client && git -C client init && git -C client config remote.lop.promisor true && @@ -162,6 +162,7 @@ test_expect_success "init + fetch with promisor.advertise set to 'true'" ' test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ @@ -169,7 +170,6 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' -c remote.lop.url="file://$(pwd)/lop" \ -c promisor.acceptfromserver=KnownName \ --no-local --filter="blob:limit=5k" server client && - test_when_finished "rm -rf client" && # Check that the largest object is still missing on the server check_missing_objects server 1 "$oid" @@ -177,6 +177,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' test_expect_success "clone with 'KnownName' and different remote names" ' git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.serverTwo.promisor=true \ @@ -184,7 +185,6 @@ test_expect_success "clone with 'KnownName' and different remote names" ' -c remote.serverTwo.url="file://$(pwd)/lop" \ -c promisor.acceptfromserver=KnownName \ --no-local --filter="blob:limit=5k" server client && - test_when_finished "rm -rf client" && # Check that the largest object is not missing on the server check_missing_objects server 0 "" && @@ -195,6 +195,7 @@ test_expect_success "clone with 'KnownName' and different remote names" ' test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ @@ -202,7 +203,6 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' -c remote.lop.url="file://$(pwd)/lop" \ -c promisor.acceptfromserver=KnownUrl \ --no-local --filter="blob:limit=5k" server client && - test_when_finished "rm -rf client" && # Check that the largest object is still missing on the server check_missing_objects server 1 "$oid" @@ -212,6 +212,7 @@ test_expect_success "clone with 'KnownUrl' and different remote urls" ' ln -s lop serverTwo && git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ @@ -219,7 +220,6 @@ test_expect_success "clone with 'KnownUrl' and different remote urls" ' -c remote.lop.url="file://$(pwd)/serverTwo" \ -c promisor.acceptfromserver=KnownUrl \ --no-local --filter="blob:limit=5k" server client && - test_when_finished "rm -rf client" && # Check that the largest object is not missing on the server check_missing_objects server 0 "" && From patchwork Tue Mar 18 11:00:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14020779 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 77CCCEAC6 for ; Tue, 18 Mar 2025 11:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295631; cv=none; b=WrSasdTwIhMWEnnciDkAYGaXpgkhAhgsRolAdbWMPKxnm3pyyEvnKXVM/CNOW0QbQrYEklRCgpVUpwAALbsZEH2HW55n12+6GrseJH5vetY5NtVAU3yFHtL6DJv5O8o63s3XLUbAFQ0/nGx4yHY+zXzF59RblL7MstqrDvMN7CA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295631; c=relaxed/simple; bh=EAX6+DuVWHToFCdolzIoY3DnJYQYHJk18th3Vo95Y1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QyHlJVoBQ/Ca4ofm6rWp8S8sgUbk4hUUI+R7Wgokq5HovXfLomNcqByHfJYNY2hqya0HtTJT23r90R5oFU2e8ldcyrYs4ZlNBzqWYPZNxi6IchAONhayGIRQkQ8qrNRxIO8ufN5R5lGVRyGMunvf/wPmHFCoWGe5Mdmgt64wXAM= 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=bsczTnzK; arc=none smtp.client-ip=209.85.128.54 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="bsczTnzK" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43d0359b1fcso20513025e9.0 for ; Tue, 18 Mar 2025 04:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742295627; x=1742900427; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tos7JzDZZvIK2pnE0wchPyv5vHFBNmawEW7wUXu8gs4=; b=bsczTnzK7gH/tKzxTEeXv+JyEWYoEj5rv2oJ4kUOsCpeJpI+coyipTpjUDfsU363Ne g+1FyGDvSC50CD8YENS+VALAHj2LH2Pu7j8PrwnE2iRt17JPIDvAGcHmLgAeC2FA+Qw2 ag3WvHAKTgwCQCXDmzsKgMWQCo7Lm6NjKwKi6aHenAZFKW2Lg8wY9i38YkDpjAClwiIg FohzAT7It7A2zCQi9oIgOwqvoIfBs6hdz4e1iqeMXtTx3z1vHBqJYrgqGbvWt/xovNAm FYTRxNr2dXTWHgBbXccxGpxXcmPkLZcsHCMeP5nKcng5jkOhYwq9QaujEXjtiKNVF32N 4FAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742295627; x=1742900427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tos7JzDZZvIK2pnE0wchPyv5vHFBNmawEW7wUXu8gs4=; b=rKA5ZurLulfiF8++iYwdG4uylrILVSYrzqIo4ZQvP/z/enig57ck+mgbGz/no70vHM tJwATtD+Gtut4Qk28YcZwY3HTJfyFvm3zdFdfB8g9MrYzPGz+r07tZG3+jUMjs/28716 Cws0IvtP4z9fGFAd254lsJsFBcy8N24xRacnyNCFmgCPywZbV2QLYaa+qHQXeZzEylTG A1KGgTAEzJMho6tr+WNH8JllY5zObdd6EPEYxROW8NnQWNTqFD/XMVKpAHdwSOu3dbnT CK4lqNMmTeY0zvg7rgkvKBS+vicGzMLTWkcqEitn4fVA+Onysd7osEdXKn2Yv8PmMzMh YIcw== X-Gm-Message-State: AOJu0Yx9sCN06wVSdIFjijtBHQA1v9IlxbMUi9ARmCzGBSDB55/Q4oxV Pk3rdfQuqssfFPKoCMrfVKV1qjcC7Q0kOdrVLpccweqtKAtqKHZiB7T4zg== X-Gm-Gg: ASbGnctehTISpbDUQz7ukusnm0i//R2eigSHMSTsyfoM9ujB8/Pia7bzNdPGDPktVYj 65X0sc8l0M736XfmNy9Z11vGwNyvffjoeNs2EzM1i8qt6RnTBAiIl+poLtaCKvjki5+OwTqvAWD jCHC5rjK97oOEypy6dSHDexx1nnjXvW4HwGhYoJbMNKFRC36CAs2l7SuV3eUaAKFIjIxN9a0Tpg /Cz5v2Y6JFPS5U4GPE/U1QgIx9PDlrocr2seUP5iqCVkJv2FmNj3den0txq8cssLdKPFrHXiM39 FGx2oCJhmaFCW/osDurSVEgU0HWXMp/st8QLs1p7JfAL+kLePd7IHRqO2mGUZiXk5yYxpLNDxdn 8Ig== X-Google-Smtp-Source: AGHT+IFNXJ67O2QM8Q0D3eFRx5vSA+pZH4t9AjR4s0IcYRZPlmVPnETjn6xiRmrjfWGEPiF5u0nxBw== X-Received: by 2002:a05:600c:a582:b0:43c:f509:2bbf with SMTP id 5b1f17b1804b1-43d3ba0f49amr14315065e9.15.1742295627077; Tue, 18 Mar 2025 04:00:27 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:f066:6e28:cef1:9d6a:ca5b:64d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fe60951sm131169515e9.26.2025.03.18.04.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 04:00:25 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Patrick Steinhardt , Taylor Blau , Eric Sunshine , Karthik Nayak , Kristoffer Haugsbakk , "brian m . carlson" , "Randall S . Becker" , Christian Couder , Christian Couder Subject: [PATCH v6 2/4] promisor-remote: fix segfault when remote URL is missing Date: Tue, 18 Mar 2025 12:00:06 +0100 Message-ID: <20250318110008.656695-3-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.4.g81387f61c3 In-Reply-To: <20250318110008.656695-1-christian.couder@gmail.com> References: <20250314141203.2548803-1-christian.couder@gmail.com> <20250318110008.656695-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using strvec_push() to push `NULL` into a 'strvec' results in a segfault, because `xstrdup(NULL)` crashes. So when an URL is missing from the config, let's not push the remote name and URL into the 'strvec's. While at it, let's also not push them in case the URL is empty. It's just not worth the trouble and it's consistent with how Git otherwise treats missing and empty URLs in the same way. Note that in case of missing or empty URL, Git uses the remote name to fetch, which can work if the remote is on the same filesystem. So configurations where the client, server and remote are all on the same filesystem may need URLs to be configured even if they are the same as the remote names. But this is a rare case, and the work around is easy enough. We leave improving the strvec API and/or xstrdup() for a future separate effort. While at it, let's also use git_config_get_string_tmp() instead of git_config_get_string() to simplify memory management. Helped-by: Jeff King Signed-off-by: Christian Couder --- promisor-remote.c | 16 +++---- t/t5710-promisor-remote-capability.sh | 61 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/promisor-remote.c b/promisor-remote.c index 6a0a61382f..ba80240f12 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -323,13 +323,15 @@ static void promisor_info_vecs(struct repository *repo, promisor_remote_init(repo); for (r = repo->promisor_remote_config->promisors; r; r = r->next) { - char *url; + const char *url; char *url_key = xstrfmt("remote.%s.url", r->name); - strvec_push(names, r->name); - strvec_push(urls, git_config_get_string(url_key, &url) ? NULL : url); + /* Only add remotes with a non empty URL */ + if (!git_config_get_string_tmp(url_key, &url) && *url) { + strvec_push(names, r->name); + strvec_push(urls, url); + } - free(url); free(url_key); } } @@ -356,10 +358,8 @@ char *promisor_remote_info(struct repository *repo) strbuf_addch(&sb, ';'); strbuf_addstr(&sb, "name="); strbuf_addstr_urlencode(&sb, names.v[i], allow_unsanitized); - if (urls.v[i]) { - strbuf_addstr(&sb, ",url="); - strbuf_addstr_urlencode(&sb, urls.v[i], allow_unsanitized); - } + strbuf_addstr(&sb, ",url="); + strbuf_addstr_urlencode(&sb, urls.v[i], allow_unsanitized); } strvec_clear(&names); diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh index e26a97f588..b35b774235 100755 --- a/t/t5710-promisor-remote-capability.sh +++ b/t/t5710-promisor-remote-capability.sh @@ -193,6 +193,25 @@ test_expect_success "clone with 'KnownName' and different remote names" ' initialize_server 1 "$oid" ' +test_expect_success "clone with 'KnownName' and missing URL in the config" ' + git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && + + # Clone from server to create a client + # Lazy fetching by the client from the LOP will fail because of the + # missing URL in the client config, so the server will have to lazy + # fetch from the LOP. + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c promisor.acceptfromserver=KnownName \ + --no-local --filter="blob:limit=5k" server client && + + # Check that the largest object is not missing on the server + check_missing_objects server 0 "" && + + # Reinitialize server so that the largest object is missing again + initialize_server 1 "$oid" +' + test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' git -C server config promisor.advertise true && test_when_finished "rm -rf client" && @@ -228,6 +247,48 @@ test_expect_success "clone with 'KnownUrl' and different remote urls" ' initialize_server 1 "$oid" ' +test_expect_success "clone with 'KnownUrl' and url not configured on the server" ' + git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && + + test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" && + git -C server config unset remote.lop.url && + + # Clone from server to create a client + # It should fail because the client will reject the LOP as URLs are + # different, and the server cannot lazy fetch as the LOP URL is + # missing, so the remote name will be used instead which will fail. + test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=KnownUrl \ + --no-local --filter="blob:limit=5k" server client && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + +test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" ' + git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && + + test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" && + git -C server config set remote.lop.url "" && + + # Clone from server to create a client + # It should fail because the client will reject the LOP as an empty URL is + # not advertised, and the server cannot lazy fetch as the LOP URL is empty, + # so the remote name will be used instead which will fail. + test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=KnownUrl \ + --no-local --filter="blob:limit=5k" server client && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" ' git -C server config promisor.advertise true && From patchwork Tue Mar 18 11:00:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14020780 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 41BBA20A5C6 for ; Tue, 18 Mar 2025 11:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295633; cv=none; b=qhTy5QX3Y8R01FZYYrVPQwax1uodt4G43r9WhvK2PTkc34bTorVYCmFfWNqe1YDgJKP06rilYmMPE9uCmv/+yNX/HzdH9VQfpQgyvpXbwnSYVlJoaqRhC++ECWWfL6Ic1lt8LIbEs2tfUYgGvZU5s9kHGusbpKYgWlTB3zLsHes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295633; c=relaxed/simple; bh=2u1IUGEt1lst84JwvtOyz3ClIUJfRs1x0VZYZBoH2jY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZpjRnGC2jQ1oC86AcF/FEXx5yZg+YtlHauTOHDclWkRCO44lFLjYAzNs0/S+kJ1FG/pbzsKvSVAH1AGcm9Imv9Qpz4gDFs5lKLQtB/faj9kQeDfV8qeCB5XzvYIpVnxRcYbpuBxolckDehVSc9cBF4XQlNdhTxhYkA68p1w5OrM= 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=neWOTbtC; arc=none smtp.client-ip=209.85.128.47 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="neWOTbtC" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43cf06eabdaso31117015e9.2 for ; Tue, 18 Mar 2025 04:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742295629; x=1742900429; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7lUCPRnE/wxdQRspVOtQR39MTq//CJyA9np0Jqr+a1g=; b=neWOTbtCJ4Ti2lCMevQLdMjPiHhU7LJR+WB4A8MunNm1zfENIU7JqNvz0sVjRWEYpV fuDCL8f28HVoTzhiY20HRnAKLrhvI31xb9eeNpp0+gokwUp7U4hsTFyeA22/9ozS6/W3 CChUyfwElwygP4XI2Wwn4SkWPnGREsg10HpAhsQJ16dc3KQPp8FEF2c8L18BoX60uiCQ w5Ok5qPHu1bGU4frKzMcsM1VMYpo7xt6ExQpZJh0XQHo7ERSJ3vXqcIyaMN9gBAY4plw CCEWcWlvua6qDLHpUpygM2VoMdG9wYjRZCafymVZFyiRNnYVc4NFf9qnlvlHQk5pW7NY 0yyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742295629; x=1742900429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7lUCPRnE/wxdQRspVOtQR39MTq//CJyA9np0Jqr+a1g=; b=etIhdVntJIOE4c1pK5wMZkL3uIP9VNW3/T17oMYTns2rEGfWMcX29AGpn8mw4Vqjay Yo5YWwWD+MXnqlaLWo5avmq+RaunUW8/WJS5KhfHcSdIEQ5aS3FKt/ESYQrEcOxAzmo3 uxXWS2CN1fp1OT9jglFDw5IXLDyDA1cGDWC1QB2lqM0Z5wtQ1GMeLB2AiO8G1YuF75Mg VKQAH3Jm7S/jI1ZBOcuCwZ5dAet5oF11VQG0ysa7fFPWey9lv8m0NjAaZVmBJluyOF+j QuSGasfy8dgYkSMybbSy4smqAB68Z4P3jk8L8BZQqCiIS+LZ3xjYdtf2yBi4iZvt2d/1 9oFA== X-Gm-Message-State: AOJu0YypZduwmvvDvqJTl3Zc63EqYL5vK3N7BG0tyQX+b9Lsq4ZXAF+e Byie2Xi5j6fTQv74XCX0Qgka14PMaYup/LVqypd0TbohxC/6Pa6Lqj/Jcg== X-Gm-Gg: ASbGncuPNFLwTXF0g9yUsAn/9DYoznDU+TlMMY+CmFPvKVSTnw2G7HK4qnPdvgA4mGY zzHa57hkBfwNT1PzKPpeJ/Ko2NWCvglAfrRhAzSVR+am/5Cd+0wes+5PnIjlIL0Mt0rYO5TMtQY T/l/CV7x/cIXk0yIibfylH7HY7u5hEgyC0895uWnznw1xxEaAWZ/r5sJ7B88oGlBfn/bRM9ned4 KZ4F9yvQXHge5PGTWEwKeQFnSU2P7XHHZwBs81CQr7EOaL9wabcKj3qFFXxe7SvzLzh/yUfIGTk 2fS264fN2omg6STk/G5lyCa8wYFVmcGOhvzca8gs1uIeLgj6fnT5mbf1giqAghm7pLT8mNVLoSM A1w== X-Google-Smtp-Source: AGHT+IFctPWrXEktSOEOq6XutGq4fqGjp/OsH/XxV8dxIuvLIPFI/IEOv6I3SZCsAorFLWla6I5quQ== X-Received: by 2002:a5d:64c2:0:b0:38c:2745:2df3 with SMTP id ffacd0b85a97d-397202a1acemr17276825f8f.37.1742295628776; Tue, 18 Mar 2025 04:00:28 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:f066:6e28:cef1:9d6a:ca5b:64d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fe60951sm131169515e9.26.2025.03.18.04.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 04:00:27 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Patrick Steinhardt , Taylor Blau , Eric Sunshine , Karthik Nayak , Kristoffer Haugsbakk , "brian m . carlson" , "Randall S . Becker" , Christian Couder , Christian Couder Subject: [PATCH v6 3/4] promisor-remote: fix possible issue when no URL is advertised Date: Tue, 18 Mar 2025 12:00:07 +0100 Message-ID: <20250318110008.656695-4-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.4.g81387f61c3 In-Reply-To: <20250318110008.656695-1-christian.couder@gmail.com> References: <20250314141203.2548803-1-christian.couder@gmail.com> <20250318110008.656695-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the 'KnownUrl' case, in should_accept_remote(), let's check that `remote_url` is not NULL before we use strcmp() to compare it with the local URL. This could avoid crashes if a server starts to not advertise any URL in the future. If `remote_url` is NULL, we should reject the URL. Let's also warn in this case because we warn otherwise when a remote is rejected to try to help diagnose things at the end of the function. And while we are checking that remote_url is not NULL and warning if it is, it makes sense to also help diagnose the case where remote_url is empty. Also while at it, let's spell "URL" with uppercase letters in all the warnings. Signed-off-by: Christian Couder --- promisor-remote.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/promisor-remote.c b/promisor-remote.c index ba80240f12..0b7b1ec45a 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -409,10 +409,15 @@ static int should_accept_remote(enum accept_promisor accept, if (accept != ACCEPT_KNOWN_URL) BUG("Unhandled 'enum accept_promisor' value '%d'", accept); + if (!remote_url || !*remote_url) { + warning(_("no or empty URL advertised for remote '%s'"), remote_name); + return 0; + } + if (!strcmp(urls->v[i], remote_url)) return 1; - warning(_("known remote named '%s' but with url '%s' instead of '%s'"), + warning(_("known remote named '%s' but with URL '%s' instead of '%s'"), remote_name, urls->v[i], remote_url); return 0; From patchwork Tue Mar 18 11:00:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14020781 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 61EFBEAC6 for ; Tue, 18 Mar 2025 11:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295635; cv=none; b=lEBlqdG7yJ6Kxsz2ea/ND3grOACSBxZ0d9mL8bQQiMMwgomvNQ5OQ1MkklzuY5fY+/+llVBErPbiIM3GpPOmaZZtkbEKF89C5r6H0OImfwUzgdQhDaokDETdDPRijh/EqR6Zdolj7FdnLdNf+oH/pQIO6jxHZZGyEsVCHhGi6iQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742295635; c=relaxed/simple; bh=w3M4ISDar+rXjewOKd131a26EFvBdqzUIfjIXcUJa/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nNsBo00EY0sAxPDmcQw9IL1+3QPUd58X7a42iAyGhwej6+g4GDyw3vR0iYtY+CZ2ZqLeDCds2GA/4psEcp5Malov2kb2eW0LV+rLu8BXNXitIwstbb6PxGu4Uw4/V83/zEwKGlHxaRm4/LerZY+lwAoLz6hdvK0rBG6rQ+msC6s= 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=mlP2AK+M; arc=none smtp.client-ip=209.85.128.45 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="mlP2AK+M" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43d04ea9d9aso14333965e9.3 for ; Tue, 18 Mar 2025 04:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742295631; x=1742900431; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hHB385iXKCd+ql3Nr7n5at37tJpKwaIjwXrXrPw3NVE=; b=mlP2AK+MtT4GYl+UO08SwIIoylRaa0NBco9zNLoYSHuW5ePzwKz97S+oyaoAJ9kzmm yQkFwdv92nz/mgBrRoZQl+b163bX89y1b4W+RFwPGSpCr8M0yI0yr4e/JGFnCgP6SWpo UKoLQjFU0IrPynCayuQYsPAeJ2vM0uu9pzuNV63NCE36Hme3CL4W9JMM3ydzjC/DrcF7 PArbWEWUo8/rLpWrAjRouBvWtbir95rV9ct9pjAoO1Mt1fq4qH20cssOVlfi/J+2UoPH WuzI2a8ERVaQgrFMjT+qyKIMZyZPbRm3Yp420jUavNoigI71N8OaLPoy/xLIagFCBJQQ oi+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742295631; x=1742900431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hHB385iXKCd+ql3Nr7n5at37tJpKwaIjwXrXrPw3NVE=; b=YEgdn4en2GPu8o3k5+u92ceURByifTSc/LegtpYWgRQSncECgykkbZamH9cZVx+uBj P1QPOzKhJmrnkkyyuyUFbY4slu8+/NC10rYWlERSrl8zVGDkNCGIz5RA63NY/q4GHIyx lS3VCB8eSimj4z6pLq+ggVSUVwx0dFlzsQgUQlCP1PZY0fj5JL3MSBo3hOzweWDKnPGS pbxawWwf7SE9yaCiy3SNNQBkuZtakjkwC2bvZTBEFgCcw2J9L1u64nASoJMytPUMLj+U nkma82tCtR6mkKVHsYW44mAXWHKUN/x+nPaybNDITn3FLQht3RoIuDT4DI3kR/BsoP4s a8cA== X-Gm-Message-State: AOJu0YxJiWzaw058+pkqWSAGMzwau7huoxXTL/now+gm3xQmGclr9NyR MKgGs9cVzm0ikufDQqCG7iZfaXH3ZXznvWIjSc3UXHxXbZkTywgwRDQ6wA== X-Gm-Gg: ASbGncv+4dBrYvgFwqQ0N6JQGUQdKq58AZS25ezdIxpbGdNuSTv69f9dzFf/+Gwq+3f pscP3RBojLmXXveRNjwhgwJPthSA38Pe+JIz9cgLwE8QiNjmPSAvBBUIo9Xm3O4VxCJaiwPAtVo OLlL52/Bz1Kxpls+uRw3Mtq206XpxT/9qFH8Vhg1Q//0PAIZBeOO/NcmrQrJBAwmzoQluqag9f3 Ol3ETVnwbtbY8480nxn8imkCLkRBa3tcM7VWj/779YpDmJ5f9JuuUamXUSTxhCXI5xTV+hF8HUq spHl5WWKBhmZQG+8EjQyEeWRcTCszjwU2qpM/zGU48nVBaev2r9aeOrkWybsDJwQ5oyW0clG6zB GLA== X-Google-Smtp-Source: AGHT+IFkTQ0LVhAxZTLqFVJeOcNbTaKCfBgzju+pYQbVXDxKZQv3capdgzx+6ZacvHErhuNK9L0TpQ== X-Received: by 2002:a05:600c:470c:b0:43c:efed:732c with SMTP id 5b1f17b1804b1-43d3ba15bacmr13506785e9.28.1742295630547; Tue, 18 Mar 2025 04:00:30 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:f066:6e28:cef1:9d6a:ca5b:64d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fe60951sm131169515e9.26.2025.03.18.04.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 04:00:29 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Patrick Steinhardt , Taylor Blau , Eric Sunshine , Karthik Nayak , Kristoffer Haugsbakk , "brian m . carlson" , "Randall S . Becker" , Christian Couder , Christian Couder Subject: [PATCH v6 4/4] promisor-remote: compare remote names case sensitively Date: Tue, 18 Mar 2025 12:00:08 +0100 Message-ID: <20250318110008.656695-5-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.4.g81387f61c3 In-Reply-To: <20250318110008.656695-1-christian.couder@gmail.com> References: <20250314141203.2548803-1-christian.couder@gmail.com> <20250318110008.656695-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Because the "[remote "nick"] fetch = ..." configuration variables have the nickname in the second part, the nicknames are case sensitive, unlike the first and the third component (i.e. "remote.origin.fetch" and "Remote.origin.FETCH" are the same thing, but "remote.Origin.fetch" and "remote.origin.fetch" are different). Let's follow the way Git works in general and compare the remote names case sensitively when processing advertised remotes. Signed-off-by: Christian Couder --- Documentation/config/promisor.adoc | 4 ++-- promisor-remote.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/config/promisor.adoc b/Documentation/config/promisor.adoc index 9192acfd24..2638b01f83 100644 --- a/Documentation/config/promisor.adoc +++ b/Documentation/config/promisor.adoc @@ -26,5 +26,5 @@ promisor.acceptFromServer:: server will be accepted. By accepting a promisor remote, the client agrees that the server might omit objects that are lazily fetchable from this promisor remote from its responses - to "fetch" and "clone" requests from the client. See - linkgit:gitprotocol-v2[5]. + to "fetch" and "clone" requests from the client. Name and URL + comparisons are case sensitive. See linkgit:gitprotocol-v2[5]. diff --git a/promisor-remote.c b/promisor-remote.c index 0b7b1ec45a..5801ebfd9b 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -370,13 +370,13 @@ char *promisor_remote_info(struct repository *repo) /* * Find first index of 'nicks' where there is 'nick'. 'nick' is - * compared case insensitively to the strings in 'nicks'. If not found + * compared case sensitively to the strings in 'nicks'. If not found * 'nicks->nr' is returned. */ static size_t remote_nick_find(struct strvec *nicks, const char *nick) { for (size_t i = 0; i < nicks->nr; i++) - if (!strcasecmp(nicks->v[i], nick)) + if (!strcmp(nicks->v[i], nick)) return i; return nicks->nr; }