From patchwork Mon Mar 10 19:28:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14010568 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (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 2CF5C15B971 for ; Mon, 10 Mar 2025 19:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635135; cv=none; b=orOir1K17oYk9L5ItYyudY/XDEDyJV7onXvoNp/VVXQE1VStBn1rOPqi9gOJQv/a49EGzAakGZ87oVtTZV9qhdFUyX2773aK3IfLqd/sPVUjoRL3vgyZbNFtgbi2V1MOCADQ5EJZZe5sB0PVNaH570ERIHG4DNEZDsvx3xu/Yqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635135; c=relaxed/simple; bh=9Oixtf8VtLt11mtugwndN5WDyIGQO6bIWKsWs5kuz2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ETSYCloXaCV3Kmt11K+X/8N10Jt5HpjygCh2wVXaXuR9y6r4rrKL6X8it32hsrEM2u0BXIX0BWaXAT2q4+Chx0ydAzLyrE662LtcTxPF57u1fL23flv8hoMY2lKf1/xUYpNS7O1dO6rnOyx4FD2pVkvRyDcb8589YBuNotiztRY= 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=Dk7O8b7M; arc=none smtp.client-ip=209.85.167.175 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="Dk7O8b7M" Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3f3d1280f3dso1276954b6e.2 for ; Mon, 10 Mar 2025 12:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741635132; x=1742239932; 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=UNuZlJ4W5k6Ov8daMR9JpIecLLiQjZVFryYurms4G8k=; b=Dk7O8b7MgwQNbCcliVoQSCUHgd9CFBLDcWy5miDLPEJ2B7olbAEReUouli1yabceTW mHKy2x4PRlIAD6dJThqGCINrAYOhntBrw9gdKubxKOnRg38ILosFa9GVDYjCBuUeQ6j4 I7uE73LBTO56mzh5pJeF9qjaytWUzqjGUv0OV8fi00Etc/vHEY/voTGcs6E9EUnCntg+ WZgC4/X/65VbFwA7Rcm1sJSdTqvAlkRsbQTYZPG559IzfdXcLL1SNdafm7RQcrsZ6DoW lK2oMxFbq1+D1H4mRswR6k7VYmuxdBsFGj3riHoFJo6PgZTawhUonKSP1L6/zWZvod/W 9pZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741635132; x=1742239932; 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=UNuZlJ4W5k6Ov8daMR9JpIecLLiQjZVFryYurms4G8k=; b=MKe9PK5Scy4Z2hxh85fkP04j0+T6a6QM9yrZaW8tKsbLlofHgAlGOsCcFiXwBFZufh ZEEZs95YeZNGWGqFRmiVfTIUWWvumGFCYE8uyIou1EtBxOkcAxFheNTgQGc2+vuW9fZg oQqkl5VsPShHq5N+6rowL2qQu3DgwPoxEOTOfnt2cmAkf0IVUOi53Rq4EVDvN6BcTD8S EHji0FstAB8cb1cw5nUlrR1OO6n1VCi53J+Q6j4n2aybB0U2HvgaJ1V5fxKAXgOe5kI4 CnUhApy14t8DHD2AGLozo4AMj+dzD915GHem8qe8e6ntty3x6qfZdzEuBVmZMC7Z7d/U /Q1Q== X-Gm-Message-State: AOJu0YxO/CRgtUibyZ5WpPet0wvDdLOwWDD1EiGaA8+KFMRv64XJDjaB kiG/rsnswi0VljeabwaVcga9Z0G8CkyogMhgXdEjnjM2sxmyP6xAzZKNMA== X-Gm-Gg: ASbGncv7XKIie2Jj/yC4sBjC1RJ/KJqeHyf5I5BLlvXy7RxiDmqpiIsE1NcBNMKN/XH vRABQeLC4ZRCLByixqvz2Pf4EmauSQHPJGssWQ9A6rw5Bd26zSq4Uppd277S85laW+1GUSOM+zS Tv4siKUBHOcsY6tjf7LbDhpH0kEcrYoibX1gY/8WKZESYV6GErPlxlsoWinH2mtwAJdT9gG550R /vo80y2tMpclNPkyuR6g0iiSRv6hxl8n3L5XqLMw6IUHZlcNZgTEheyKIrAgte4NX1leIAgMvhm inBVDkj09zLOBLxFL69l1XQDksdmkVEqLjgoQNj5n2t2Oga2Q9g+Ff1UucDsKww= X-Google-Smtp-Source: AGHT+IH8JyXc1dCfDVbBvN3kmsnUt4IRkDiKIOD0mkidD1GAUIsy895n0NxGow5c4hgzgmtReyqVOQ== X-Received: by 2002:a05:6808:2013:b0:3f9:c668:2cb8 with SMTP id 5614622812f47-3f9c668319amr1253080b6e.13.1741635132516; Mon, 10 Mar 2025 12:32:12 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3f861f30de5sm697819b6e.46.2025.03.10.12.32.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 12:32:11 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, Justin Tobler Subject: [PATCH 1/4] rev-list: inline `show_object_with_name()` in `show_object()` Date: Mon, 10 Mar 2025 14:28:26 -0500 Message-ID: <20250310192829.661692-2-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250310192829.661692-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `show_object_with_name()` function only has a single call site. Inline call to `show_object_with_name()` in `show_object()` so the explicit function can be cleaned up and live closer to where it is used. While at it, factor out the code that prints the OID and newline for both objects with and without a name. In a subsequent commit, `show_object()` is modified to support printing object information in a NUL-delimited format. Signed-off-by: Justin Tobler --- builtin/rev-list.c | 13 +++++++++---- revision.c | 8 -------- revision.h | 2 -- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index bb26bee0d4..dcd079c16c 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -357,10 +357,15 @@ static void show_object(struct object *obj, const char *name, void *cb_data) return; } - if (arg_show_object_names) - show_object_with_name(stdout, obj, name); - else - printf("%s\n", oid_to_hex(&obj->oid)); + printf("%s", oid_to_hex(&obj->oid)); + + if (arg_show_object_names) { + putchar(' '); + for (const char *p = name; *p && *p != '\n'; p++) + putchar(*p); + } + + putchar('\n'); } static void show_edge(struct commit *commit) diff --git a/revision.c b/revision.c index c4390f0938..0eaebe4478 100644 --- a/revision.c +++ b/revision.c @@ -59,14 +59,6 @@ implement_shared_commit_slab(revision_sources, char *); static inline int want_ancestry(const struct rev_info *revs); -void show_object_with_name(FILE *out, struct object *obj, const char *name) -{ - fprintf(out, "%s ", oid_to_hex(&obj->oid)); - for (const char *p = name; *p && *p != '\n'; p++) - fputc(*p, out); - fputc('\n', out); -} - static void mark_blob_uninteresting(struct blob *blob) { if (!blob) diff --git a/revision.h b/revision.h index 71e984c452..21c6a69899 100644 --- a/revision.h +++ b/revision.h @@ -489,8 +489,6 @@ void mark_parents_uninteresting(struct rev_info *revs, struct commit *commit); void mark_tree_uninteresting(struct repository *r, struct tree *tree); void mark_trees_uninteresting_sparse(struct repository *r, struct oidset *trees); -void show_object_with_name(FILE *, struct object *, const char *); - /** * Helpers to check if a reference should be excluded. */ From patchwork Mon Mar 10 19:28:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14010569 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (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 26EB12309B3 for ; Mon, 10 Mar 2025 19:32:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635136; cv=none; b=kp2IUQDonPPAW5eub3BuiDZsEYcgEKwxpFitkZu36pIgUMTMMsIwqC8Q3cY2j68m6Ot56hMn1KgcDYirnoyiRaTM1ZwpVSrrvN6SEs5NvF4xN1mRFy/qT0t79jbvo86dX9jlge5Mubrp8mTiM52HnAVgePUbn//QkuX+HF0Qd48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635136; c=relaxed/simple; bh=opPvqbuSojM7C18Au7j9w0k+hzvHe5F6EHrCLfwU8KE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I0MtdOYuLstPMtyHMWPI9J0QROdl3lBHia572oE0TQmug3dXmTU0PVBqeWcduFuvIuzaKhVeut+psrV6cONuRP1AUwxBWTUAu83y4gfPscWDdEziGXChcW6DhjhGOb52E0S5hbPOTY0Zna7JUmQF2ySyXz3mds05Qyq2zKPMdRg= 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=eKMY+dxf; arc=none smtp.client-ip=209.85.167.177 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="eKMY+dxf" Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3f682a2c3c8so2333661b6e.1 for ; Mon, 10 Mar 2025 12:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741635134; x=1742239934; 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=lFid9FOUBgE6oHvchTwDzqtDPMt9SuyhXyG5MJ9m4c4=; b=eKMY+dxfAtiW8TuzyjQSge0//n9A6zZC+A2KDv+HCDlB3IxKDWVwjaC37UibUaC7th 7OrBnfu+Jz5wzTNpWjSWllQQq83Z1L+baHFBsStNbFBpfFMLnS7pmr2GjV8cAK6cuLOd YsLLMHr5fJ17B1Jy5tODTR4PEfRxcxU1yuF3dT8fQflg5wmTeW/c3Gdm5uEfpoi21jya gs/rnYFt9NmLNbS6m3VqczIoc4z5wOb4oKdMURt9Vu0C0rSGt6vWAEW22eUrvf+EYPRE gzgIWSmIYDvluvYT4wFsADjx918kdkN/UMmHMzdmgCF77Z40EQnMPkD1svIYygSK00vU IFzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741635134; x=1742239934; 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=lFid9FOUBgE6oHvchTwDzqtDPMt9SuyhXyG5MJ9m4c4=; b=AUAno0SK3sR7MQlaFcHzUQ9LMWw9FTuBkXPtA7VzTqBoXdgUp+bq6c76+THTj8w1dV uHhygg34fMUwkpO5XGv276LHiXhClFwtU0dBEFHdJhmC4mikrvIh6+2hrP18dePpUCgE jPrycpXFb374O7BE4uqNaqd3UlE2zIf5FFOJaT+ocHfDxviuGiWvYfyEnR+r2cFbC+op pJP+6E1UonGxlOmUTWOtg549ZJzuCv6yz/hbhHcl+dveQgOjJtTkwh+QfXaRWGje+0UB EIa8v8UPT1ef6Uq6rlahCnTW7yfLdQU5YcSVESjlPsh5dlvb5i2fX/lfYjnYL9cXJMpR MPmg== X-Gm-Message-State: AOJu0Yy6sIt9PsmydCOSM4DBTwKWn+DaAU0dLKqNQbcopCBNw7xHnBZP uzXA3p8/bVQy0W9kjH1Gq50pK4/2NWD4UIjwqK60bGJsuQshrWcoJI2KVg== X-Gm-Gg: ASbGncs6jl32mYRGt/RMJGa9BMwVYoxF63mWLOa4YjqckS+VWoRMHJNfkRLPvbrMe1w oSRk8/OFQLJAWf7GBEM/EN6XbTpQJpUR/9sagfQhaSKUqzLUeUja5XJ0wseWKIKVDT1/+rJg5oB PBuat7WZx0QP+wZ4w0eWE/ez/3q9B2Fy958Jr+1g0igZeECbXTLBPEvub6NpF+KIfPQXkELGxYd TRjWh8kYpaWSKyHotsgCne7IKk1QNMlMojkVIBKN/h0mxeubZnQwu9IOltWwl3a/gjPFPRQuKog KDMyiSNx0H/ZfH5kcJWsZ/rvVY4jW+f5tayqaorUdnUMMOZc7AQtNGTR9MbfdCw= X-Google-Smtp-Source: AGHT+IFpgLFAhSSsOw7eyfWH8JN4HnAWJ0nj0k015YpLeDVib//luh8dx6NHx1bLrWGpf+83NQbBNg== X-Received: by 2002:a05:6808:1526:b0:3fa:3a0:137a with SMTP id 5614622812f47-3fa03a05480mr902335b6e.17.1741635133672; Mon, 10 Mar 2025 12:32:13 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3f861f30de5sm697819b6e.46.2025.03.10.12.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 12:32:12 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, Justin Tobler Subject: [PATCH 2/4] rev-list: refactor early option parsing Date: Mon, 10 Mar 2025 14:28:27 -0500 Message-ID: <20250310192829.661692-3-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250310192829.661692-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Before invoking `setup_revisions()`, the `--missing` and `--exclude-promisor-objects` options are parsed early. In a subsequent commit, another option is added that must be parsed early. Refactor the code to parse both options in a single early pass. Signed-off-by: Justin Tobler --- builtin/rev-list.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index dcd079c16c..04d9c893b5 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -16,6 +16,7 @@ #include "object-file.h" #include "object-store-ll.h" #include "pack-bitmap.h" +#include "parse-options.h" #include "log-tree.h" #include "graph.h" #include "bisect.h" @@ -639,19 +640,15 @@ int cmd_rev_list(int argc, if (!strcmp(arg, "--exclude-promisor-objects")) { fetch_if_missing = 0; revs.exclude_promisor_objects = 1; - break; - } - } - for (i = 1; i < argc; i++) { - const char *arg = argv[i]; - if (skip_prefix(arg, "--missing=", &arg)) { - if (revs.exclude_promisor_objects) - die(_("options '%s' and '%s' cannot be used together"), "--exclude-promisor-objects", "--missing"); - if (parse_missing_action_value(arg)) - break; + } else if (skip_prefix(arg, "--missing=", &arg)) { + parse_missing_action_value(arg); } } + die_for_incompatible_opt2(revs.exclude_promisor_objects, + "--exclude_promisor_objects", + arg_missing_action, "--missing"); + if (arg_missing_action) revs.do_not_die_on_missing_objects = 1; From patchwork Mon Mar 10 19:28:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14010570 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.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 A8838235C17 for ; Mon, 10 Mar 2025 19:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635138; cv=none; b=kHUQX2McmQR0SbwUFv3LTABtg7bRqOdGWYoRb6NE/zcYU6csdObbpYxXcUbNOehrKsEhRzuiytco7FV7/WWDwGSR64MON39JPqt7rVHBSAHE/swsPxWmc0ZSRRmMBzasNURKuhFEcJPRXnHYY1Nm288mC/MoExKmaGyp696OD4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635138; c=relaxed/simple; bh=Qdj5XL2FzQf4k8X80NPbvZF0BGr5f6tdeILTIbjfEEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qQOpate6u+Eym8qvRs83+WrCz1uaKdEWcUoBR1VHoh6+YEEvH5JTIebMGzQy3T+dmVePOHVetv8KYUXYg0EacnZ7+fZrTkRYhOdwHDO23TTvWCniZLa6ltaDUEmsbyu5Rzm/0xfr7jgwSut6ZVOM7fBeI8IVAlC9N6dV1IoamyE= 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=e9tWRPkc; arc=none smtp.client-ip=209.85.210.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="e9tWRPkc" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-7272cc739f7so3100995a34.1 for ; Mon, 10 Mar 2025 12:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741635135; x=1742239935; 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=dKf7zRU5/PB/c6d9zXcaQLXv9ej5IdDNVPo7BHtUQrw=; b=e9tWRPkcBJ2f8E/OANLwFF+VcVj7kv4RANGPXt3oF1pZs2SJYCvtsA80M5OxHCY/y2 TTK2pvJmG+YJLK4hJu/0L4Q0DiVCtwV66B95bhmV01OOtIQX4r7TRkx2Qp92DCyb0CWR BI8/OQsjaocoBFX8NlS9umkHkeDJhWBoFpDXPrzK9DFqSNuFnfo3oZ8cnEIw07DuNBVQ vNFdwfQ1hNf7NiGfB3+GZgL/m4uevw0q9/U3yHaVUgv8XKroTKh/AbkjQNM3KLBVpR2E xT7QkgWa9VkOMTgCytH+3P9IADfxHncrWQhbTnbsPg59j9EHrpsK1+t4heR1ARCzmK6d +9aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741635135; x=1742239935; 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=dKf7zRU5/PB/c6d9zXcaQLXv9ej5IdDNVPo7BHtUQrw=; b=SE03N9y2LGVGcYibia24czqRUyo4ygp072CB2Tz7h8C8ursnpQaXh3VvWjOUvDnnZ5 gGJSD1eUFcdCjdcsZy3t/bHRUzPJ5AiGW1O+v02w6z9MkLP2PUvJ2A8WANCXeCSQihIY LTdlGWDv0JZ2/GpPywosLzmsY4hpL6DtHftadea0uFAvbY+SvxFBjQLbfz7UO9b0PtNT 1AqU3p2meKMW0iKzP5iuzn6mQv32p2zwir7WSh3sq4thqCnr2KVsmkgXkGztQ7lkUPgw 64XDWPQRJ/Y1xjW5XTF1kA62c3sdWsiyFghMv+N+IRJURh0gM/uknYHTy2w2SbMV3E42 Mqvg== X-Gm-Message-State: AOJu0YxFIyOgvI8pFgeGZpWb3d4hqD+b2ppCAHI9xYFizK98wAbXUfe/ jvwM8Zld0nDeKOikA+PH/LuSHWXUzfMCCwrmIzRM5Z6u/+YZZSbrTLx+hA== X-Gm-Gg: ASbGncuZhqtVE6iKoFX+O8YzNIIHpRamFuAMQ+EnMaEsnTRSupwsavC12urH8ICQoSQ yhrEWMFXEHh5+q6D9Ps4mmDG9yb1t+PGUtMeufRmb+iX5mA5aiMg+wIbBP5GPxdK1uAXE/HSnjM 7qWKe16f4agJaxIc58unudV8dU9RldTWyIiMc3ZKoulfnGwfpV7dIPKuIFBH7svY1EDvrMhmYWi EQvTt/6M2+3wzGPqve4whVu1QI2g0YW7ueSo5Mz/IHxOI7GXwDyJk7QqXn2+bae/xGSn7xijNln otSsIgGHvsV2Zv+BgH65PIJPVFApGu5XdfVW38UdVr+1/eeN+6Q6 X-Google-Smtp-Source: AGHT+IEFDVYN/+FnF+NUj5zowWM3KQ63zHIrMdMRg5FYdQ536xtPHczgfNG3iIzvxrVZR7GfnmqYjQ== X-Received: by 2002:a05:6808:10cd:b0:3f3:fe04:f86 with SMTP id 5614622812f47-3fa28dfb00dmr551334b6e.0.1741635135109; Mon, 10 Mar 2025 12:32:15 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3f861f30de5sm697819b6e.46.2025.03.10.12.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 12:32:14 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, Justin Tobler Subject: [PATCH 3/4] rev-list: support delimiting objects with NUL bytes Date: Mon, 10 Mar 2025 14:28:28 -0500 Message-ID: <20250310192829.661692-4-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250310192829.661692-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When walking objects, git-rev-list(1) prints each object entry on a separate line. Some options, such as `--objects`, may print additional information about tree and blob object on the same line in the form: $ git rev-list --objects SP [] LF Note that in this form the SP is appended regardless of whether the tree or blob object has path information available. Paths containing a newline are also truncated at the newline. Introduce the `-z` option for git-rev-list(1) which reformats the output to use NUL-delimiters between objects and associated info. Each object line uses two NUL bytes to indicate the end of an object entry and a single NUL byte to delimit between object information in the following form: $ git rev-list -z --objects [NUL ] NUL NUL For now, the `--objects` flag is the only option that can be used in combination with `-z`. In this mode, the object path is not truncated at newlines. In a subsequent commit, NUL-delimiter support for other options is added. Other options that do not make sense with be used in combination with `-z` are rejected. Signed-off-by: Justin Tobler --- Documentation/rev-list-options.adoc | 18 +++++++++++++ builtin/rev-list.c | 39 +++++++++++++++++++++++++---- t/t6000-rev-list-misc.sh | 34 +++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc index 785c0786e0..d21016d657 100644 --- a/Documentation/rev-list-options.adoc +++ b/Documentation/rev-list-options.adoc @@ -361,6 +361,24 @@ ifdef::git-rev-list[] --progress=
:: Show progress reports on stderr as objects are considered. The `
` text will be printed with each progress update. + +-z:: + Instead of being newline-delimited, each outputted object is delimited + with two NUL bytes in the following form: ++ +----------------------------------------------------------------------- + NUL NUL +----------------------------------------------------------------------- ++ +When the `--objects` option is also present, available object name information +is printed in the following form without any truncation for object names +containing newline characters: ++ +----------------------------------------------------------------------- + [NUL ] NUL NUL +----------------------------------------------------------------------- ++ +This option is only compatible with `--objects`. endif::git-rev-list[] History Simplification diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 04d9c893b5..86b3ce5806 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -65,6 +65,7 @@ static const char rev_list_usage[] = " --abbrev-commit\n" " --left-right\n" " --count\n" +" -z\n" " special purpose:\n" " --bisect\n" " --bisect-vars\n" @@ -97,10 +98,23 @@ static int arg_show_object_names = 1; #define DEFAULT_OIDSET_SIZE (16*1024) +static int nul_delim; static int show_disk_usage; static off_t total_disk_usage; static int human_readable; +static void print_object_term(int nul_delim) +{ + char line_sep = '\n'; + + if (nul_delim) + line_sep = '\0'; + + putchar(line_sep); + if (nul_delim) + putchar(line_sep); +} + static off_t get_object_disk_usage(struct object *obj) { off_t size; @@ -264,7 +278,7 @@ static void show_commit(struct commit *commit, void *data) if (revs->commit_format == CMIT_FMT_ONELINE) putchar(' '); else if (revs->include_header) - putchar('\n'); + print_object_term(nul_delim); if (revs->verbose_header) { struct strbuf buf = STRBUF_INIT; @@ -361,12 +375,17 @@ static void show_object(struct object *obj, const char *name, void *cb_data) printf("%s", oid_to_hex(&obj->oid)); if (arg_show_object_names) { - putchar(' '); - for (const char *p = name; *p && *p != '\n'; p++) - putchar(*p); + if (nul_delim && *name) { + putchar('\0'); + printf("%s", name); + } else if (!nul_delim) { + putchar(' '); + for (const char *p = name; *p && *p != '\n'; p++) + putchar(*p); + } } - putchar('\n'); + print_object_term(nul_delim); } static void show_edge(struct commit *commit) @@ -642,6 +661,8 @@ int cmd_rev_list(int argc, revs.exclude_promisor_objects = 1; } else if (skip_prefix(arg, "--missing=", &arg)) { parse_missing_action_value(arg); + } else if (!strcmp(arg, "-z")) { + nul_delim = 1; } } @@ -757,6 +778,14 @@ int cmd_rev_list(int argc, usage(rev_list_usage); } + + if (nul_delim) { + if (revs.graph || revs.verbose_header || show_disk_usage || + info.show_timestamp || info.header_prefix || bisect_list || + use_bitmap_index || revs.edge_hint || arg_missing_action) + die(_("-z option used with unsupported option")); + } + if (revs.commit_format != CMIT_FMT_USERFORMAT) revs.include_header = 1; if (revs.commit_format != CMIT_FMT_UNSPECIFIED) { diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh index 6289a2e8b0..25c2f2f238 100755 --- a/t/t6000-rev-list-misc.sh +++ b/t/t6000-rev-list-misc.sh @@ -182,4 +182,38 @@ test_expect_success 'rev-list --unpacked' ' test_cmp expect actual ' +test_expect_success 'rev-list -z' ' + test_when_finished rm -rf repo && + + git init repo && + test_commit -C repo 1 && + test_commit -C repo 2 && + + oid1=$(git -C repo rev-parse HEAD) && + oid2=$(git -C repo rev-parse HEAD~) && + + printf "%s\0\0%s\0\0" "$oid1" "$oid2" >expect && + git -C repo rev-list -z HEAD >actual && + + test_cmp expect actual +' + +test_expect_success 'rev-list -z --objects' ' + test_when_finished rm -rf repo && + + git init repo && + test_commit -C repo 1 && + test_commit -C repo 2 && + + oid1=$(git -C repo rev-parse HEAD:1.t) && + oid2=$(git -C repo rev-parse HEAD:2.t) && + path1=1.t && + path2=2.t && + + printf "%s\0%s\0\0%s\0%s\0\0" "$oid1" "$path1" "$oid2" "$path2" >expect && + git -C repo rev-list -z --objects HEAD:1.t HEAD:2.t >actual && + + test_cmp expect actual +' + test_done From patchwork Mon Mar 10 19:28:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14010571 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (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 BFB8D236449 for ; Mon, 10 Mar 2025 19:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635139; cv=none; b=H9jC0d9vMkMRwuQW9DHGK/z23roMvggNHJz4VzbnzXypv+kdENcXyOSrIetYUWtu8g+x+pibQKGWJKdANLAR1xfi+rBgmA5mOAFQDvElcZMKPkTm5RxCFCYAucmAjARl4RaqGYFd30wzuEGiL9URn8RCTecOukn+XsOSqo95x5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741635139; c=relaxed/simple; bh=4Tndw1GYlY8PiPzX1zL//L6P7E3PCl6u8LKT4wjlyuI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bvcsw1rCvZxgFbKP0aEQ685LSqWLvZy9khxn9OZ9HVdjRc+miM708iXTH97DfJxpaz26scRndzMuexJcX05Bfye9ufvSlvtzrBUWRF6XOkJgB/kfh7nROGtVh38rFRQX5ARJKS3MzLdA62sxaPsFpd58injgHfj+nX78b+eKo3E= 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=gxcDzRl5; arc=none smtp.client-ip=209.85.167.182 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="gxcDzRl5" Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3fa0eb29cebso235304b6e.0 for ; Mon, 10 Mar 2025 12:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741635136; x=1742239936; 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=XZ81+t9Lx38WfPyXWYaI6JgA8qqe8G7JF74fWb4C/V4=; b=gxcDzRl59c5EsGjRsLXtrykiqQxrf6BDgNYCLpiqB2dwLTXbY/2VEnRQSD1zmhcdBj lYW3SsB0nPZomm1HGyAG2b0Ho48cln/esbkN2gnT5QapIkIg3zUHzlte3zs7LH/jU6Jp T+Qn6S3dHhjiXcOu5sf0Rz+4O/T3hoL6YcCtu1wFgq5/HppFjep/q6gPP0oE6DHhXv9J 9HSziX7DHk1My2J47tkSZgHi0rq3CShkb4tltvkViJ+l9ABr6qSMFjJc4KDn3ma0p2MN bC7B4+BLGEYuyJW4UkSFpqXhUyQu7JDpD0/aECMplPsrzfGHzBQj/011d7yz4o309V0g 8bnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741635136; x=1742239936; 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=XZ81+t9Lx38WfPyXWYaI6JgA8qqe8G7JF74fWb4C/V4=; b=oXoXmZSrDZ2xUiEV7hmWcva8vDXu5z8hI19Wp9S9VLV6nsb7Gc4x6jPNbk1CyF395I mjcQAcdPQf/DUSW5WJ/Oj2BdwvNJvG5WqkU+QQk8IgJukwZoqTI8lXZOFVTPCSAlpxTO ZdZMRr+9mCqPiYJpdeEKNdkeXlHHg1iDUzuriq8dz/uabTKsbRaQPxRWtI7PcM4UemFq C5LLQl/kSN2ZLz7JhzzqQ70Q2aLmcReg8EzOst9zj1q6nBAo/cMbEXGOA4Om63LLxbgJ q+v1Jc3LByf242w3vaaD8mnYvvmyPfPuaEGeujtH2WGyH5MSUOzeu73/ZNib94AHV+PT upOQ== X-Gm-Message-State: AOJu0YznTBpKVHUm0Rj+s2yE1Tddyf1WDxq1pgzLAzKI5PN0Aep5/y6/ Uc1+dLcWIwiFqFy+cLA55RmlCjlZgEBoOX1jRE8c4r2Pn6e4Ha8/7J6eAQ== X-Gm-Gg: ASbGncv3h9Ro9FdTcnb9yRY7mFOIMREMirMrlwP7Y9xNdELxzEcF6MgWRTR/4+txCbc Ct3gGP5IvcU7ntQWlZRRfHLyAPmlvynuBeywEkT46Nxur33IPlIdNyhrt+3rrBT16zF1XpvKVlc 8LgQN86Bgbn9cm5uaKBxNLXifx6DD50Qw9vqSoPPXk/qEa0sJf9FPRzkt9FnesR+lPxh+XDmv8l RI5KgWNIxtNddU/FL6pov0iZ4q4FedLGs3W/LYAlwxyaBex7kyq0oUHgshTuVltLyB34O8OkywR V+OcAgVwN0KmQBE4CEdCsAmU4Gs518peSzdLhOkluzfK2Nx5aQec X-Google-Smtp-Source: AGHT+IF8gGA9+gPkkT16OjrPEYjIjWVrfYFubeUP0GfOylzLF9P+bYE06IhD92rolWuJt9nPDhg3ZA== X-Received: by 2002:a05:6808:3a09:b0:3f9:aeb6:6e92 with SMTP id 5614622812f47-3fa2badc1a7mr429047b6e.9.1741635136525; Mon, 10 Mar 2025 12:32:16 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3f861f30de5sm697819b6e.46.2025.03.10.12.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 12:32:15 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, Justin Tobler Subject: [PATCH 4/4] rev-list: support NUL-delimited --missing option Date: Mon, 10 Mar 2025 14:28:29 -0500 Message-ID: <20250310192829.661692-5-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250310192829.661692-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `--missing={print,print-info}` option for git-rev-list(1) prints missing objects found while performing the revision walk. Add support for printing missing objects in a NUL-delimited format when the `-z` option is enabled. $ git rev-list -z --missing=print-info NUL NUL ? [NUL =]... NUL NUL In this mode, values containing special characters or spaces are printed as-is without being escaped or quoted. Signed-off-by: Justin Tobler --- Documentation/rev-list-options.adoc | 10 +++++++++- builtin/rev-list.c | 27 +++++++++++++++++++------- t/t6022-rev-list-missing.sh | 30 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc index d21016d657..48648b7507 100644 --- a/Documentation/rev-list-options.adoc +++ b/Documentation/rev-list-options.adoc @@ -378,7 +378,15 @@ containing newline characters: [NUL ] NUL NUL ----------------------------------------------------------------------- + -This option is only compatible with `--objects`. +When the `--missing` option is provided, missing objects are printed in the +following form where value is printed as-is without any token specific +encoding: ++ +----------------------------------------------------------------------- +? [NUL =]... NUL NUL +----------------------------------------------------------------------- ++ +This option is only compatible with `--objects` and `--missing`. endif::git-rev-list[] History Simplification diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 86b3ce5806..5bbc4a787e 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -145,25 +145,38 @@ static void print_missing_object(struct missing_objects_map_entry *entry, int print_missing_info) { struct strbuf sb = STRBUF_INIT; + char info_sep = ' '; + + if (nul_delim) + info_sep = '\0'; + + printf("?%s", oid_to_hex(&entry->entry.oid)); if (!print_missing_info) { - printf("?%s\n", oid_to_hex(&entry->entry.oid)); + print_object_term(nul_delim); return; } if (entry->path && *entry->path) { struct strbuf path = STRBUF_INIT; - strbuf_addstr(&sb, " path="); - quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP); - strbuf_addbuf(&sb, &path); + strbuf_addf(&sb, "%cpath=", info_sep); + + if (nul_delim) { + strbuf_addstr(&sb, entry->path); + } else { + quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP); + strbuf_addbuf(&sb, &path); + } strbuf_release(&path); } if (entry->type) - strbuf_addf(&sb, " type=%s", type_name(entry->type)); + strbuf_addf(&sb, "%ctype=%s", info_sep, type_name(entry->type)); + + fwrite(sb.buf, sizeof(char), sb.len, stdout); + print_object_term(nul_delim); - printf("?%s%s\n", oid_to_hex(&entry->entry.oid), sb.buf); strbuf_release(&sb); } @@ -782,7 +795,7 @@ int cmd_rev_list(int argc, if (nul_delim) { if (revs.graph || revs.verbose_header || show_disk_usage || info.show_timestamp || info.header_prefix || bisect_list || - use_bitmap_index || revs.edge_hint || arg_missing_action) + use_bitmap_index || revs.edge_hint) die(_("-z option used with unsupported option")); } diff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh index 3e2790d4c8..3ae25e4cfb 100755 --- a/t/t6022-rev-list-missing.sh +++ b/t/t6022-rev-list-missing.sh @@ -198,4 +198,34 @@ do ' done +test_expect_success "-z nul-delimited --missing" ' + test_when_finished rm -rf repo && + + git init repo && + ( + cd repo && + git commit --allow-empty -m first && + + path="foo bar" && + echo foobar >"$path" && + git add -A && + git commit -m second && + + oid=$(git rev-parse "HEAD:$path") && + type="$(git cat-file -t $oid)" && + + obj_path=".git/objects/$(test_oid_to_path $oid)" && + + git rev-list -z --objects --no-object-names \ + HEAD ^"$oid" >expect && + printf "?%s\0path=%s\0type=%s\0\0" "$oid" "$path" "$type" >>expect && + + mv "$obj_path" "$obj_path.hidden" && + git rev-list -z --objects --no-object-names \ + --missing=print-info HEAD >actual && + + test_cmp expect actual + ) +' + test_done