From patchwork Thu Mar 13 00:17:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14014088 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.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 25E836AAD for ; Thu, 13 Mar 2025 00:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825276; cv=none; b=bkzNcnfONcTyiMl6OTmLRql3nlrXwCnIRUzz93CE8ha0YRR6JBlyIhll6trEWoCjzblAQpuVIyY2OpekBHpfQbrw92AapCJmOKXpN4wHtKugWTkpQnSux1onlaMHPyl8tPnCym/2XF0TZd0ViD8GkEhqaSXP/KFzTkkvHCj0SYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825276; c=relaxed/simple; bh=9Oixtf8VtLt11mtugwndN5WDyIGQO6bIWKsWs5kuz2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gI0LuYUsdu5aYuX/GfNR48ielCnATWBUrwL1JzLPkkvPnlQvuyACoHGeecU2Ou6lvhgUdOomNecaJCE6/ZTKA9K190Axa868bOxWujQTGe3ZIA7NN1e+2FPtVPGDmU72ULfZdSKkDs5ZNuqK6Qcb33tKDsqgM2zfWt05OCO0SpE= 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=Zm52nfOu; arc=none smtp.client-ip=209.85.210.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="Zm52nfOu" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-72b7a53ceb6so347302a34.0 for ; Wed, 12 Mar 2025 17:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741825274; x=1742430074; 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=Zm52nfOuDJYHgCCrDLthLL4Gcw7/fyuuvU9p3fSbW0USEIGbzF455I/0KQguawtXuh 3bzTSJlm0+ZFz5/EVDkZSd2rpKfxXifckNLsawRK25c1GK8OX6eL7LPbH8w40eNXG1Jd FE1UEG3mBToZBQOJ//S1ZfhwoTFHhipEC2CHQ7KfB/8fY2MjpJl61iK3x7FY0h3WEmRV 1GV9HFSqO2BPvJKzz99qqS4H2CkLXXBHtJ1oCIUsPGoQ9qffbHxPhKVVzhJ6C/iiZpEs QudkbOGHVVxzRqTO5gEvsmYlVot/rbvoF3Kgcoo4+lNLktVc+BU/Gxa1F/Ioe0vwI6WC 2SKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741825274; x=1742430074; 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=PMSV45huiJ4BqXBBJsiq1vxUgv7I8DThi4TNRic8SFot0xZgOqHddqLNboJoQagw/R joLvNh3gGmfgJpMr8LxhR4qKyvbD/0RT0Fsf+N3e6puYmWxYYGeBLdvpNLTIHJFop8yN o47LybrWbgwwHEqx+5J5flGKCB4CLW4D2+er5ATRqmjHsuFbRarLj/LY0YBlT+Na/ZJz ElUIuOzx5yuScjvbxFwS1RNlgVwr76V1axnitYrCR/gUlhIS9gsZKmQfTUzjp2q7Gx+C 41Qk6oJey+C99OUHKH7//cUh7gJYR1Qm07ceJIJBOKaKfYEyYE0CbJHf9isjbcN/3bHO nW7Q== X-Gm-Message-State: AOJu0YzK2CCBC0oHnnMPj5gkCfwy0p6H47TSEWBBc6FMXhU8QiSrNmKE 70CYCPam6p9R5uatihrI24jAy2wEva71tIQQxVu1eM7FOPioRM9wYFvWtxK+ X-Gm-Gg: ASbGncstf9qJdV/dgndFeG46IgZyk9fgoVmBJG0dSZkjfyosVZDsWagGmy4dZMJBhFU c53nEyAS2LM3a/o6H0/satk/Jx7/kmJEdvXF/WHJCESQe25CBO1QxbfDfpQUToSSiO2K465aDis CNAFiIc9n7f7nXC/ooK8/CvvnbtjKHkB+TbuO83BoWEtny+5wLij1rTzstaz4pITRz87zhQ/eri H3zCaEdGEYaAUcjHnOMFQe6rXDi+scEYfUfpugWfyOwE7N1MZgL+m+l2trbXGxGjQU9csOsh6Rl 2/JSB55QB35oF0/An2ppRo5nzKA0In5LFRIhjOl5rNaS5Oab8d4q X-Google-Smtp-Source: AGHT+IGFC5BZtvftr513PR6QoED2qTyMWXyJtQdimhKuQqJQ1IzgcaAbV2ppIb798jVOT57kxELGQQ== X-Received: by 2002:a05:6830:1614:b0:72a:48d1:7fca with SMTP id 46e09a7af769-72bb18ce1a2mr294314a34.4.1741825273805; Wed, 12 Mar 2025 17:21:13 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-72bb267a8b4sm24028a34.9.2025.03.12.17.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 17:21:13 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, peff@peff.net, ben.knoble@gmail.com, Justin Tobler Subject: [PATCH v2 1/6] rev-list: inline `show_object_with_name()` in `show_object()` Date: Wed, 12 Mar 2025 19:17:01 -0500 Message-ID: <20250313001706.3390502-2-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250313001706.3390502-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> <20250313001706.3390502-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 Thu Mar 13 00:17:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14014089 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54AC42E338A for ; Thu, 13 Mar 2025 00:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825277; cv=none; b=MFcLJbdg8SwzMaq7iQL7ejZkSqL2jm+sIk6M0n6o6+IgWgiAV8NGq/b0vcgyfu5Cl3OUrDBBdDRSMN2s6NSijV6UpHCiPeGZs3kb8Ghy2bvAKzJZuh+o/BhpQINcMKssPUF3ZaWJ8URjEE/pcHEpWxDwik6EOzp8hYCxNR9jENI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825277; c=relaxed/simple; bh=opPvqbuSojM7C18Au7j9w0k+hzvHe5F6EHrCLfwU8KE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Byue+duVuuJbKgarIXOxJ11guKVvB0bEBUIIf/7c6aVsbWAjwpocOsCABbAa37WlqQzupQZOQmb1/25EWZKlK98nQd6uI9bTcjl7BQOXD9R2QTf+ndZm1aBnka20x/tKCYSQaIXbt3zxDDs1rgxh5wqYNUUcIxNHHRGFIqbmceE= 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=UlXhfnyf; arc=none smtp.client-ip=209.85.161.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UlXhfnyf" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5fe8759153dso154287eaf.1 for ; Wed, 12 Mar 2025 17:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741825275; x=1742430075; 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=UlXhfnyfgf8eBsOLpZkwDgHM2haogXzCqb5jv1XFOhAlM9mpGxvb1PnGF1qMXbxoYD 3pcGzHT6u63wZcLaidtN3ZkBvkp4K2ZRm1jdj97Q/88tkTElevHfAPkIfR9JnKIGtC3p 5QLGK2EB9eL8BtfbMFAXbNwAK9FIbNb5EvIgfMpMZ8MbKLbL2RVK5UhAjqSv4ETZ0xEW +x2I9LkydHEh1sjfvrRvZ9sR+Zz494QsR2L6R0oNXb8ZlpkzIdHG9GqA4YvsVOGgm8v8 YZJ4TOwjbyIAjfkeFtKD+INKsDwPExWoaWXSfMW+a2FwF6zb68W32/EMWxFgQesa569E P8zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741825275; x=1742430075; 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=t14JtOpWUKZnu5uaWVKJblzPuES74+Jc4fVij90cLQZVb2Xc/hbKC9cb0e9ems7RGN pm3yr4wW0UEp7kPdqPXGU+ipNDOZ8O2Rke2uLrz9c0P6lMBHWrM6Uvt5IkYNUY8zG17g n5BTlRXr3B/8Za7JFWuRfOOhZchTVdWwwSCfOcFtc2V4u/jhmSU6YluQmau2BbQ0p1WO At/Ky5T4nvQrWXYiCrlhfpkW+HVzKjsFXFSL6LN6K43gyy40lETdJYTwAA18MrOeCclP BCCI7Zn1y7d3jZSdUju7O+Vv4Vt6BP9Hk1gAJELbaMXB+Her2uyc23aj+2dF72HRUcLH 228A== X-Gm-Message-State: AOJu0YzqsPZrwLblaAeVVW+WClb4QbmBtMKekq2beiMPslEcRBLFPou5 0b6KhVECCcrLXUz4Jsbwg9N7FvgPDASfUIp3j3wWYJeeT1Tyw1PpYMKd6an3 X-Gm-Gg: ASbGnctRavSWGgguJE46h59JglBZF8hkReE8qG+KwjfGrSxd6zGjOXyOUsY/jiv4fuL XsUtmG0Ng5PEGa6VLMibXwO4MxC6ho1QAShG0VlVvWOTpwmWKwyp4dw3kkOI6YNcb8zAATy2GEg eFASkmxc03E3Xpvd9cNsViRddFUkGASYvOiuPTFbomSPG6Jp2JsqvoFZUcdQP6p704vf+2N5lTp ceYwTqk4R41xH94JeHQuF8ELfCYnH8kz1Huur3nByyKvIsBI4YFdj3wM1vgqzIXD/q4fmhUuvx2 UdphM22N4Zun8qUMQ/zx47TEjAnBL4QzX0PRSy+XSXJLP6psJBbV X-Google-Smtp-Source: AGHT+IFpWLw2uJSIs6l5Ta2td7TB5ZK4ADvT3FaAIWR8SC3OsajkrpSJX7qr2P71dRMi4o4f5Zr9lg== X-Received: by 2002:a05:6870:d285:b0:2c1:b58c:c0c with SMTP id 586e51a60fabf-2c26138a516mr13298320fac.34.1741825274901; Wed, 12 Mar 2025 17:21:14 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-72bb267a8b4sm24028a34.9.2025.03.12.17.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 17:21:14 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, peff@peff.net, ben.knoble@gmail.com, Justin Tobler Subject: [PATCH v2 2/6] rev-list: refactor early option parsing Date: Wed, 12 Mar 2025 19:17:02 -0500 Message-ID: <20250313001706.3390502-3-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250313001706.3390502-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> <20250313001706.3390502-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 Thu Mar 13 00:17:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14014090 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 2739A8C1E for ; Thu, 13 Mar 2025 00:21: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=1741825278; cv=none; b=RZSHdwrzNlfuZDiqMXN/X83/hOS25VUeinaAmj/3Lqu5zdrNqre9CER23i5qyKaOPTA9kBzOuheTbFVgTSOaXu4Qs3Pvzd5sUIMqV7vfkldYJcPj9WrOHzIUsN0MmI0VcqKfPtVTVHtbmK1qber0VjboH6MqrklokgC0fCQOREI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825278; c=relaxed/simple; bh=XW5L3G90FzM5AEckAAFfWU3a2fE6OjPX2Pq2jhr5/c8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qkSZ4wzS05rJyd8l0vzORflLUAmotasquLMDGcDq4C5cm0lWY5p2BC2BLdG4IFqSSfF2ogRSTotREp2XbWiUOtLOU+oM+2Y8nGLHsIaC2ylst5SMdnXhntpUrAcGdKzDRfXggrg4cydqW4tY2qGzM7sTAI9FaG6+pWlHm+TU7D4= 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=lKSN7eOI; 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="lKSN7eOI" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-728a433ec30so462426a34.1 for ; Wed, 12 Mar 2025 17:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741825276; x=1742430076; 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=doN1OqOqzF/i94F7+VO7WMeXNO5T3b3R+IP2A8tbVIw=; b=lKSN7eOIJo1rhFhULNcBBtVRLROGIElrJudKhSmuenkb8e6rEQV42TdcbZ6HzTuher dozJIyZXl6LYcxZZghoxXzwi7z10bi+G8s8IgeTpOXUjrrfTqDzkc9SYIwwF9lYyRnak vfpUTidZVHQ7Oap0/YDbsiQJVcdhV5hqi9UWGF8VjQ++Swau8sdI03EPoEHlCHoX3zm4 G2zmDpx62vvbual7DrYp8vYhYMQFS4uPxX+2JtyfEzQUkM01ZcZLULdUSRiuD5Uaoa9w RvxgDzVngJmz/W9oUPGlYdxHLgkxvXg20WoBzyA9vqJIOEIxtyskyUrbOmh3vcwAYLP6 YeQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741825276; x=1742430076; 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=doN1OqOqzF/i94F7+VO7WMeXNO5T3b3R+IP2A8tbVIw=; b=OqhqIHtARdYfWHG5Qy23QHFJz7IB0TDEqpoQosG0NuyNyiegy50E6cZwfdD4b6DySp MQlgllUzTX960a8kwUKu+Dw/qW2R5Zig1X++PvOt7nFK+mdbzd/HT8zfxmaw1ve9iiiT kMb/BYwcZdM7EvpoZTncW8XrhzIgxFZK6qrdsfIbsE7RHtjgkZ4XCaYFQEYa7XAmkG1D mbyYTPsCWAhsRJBkhuY7sTOUm+SRgVxva9ImT/dUmPUD9p9BeudpC5flWrSVDYHx6UrZ YMQje9ovIW4EoAnEGFI+b8BjeE4nfbLOgquuTU7jE6dni3sxG5quA6ofLJFi84j/lhM4 7/pA== X-Gm-Message-State: AOJu0YzrSxmvJvICEyBv6swilcq1EwsQ5R5OlhBe3S2krgNvdlMC08vN CuChTLhcS6OZ5ah41p5TEyvlC4BZe7CIx+2b7Oljv250RCnTk4sB1ivf5c1O X-Gm-Gg: ASbGncvXGfd6it1IcqsmlZHx2zF6NyVPPiImljxp8z/n2MYBDsW47FJViA1KjfJLQ4/ PONPAJy69Mhmlz3s35UEaDujCZyB4aHy0j376LXKuhol5RYX321SUP+1gBIth0hZyDF7iVX1y4c f70L09sXpKXc77mqke/Y7aVuadJfpQIe7NJKYgGr7caT9HbxQ55u9+/ebox29LJAj20XMxq+DgD cXxPWbh55qgG4mMFeoa+QWv/pr9ZkFr3Wb5o+h3IGr4CVrwFcTAB3wiCqoMgRRJuyjN64Uw6pEt dAlKcb3+V6AlYLtp267VCDuDqQ5UINYqCQZ0LA3MjTjRof433IVN X-Google-Smtp-Source: AGHT+IFb2bOvWwGFSE3lN6pr/Z2aXqOdTK6mm8LtX/NdlEOiT8kBiy7tyde/EJP49ehdOgYFYGvK9g== X-Received: by 2002:a05:6830:718b:b0:72a:1821:aa9c with SMTP id 46e09a7af769-72a37b6ffaamr15040540a34.8.1741825275920; Wed, 12 Mar 2025 17:21:15 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-72bb267a8b4sm24028a34.9.2025.03.12.17.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 17:21:15 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, peff@peff.net, ben.knoble@gmail.com, Justin Tobler Subject: [PATCH v2 3/6] revision: support NUL-delimited --stdin mode Date: Wed, 12 Mar 2025 19:17:03 -0500 Message-ID: <20250313001706.3390502-4-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250313001706.3390502-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> <20250313001706.3390502-1-jltobler@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When `setup_revisions()` parses the `--stdin` option, revision and pathspec arguments are read from stdin. Each line of input is handled as a separate argument. Introduce the `nul_delim_stdin` field to `setup_revision_opt` that, when enabled, uses a NUL byte to delimit between stdin arguments instead of newline. Signed-off-by: Justin Tobler --- revision.c | 19 +++++++++++-------- revision.h | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/revision.c b/revision.c index 0eaebe4478..5de6309830 100644 --- a/revision.c +++ b/revision.c @@ -2275,10 +2275,10 @@ int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsig return ret; } -static void read_pathspec_from_stdin(struct strbuf *sb, - struct strvec *prune) +static void read_pathspec_from_stdin(struct strbuf *sb, struct strvec *prune, + int line_term) { - while (strbuf_getline(sb, stdin) != EOF) + while (strbuf_getdelim_strip_crlf(sb, stdin, line_term) != EOF) strvec_push(prune, sb->buf); } @@ -2905,8 +2905,8 @@ static int handle_revision_pseudo_opt(struct rev_info *revs, return 1; } -static void read_revisions_from_stdin(struct rev_info *revs, - struct strvec *prune) +static void read_revisions_from_stdin(struct rev_info *revs, struct strvec *prune, + int line_term) { struct strbuf sb; int seen_dashdash = 0; @@ -2918,7 +2918,7 @@ static void read_revisions_from_stdin(struct rev_info *revs, warn_on_object_refname_ambiguity = 0; strbuf_init(&sb, 1000); - while (strbuf_getline(&sb, stdin) != EOF) { + while (strbuf_getdelim_strip_crlf(&sb, stdin, line_term) != EOF) { if (!sb.len) break; @@ -2946,7 +2946,7 @@ static void read_revisions_from_stdin(struct rev_info *revs, die("bad revision '%s'", sb.buf); } if (seen_dashdash) - read_pathspec_from_stdin(&sb, prune); + read_pathspec_from_stdin(&sb, prune, line_term); strbuf_release(&sb); warn_on_object_refname_ambiguity = save_warning; @@ -3019,13 +3019,16 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s } if (!strcmp(arg, "--stdin")) { + int term = opt && opt->nul_delim_stdin ? '\0' : '\n'; + if (revs->disable_stdin) { argv[left++] = arg; continue; } if (revs->read_from_stdin++) die("--stdin given twice?"); - read_revisions_from_stdin(revs, &prune_data); + read_revisions_from_stdin(revs, &prune_data, + term); continue; } diff --git a/revision.h b/revision.h index 21c6a69899..0e680c3667 100644 --- a/revision.h +++ b/revision.h @@ -439,7 +439,8 @@ struct setup_revision_opt { void (*tweak)(struct rev_info *); unsigned int assume_dashdash:1, allow_exclude_promisor_objects:1, - free_removed_argv_elements:1; + free_removed_argv_elements:1, + nul_delim_stdin:1; unsigned revarg_opt; }; int setup_revisions(int argc, const char **argv, struct rev_info *revs, From patchwork Thu Mar 13 00:17:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14014091 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 6170CFC0B for ; Thu, 13 Mar 2025 00:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825280; cv=none; b=NYSOAXDXBDWVuUhssaNVuY+KceqG3GuHRhj+ytePOmsQxiU5ySxISVup03BLWCqdpm7pDGKGKDqXQ4PGsoQaAjtyb6frXL5UAt08hx7qvyoubGJf87NOdpB7hl+HJxr0ObdPLA60FYjZ3nCySwyJoqKp8amSYlfqs4txG20oq+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825280; c=relaxed/simple; bh=pnUrcVzfhDwmwHhW7nXOCQMnp1DWq9nvmw8OyM14Z6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B4JE2ZKVUVD/GNdYtGlutkXDkJNPVoov7KZzmjeKRPyQuRCrwq+JzAenT5u+S3C8dKr3WhNatRrrwjhcUlSuODv/nYTyoET3qv+IHwNFS3ql/Hwu0EbEM+5dcEMvIKMcgTaZEywqdDFkeO6jyiRqHKaKD1AO8qOvdV7TcLOaGZQ= 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=RA73Zmbk; arc=none smtp.client-ip=209.85.210.44 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="RA73Zmbk" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-72a0a9cb29fso253863a34.0 for ; Wed, 12 Mar 2025 17:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741825277; x=1742430077; 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=XG/RDhQ++6Lu7GLLG+X9qvWRXgk7wQ2sLknwdcmVfH4=; b=RA73ZmbkYrou7B3wj90kKeAJ/pkG1h2Fvfc+kBAGn4O/EHhVUT95AJ+dgKj1AJLh3I spOwNnls62XxKZuW7Ci33dsmDgVHRMAf3BBDcJYqnHub3DicUcxDB1leN7lFUWxxgLaz El9St7zwz5BSYQOWVpjXol5cDnHoJX6zh+wvXZp7CMgdeWsog4jQ1RhthsRrhePU+SNo 6JAZEpoN0QO7Oia3MP48C+l3BFtb4pauWSu/1EUIGA2ryp/+4VtIw/8v0h3PdLS3rqgU 20tD9Y6gdeC8hmnXbWhUM0N/V4U6avtjud1WpLgQPERAyK+ajgkuh4pVgHSHDv8Or+XR ZEmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741825277; x=1742430077; 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=XG/RDhQ++6Lu7GLLG+X9qvWRXgk7wQ2sLknwdcmVfH4=; b=gJnivHumpmt+5p/3u34ZZgA18ejz5BGrxNJ/ZedsMgZjnDYOsTihGACsb60sp89pRq zNyKxNJBtxUkGGpQL7INDYcB68JgK8aHX4AJEGdOsCElG5h1kT0tIqvULqd3TVFUMua7 BNthdISqMuKXxgngg6Z5fGUPj5qzIvC4rPuIWbrKEfTZPVc1eLHuC1dpcvi4fVmIF1I/ Vvfbe7Dcayf1Q6EEkV82o/tYKcq38dHep6Yzrp8oZ+LLBAAELadH5PWkAlx6Q9FEH5UY bUD2yyy4IVzTg5h3+KW7KE8GgbptbttRcWes+S3VTc1/Q5hylH4RjZ1hg/KmLwo1lFTB Mt9g== X-Gm-Message-State: AOJu0YwhYC91qy146+W9rHMY7aotiM1WLWjblzs19k3xqoM0tJnMR8c5 buHjFcoeq8580PB1ZSQRzWPQkZSSj2KCtDmfHmFoe7DQ3jdyMCqIWsfHvGLD X-Gm-Gg: ASbGncsdrVTyphy1m2TOJi+mnwiU2Wj6cyrcHLz0ivoaMjpfNo9SJATL7YmhJOl9IS8 OwtTsorXODNtmJLpW0tB4u1jXVtetjPnt960VWtIjnaQq6D7nV8uJCFPqZXLaq2xsnEDz6wbXaN CmSdAepHISSyrxHWt4dTUOspsCOKeuBhzhai0RwJLFh3ln04OtCy5TRb98g2uB3LA5Jt3HfgH6y cJzLUwG75YAP5RZbRgr8pQZNKUza5lHZTYzoP4tFqSOAald/aRfwOXT+hCMaePMnAhWckWjdcOF mj4vCQ0qBJBY+yhnIzMtl6yFhKUTlB7NDOADS12ayKuE+RXjdZDdrGcO9PETpKw= X-Google-Smtp-Source: AGHT+IFxyRTSFp2ezk7O+1aopi2Uq7tGRVE+aXH/kJDKXOgh0fnjwRIyeKSXKIu25iWRmaB403y0wA== X-Received: by 2002:a05:6830:6c8e:b0:72a:449e:2b6e with SMTP id 46e09a7af769-72a449e302emr8746164a34.5.1741825277089; Wed, 12 Mar 2025 17:21:17 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-72bb267a8b4sm24028a34.9.2025.03.12.17.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 17:21:16 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, peff@peff.net, ben.knoble@gmail.com, Justin Tobler Subject: [PATCH v2 4/6] rev-list: support delimiting objects with NUL bytes Date: Wed, 12 Mar 2025 19:17:04 -0500 Message-ID: <20250313001706.3390502-5-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250313001706.3390502-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> <20250313001706.3390502-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 in the following form: $ git rev-list -z --objects NUL [path= NUL] In this form, the start of each record is signaled by an OID entry that is all hexidecimal and does not contain any '='. Additional path info from `--objects` is appended to the record as a token/value pair `path=` as-is without any truncation. In this mode, revision and pathspec arguments provided on stdin with the `--stdin` option are also separated by a NUL byte instead of being newline delimited. For now, the `--objects` and `--stdin` flag are the only options that can be used in combination with `-z`. In a subsequent commit, NUL-delimited 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 | 23 ++++++++++++++++++ builtin/rev-list.c | 36 +++++++++++++++++++++++++---- t/t6000-rev-list-misc.sh | 35 ++++++++++++++++++++++++++++ t/t6017-rev-list-stdin.sh | 9 ++++++++ 4 files changed, 98 insertions(+), 5 deletions(-) diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc index 785c0786e0..166d3cd19e 100644 --- a/Documentation/rev-list-options.adoc +++ b/Documentation/rev-list-options.adoc @@ -361,6 +361,29 @@ 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 and its + accompanying metadata is delimited using NUL bytes in the following + form: ++ +----------------------------------------------------------------------- + NUL [= NUL]... +----------------------------------------------------------------------- ++ +Additional object metadata, such as object paths, is printed using the +`=` form. Token values are printed as-is without any +encoding/truncation. An OID entry never contains a '=' character and thus +is used to signal the start of a new object record. Examples: ++ +----------------------------------------------------------------------- + NUL + NUL path= NUL +----------------------------------------------------------------------- ++ +This mode is only compatible with the `--objects` output option. Also, revision +and pathspec argument parsing on stdin with the `--stdin` option is NUL byte +delimited instead of using newlines while in this mode. endif::git-rev-list[] History Simplification diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 04d9c893b5..f048500679 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,6 +98,9 @@ static int arg_show_object_names = 1; #define DEFAULT_OIDSET_SIZE (16*1024) +static char line_term = '\n'; +static char info_term = ' '; + static int show_disk_usage; static off_t total_disk_usage; static int human_readable; @@ -264,7 +268,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'); + putchar(line_term); if (revs->verbose_header) { struct strbuf buf = STRBUF_INIT; @@ -361,12 +365,16 @@ 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 (line_term) { + putchar(info_term); + for (const char *p = name; *p && *p != '\n'; p++) + putchar(*p); + } else if (*name) { + printf("%cpath=%s", info_term, name); + } } - putchar('\n'); + putchar(line_term); } static void show_edge(struct commit *commit) @@ -642,6 +650,10 @@ 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")) { + s_r_opt.nul_delim_stdin = 1; + line_term = '\0'; + info_term = '\0'; } } @@ -757,6 +769,20 @@ int cmd_rev_list(int argc, usage(rev_list_usage); } + + /* + * Reject options currently incompatible with -z. For some options, this + * is not an inherent limitation and support may be implemented in the + * future. + */ + if (!line_term) { + if (revs.graph || revs.verbose_header || show_disk_usage || + info.show_timestamp || info.header_prefix || bisect_list || + use_bitmap_index || revs.edge_hint || revs.left_right || + revs.cherry_mark || arg_missing_action || revs.boundary) + 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..dfbbc0aee6 100755 --- a/t/t6000-rev-list-misc.sh +++ b/t/t6000-rev-list-misc.sh @@ -182,4 +182,39 @@ 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%s\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\0path=%s\0%s\0path=%s\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 diff --git a/t/t6017-rev-list-stdin.sh b/t/t6017-rev-list-stdin.sh index 4821b90e74..362a8b126a 100755 --- a/t/t6017-rev-list-stdin.sh +++ b/t/t6017-rev-list-stdin.sh @@ -148,4 +148,13 @@ test_expect_success '--not via stdin does not influence revisions from command l test_cmp expect actual ' +test_expect_success 'NUL-delimited stdin' ' + printf "%s\0%s\0%s\0" "HEAD" "--" "file-1" > input && + + git rev-list -z --objects HEAD -- file-1 >expect && + git rev-list -z --objects --stdin actual && + + test_cmp expect actual +' + test_done From patchwork Thu Mar 13 00:17:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14014092 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.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 E2112171A1 for ; Thu, 13 Mar 2025 00:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825280; cv=none; b=HOOTMYelneN4DScKPH1yIe7YgDcyBN9/y6vuf4D+sr17tAFRQI0Eakw5FoIlc3x2MhKjOY0FLOf+u+9wq3UbdWj/gIxazYzs4nMb+6rFvAJnvARqgsf5YZd5CpN8O7JfR31meLOgRnqpRWqqOwEdwW6aB22CMdebzhpq2D3GXos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825280; c=relaxed/simple; bh=gYWd2UysEDCejPSk51VO768ILMZAw/Y2DuAOHQdghqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Whh9Xo9oF2ygqqoLrxc7VliiuuhSKxFTRr6L2fUO/pPjPnID4JBmA2DLeZnZ4ez7d+7O43czi2NVzy/2/hPKW9Ed5ptKCLDdFrfKacvCr8EwGARnK83IQ7or24woUmNYXQba9iUNVZETAXZxY7mLOzhcTmBwKNkxr06DVoAc3Js= 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=iwQJWvJG; arc=none smtp.client-ip=209.85.160.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="iwQJWvJG" Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-2bcc5c887efso308867fac.2 for ; Wed, 12 Mar 2025 17:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741825278; x=1742430078; 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=iCocxmumCV6uM+PNn3kbpQHCGZ2ek0wvXPlooZeMPT0=; b=iwQJWvJGJWobXJ1lX4z0bFudl0csVIJ+kkpiIjOphUzjFgns7ZuuszuFeCnWDmhpWh yPhqhYOVx7P9Q+P/DwMOQFn08oDBLsjoq1zenGBLPXZ3LNtTZk3gAGKsh+uSmt1edfUx OvCQID1p2EC4EyfMW4hhgC+QqivQ7GgAfqQS1KwS48LDTuT5fZu7Vm9KO9juQoTk7z5C yO4tjtmn66rGv9QqdKIcFMpQAGX9EuHIzDAMWcurSy+bWFvzsaK7R4NmvHeB91RqEyo7 PFDowEj6LkQgxag7zBO+rcEgNhL/hgOZBxo88gWiXP0FarH14bREFrXUSiANdF/r87FQ 2cxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741825278; x=1742430078; 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=iCocxmumCV6uM+PNn3kbpQHCGZ2ek0wvXPlooZeMPT0=; b=d6Q+nAn9g0FG8Ozfc3SnqkVU4UNOHCzMGo8QmrwMX1+0LpMWkDzrF4Y8C51JoBBfh3 4eRnh/q9lj9xIShPLIlZN6a850GY5IT7ktc/ng1NiWy6umX+lEGyVfotPfv87xIkQbRj cv5bC3zEyzZdWjCCPzf66Ia9ijzD/XD/CLAB1pS6WN7KSZ3ttjsXdRP80OPx3BoD5EWM GefUYjuwMtHfevvYoEyzX1Zbyycz833uXFiGLfyTsn/C9DLyxJtWZ2iZrRIJCB8Qq9BB YL5g9WXZWeJwHdte1cJI+esy1XLnTPTRgHdfypculQCzl9qblSi9ouOmDJT0KlN26pJ7 0DkA== X-Gm-Message-State: AOJu0Yzt7+ui+LPooaBr/FSwZ0hyTQfXeiPd1KRa6wi1TglK0kGD1G+E P99AW+VLflpwlZ/gwjAOEyy6ArkLISUraIuoDFdyZkz52nXwqeNBkjeeySku X-Gm-Gg: ASbGncus9IhapXFgerEZ74CT8S+nxWCwLSKAklEu2olMoqRsGbP5akcXRdv8Fz9uDca TsnkwS6lUw8yHXKAMdhx8sewAHOlb/y38t+LvqffwyRXL3ODkGCd7oLgxIiH2GedOvu2EYl2Z7j rFkTLii4ASwuh9hnIrmrd/Q5MM9LM+2cmk7JychQjjMbTLPQprlDyNqdQzgdAoYqNR6bYgeq6bJ QWCpQvYbr9XAbW5OFtbr00xftwj7pOAj6JCReSBqqaNUEPVJXmlt9St00XGAPhKCKC9gSLe/bY5 qMhi7oNP+HgPLjz5bAWDAEm2WXF7sqiVTyKapC1WJarn1uNFU5GZ X-Google-Smtp-Source: AGHT+IGBmmjeK5gIhzbh1B6lk+z2K2hxxgA7GxXU5hhtyT5oX864cf/gMJ4MF62gJx4UPs4xShdBKg== X-Received: by 2002:a05:6870:aa90:b0:2c1:6949:2ba3 with SMTP id 586e51a60fabf-2c2e89d213bmr5723474fac.33.1741825277703; Wed, 12 Mar 2025 17:21:17 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-72bb267a8b4sm24028a34.9.2025.03.12.17.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 17:21:17 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, peff@peff.net, ben.knoble@gmail.com, Justin Tobler Subject: [PATCH v2 5/6] rev-list: support NUL-delimited --boundary option Date: Wed, 12 Mar 2025 19:17:05 -0500 Message-ID: <20250313001706.3390502-6-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250313001706.3390502-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> <20250313001706.3390502-1-jltobler@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `--boundary` option for git-rev-list(1) prints boundary objects found while performing the object walk in the form: $ git rev-list --boundary - LF Add support for printing boundary objects in a NUL-delimited format when the `-z` option is enabled. $ git rev-list -z --boundary NUL boundary=yes NUL In this mode, instead of prefixing the boundary OID with '-', a separate `boundary=yes` token/value pair is appended. Signed-off-by: Justin Tobler --- Documentation/rev-list-options.adoc | 16 +++++++++------- builtin/rev-list.c | 9 +++++++-- t/t6000-rev-list-misc.sh | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc index 166d3cd19e..d400d76cf2 100644 --- a/Documentation/rev-list-options.adoc +++ b/Documentation/rev-list-options.adoc @@ -371,19 +371,21 @@ ifdef::git-rev-list[] NUL [= NUL]... ----------------------------------------------------------------------- + -Additional object metadata, such as object paths, is printed using the -`=` form. Token values are printed as-is without any -encoding/truncation. An OID entry never contains a '=' character and thus -is used to signal the start of a new object record. Examples: +Additional object metadata, such as object paths or boundary objects, is +printed using the `=` form. Token values are printed as-is +without any encoding/truncation. An OID entry never contains a '=' character +and thus is used to signal the start of a new object record. Examples: + ----------------------------------------------------------------------- NUL NUL path= NUL + NUL boundary=yes NUL ----------------------------------------------------------------------- + -This mode is only compatible with the `--objects` output option. Also, revision -and pathspec argument parsing on stdin with the `--stdin` option is NUL byte -delimited instead of using newlines while in this mode. +This mode is only compatible with the `--objects` and `--boundary` output +options. Also, revision and pathspec argument parsing on stdin with the +`--stdin` option is NUL byte delimited instead of using newlines while in this +mode. endif::git-rev-list[] History Simplification diff --git a/builtin/rev-list.c b/builtin/rev-list.c index f048500679..7c6d4b25b0 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -240,13 +240,18 @@ static void show_commit(struct commit *commit, void *data) fputs(info->header_prefix, stdout); if (revs->include_header) { - if (!revs->graph) + if (!revs->graph && line_term) fputs(get_revision_mark(revs, commit), stdout); if (revs->abbrev_commit && revs->abbrev) fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid, revs->abbrev), stdout); else fputs(oid_to_hex(&commit->object.oid), stdout); + + if (!line_term) { + if (commit->object.flags & BOUNDARY) + printf("%cboundary=yes", info_term); + } } if (revs->print_parents) { struct commit_list *parents = commit->parents; @@ -779,7 +784,7 @@ int cmd_rev_list(int argc, if (revs.graph || revs.verbose_header || show_disk_usage || info.show_timestamp || info.header_prefix || bisect_list || use_bitmap_index || revs.edge_hint || revs.left_right || - revs.cherry_mark || arg_missing_action || revs.boundary) + revs.cherry_mark || arg_missing_action) die(_("-z option used with unsupported option")); } diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh index dfbbc0aee6..349bf5ec3d 100755 --- a/t/t6000-rev-list-misc.sh +++ b/t/t6000-rev-list-misc.sh @@ -217,4 +217,20 @@ test_expect_success 'rev-list -z --objects' ' test_cmp expect actual ' +test_expect_success 'rev-list -z --boundary' ' + 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%s\0boundary=yes\0" "$oid1" "$oid2" >expect && + git -C repo rev-list -z --boundary HEAD~.. >actual && + + test_cmp expect actual +' + test_done From patchwork Thu Mar 13 00:17:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Tobler X-Patchwork-Id: 14014093 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.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 A3FF91C6BE for ; Thu, 13 Mar 2025 00:21:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825281; cv=none; b=CRTnSgMnPF6PJ1B+4j7brqbC70mgyPnpQHSnC+S2Ubmwo9lRMGg2CntAJIAULSU1lYpXeIXrftZRcKzv9VPDRQRihuX4TPMcbmq9DbsH38DHbXtpto5dEXrnohnp4uwXPoU8B2PGjlziNiZbXuLXV3HUTD3cXdtgtR1ePHvi2Us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741825281; c=relaxed/simple; bh=GEbKqhgo25l2t0MfK+P4XVpt6b+YDHqVjJcQzMdWS+U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mDfHFR+OWkMoDzXI8xNW2739GrwCCpqaQVkL3LzT+elKDl3mO4H0QzcsbwID/zPpcPU+tpoYsCzxO61CoG8TKfFUtnDm9MM4Z4n6NsNa3fknk2TuwRI7fWbAF7wkUEQrnpg1k0hw31PTGwUBH/swr2JCumT3hMOkRT2lOLV2zDI= 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=Bep9IcS2; arc=none smtp.client-ip=209.85.160.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="Bep9IcS2" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-2bcdf5ea8faso331185fac.2 for ; Wed, 12 Mar 2025 17:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741825278; x=1742430078; 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=yp2lDt+EZG37miPI5lzgUD+a7tu6ByGR1ar3CRq+T74=; b=Bep9IcS2sbBM9t0Olv1fwyrHJ4q84crg8NCSLMTb4Z4n2pFbb87zXdzP2Oxjb4bVnb ihWWP26cotp1WCJFe3BecumJ03qa1LdzKuL7LQsxrn3CtxBqpwEgT+XvW/8ZzJxtjPY7 pqkvVj2PEhou3CkHK69mjPQDPRImZzLnaU1INQM7HwkVG3l8ltGdWiOKyKvmQWCSuWut kzS7eDtCyr28QdDkL5Z4BLDbV7ZCMt2qYp3dnOAobUGPvC2ZvIqoBbRzusxh5v9t1yS6 nxsJy34zIuzrwMKWHjw5Cpll+yXPrrgFh4u5pwv2aNabSJ8cxozxSrUeH8UGb6MLcB5/ oqpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741825278; x=1742430078; 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=yp2lDt+EZG37miPI5lzgUD+a7tu6ByGR1ar3CRq+T74=; b=LrV8C6n4TTmgJjtMa1YzlTmJL1M9l/Z5pNT/FkOIYBfw7uJ/GF7FDIu1RUby6F2b6q kQ5wgEGYAgw01/0Lrlp7udqGs0xHCy3L7nzxUvANFbgW2UoQ3Ulo4YdNtYkhQqbEC7bt zqWA3FBik2DnpM/yTlb9fPVZvhbCLo6uKcah1lNkvx9evxWzskn3Ju7Ra5uiJ8nGbTDf /XfqWitWfUF6hWuJd6y9zf3DK+gkg8IiXLhO0/KPBq5GepegSVQwtqMlQFlPwxcxBU36 jSgtsIm/l+a1wiLvE1Ez1FN3XcsP7uNA+jKiFOVDaWP8nXuz73/T4QlqDVRxxmeO5fgl MtqA== X-Gm-Message-State: AOJu0YxMlGniUMtzGWdviiv6MbiCwunkaEANxQPOzqJOl2Y/8Klu81Wu dFAg069vNuPqIWCv7Q9IeF8psAin1gswyF6LaVVSZ/oepRvtY0wT62r1VouQ X-Gm-Gg: ASbGncsBFhChwTut2SRrpWSdSU6V4aKMYzMRdTs0U6BUPyBH5XRaeKdfeSxsiQKXPhA wLkkm7p6THyAQOKm12Jc/sfVLDJ3e23cTo17WTFTokBueGLKCssCASesJcUTzXFCbUWMT0SP9e7 Iw0ETd6eq+L7hEzD+DEYGONNVfp/k0iSX7EJbzE6tinaT3jmRN48eoI7RHW+QK3HsSTUFGePCQu mSTUmeE6igTeBJS2muZ2qeOv728zI1aZB7D+66UoVTp4KpzymuCG8wElF9lAsjcGfXLdgQo4JtP 50rOKGMEfSNqvkYQSyvsN8ALP2qjNf5JIbWgFOPMyUCG7UMXjetH X-Google-Smtp-Source: AGHT+IE+Lqfo9cjbTrf7C9A5y4c2dAr8DwQQCMLN5d0L8/zyjTSM0g2YwayJTOPe5cDAt4F7TGFRaQ== X-Received: by 2002:a05:6871:8005:b0:29e:3921:b1ea with SMTP id 586e51a60fabf-2c26142a194mr13858104fac.30.1741825278478; Wed, 12 Mar 2025 17:21:18 -0700 (PDT) Received: from denethor.localdomain ([136.50.74.45]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-72bb267a8b4sm24028a34.9.2025.03.12.17.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 17:21:17 -0700 (PDT) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, christian.couder@gmail.com, peff@peff.net, ben.knoble@gmail.com, Justin Tobler Subject: [PATCH v2 6/6] rev-list: support NUL-delimited --missing option Date: Wed, 12 Mar 2025 19:17:06 -0500 Message-ID: <20250313001706.3390502-7-jltobler@gmail.com> X-Mailer: git-send-email 2.49.0.rc2 In-Reply-To: <20250313001706.3390502-1-jltobler@gmail.com> References: <20250310192829.661692-1-jltobler@gmail.com> <20250313001706.3390502-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 object walk in the form: $ git rev-list --missing=print-info ? [SP =]... LF 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 missing=yes NUL [= NUL]... In this mode, values containing special characters or spaces are printed as-is without being escaped or quoted. Instead of prefixing the missing OID with '?', a separate `missing=yes` token/value pair is appended. Signed-off-by: Justin Tobler --- Documentation/rev-list-options.adoc | 13 ++++++------ builtin/rev-list.c | 29 ++++++++++++++++++++------- t/t6022-rev-list-missing.sh | 31 +++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc index d400d76cf2..145ded5c78 100644 --- a/Documentation/rev-list-options.adoc +++ b/Documentation/rev-list-options.adoc @@ -371,8 +371,8 @@ ifdef::git-rev-list[] NUL [= NUL]... ----------------------------------------------------------------------- + -Additional object metadata, such as object paths or boundary objects, is -printed using the `=` form. Token values are printed as-is +Additional object metadata, such as object paths or boundary/missing objects, +is printed using the `=` form. Token values are printed as-is without any encoding/truncation. An OID entry never contains a '=' character and thus is used to signal the start of a new object record. Examples: + @@ -380,12 +380,13 @@ and thus is used to signal the start of a new object record. Examples: NUL NUL path= NUL NUL boundary=yes NUL + NUL missing=yes NUL [= NUL]... ----------------------------------------------------------------------- + -This mode is only compatible with the `--objects` and `--boundary` output -options. Also, revision and pathspec argument parsing on stdin with the -`--stdin` option is NUL byte delimited instead of using newlines while in this -mode. +This mode is only compatible with the `--objects`, `--boundary`, and +`--missing` output options. Also, revision and pathspec argument parsing on +stdin with the `--stdin` option is NUL byte delimited instead of using newlines +while in this mode. endif::git-rev-list[] History Simplification diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 7c6d4b25b0..d7b4dd48ff 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -136,24 +136,39 @@ static void print_missing_object(struct missing_objects_map_entry *entry, { struct strbuf sb = STRBUF_INIT; + if (line_term) + putchar('?'); + + printf("%s", oid_to_hex(&entry->entry.oid)); + + if (!line_term) + printf("%cmissing=yes", info_term); + if (!print_missing_info) { - printf("?%s\n", oid_to_hex(&entry->entry.oid)); + putchar(line_term); 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_term); + + if (line_term) { + quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP); + strbuf_addbuf(&sb, &path); + } else { + strbuf_addstr(&sb, entry->path); + } strbuf_release(&path); } if (entry->type) - strbuf_addf(&sb, " type=%s", type_name(entry->type)); + strbuf_addf(&sb, "%ctype=%s", info_term, type_name(entry->type)); + + fwrite(sb.buf, sizeof(char), sb.len, stdout); + putchar(line_term); - printf("?%s%s\n", oid_to_hex(&entry->entry.oid), sb.buf); strbuf_release(&sb); } @@ -784,7 +799,7 @@ int cmd_rev_list(int argc, if (revs.graph || revs.verbose_header || show_disk_usage || info.show_timestamp || info.header_prefix || bisect_list || use_bitmap_index || revs.edge_hint || revs.left_right || - revs.cherry_mark || arg_missing_action) + revs.cherry_mark) 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..08e92dd002 100755 --- a/t/t6022-rev-list-missing.sh +++ b/t/t6022-rev-list-missing.sh @@ -198,4 +198,35 @@ 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\0missing=yes\0path=%s\0type=%s\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