From patchwork Thu Feb 8 13:50:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13549836 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 37073763EF for ; Thu, 8 Feb 2024 13:51:20 +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=1707400281; cv=none; b=jSEKNbaEfX3od0PWK6gOBXDfbSCriyiU1Wg1MJyvzw0+jQd9wOnL/K7ZjlKbnfJ77bm21K5q2qiAaCLGKjanc7a2tsFBc0FPNjlp78REhF/zqg/lAbTR7PmAn/CX/NJziK6v83iGKxSt20hxkDga8RyxVPIXooeM+3urealmjAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707400281; c=relaxed/simple; bh=WlAVCZv1vTIGI27NO4zu0LVYzGNW9oTXI51RaMttLjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ejEeORorv8rgFCkkkZYSeCD+fgoyRBxARQIX4l6tR7P+SBkPES22ebYC13CA34ErQJsrDfn5aBbT6ot/yUv2SFcWASfmxsfMpoErqjQvV0Sp6Y7KhJj8qxV2fFhay0C6jj4frKuK/jnttBqFhojL7siTgYg7s0YgalX+EqsV4l0= 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=WnLbNxDS; 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="WnLbNxDS" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4101fc00832so11846825e9.3 for ; Thu, 08 Feb 2024 05:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707400278; x=1708005078; 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=CDTU2iJB3MJ6UQ/7B8AuIDzoCBbdaRMCgCBIY8DkBhk=; b=WnLbNxDSpGMOxYkhUPmZ3XPb4BH+nj/frN75d1Qg/u2oHIKSpAoPOI/h5BVA+7vK7Q YF+andPxHOY7XU9+/oEKLlMESFGj32wptH/xDB0S3kMWPrx8xCHlhcWuU3f+2TtAQRLf CWETeuLvQPltR+uPVMrQOCvUWNoG4/wiOcDkrOEOiKRRXIbc3QxFelOA0z+yRVlFZWDd 7o2d+B5AmC56KH73iiLiu7Sg8AzYSo3pqNiPTw8OFvQLb+pLD4dZVLWmCHNT83ydUcvq 75j7tA2Bw/TgpCS1oOw1uqiizBeIhecZyxrbWnkchPKWdQfJA18ZQxQ+KfhgNwi7IYva Q/Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707400278; x=1708005078; 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=CDTU2iJB3MJ6UQ/7B8AuIDzoCBbdaRMCgCBIY8DkBhk=; b=ICbLNX3NDFiCS8k6Fo4iDR8cC5E73XmXg+L3MNmcwLspBhYen6fkGTr8ADaABc2Os9 xS915ncG9Qu5i22uxhRIqmpIsguyMw2bSdgV5hnz1PJoh7lZY5OaaNuXmSGf67IC/4hZ Ie23x7/23XKWOflJK1++Ms9+gHH9SADxcu91qnr2+PozRRXNEMNk4dQN6KUHRqUwCgvc rra/SLvkADd2vKvEJ31njl1RUtKMTm7s4Gwy+o13sI5OhpH0TOGygxVI7dFp0NRbjNjB zNs+tI5JLwD1C95O/FCpd/JqAk6nEwnLkmugOhBq2JAr2ObCLfJ8x1As1UjAmDL3cFlr 7NQw== X-Gm-Message-State: AOJu0YxcNkxOOCiNWGSVjzX59MSk8Olv5uNVRjR+r/JeYyst943jC2lL fyG8G6GlL0tvE7O4exfiurfEl40jMTXqZk6lk2o0+gJobmTBzbij7DyG5xiJ X-Google-Smtp-Source: AGHT+IGL6c6LPoLFw1Po6H3XY2dBcPy/6YN15maOksa2FCVx9tMj7KYcNeNdl6Q82Bnqn/pckQLd1Q== X-Received: by 2002:a05:600c:3d91:b0:410:5578:d9a0 with SMTP id bi17-20020a05600c3d9100b004105578d9a0mr4701wmb.21.1707400277472; Thu, 08 Feb 2024 05:51:17 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW/ujc9tPPZyMvTYpILC4NuJGjNb02YjMYvDEGWfBahl0PZCMJLp6xut6T2sqUiVJe/bvO7Wt/WDLcvl4QIdvRmtvexUOpxrRlo6NT3RwNxQhjfJb+BuX5/fHpwNgitcFqLZgBF0dPt5Ewe+yX1ssyE0Ny6eSe6A9kI4R/AgHngooaxn2Xjd+q9jM1xpT1zgWM0aTroxm+aPRIqclvjggp10B5YijJHDAv0Hk1aCMva Received: from localhost.localdomain ([2001:861:3f04:7ca0:4c16:5b8b:3341:9836]) by smtp.gmail.com with ESMTPSA id j12-20020a05600c190c00b0040ebf603a89sm1698307wmq.11.2024.02.08.05.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:51:17 -0800 (PST) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , John Cai , Linus Arver , Christian Couder , Eric Sunshine , Christian Couder Subject: [PATCH v2 1/4] revision: clarify a 'return NULL' in get_reference() Date: Thu, 8 Feb 2024 14:50:52 +0100 Message-ID: <20240208135055.2705260-2-christian.couder@gmail.com> X-Mailer: git-send-email 2.43.0.565.g97b5fd12a3.dirty In-Reply-To: <20240208135055.2705260-1-christian.couder@gmail.com> References: <20240208135055.2705260-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 general when we know a pointer variable is NULL, it's clearer to explicitly return NULL than to return that variable. In get_reference() when 'object' is NULL, we already return NULL when 'revs->exclude_promisor_objects && is_promisor_object(oid)' is true, but we return 'object' when 'revs->ignore_missing' is true. Let's make the code clearer and more uniform by also explicitly returning NULL when 'revs->ignore_missing' is true. Helped-by: Eric Sunshine Signed-off-by: Christian Couder --- revision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 2424c9bd67..4c5cd7c3ce 100644 --- a/revision.c +++ b/revision.c @@ -385,7 +385,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name, if (!object) { if (revs->ignore_missing) - return object; + return NULL; if (revs->exclude_promisor_objects && is_promisor_object(oid)) return NULL; die("bad object %s", name); From patchwork Thu Feb 8 13:50:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13549837 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 120AA76C6A for ; Thu, 8 Feb 2024 13:51:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707400284; cv=none; b=QjyJGAkt5zvKuejvxzhEdJmheHGEvifOFwwCK6LIXDYaVsJDZfErboSke1Cv4FKt9qPSZyEPOxGWtId66TeVVZWdK5e/nnuTrRFXzmzgZ3jJwmgIgFj9YYEVQ/hD+nbJpuhaRs56Ok+4I16VSICD2Zz91VTJ/jaE3uV3HLnIIp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707400284; c=relaxed/simple; bh=45ufkIQzxDtRIrHSNLkv/FGBfeRbsrOrwSHiILwjwsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YaAIBOh0duJwj0dYnc9KBlkhfiosPedjMjVB3/VJIJ5dJMz8xmW1TkohlFjvWJdTq3/5WBXeDBXO0SaQYwG43VqYpSNurud4brr7yxwppKAN95krutfvEzuBY7Did/ZTo9CVfI8d504okCDMrBsj4gaocxfwROdOpB9PLqy0tOc= 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=breguh2n; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="breguh2n" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-511234430a4so3742906e87.3 for ; Thu, 08 Feb 2024 05:51:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707400278; x=1708005078; 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=E/i/lyJ+wzUg0LWI3ZUdwHbk/ESQ2s6tD9llOIvj6GY=; b=breguh2n3p1s/tDKAleNvacG2XeAGcWXV4aKedjzN/hnmgr4KI6lf5gIi6+zdvHnZS ytgX+FloJ0ulnyc/5YZe6IHnePUB6feZCZ2FznJLcJzafUAwMM4lMjX3wmWM7ISb4+xt Lc5OlT5GqJEPTVq9W4hE9Pe4LW9nnxoNMcsIFA/25EkHg9YUtDcs50u4WtWFsBTJOSQu 1yjXg/YXojwGbIbiYAdKZqstmtgyuRP/bHziiumMsQ2gahBCJp6Ua4QH37cX4y7Iljd3 zS3faQOkgl/E4JpvYKdTGzeS2dz7mI+81QL/tNlUt7hydUIpMcuADoj5gJQLN89xZsVD 2wUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707400278; x=1708005078; 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=E/i/lyJ+wzUg0LWI3ZUdwHbk/ESQ2s6tD9llOIvj6GY=; b=sJxZ0qcDohRpCbDCFfPZiNvXOfpmjxfogUUKeiv3IfYs7yBxYftp1a4ZIlCeRnqEs2 d1Z2fScZRi/PzR7wQmNA0hvBC5S5Pn7ohsNO3VxAcnOLxv6fCo2SMPZnqhqA/rs+TVWm R/rMWBRDBWJsQwebPg2d9jiVSqAKSsEaEDZw3I/DQ93zoin16n0O01BJGoUeQIQN8po+ y4II2dj5xNl37SSX5J9ATcasHYB7peTm3HgFqMIgmeCrcoFx+URGITygvP4lKkO6E/Nr cz7kvbocIJ2dXPLqVofTL37jNOoi8BhGgb7/nsICLFb3qNxlQL5Oj9F+vxrNokrW8xLO BJFQ== X-Gm-Message-State: AOJu0YwdVmyaMCfDBl+lsUsejuhAX0ie9d26uYDRtFxIH5SqOMHlsdL0 3cLgbMghB6O0R8JDHlhp287UMLOMxy2eiV58+UT9Rd+jklfGHaHO4aJGTBh6 X-Google-Smtp-Source: AGHT+IGNwJnm7aMGOckC9SaXbJPfo3SLQCi13J+CVHYGHwOq9zj7bXOfLLwE3UJNvej7X5DLvL+qEA== X-Received: by 2002:ac2:4c45:0:b0:511:2dfc:9ffc with SMTP id o5-20020ac24c45000000b005112dfc9ffcmr7494441lfk.60.1707400278531; Thu, 08 Feb 2024 05:51:18 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVvUM0oFZXBMwOWBA4+jadn9RUxNEcY8MtSzuOjaCzb40TB+53uczaDONAR+ZrF/cqKaDRLDsih910fY2CNzKSXcSLwo42bolgpvKbilkrUdLtpzrNDiiGE/J/6/TUIlPJqBO6EI5amSJul1JFOdUaFGxMHb7y/ZroC/qP4NBA7iGIl1dklDDpsaE3K82Em/8n512jkg3g= Received: from localhost.localdomain ([2001:861:3f04:7ca0:4c16:5b8b:3341:9836]) by smtp.gmail.com with ESMTPSA id j12-20020a05600c190c00b0040ebf603a89sm1698307wmq.11.2024.02.08.05.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:51:17 -0800 (PST) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , John Cai , Linus Arver , Christian Couder , Christian Couder Subject: [PATCH v2 2/4] oidset: refactor oidset_insert_from_set() Date: Thu, 8 Feb 2024 14:50:53 +0100 Message-ID: <20240208135055.2705260-3-christian.couder@gmail.com> X-Mailer: git-send-email 2.43.0.565.g97b5fd12a3.dirty In-Reply-To: <20240208135055.2705260-1-christian.couder@gmail.com> References: <20240208135055.2705260-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 a following commit, we will need to add all the oids from a set into another set. In "list-objects-filter.c", there is already a static function called add_all() to do that. Let's rename this function oidset_insert_from_set() and move it into oidset.{c,h} to make it generally available. While at it, let's remove a useless `!= NULL`. Signed-off-by: Christian Couder --- list-objects-filter.c | 11 +---------- oidset.c | 10 ++++++++++ oidset.h | 6 ++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/list-objects-filter.c b/list-objects-filter.c index da287cc8e0..4346f8da45 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -711,15 +711,6 @@ static void filter_combine__free(void *filter_data) free(d); } -static void add_all(struct oidset *dest, struct oidset *src) { - struct oidset_iter iter; - struct object_id *src_oid; - - oidset_iter_init(src, &iter); - while ((src_oid = oidset_iter_next(&iter)) != NULL) - oidset_insert(dest, src_oid); -} - static void filter_combine__finalize_omits( struct oidset *omits, void *filter_data) @@ -728,7 +719,7 @@ static void filter_combine__finalize_omits( size_t sub; for (sub = 0; sub < d->nr; sub++) { - add_all(omits, &d->sub[sub].omits); + oidset_insert_from_set(omits, &d->sub[sub].omits); oidset_clear(&d->sub[sub].omits); } } diff --git a/oidset.c b/oidset.c index d1e5376316..91d1385910 100644 --- a/oidset.c +++ b/oidset.c @@ -23,6 +23,16 @@ int oidset_insert(struct oidset *set, const struct object_id *oid) return !added; } +void oidset_insert_from_set(struct oidset *dest, struct oidset *src) +{ + struct oidset_iter iter; + struct object_id *src_oid; + + oidset_iter_init(src, &iter); + while ((src_oid = oidset_iter_next(&iter))) + oidset_insert(dest, src_oid); +} + int oidset_remove(struct oidset *set, const struct object_id *oid) { khiter_t pos = kh_get_oid_set(&set->set, *oid); diff --git a/oidset.h b/oidset.h index ba4a5a2cd3..262f4256d6 100644 --- a/oidset.h +++ b/oidset.h @@ -47,6 +47,12 @@ int oidset_contains(const struct oidset *set, const struct object_id *oid); */ int oidset_insert(struct oidset *set, const struct object_id *oid); +/** + * Insert all the oids that are in set 'src' into set 'dest'; a copy + * is made of each oid inserted into set 'dest'. + */ +void oidset_insert_from_set(struct oidset *dest, struct oidset *src); + /** * Remove the oid from the set. * From patchwork Thu Feb 8 13:50:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13549838 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 BFDF27992A for ; Thu, 8 Feb 2024 13:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707400284; cv=none; b=YHyZ2Rf7fMv9C2VMc6mdj3MASltyrh2UzxN712CMTzwW0HXVdzBbyDlaKjLPL70sFvMgTrQe6aTpEUJHJvR24N+Vw7WRa28XshwDJtQG4np3c8ABPcjcGj5XaQtGw9pLvEVbH2sN+SnE0UiKUpZH5TLEegAaiXi8jyZjFkv82sQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707400284; c=relaxed/simple; bh=s9qAo856TVOCYcvuar1zN+ihM0EK7v651thbz23dwBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ThWLpxGIDPp9jhWPyuEN/M9rAyLrTj4nxO5zhJ4wU9C3RGbDAV2jCHKUgY+NGW5BWd6ZwAM8uBdDMCLBXW19RNeAQ5NNn2l/nho9Lrg079yrJuZb8J36DGLtqcJ6Iy5c3i+/k1AqKU2uOfFjeClQ+Nhx5DEiGCztmML3LLBh8GM= 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=HtFh3WjT; arc=none smtp.client-ip=209.85.128.42 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="HtFh3WjT" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40fe59b22dbso14518875e9.3 for ; Thu, 08 Feb 2024 05:51:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707400280; x=1708005080; 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=E+UIwR/KIMl/hnSAFHUpRslKh//fN9VcqaodOGZidLg=; b=HtFh3WjThdHBva1TKH1WtnC1dliSbyAHGqs7b55n4TbNo6Z5b5h3sdbvbFu7jnjM8s 34o+X6eAMO8GSLS69KXzsnRaoGjdSz3hVxN70ueF+QkfU/4ihl1PeMjxlatdGHIDMYMU 6//vH40sVT62A1OUlA+CvST/kSI1r3W8/4mE8ShrrRrsKovuxzcghH6i8AIxwRpJ0PVz e5Lrl6uIW/Ov5ZV9zavtacfUTGvLMct7zXPTwu/dR0MzaC87lLSTbnGxSQTpuT3GQ1GB MP5S7llkGFbDxA/djDK03KwVVzCVSthulPDnBPoXQZeik4dJfNCuoJEbVoRztpnzot5I ylPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707400280; x=1708005080; 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=E+UIwR/KIMl/hnSAFHUpRslKh//fN9VcqaodOGZidLg=; b=MByzI53t6St6SXNZdTTzjcvpF8fKBDNoEwiMuN/4WLCTpNlaeWJQhZDTKcQAovcRgV 7YXAAAvgAN5f0PCr4ACY+NIK76BfFuEL8lGFHZ7qibNguOO8JoGh0XDUUepoEZqblGeJ awRLbe9fUJgyRFixOMiN6QyyK/unyl5nKBjZnGq2uVQ2813HgrJuIM+5dWpPxjM3LxF0 S2DzviFhWUsRpUISZnWbYiR0Khg7kepyq0bwCFCQaqYloRdWp52cubBuNT6X1ipLigxR n5VGaUs9UAEaUCYKujsCBHBmVneIgULwnSXC/Rd97YPbx/aw4DqwBtBCuioLL16aHzKc ISew== X-Gm-Message-State: AOJu0Yxh/Xs6stCRxGM7ieyEOP/rAl2msy3slicRKKBT2kc9Bm6rHibO mReApk9HSBa8y/URnVT/mzxU1cF0rw2Oy+WrI0DQDsmkuokLxpxY6yGAvLqg X-Google-Smtp-Source: AGHT+IGwF2di7rE7dZ1WtTeifg+55eLdEjDqCvTcSmKyjURFseaPJs21YlIhtaZwHwhHvlQJG7nSgw== X-Received: by 2002:a05:600c:4f54:b0:40f:dc4e:69e8 with SMTP id m20-20020a05600c4f5400b0040fdc4e69e8mr7359669wmq.27.1707400279960; Thu, 08 Feb 2024 05:51:19 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVJgRBAANB+jLNxEGJw581hKE9F+UNTIMlx+lFS10MRiTa1ofq8Y6rWQpDH4m/fNKQ2QzPyHtVcO+RUqelTuhb33kJydYqJOUgCb8ECMcbG8vgbBj9TgNKGEtvsX/Bfazv9In60Ej967jXOZfc3e2bKFCocL4AA/iMi8hXqEe0490NWVXKq1UsJMKEaAOS8fyDJNoiovDk= Received: from localhost.localdomain ([2001:861:3f04:7ca0:4c16:5b8b:3341:9836]) by smtp.gmail.com with ESMTPSA id j12-20020a05600c190c00b0040ebf603a89sm1698307wmq.11.2024.02.08.05.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:51:18 -0800 (PST) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , John Cai , Linus Arver , Christian Couder , Christian Couder Subject: [PATCH v2 3/4] t6022: fix 'test' style and 'even though' typo Date: Thu, 8 Feb 2024 14:50:54 +0100 Message-ID: <20240208135055.2705260-4-christian.couder@gmail.com> X-Mailer: git-send-email 2.43.0.565.g97b5fd12a3.dirty In-Reply-To: <20240208135055.2705260-1-christian.couder@gmail.com> References: <20240208135055.2705260-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Christian Couder --- t/t6022-rev-list-missing.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh index 211672759a..5f1be7abb5 100755 --- a/t/t6022-rev-list-missing.sh +++ b/t/t6022-rev-list-missing.sh @@ -46,9 +46,10 @@ do git rev-list --objects --no-object-names \ HEAD ^$obj >expect.raw && - # Blobs are shared by all commits, so evethough a commit/tree + # Blobs are shared by all commits, so even though a commit/tree # might be skipped, its blob must be accounted for. - if [ $obj != "HEAD:1.t" ]; then + if test $obj != "HEAD:1.t" + then echo $(git rev-parse HEAD:1.t) >>expect.raw && echo $(git rev-parse HEAD:2.t) >>expect.raw fi && From patchwork Thu Feb 8 13:50:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13549839 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 97BC583CCB for ; Thu, 8 Feb 2024 13:51:24 +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=1707400287; cv=none; b=AfBEVbUgxa2qT23LpwzUldNoTgnEbMTJoJ5P/xfaDkzvC8U7mLCJJcKUeo01MT11FaBoLWw+BSImxAazN7semhUgvoU0V+aIyH6tjqW6rJC6TDWFY7GrSKwuKzsf6APydlva0rRrRHQYfxuMHMzc3e05kTIeGN5oBnwixCzXmHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707400287; c=relaxed/simple; bh=0XguJFMNqmcv8urfJQhpyVVg48IXxLWtFEgDaNdYTuw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXCNDBUNG30zWzzc/qDig0LSFYUhQe0Lur6Whd2s+t7h/7DnuDXJmBGKYK8jsCvWKMOpHgDIl2rGaSkYHZIIPgAbtETYkcU7JKTijTHc3Cs5gp7QlmhTM6/8UCOi5hXuNVGxVomEcl94KJOABFLN33iey2NgPcJGmS1k+R2Sjro= 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=B0DceWRf; 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="B0DceWRf" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40ff28388a6so16693675e9.1 for ; Thu, 08 Feb 2024 05:51:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707400282; x=1708005082; 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=99P5cdie6O7ryQzlt91sTZu4Un7JX4h23FdP6SfLDLQ=; b=B0DceWRfV+qpIQxAKcqwAh55Vm4eENzWh53Zomf8eTmFd2ZKmJMhw0dXf6cgxxHzwd 59vFtPFf2CDm6M9LeeLzajVixYUePoJv66vMVO/bvkCcke9D9dK23j6YjGLKJ78U3OCm FPgF1ziykY6wvr1RMl5ilu+zRE/mBMOL4Z+3Iq0ZjnSzHGndqQNsF+CP+CrEilCJIMLz NQa7SdKAo4vUq9QEeFFvT2CpLP1f9yJ/95DVQdrTpz/NzwN6KBgnVMYxsssETgB+l7VE LpYwqaTsoc7p8Cz/mhvPjKTsC2MJBNiZ78aDj1j8xZUv0+YRmqKLJwWhHPFT3e3/Py9K uW6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707400282; x=1708005082; 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=99P5cdie6O7ryQzlt91sTZu4Un7JX4h23FdP6SfLDLQ=; b=TpidzHyLNuwNgivUrfhNgAPoxJ9rJo2yjdnDLPhSZHlZSr4d6AZ8CqBVX+8C6hv55P cNzpBzEInNScgglxxPrOonmOHzsxJEcmRtmnccd5oCyB4HDvld5MA0CLk+LRr7cdCB8A WHCuOJirEfk9VyPbFOLhYk83CuBwbwyKamRs4Uff9+xhIUqfRnwFsBc/AdBICfr45JKw aghyoPb8ZXT1+1THVMJWhCWXgCVShh0mqxlD1eQprO+JKmEoRYl73A0yAQ/TvDxEtRhD riG3HjCuy3RJFqrUbYBWbADCjW6RF0aL9pYpPQV/W+aThjLMtel7DatRbwvG7MO5LoUU tRFA== X-Gm-Message-State: AOJu0Yy17clcPix6F0c1JFYRlrv/psAwEMNSc2KB5uiTOpDoGUdPivOO yF6RStHM5xWnHPzO0JOlD7VNr7wp3ia6yXWaFWoDybvaHDpf6q8U8nIGymJy X-Google-Smtp-Source: AGHT+IGwF1jf2hNvhdBcbk0bgvEPYXxkn5Aa9VMN0M+buxN1x7qEmu+IlqdjVjA2wnaKN2JMJmNdGg== X-Received: by 2002:a05:600c:35cf:b0:40f:cd21:40d4 with SMTP id r15-20020a05600c35cf00b0040fcd2140d4mr7249502wmq.25.1707400282024; Thu, 08 Feb 2024 05:51:22 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUweyGtK/6fUM0NlKYfY0XLIzi54t4EdSoeA/VDStpdz7Bt+ZsruQE1XI9sty8XAv9kU0tt53HuSPzHNsb8CoxbKh8Zk6y1vS0zoa6qBcIOSx8SX0G9EjzmGuxdChi6Ovm3Z6taixujGZO1axJB+U8NNorVqO7sjM4VQRT7ZF52Wjt/n+QewdYG5UeTkZ+gZ6MFwYhOHzA= Received: from localhost.localdomain ([2001:861:3f04:7ca0:4c16:5b8b:3341:9836]) by smtp.gmail.com with ESMTPSA id j12-20020a05600c190c00b0040ebf603a89sm1698307wmq.11.2024.02.08.05.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:51:20 -0800 (PST) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , John Cai , Linus Arver , Christian Couder , Christian Couder Subject: [PATCH v2 4/4] rev-list: allow missing tips with --missing=[print|allow*] Date: Thu, 8 Feb 2024 14:50:55 +0100 Message-ID: <20240208135055.2705260-5-christian.couder@gmail.com> X-Mailer: git-send-email 2.43.0.565.g97b5fd12a3.dirty In-Reply-To: <20240208135055.2705260-1-christian.couder@gmail.com> References: <20240208135055.2705260-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 9830926c7d (rev-list: add commit object support in `--missing` option, 2023-10-27) we fixed the `--missing` option in `git rev-list` so that it works with with missing commits, not just blobs/trees. Unfortunately, such a command would still fail with a "fatal: bad object " if it is passed a missing commit, blob or tree as an argument (before the rev walking even begins). When such a command is used to find the dependencies of some objects, for example the dependencies of quarantined objects (see the "QUARANTINE ENVIRONMENT" section in the git-receive-pack(1) documentation), it would be better if the command would instead consider such missing objects, especially commits, in the same way as other missing objects. If, for example `--missing=print` is used, it would be nice for some use cases if the missing tips passed as arguments were reported in the same way as other missing objects instead of the command just failing. We could introduce a new option to make it work like this, but most users are likely to prefer the command to have this behavior as the default one. Introducing a new option would require another dumb loop to look for that options early, which isn't nice. Also we made `git rev-list` work with missing commits very recently and the command is most often passed commits as arguments. So let's consider this as a bug fix related to these previous change. While at it let's add a NEEDSWORK comment to say that we should get rid of the existing ugly dumb loops that parse the `--exclude-promisor-objects` and `--missing=...` options early. Helped-by: Linus Arver Signed-off-by: Christian Couder --- Documentation/rev-list-options.txt | 4 +++ builtin/rev-list.c | 15 +++++++- revision.c | 14 ++++++-- t/t6022-rev-list-missing.sh | 56 ++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index a583b52c61..bb753b6292 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -1019,6 +1019,10 @@ Unexpected missing objects will raise an error. + The form '--missing=print' is like 'allow-any', but will also print a list of the missing objects. Object IDs are prefixed with a ``?'' character. ++ +If some tips passed to the traversal are missing, they will be +considered as missing too, and the traversal will ignore them. In case +we cannot get their Object ID though, an error will be raised. --exclude-promisor-objects:: (For internal use only.) Prefilter object traversal at diff --git a/builtin/rev-list.c b/builtin/rev-list.c index b3f4783858..ec9556f135 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -545,6 +545,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) * * Let "--missing" to conditionally set fetch_if_missing. */ + /* + * NEEDSWORK: These dump loops to look for some options early + * are ugly. We really need setup_revisions() to have a + * mechanism to allow and disallow some sets of options for + * different commands (like rev-list, replay, etc). Such + * mechanism should do an early parsing of option and be able + * to manage the `--exclude-promisor-objects` and `--missing=...` + * options below. + */ for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (!strcmp(arg, "--exclude-promisor-objects")) { @@ -753,8 +762,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) if (arg_print_omitted) oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE); - if (arg_missing_action == MA_PRINT) + if (arg_missing_action == MA_PRINT) { oidset_init(&missing_objects, DEFAULT_OIDSET_SIZE); + /* Already add missing tips */ + oidset_insert_from_set(&missing_objects, &revs.missing_commits); + oidset_clear(&revs.missing_commits); + } traverse_commit_list_filtered( &revs, show_commit, show_object, &info, diff --git a/revision.c b/revision.c index 4c5cd7c3ce..80c349d347 100644 --- a/revision.c +++ b/revision.c @@ -388,6 +388,10 @@ static struct object *get_reference(struct rev_info *revs, const char *name, return NULL; if (revs->exclude_promisor_objects && is_promisor_object(oid)) return NULL; + if (revs->do_not_die_on_missing_objects) { + oidset_insert(&revs->missing_commits, oid); + return NULL; + } die("bad object %s", name); } object->flags |= flags; @@ -1947,6 +1951,7 @@ void repo_init_revisions(struct repository *r, init_display_notes(&revs->notes_opt); list_objects_filter_init(&revs->filter); init_ref_exclusions(&revs->ref_excludes); + oidset_init(&revs->missing_commits, 0); } static void add_pending_commit_list(struct rev_info *revs, @@ -2178,13 +2183,18 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl if (revarg_opt & REVARG_COMMITTISH) get_sha1_flags |= GET_OID_COMMITTISH; + /* + * Even if revs->do_not_die_on_missing_objects is set, we + * should error out if we can't even get an oid, as + * `--missing=print` should be able to report missing oids. + */ if (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc)) return revs->ignore_missing ? 0 : -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); object = get_reference(revs, arg, &oid, flags ^ local_flags); if (!object) - return revs->ignore_missing ? 0 : -1; + return (revs->ignore_missing || revs->do_not_die_on_missing_objects) ? 0 : -1; add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags); add_pending_object_with_path(revs, object, arg, oc.mode, oc.path); free(oc.path); @@ -3830,8 +3840,6 @@ int prepare_revision_walk(struct rev_info *revs) FOR_EACH_OBJECT_PROMISOR_ONLY); } - oidset_init(&revs->missing_commits, 0); - if (!revs->reflog_info) prepare_to_use_bloom_filter(revs); if (!revs->unsorted_input) diff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh index 5f1be7abb5..78387eebb3 100755 --- a/t/t6022-rev-list-missing.sh +++ b/t/t6022-rev-list-missing.sh @@ -78,4 +78,60 @@ do done done +for missing_tip in "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t" +do + # We want to check that things work when both + # - all the tips passed are missing (case existing_tip = ""), and + # - there is one missing tip and one existing tip (case existing_tip = "HEAD") + for existing_tip in "" "HEAD" + do + for action in "allow-any" "print" + do + test_expect_success "--missing=$action with tip '$missing_tip' missing and tip '$existing_tip'" ' + oid="$(git rev-parse $missing_tip)" && + path=".git/objects/$(test_oid_to_path $oid)" && + + # Before the object is made missing, we use rev-list to + # get the expected oids. + if test "$existing_tip" = "HEAD" + then + git rev-list --objects --no-object-names \ + HEAD ^$missing_tip >expect.raw + else + >expect.raw + fi && + + # Blobs are shared by all commits, so even though a commit/tree + # might be skipped, its blob must be accounted for. + if test "$existing_tip" = "HEAD" && test $missing_tip != "HEAD:1.t" + then + echo $(git rev-parse HEAD:1.t) >>expect.raw && + echo $(git rev-parse HEAD:2.t) >>expect.raw + fi && + + mv "$path" "$path.hidden" && + test_when_finished "mv $path.hidden $path" && + + git rev-list --missing=$action --objects --no-object-names \ + $oid $existing_tip >actual.raw && + + # When the action is to print, we should also add the missing + # oid to the expect list. + case $action in + allow-any) + ;; + print) + grep ?$oid actual.raw && + echo ?$oid >>expect.raw + ;; + esac && + + sort actual.raw >actual && + sort expect.raw >expect && + test_cmp expect actual + ' + done + done +done + test_done