From patchwork Mon Oct 17 02:23:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B75DC433FE for ; Mon, 17 Oct 2022 02:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbiJQCXc (ORCPT ); Sun, 16 Oct 2022 22:23:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbiJQCX0 (ORCPT ); Sun, 16 Oct 2022 22:23:26 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90A813ED5D for ; Sun, 16 Oct 2022 19:23:25 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id bk15so16377261wrb.13 for ; Sun, 16 Oct 2022 19:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=CNgLLqtbOnMTt48SDCS+y+l4hNAduY13uCwvFG6xpqg=; b=qDSc6UTIfxtoaowCfJ+Ho9a0MP52XjbOuL4c4AKa6eF0mDXlBMHo+KuLYxfR6z0r5b PTbblFSicpHOcDk5lluQ/eOOVP6zX8emeEftBzPwABUZyz94RbxO3i3Ic8zduCaToWGg 9ihJX9UgsD1PHkul6n1hjk5/4TKMLTod4fzWD7qsL6NSEAj6kC8bFcCJR+UVjltbeH+6 W162QwNge7lVyy1ElQDifM6+eUCtK0NMHKsO45otLXTZBvvvqCr/WEj5h3q1rcwJlBGm t5NbiFULiQgKdocNah1LbFO2TKlZOQgUwLdT8HPfadDaRYg4FbucF2dj8C1WHpgQVSQx HwOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CNgLLqtbOnMTt48SDCS+y+l4hNAduY13uCwvFG6xpqg=; b=eQNJZUym8PCCGDtAM0hfUL69UgzMAogyDer3mQwcDmqvru42kJO4mNvCi5nQfaQeAr QqCeORRBkcA4LcMlnFy7mq08kxv9FBaDR/qRSMKw5S2pSQie35P9fMXyDuGgqUaFTP7d 8VZ4r1EY5WNR2fgzoFSNIajhnOWQ01fnYGpeIr7AD5BzkLLa5Qh0Cd6QX3W9ga8C2+bq EHDFbydi758vhKfbX8G8g15Lt3dzbmgheMDSdzcyyILQU15ebCSbUYOptOdnrQZXvcVx 4ymjP4Ke1doYDKRhGcrAyEZbHiL9oZLwCrQnlnXBLVVigVeLGBG/Fjl0SvnAashZ0mAM rjPA== X-Gm-Message-State: ACrzQf3HNU94wEA9YBMF0KyfBICyD17svz7i/AuFyqnsyxC3Bl9Q6iSd GeTZXZAntNq8XX8zOaEont81yO/gUls= X-Google-Smtp-Source: AMsMyM4l7Xx38sy9crUALmHg26DUZs7C7PAkzEROsHFKr0J79Zl7CxypDD5o8vGHTis030ZUJy/IHQ== X-Received: by 2002:a5d:64c2:0:b0:22e:41b0:42ca with SMTP id f2-20020a5d64c2000000b0022e41b042camr4861007wri.411.1665973403839; Sun, 16 Oct 2022 19:23:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w16-20020adf8bd0000000b0022f40a2d06esm7387143wra.35.2022.10.16.19.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:23 -0700 (PDT) Message-Id: <79959a54eb4c1a0812b1f4643530069a63e549f4.1665973401.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:13 +0000 Subject: [PATCH v3 1/9] tree: do not use the_repository for tree traversal methods. Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Alphadelta14 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alphadelta14 From: Alphadelta14 Expect that tree walking may switch repository contexts for cases such as submodules. Added compatibility macros for existing cases. Annotate an existing issue where repo is wrong when traversing. Signed-off-by: Heather Lapointe --- tree.c | 15 +++++++++------ tree.h | 14 ++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tree.c b/tree.c index 410e3b477e5..13f9173d45e 100644 --- a/tree.c +++ b/tree.c @@ -22,7 +22,7 @@ int read_tree_at(struct repository *r, int len, oldlen = base->len; enum interesting retval = entry_not_interesting; - if (parse_tree(tree)) + if (repo_parse_tree(r, tree)) return -1; init_tree_desc(&desc, tree->buffer, tree->size); @@ -58,7 +58,11 @@ int read_tree_at(struct repository *r, oid_to_hex(&entry.oid), base->buf, entry.path); - if (parse_commit(commit)) + // FIXME: This is the wrong repo instance (it refers to the superproject) + // it will always fail as is (will fix in later patch) + // This current codepath isn't executed by any existing callbacks + // so it wouldn't show up as an issue at this time. + if (repo_parse_commit(r, commit)) die("Invalid commit %s in submodule path %s%s", oid_to_hex(&entry.oid), base->buf, entry.path); @@ -121,7 +125,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size) return 0; } -int parse_tree_gently(struct tree *item, int quiet_on_missing) +int repo_parse_tree_gently(struct repository *r, struct tree *item, int quiet_on_missing) { enum object_type type; void *buffer; @@ -129,7 +133,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing) if (item->object.parsed) return 0; - buffer = read_object_file(&item->object.oid, &type, &size); + buffer = repo_read_object_file(r, &item->object.oid, &type, &size); if (!buffer) return quiet_on_missing ? -1 : error("Could not read %s", @@ -149,9 +153,8 @@ void free_tree_buffer(struct tree *tree) tree->object.parsed = 0; } -struct tree *parse_tree_indirect(const struct object_id *oid) +struct tree *repo_parse_tree_indirect(struct repository *r, const struct object_id *oid) { - struct repository *r = the_repository; struct object *obj = parse_object(r, oid); return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE); } diff --git a/tree.h b/tree.h index 6efff003e21..cc6402e4738 100644 --- a/tree.h +++ b/tree.h @@ -18,15 +18,21 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid); int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); -int parse_tree_gently(struct tree *tree, int quiet_on_missing); -static inline int parse_tree(struct tree *tree) +int repo_parse_tree_gently(struct repository *r, struct tree *tree, int quiet_on_missing); +static inline int repo_parse_tree(struct repository *r, struct tree *tree) { - return parse_tree_gently(tree, 0); + return repo_parse_tree_gently(r, tree, 0); } + +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#define parse_tree(tree) repo_parse_tree(the_repository, tree) +#define parse_tree_gently(tree, quiet_on_missing) repo_parse_tree_gently(the_repository, tree, quiet_on_missing) +#define parse_tree_indirect(oid) repo_parse_tree_indirect(the_repository, oid) +#endif void free_tree_buffer(struct tree *tree); /* Parses and returns the tree in the given ent, chasing tags and commits. */ -struct tree *parse_tree_indirect(const struct object_id *oid); +struct tree *repo_parse_tree_indirect(struct repository *r, const struct object_id *oid); int cmp_cache_name_compare(const void *a_, const void *b_); From patchwork Mon Oct 17 02:23:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008102 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEAB6C4332F for ; Mon, 17 Oct 2022 02:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbiJQCXe (ORCPT ); Sun, 16 Oct 2022 22:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbiJQCXa (ORCPT ); Sun, 16 Oct 2022 22:23:30 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FA5544549 for ; Sun, 16 Oct 2022 19:23:26 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id i131-20020a1c3b89000000b003c6c154d528so4702167wma.4 for ; Sun, 16 Oct 2022 19:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Xs/KCUkfn9ByRJHNiJHiUVJxgB62lsS+0U9fDXCTndo=; b=il4+4wlzqlAW9tqZ6EC2OpFvk4IMzO455MuBsZAaXDbEXPzaIlAlZs3sfXs9afcBsB xIRKGqYXrWLkf/wDngbTv/NfnkfIpLBInziXCNQy/BbGgW9MFs7KkI2jAO0oRgf+BER8 0Y9ph0W2oBOh3j+EIID9cb0ZOq1ckJp4vS893/3aLWysA9KtB2pzlCRXRw7icGXdCZVz jKOjx2nCOaWwjFMM2D9Rgn4jeMQIhCJ82sJ5wkDVTVmXCfFDg9IinFHhIMG1yOMy4EON 2OGWcavzm7JU1OaPDWlig9GZ8QjidFbOlNHTzOFLkhiikErfS7rqk+NVFwXvYdGDx/LD Zzpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xs/KCUkfn9ByRJHNiJHiUVJxgB62lsS+0U9fDXCTndo=; b=4BMjoQgLEoH7F9SzhJRRRtIjNbaeIg5lxgoV09RSTtKaPWXLOkSk05sHNVzbTGvwbf uEv3F66hmxFEzEACyjZrC44j9+oKhgwEnidHG+OVG5wqAK8Mfjhu/3YJwus/96sqcF/Y DaXAhl9gZqA+Y70wezNWiIqIJgvphPINWn5mIALwn2doInVlZkQxiryXGL38rxDrSCb0 YNMWcLZCP/TlrXLdwmklh4Wqyinhb87RVdwdRLYh7fDG31AfpJB0R8k0gsWeT/cduUjR ULhvEfmtHD7mLuxYaNls4VyPaSK5T7Heji4zN6vtKRsTnD+6NW6HkQwkqyuerK/MPnN7 tJNA== X-Gm-Message-State: ACrzQf0JRYRpwlb7vocP19HLL2XoB2OH072gHMdYAQnNSlsd889bdLb/ HpjwEbKtNGMrSFEVO9BMIk8uqI6YYxc= X-Google-Smtp-Source: AMsMyM4LjnXqvCouMq5rbWxMgCJp7dhQL6cv9SsE6QxVbFVMCpEz5b+UqwYYgnbaGndqzMpkuEBjBw== X-Received: by 2002:a05:600c:444f:b0:3c6:deac:d662 with SMTP id v15-20020a05600c444f00b003c6deacd662mr13744870wmn.89.1665973404729; Sun, 16 Oct 2022 19:23:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n14-20020a5d400e000000b0022ae401e9e0sm7250633wrp.78.2022.10.16.19.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:24 -0700 (PDT) Message-Id: <2291e0f9b5c61f9668b206b85368829db9384bb3.1665973401.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:14 +0000 Subject: [PATCH v3 2/9] tree: update cases to use repo_ tree methods Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe For cases which had already had a repository instance, update those to use the repo_parse_tree* methods. Leave the remaining invocations that were already using the_repository alone. Signed-off-by: Heather Lapointe --- merge.c | 4 ++-- reset.c | 2 +- revision.c | 4 ++-- sequencer.c | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/merge.c b/merge.c index 2382ff66d35..1efc4440c03 100644 --- a/merge.c +++ b/merge.c @@ -63,12 +63,12 @@ int checkout_fast_forward(struct repository *r, memset(&trees, 0, sizeof(trees)); memset(&t, 0, sizeof(t)); - trees[nr_trees] = parse_tree_indirect(head); + trees[nr_trees] = repo_parse_tree_indirect(r, head); if (!trees[nr_trees++]) { rollback_lock_file(&lock_file); return -1; } - trees[nr_trees] = parse_tree_indirect(remote); + trees[nr_trees] = repo_parse_tree_indirect(r, remote); if (!trees[nr_trees++]) { rollback_lock_file(&lock_file); return -1; diff --git a/reset.c b/reset.c index e3383a93343..a0ac5e8a684 100644 --- a/reset.c +++ b/reset.c @@ -153,7 +153,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts) goto leave_reset_head; } - tree = parse_tree_indirect(oid); + tree = repo_parse_tree_indirect(r, oid); prime_cache_tree(r, r->index, tree); if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { diff --git a/revision.c b/revision.c index 36e31942cee..dab5ddaf039 100644 --- a/revision.c +++ b/revision.c @@ -74,7 +74,7 @@ static void mark_tree_contents_uninteresting(struct repository *r, struct tree_desc desc; struct name_entry entry; - if (parse_tree_gently(tree, 1) < 0) + if (repo_parse_tree_gently(r, tree, 1) < 0) return; init_tree_desc(&desc, tree->buffer, tree->size); @@ -181,7 +181,7 @@ static void add_children_by_path(struct repository *r, if (!tree) return; - if (parse_tree_gently(tree, 1) < 0) + if (repo_parse_tree_gently(r, tree, 1) < 0) return; init_tree_desc(&desc, tree->buffer, tree->size); diff --git a/sequencer.c b/sequencer.c index a4d85f1fbdd..a4c09dfa182 100644 --- a/sequencer.c +++ b/sequencer.c @@ -685,9 +685,9 @@ static int do_recursive_merge(struct repository *r, o.buffer_output = 2; o.show_rename_progress = 1; - head_tree = parse_tree_indirect(head); - next_tree = next ? get_commit_tree(next) : empty_tree(r); - base_tree = base ? get_commit_tree(base) : empty_tree(r); + head_tree = repo_parse_tree_indirect(r, head); + next_tree = next ? repo_get_commit_tree(r, next) : empty_tree(r); + base_tree = base ? repo_get_commit_tree(r, base) : empty_tree(r); for (i = 0; i < opts->xopts_nr; i++) parse_merge_opt(&o, opts->xopts[i]); From patchwork Mon Oct 17 02:23:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B99F4C43217 for ; Mon, 17 Oct 2022 02:23:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbiJQCXh (ORCPT ); Sun, 16 Oct 2022 22:23:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbiJQCXb (ORCPT ); Sun, 16 Oct 2022 22:23:31 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CBF544563 for ; Sun, 16 Oct 2022 19:23:27 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l16-20020a05600c4f1000b003c6c0d2a445so9012771wmq.4 for ; Sun, 16 Oct 2022 19:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Wpn/YUgBa26+xjIpiTP0kqX7J5Xquv2lYGc9NSgjxTs=; b=mfgBT3uzNZXQiajoJXDSAmn+FRZeavp/HqQ09k8G3EEbrhz5dWhKazI2koDAXo+AzH Uvbbnz7JjUuNf6HuVGgaaFBuN7il2kH+ybCMbavBkZcso8nyJ4Hxzco5HfItf4MRleX9 vTvICBn7/3AWgtOb3zf3vbtDJKaIiGozkMfUViF33nik7vrYUIfX4bFEgnprLr4MZ2Ha 1H7WDoApa7aJh/QRDH6d5TQqV2GzlWno2kRnuW3w5TXh5VgA2Uj6kQXH+B0GME6pT87w NDR+uRAX0blBZdjfAVFJxHelifVx+nHqqaItKuNH+TNdcDIRHFnvJuiOXuHBAplKB0dv n0gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wpn/YUgBa26+xjIpiTP0kqX7J5Xquv2lYGc9NSgjxTs=; b=eoDi1+8X6MwgQ6kcoYGiSm+e+5stB33uabgLNFDJH1GxKEkeueyEHtEDmdOHPCUuU9 ZqVffI3WnFhvp6jS6jLpCjprmTbD2C1hbT4HJVExvIKSe+OyyLOqVKcUwbsVPMNWev/g 5ioW1qiOGf16+cxT4fqjA9Wmd8czUdKmBIUkMjHqJrTXUxIIZiBCYHg0tXCmV5vkK9cB vBuJv9Ar71Z+nKgJ6txRcY8ZlS9Aj/WRDtRe73N/TE//Sw7CBm1oOkXRkn5sewUX2gjw IbtN//rQLHKNb4crwSfNUJ9VRT/++rkPjJYx1g04+YjOubsAQttTbaKIaVnvb8/Livbg 1Yng== X-Gm-Message-State: ACrzQf0cmtYShxhxoLUWPpRALcOXwOtxDh4A+uiUdrhq6gYD6tMaL/Lw c/pdNORrkInkRGpkmSylwOQq1xbbxs0= X-Google-Smtp-Source: AMsMyM63iCoPVlh82VOFRjXvCQeYccHN2ETJrfZW0BCCjfTtaNxkLMb1Gff/J9RPdLUX3pI/+CjZvQ== X-Received: by 2002:a05:600c:524e:b0:3c6:eb24:c05c with SMTP id fc14-20020a05600c524e00b003c6eb24c05cmr8236403wmb.100.1665973405921; Sun, 16 Oct 2022 19:23:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h12-20020a05600c314c00b003c6ee9e254dsm6167316wmo.32.2022.10.16.19.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:25 -0700 (PDT) Message-Id: <9a07c6932f4c7ef844df1fc4f5b6b9feb1810135.1665973401.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:15 +0000 Subject: [PATCH v3 3/9] tree: increase test coverage for tree.c Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe This highlights some buggy behavior from read_tree for submodules that was not being executed. This introduces a test-tool tree-read-tree-at command (the complex name is because it is not related to the read-tree command). Signed-off-by: Heather Lapointe --- Makefile | 1 + t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/helper/test-tree-read-tree-at.c | 40 +++++++++++++++++++ t/t1023-tree-read-tree-at.sh | 65 +++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 t/helper/test-tree-read-tree-at.c create mode 100755 t/t1023-tree-read-tree-at.sh diff --git a/Makefile b/Makefile index 6bfb62cbe94..52d17ca7276 100644 --- a/Makefile +++ b/Makefile @@ -788,6 +788,7 @@ TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o TEST_BUILTINS_OBJS += test-submodule.o TEST_BUILTINS_OBJS += test-subprocess.o TEST_BUILTINS_OBJS += test-trace2.o +TEST_BUILTINS_OBJS += test-tree-read-tree-at.o TEST_BUILTINS_OBJS += test-urlmatch-normalization.o TEST_BUILTINS_OBJS += test-userdiff.o TEST_BUILTINS_OBJS += test-wildmatch.o diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index d1d013bcd92..a8a9bedec5f 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -82,6 +82,7 @@ static struct test_cmd cmds[] = { { "submodule-nested-repo-config", cmd__submodule_nested_repo_config }, { "subprocess", cmd__subprocess }, { "trace2", cmd__trace2 }, + { "tree-read-tree-at", cmd__tree_read_tree_at }, { "userdiff", cmd__userdiff }, { "urlmatch-normalization", cmd__urlmatch_normalization }, { "xml-encode", cmd__xml_encode }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 6b46b6444b6..409fddfaeb8 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -76,6 +76,7 @@ int cmd__submodule_config(int argc, const char **argv); int cmd__submodule_nested_repo_config(int argc, const char **argv); int cmd__subprocess(int argc, const char **argv); int cmd__trace2(int argc, const char **argv); +int cmd__tree_read_tree_at(int argc, const char **argv); int cmd__userdiff(int argc, const char **argv); int cmd__urlmatch_normalization(int argc, const char **argv); int cmd__xml_encode(int argc, const char **argv); diff --git a/t/helper/test-tree-read-tree-at.c b/t/helper/test-tree-read-tree-at.c new file mode 100644 index 00000000000..bba759bb264 --- /dev/null +++ b/t/helper/test-tree-read-tree-at.c @@ -0,0 +1,40 @@ +/* This tests tree.c's read_tree / read_tree_at. +We call it tree-read-tree-at to disambiguate with the read-tree tool. +*/ +#include "cache.h" +#include "pathspec.h" +#include "test-tool.h" +#include "tree.h" + +static int test_handle_entry(const struct object_id *oid, + struct strbuf *base, const char *filename, + unsigned mode, void *context UNUSED) { + printf("%i %s %s%s\n", mode, oid_to_hex(oid), base->buf, filename); + if (S_ISDIR(mode) || S_ISGITLINK(mode)) { + return READ_TREE_RECURSIVE; + } + return 0; +} + +int cmd__tree_read_tree_at(int argc UNUSED, const char **argv) +{ + struct pathspec pathspec; + struct tree *tree; + struct repository *repo; + struct object_id oid; + + setup_git_directory(); + repo = the_repository; + assert(repo); + + parse_pathspec(&pathspec, 0, + PATHSPEC_PREFER_FULL, + "", argv); + + assert(repo_get_oid(repo, "HEAD", &oid) == 0); + tree = repo_parse_tree_indirect(repo, &oid); + assert(tree); + pathspec.recurse_submodules = 1; + read_tree(repo, tree, &pathspec, test_handle_entry, NULL); + return 0; +} diff --git a/t/t1023-tree-read-tree-at.sh b/t/t1023-tree-read-tree-at.sh new file mode 100755 index 00000000000..9e5ce3abb4b --- /dev/null +++ b/t/t1023-tree-read-tree-at.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# tests for tree.c (not read-tree.c) +test_description='Test read_tree / read_tree_at' +. ./test-lib.sh + +test_expect_success 'read_tree basic' ' + rm -rf walk_tree_basic && + git init walk_tree_basic && + ( + cd walk_tree_basic && + set -x && + + mkdir -p dir1/dirA && + mkdir -p dir1/dirB && + mkdir -p dir2 && + echo "file1" > file1.txt && + echo "file2" > file2.txt && + # uncommitted + echo "file3" > file3.txt && + + echo "file1A1" > dir1/dirA/file1.txt && + git add file1.txt file2.txt dir1/dirA/file1.txt && + git commit -m "initial commit" && + + test-tool tree-read-tree-at . > walk1.txt && + grep " file1.txt" walk1.txt && + ! grep " file3.txt" walk1.txt && + ! grep " dir1/dirB" walk1.txt && + grep " dir1/dirA/file1.txt" walk1.txt + ) +' + +test_expect_success 'read_tree submodules' ' + rm -rf walk_tree_submodules && + git init submodule1 && + ( + cd submodule1 && + mkdir -p dir1/dirA && + echo "dir2/sub1/file1.txt" > file1.txt && + echo "dir2/sub1/file1A1.txt" > dir1/dirA/file1.txt && + git add file1.txt dir1/dirA/file1.txt && + git commit -m "initial commit" + ) && + git init walk_tree_submodules && + ( + cd walk_tree_submodules && + + mkdir -p dir2 && + echo "file1" > file1.txt && + echo "dir2/file2" > dir2/file2.txt && + git add file1.txt dir2/file2.txt && + git commit -m "initial commit" && + + git submodule add ../submodule1 dir2/sub1 && + git commit -m "add submodule1" && + + test-tool tree-read-tree-at . > walk2.txt && + grep " file1.txt" walk2.txt && + grep " dir2/sub1/file1.txt" walk2.txt && + grep " dir2/sub1/dir1/dirA/file1.txt" walk2.txt + ) +' + +test_done From patchwork Mon Oct 17 02:23:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62D60C43219 for ; Mon, 17 Oct 2022 02:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230166AbiJQCXp (ORCPT ); Sun, 16 Oct 2022 22:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230194AbiJQCXb (ORCPT ); Sun, 16 Oct 2022 22:23:31 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4DDA4456A for ; Sun, 16 Oct 2022 19:23:28 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id r8-20020a1c4408000000b003c47d5fd475so11738457wma.3 for ; Sun, 16 Oct 2022 19:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=z0UkilmK87anbGZ29VLzarKINo9qRuRnMdxXyeK1GGM=; b=BJ9YVMg+DEDBSu3QG9sWlfJuGzSKJisM883M57HjIlVn9fUJQLorNhHXkCzFjGP3wN 9Li9lpSQr1ZxGJAd7ykNE0yrz295+mGYNboblQNRQ9QP2Lnc8aghOF/zy4sCHITTcUcK tL0lhLdVLVgzZcKzkpV26p4NCekxANrppg8zoGJ4EtWzPYp7Ry9scpdVvjCOBPhDn0uv n34a1i4w7C3vZb/yh6XzB2bLQgYY09MzfibZkVJV3sVOBxKr2MZi6CSTHcaxOtaaaGWx 58wjAXoEZhAjnfm8fyQ2yjUnac5SGcftXfZWe0E3AQW1V64UXWWT/egOO1+GMMscruXN cM1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z0UkilmK87anbGZ29VLzarKINo9qRuRnMdxXyeK1GGM=; b=fyk0XQVzGeXEzI3RHWH0kwqT3V4y+6cpxvtZsRnklUwVG6YUbcmL6b/t8H56+b/txo PwC/oCMzc5ILyx9vpUg4kTU3hlYrgx+G4j8fXri6ez8qSO1AnOKGQfr1fPEGwEBOlD3A +Nnb9vWfEHElSUqOCggqDt148MKqWXo62nbykOX/3ZKgfG0F+aB3z3qAzgpfkGxWLFoR MYwvnGvYdlX8K6FavFCHs3rSIijWGhfTbtf2ZnAvH1EkYiblatO1wyCO6Bq00DA3nrBx QUQKftA9YJLmcJpE1QsmLFJ0FY4lWVcbWJP1+zWGvDcn/KNYpDQ01DFu1/b77nJcTHZo Sf3w== X-Gm-Message-State: ACrzQf0uhgxkb9jmJgF4/aptCjqVZoZeaqPilAvb0+DvNHVQAbhLmaT0 1CI1g6v/1lhTPNdpTCoDKSl3Y6eWHtU= X-Google-Smtp-Source: AMsMyM4aKwhWT8TrMBRgRgGSEkiVEbAS44+3687FD3ckaztVxg8V5DZNmOscwxW3ahSDSshDS2RXYw== X-Received: by 2002:a05:600c:2754:b0:3c6:aba7:5c93 with SMTP id 20-20020a05600c275400b003c6aba75c93mr5455659wmw.177.1665973406779; Sun, 16 Oct 2022 19:23:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r3-20020a05600c158300b003c21ba7d7d6sm8420313wmf.44.2022.10.16.19.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:26 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:16 +0000 Subject: [PATCH v3 4/9] tree: handle submodule case for read_tree_at properly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe This supports traversal into an actual submodule for read_tree_at. The logic is blocked on pathspec->recurse_submodules now, but previously hadn't been executed due to all fn() cases returning early for submodules. Signed-off-by: Heather Lapointe --- tree.c | 88 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/tree.c b/tree.c index 13f9173d45e..2a087c010f9 100644 --- a/tree.c +++ b/tree.c @@ -8,6 +8,7 @@ #include "alloc.h" #include "tree-walk.h" #include "repository.h" +#include "pathspec.h" const char *tree_type = "tree"; @@ -47,40 +48,73 @@ int read_tree_at(struct repository *r, return -1; } - if (S_ISDIR(entry.mode)) + if (S_ISDIR(entry.mode)) { oidcpy(&oid, &entry.oid); - else if (S_ISGITLINK(entry.mode)) { - struct commit *commit; - commit = lookup_commit(r, &entry.oid); + len = tree_entry_len(&entry); + strbuf_add(base, entry.path, len); + strbuf_addch(base, '/'); + retval = read_tree_at(r, lookup_tree(r, &oid), + base, pathspec, + fn, context); + strbuf_setlen(base, oldlen); + if (retval) + return -1; + } else if (pathspec->recurse_submodules && S_ISGITLINK(entry.mode)) { + struct commit *commit; + struct repository subrepo; + struct repository* subrepo_p = &subrepo; + struct tree* submodule_tree; + char *submodule_rel_path; + int name_base_len = 0; + + len = tree_entry_len(&entry); + strbuf_add(base, entry.path, len); + submodule_rel_path = base->buf; + // repo_submodule_init expects a path relative to submodule_prefix + if (r->submodule_prefix) { + name_base_len = strlen(r->submodule_prefix); + // we should always expect to start with submodule_prefix + assert(!strncmp(submodule_rel_path, r->submodule_prefix, name_base_len)); + // strip the prefix + submodule_rel_path += name_base_len; + // if submodule_prefix doesn't end with a /, we want to get rid of that too + if (is_dir_sep(submodule_rel_path[0])) { + submodule_rel_path++; + } + } + + if (repo_submodule_init(subrepo_p, r, submodule_rel_path, null_oid())) + die("couldn't init submodule %s", base->buf); + + if (repo_read_index(subrepo_p) < 0) + die("index file corrupt"); + + commit = lookup_commit(subrepo_p, &entry.oid); if (!commit) - die("Commit %s in submodule path %s%s not found", + die("Commit %s in submodule path %s not found", oid_to_hex(&entry.oid), - base->buf, entry.path); - - // FIXME: This is the wrong repo instance (it refers to the superproject) - // it will always fail as is (will fix in later patch) - // This current codepath isn't executed by any existing callbacks - // so it wouldn't show up as an issue at this time. - if (repo_parse_commit(r, commit)) - die("Invalid commit %s in submodule path %s%s", + base->buf); + + if (repo_parse_commit(subrepo_p, commit)) + die("Invalid commit %s in submodule path %s", oid_to_hex(&entry.oid), - base->buf, entry.path); + base->buf); - oidcpy(&oid, get_commit_tree_oid(commit)); - } - else - continue; + submodule_tree = repo_get_commit_tree(subrepo_p, commit); + oidcpy(&oid, submodule_tree ? &submodule_tree->object.oid : NULL); - len = tree_entry_len(&entry); - strbuf_add(base, entry.path, len); - strbuf_addch(base, '/'); - retval = read_tree_at(r, lookup_tree(r, &oid), - base, pathspec, - fn, context); - strbuf_setlen(base, oldlen); - if (retval) - return -1; + strbuf_addch(base, '/'); + + retval = read_tree_at(subrepo_p, lookup_tree(subrepo_p, &oid), + base, pathspec, + fn, context); + if (retval) + die("failed to read tree for %s", base->buf); + strbuf_setlen(base, oldlen); + repo_clear(subrepo_p); + } + // else, this is a file (or a submodule, but no pathspec->recurse_submodules) } return 0; } From patchwork Mon Oct 17 02:23:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008106 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04307C4332F for ; Mon, 17 Oct 2022 02:23:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbiJQCXq (ORCPT ); Sun, 16 Oct 2022 22:23:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbiJQCXb (ORCPT ); Sun, 16 Oct 2022 22:23:31 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF4A54456F for ; Sun, 16 Oct 2022 19:23:29 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id j16so16438048wrh.5 for ; Sun, 16 Oct 2022 19:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=UrBojq2Dd90cjmbzNdU3/wlCsY8ddFuvZ0iEklEsrh8=; b=BmLfQw8b/9F/6MMM/7jSicXBUg4D0ryEGzjkM/mH07d+31ZiRpdvSLQ1qPfHuTbTte emGRoJA8Hxkv2kP0VlIAHe4/7UXryZEkR90DobsZBqeGP6u8XTNmsdmlI/N7rksCcMfB 5O/IWHP6W4uAfyn7p2opBKo5mxvsJxDIaB2vFLZYfz8Dv0W5t/GBssihnF5wn1z0Ptkr oNmKRzFCkCRwEu1BWKkOc0MQrn/HI3R2r6yym9O1GGJ1iDygjTNJDjOUl3tljGDziK/A iCpFNQmm5MvU0iCNWcyrcDkIg/Tk6uuy8jgUm7CWF/jPX4EojlhNtWSmTgM52Z5d8/Mx ZSTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UrBojq2Dd90cjmbzNdU3/wlCsY8ddFuvZ0iEklEsrh8=; b=mSR6B1Xxma9fIFKd0S5ZHIZfTf3JEonEN3zKJop+HhdWSvQEupLPyDbl5CoJ69+r2N dFOakoPaoNNghpKDeDG6EZXcztWpSOZP+cIue8kNrUY7PY3N7RVQNUiAt84R1tuoCcYs eUqozVIHN4piFBxGVi64JKEcnV2PTDPBM2KUmnHwmZUSFWw+5DqWsxj6qyj/L8QOD9vW PwUPYE1xBOMqg6+7gsbiu1JxxOLXgYsCFuTcoXa4TdwdNnv2waB0NbSVk5QXyLEAJklq LbS3s7397n4tik3M0nZSgyfhmkpVFbDkV8p3rAzpanxWO+T3kLHCq0RrvlsFDHLsMubz iMjQ== X-Gm-Message-State: ACrzQf2YbQe0c1jKijwqpj8wT2Mknu1wieepfb8ILFMNB0QSbdbqAfWs kaf1/vjamp6Z+FI8xb+5NpY2vhm3N3M= X-Google-Smtp-Source: AMsMyM407ARhx7z4ypcbMCFyaNndHMxW69wdEuU+WLK0tUepXPmM/gVPXM79iMxEs42Giw4inCF5Og== X-Received: by 2002:adf:fec6:0:b0:22e:3218:f7e1 with SMTP id q6-20020adffec6000000b0022e3218f7e1mr4665115wrs.522.1665973407914; Sun, 16 Oct 2022 19:23:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c10-20020a05600c0a4a00b003c6cdbface4sm9086580wmq.11.2022.10.16.19.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:27 -0700 (PDT) Message-Id: <376345fdf66b274a7ce3dfff4d0a2b185858147c.1665973401.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:17 +0000 Subject: [PATCH v3 5/9] tree: add repository parameter to read_tree_fn_t Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe Add a repo paramter to read_tree_fn_t because most callbacks do need some repo instance. This avoids having to use the_repository functions otherwise and improves repo context switching for submodules. Signed-off-by: Heather Lapointe --- archive.c | 11 ++++++---- builtin/checkout.c | 4 +++- builtin/log.c | 4 +++- builtin/ls-files.c | 8 ++++++-- builtin/ls-tree.c | 34 ++++++++++++++++++++----------- merge-recursive.c | 4 +++- sparse-index.c | 4 +++- t/helper/test-tree-read-tree-at.c | 3 ++- tree.c | 2 +- tree.h | 2 +- wt-status.c | 4 +++- 11 files changed, 54 insertions(+), 26 deletions(-) diff --git a/archive.c b/archive.c index 61a79e4a227..15f3ac92dfc 100644 --- a/archive.c +++ b/archive.c @@ -225,7 +225,9 @@ static int write_directory(struct archiver_context *c) return ret ? -1 : 0; } -static int queue_or_write_archive_entry(const struct object_id *oid, +static int queue_or_write_archive_entry( + struct repository *r, + const struct object_id *oid, struct strbuf *base, const char *filename, unsigned mode, void *context) { @@ -246,7 +248,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid, /* Borrow base, but restore its original value when done. */ strbuf_addstr(base, filename); strbuf_addch(base, '/'); - check = get_archive_attrs(c->args->repo->index, base->buf); + check = get_archive_attrs(r->index, base->buf); strbuf_setlen(base, baselen); if (check_attr_export_ignore(check)) @@ -382,7 +384,8 @@ struct path_exists_context { struct archiver_args *args; }; -static int reject_entry(const struct object_id *oid UNUSED, +static int reject_entry( + struct repository *r, const struct object_id *oid UNUSED, struct strbuf *base, const char *filename, unsigned mode, void *context) @@ -394,7 +397,7 @@ static int reject_entry(const struct object_id *oid UNUSED, struct strbuf sb = STRBUF_INIT; strbuf_addbuf(&sb, base); strbuf_addstr(&sb, filename); - if (!match_pathspec(ctx->args->repo->index, + if (!match_pathspec(r->index, &ctx->pathspec, sb.buf, sb.len, 0, NULL, 1)) ret = READ_TREE_RECURSIVE; diff --git a/builtin/checkout.c b/builtin/checkout.c index 2a132392fbe..ee98858afe6 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -124,7 +124,9 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm } -static int update_some(const struct object_id *oid, struct strbuf *base, +static int update_some( + struct repository *r UNUSED, + const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *context UNUSED) { int len; diff --git a/builtin/log.c b/builtin/log.c index ee19dc5d450..608a448fe4d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -698,7 +698,9 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) return 0; } -static int show_tree_object(const struct object_id *oid UNUSED, +static int show_tree_object( + struct repository *r UNUSED, + const struct object_id *oid UNUSED, struct strbuf *base UNUSED, const char *pathname, unsigned mode, void *context) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 4cf8a236483..fbb07fa08c2 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -533,7 +533,9 @@ static int read_one_entry_opt(struct index_state *istate, return add_index_entry(istate, ce, opt); } -static int read_one_entry(const struct object_id *oid, struct strbuf *base, +static int read_one_entry( + struct repository *r UNUSED, + const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *context) { @@ -547,7 +549,9 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, * This is used when the caller knows there is no existing entries at * the stage that will conflict with the entry being added. */ -static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, +static int read_one_entry_quick( + struct repository *r UNUSED, + const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *context) { diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index c3ea09281af..dd571abad1c 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -141,8 +141,10 @@ static int show_recursive(const char *base, size_t baselen, const char *pathname return 0; } -static int show_tree_fmt(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *context UNUSED) +static int show_tree_fmt( + struct repository *r UNUSED, + const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, void *context UNUSED) { size_t baselen; int recurse = 0; @@ -211,9 +213,11 @@ static void show_tree_common_default_long(struct strbuf *base, strbuf_setlen(base, baselen); } -static int show_tree_default(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, - void *context UNUSED) +static int show_tree_default( + struct repository *r, + const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, + void *context UNUSED) { int early; int recurse; @@ -224,12 +228,14 @@ static int show_tree_default(const struct object_id *oid, struct strbuf *base, return early; printf("%06o %s %s\t", data.mode, type_name(data.type), - find_unique_abbrev(data.oid, abbrev)); + repo_find_unique_abbrev(r, data.oid, abbrev)); show_tree_common_default_long(base, pathname, data.base->len); return recurse; } -static int show_tree_long(const struct object_id *oid, struct strbuf *base, +static int show_tree_long( + struct repository *r, + const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *context UNUSED) { @@ -244,7 +250,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base, if (data.type == OBJ_BLOB) { unsigned long size; - if (oid_object_info(the_repository, data.oid, &size) == OBJ_BAD) + if (oid_object_info(r, data.oid, &size) == OBJ_BAD) xsnprintf(size_text, sizeof(size_text), "BAD"); else xsnprintf(size_text, sizeof(size_text), @@ -254,12 +260,14 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base, } printf("%06o %s %s %7s\t", data.mode, type_name(data.type), - find_unique_abbrev(data.oid, abbrev), size_text); + repo_find_unique_abbrev(r, data.oid, abbrev), size_text); show_tree_common_default_long(base, pathname, data.base->len); return recurse; } -static int show_tree_name_only(const struct object_id *oid, struct strbuf *base, +static int show_tree_name_only( + struct repository *r UNUSED, + const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *context UNUSED) { @@ -280,7 +288,9 @@ static int show_tree_name_only(const struct object_id *oid, struct strbuf *base, return recurse; } -static int show_tree_object(const struct object_id *oid, struct strbuf *base, +static int show_tree_object( + struct repository *r, + const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *context UNUSED) { @@ -292,7 +302,7 @@ static int show_tree_object(const struct object_id *oid, struct strbuf *base, if (early >= 0) return early; - printf("%s%c", find_unique_abbrev(oid, abbrev), line_termination); + printf("%s%c", repo_find_unique_abbrev(r, oid, abbrev), line_termination); return recurse; } diff --git a/merge-recursive.c b/merge-recursive.c index 4ddd3adea00..dccde276655 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -456,7 +456,9 @@ static void unpack_trees_finish(struct merge_options *opt) clear_unpack_trees_porcelain(&opt->priv->unpack_opts); } -static int save_files_dirs(const struct object_id *oid UNUSED, +static int save_files_dirs( + struct repository *r UNUSED, + const struct object_id *oid UNUSED, struct strbuf *base, const char *path, unsigned int mode, void *context) { diff --git a/sparse-index.c b/sparse-index.c index e4a54ce1943..4187c7ce9c4 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -232,7 +232,9 @@ static void set_index_entry(struct index_state *istate, int nr, struct cache_ent add_name_hash(istate, ce); } -static int add_path_to_index(const struct object_id *oid, +static int add_path_to_index( + struct repository *r UNUSED, + const struct object_id *oid, struct strbuf *base, const char *path, unsigned int mode, void *context) { diff --git a/t/helper/test-tree-read-tree-at.c b/t/helper/test-tree-read-tree-at.c index bba759bb264..d2bcc8c849a 100644 --- a/t/helper/test-tree-read-tree-at.c +++ b/t/helper/test-tree-read-tree-at.c @@ -6,7 +6,8 @@ We call it tree-read-tree-at to disambiguate with the read-tree tool. #include "test-tool.h" #include "tree.h" -static int test_handle_entry(const struct object_id *oid, +static int test_handle_entry( + struct repository *r UNUSED, const struct object_id *oid, struct strbuf *base, const char *filename, unsigned mode, void *context UNUSED) { printf("%i %s %s%s\n", mode, oid_to_hex(oid), base->buf, filename); diff --git a/tree.c b/tree.c index 2a087c010f9..17c3af819e2 100644 --- a/tree.c +++ b/tree.c @@ -38,7 +38,7 @@ int read_tree_at(struct repository *r, continue; } - switch (fn(&entry.oid, base, + switch (fn(r, &entry.oid, base, entry.path, entry.mode, context)) { case 0: continue; diff --git a/tree.h b/tree.h index cc6402e4738..94b1e11d9eb 100644 --- a/tree.h +++ b/tree.h @@ -37,7 +37,7 @@ struct tree *repo_parse_tree_indirect(struct repository *r, const struct object_ int cmp_cache_name_compare(const void *a_, const void *b_); #define READ_TREE_RECURSIVE 1 -typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, void *); +typedef int (*read_tree_fn_t)(struct repository *r, const struct object_id *, struct strbuf *, const char *, unsigned int, void *); int read_tree_at(struct repository *r, struct tree *tree, struct strbuf *base, diff --git a/wt-status.c b/wt-status.c index 5813174896c..cff2a780f32 100644 --- a/wt-status.c +++ b/wt-status.c @@ -665,7 +665,9 @@ static void wt_status_collect_changes_index(struct wt_status *s) release_revisions(&rev); } -static int add_file_to_list(const struct object_id *oid, +static int add_file_to_list( + struct repository *r UNUSED, + const struct object_id *oid, struct strbuf *base, const char *path, unsigned int mode, void *context) { From patchwork Mon Oct 17 02:23:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29AFCC4332F for ; Mon, 17 Oct 2022 02:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbiJQCXs (ORCPT ); Sun, 16 Oct 2022 22:23:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230188AbiJQCXc (ORCPT ); Sun, 16 Oct 2022 22:23:32 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C46444B3 for ; Sun, 16 Oct 2022 19:23:30 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id c3-20020a1c3503000000b003bd21e3dd7aso11748491wma.1 for ; Sun, 16 Oct 2022 19:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=5u8xPLS2v7BwRZyTpchM0gF0aTO+EpZNRYLutPsguao=; b=obH6Xe1H9mWa5ji2pfINit/0k6b0bivaGM0WVb5ehMWmT9dwoelo3303iu3C7i4QJ0 4kIGu0e7RQdPZm/x+McqcrPopNMBb1miD6HIAxPPX5PgQcjl9GnW2qGKoMMr/8xWZQUU tkhw8pVCyhe0wgoNbaSD2WUghU0MIEB75dLaV49gqFUL7unjiK9oIGbiutoyDCy5/Si0 2+7etIquLu+4nsu4nXI2pU9IdAkMo8W4+MHOuhLV5pz+6Qcf4B0pe25WTiScl2OgpCUY fvG67cFcUY9/kelYowZrUarxTTW3Lut905mVDJY2DAYQzWkI1t++M8gAhlxAtTCOjTrH dYrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5u8xPLS2v7BwRZyTpchM0gF0aTO+EpZNRYLutPsguao=; b=Dux4pZ3G1fhF8/Trdkqop3oP2E7qsWL5klA+7eCRYjBK5aUzczl9PuDS8RMHFPghpz qmGtGgD9Z/VMyWtdstbdX2sgNjd+Ii+KTSRhMn+08vwUdRT7t0VPw6IwFgDC0A9313yk l2oIjOa8y2THSHjL02jg3cR1GzaEg45EZ/k1hw2OSMbdFYn3xQnqeq5GXCo/Uo6xMzXy SURdHLKPTngyHpPIzWUOcsXBE4Yy0C5/a76wsMMw2Px8GG4EUtY8b3/ymp3gObqhMGie olgVpiyuVZQOSSVFhmCDL7Np4nBGN8IcytZtTls1cVMY9AVAIFyAGAE5zOjK/OuxdQIV iNYw== X-Gm-Message-State: ACrzQf1OPKd/fGiLyjvVYb3vLOC2t2n7RX4RD45lI3w1cPbork9bJrNT +HlVYh/O89YIuYxlENKRohIo4WFtAzY= X-Google-Smtp-Source: AMsMyM70xOH5857xeMqAbYKqp9U/vTGJdpyEH0/hdGnDSxRZvdh0zdh0iHC2lfDxV43jbe95t4MFXw== X-Received: by 2002:a05:600c:4410:b0:3c6:f04b:daa2 with SMTP id u16-20020a05600c441000b003c6f04bdaa2mr5760970wmn.186.1665973408865; Sun, 16 Oct 2022 19:23:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r16-20020a05600c35d000b003a84375d0d1sm14940183wmq.44.2022.10.16.19.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:28 -0700 (PDT) Message-Id: <1b9b049d64fc4ea919c94e57b74a1760b3837892.1665973401.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:18 +0000 Subject: [PATCH v3 6/9] archive: pass repo objects to write_archive handlers Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe Use contextual repos instead of the_repository or args->repo to ensure that submodules will be handled correctly since they use multiple repo instances. Signed-off-by: Heather Lapointe --- archive-tar.c | 15 ++++++++++----- archive-zip.c | 15 +++++++++------ archive.c | 38 ++++++++++++++++++++++---------------- archive.h | 14 +++++++++++--- 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/archive-tar.c b/archive-tar.c index 3e4822b6840..5a2d42ff229 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -18,6 +18,7 @@ static unsigned long offset; static int tar_umask = 002; static int write_tar_filter_archive(const struct archiver *ar, + struct repository *repo, struct archiver_args *args); /* @@ -246,7 +247,9 @@ static void write_extended_header(struct archiver_args *args, write_blocked(buffer, size); } -static int write_tar_entry(struct archiver_args *args, +static int write_tar_entry( + struct repository *repo, + struct archiver_args *args, const struct object_id *oid, const char *path, size_t pathlen, unsigned int mode, @@ -316,7 +319,7 @@ static int write_tar_entry(struct archiver_args *args, if (buffer) write_blocked(buffer, size); else - err = stream_blocked(args->repo, oid); + err = stream_blocked(repo, oid); } return err; } @@ -422,12 +425,13 @@ static int git_tar_config(const char *var, const char *value, void *cb) } static int write_tar_archive(const struct archiver *ar UNUSED, + struct repository *repo, struct archiver_args *args) { int err = 0; write_global_extended_header(args); - err = write_archive_entries(args, write_tar_entry); + err = write_archive_entries(repo, args, write_tar_entry); if (!err) write_trailer(); return err; @@ -462,6 +466,7 @@ static void tgz_write_block(const void *data) static const char internal_gzip_command[] = "git archive gzip"; static int write_tar_filter_archive(const struct archiver *ar, + struct repository *repo, struct archiver_args *args) { #if ZLIB_VERNUM >= 0x1221 @@ -484,7 +489,7 @@ static int write_tar_filter_archive(const struct archiver *ar, gzstream.next_out = outbuf; gzstream.avail_out = sizeof(outbuf); - r = write_tar_archive(ar, args); + r = write_tar_archive(ar, repo, args); tgz_deflate(Z_FINISH); git_deflate_end(&gzstream); @@ -506,7 +511,7 @@ static int write_tar_filter_archive(const struct archiver *ar, die_errno(_("unable to redirect descriptor")); close(filter.in); - r = write_tar_archive(ar, args); + r = write_tar_archive(ar, repo, args); close(1); if (finish_command(&filter) != 0) diff --git a/archive-zip.c b/archive-zip.c index 0456f1ebf15..2c1f943a6cc 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -283,7 +283,9 @@ static int entry_is_binary(struct index_state *istate, const char *path, #define STREAM_BUFFER_SIZE (1024 * 16) -static int write_zip_entry(struct archiver_args *args, +static int write_zip_entry( + struct repository *repo, + struct archiver_args *args, const struct object_id *oid, const char *path, size_t pathlen, unsigned int mode, @@ -340,7 +342,7 @@ static int write_zip_entry(struct archiver_args *args, if (!buffer) { enum object_type type; - stream = open_istream(args->repo, oid, &type, &size, + stream = open_istream(repo, oid, &type, &size, NULL); if (!stream) return error(_("cannot stream blob %s"), @@ -349,7 +351,7 @@ static int write_zip_entry(struct archiver_args *args, out = NULL; } else { crc = crc32(crc, buffer, size); - is_binary = entry_is_binary(args->repo->index, + is_binary = entry_is_binary(repo->index, path_without_prefix, buffer, size); out = buffer; @@ -426,7 +428,7 @@ static int write_zip_entry(struct archiver_args *args, break; crc = crc32(crc, buf, readlen); if (is_binary == -1) - is_binary = entry_is_binary(args->repo->index, + is_binary = entry_is_binary(repo->index, path_without_prefix, buf, readlen); write_or_die(1, buf, readlen); @@ -459,7 +461,7 @@ static int write_zip_entry(struct archiver_args *args, break; crc = crc32(crc, buf, readlen); if (is_binary == -1) - is_binary = entry_is_binary(args->repo->index, + is_binary = entry_is_binary(repo->index, path_without_prefix, buf, readlen); @@ -619,6 +621,7 @@ static int archive_zip_config(const char *var, const char *value, } static int write_zip_archive(const struct archiver *ar UNUSED, + struct repository *repo, struct archiver_args *args) { int err; @@ -629,7 +632,7 @@ static int write_zip_archive(const struct archiver *ar UNUSED, strbuf_init(&zip_dir, 0); - err = write_archive_entries(args, write_zip_entry); + err = write_archive_entries(repo, args, write_zip_entry); if (!err) write_zip_trailer(args->commit_oid); diff --git a/archive.c b/archive.c index 15f3ac92dfc..2cca7bc5c8a 100644 --- a/archive.c +++ b/archive.c @@ -134,7 +134,9 @@ static int check_attr_export_subst(const struct attr_check *check) return check && ATTR_TRUE(check->items[1].value); } -static int write_archive_entry(const struct object_id *oid, const char *base, +static int write_archive_entry( + struct repository *repo, + const struct object_id *oid, const char *base, int baselen, const char *filename, unsigned mode, void *context) { @@ -160,7 +162,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base, if (!S_ISDIR(mode)) { const struct attr_check *check; - check = get_archive_attrs(args->repo->index, path_without_prefix); + check = get_archive_attrs(repo->index, path_without_prefix); if (check_attr_export_ignore(check)) return 0; args->convert = check_attr_export_subst(check); @@ -169,7 +171,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base, if (S_ISDIR(mode) || S_ISGITLINK(mode)) { if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); - err = write_entry(args, oid, path.buf, path.len, mode, NULL, 0); + err = write_entry(repo, args, oid, path.buf, path.len, mode, NULL, 0); if (err) return err; return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); @@ -180,14 +182,14 @@ static int write_archive_entry(const struct object_id *oid, const char *base, /* Stream it? */ if (S_ISREG(mode) && !args->convert && - oid_object_info(args->repo, oid, &size) == OBJ_BLOB && + oid_object_info(repo, oid, &size) == OBJ_BLOB && size > big_file_threshold) - return write_entry(args, oid, path.buf, path.len, mode, NULL, size); + return write_entry(repo, args, oid, path.buf, path.len, mode, NULL, size); buffer = object_file_to_archive(args, path.buf, oid, mode, &type, &size); if (!buffer) return error(_("cannot read '%s'"), oid_to_hex(oid)); - err = write_entry(args, oid, path.buf, path.len, mode, buffer, size); + err = write_entry(repo, args, oid, path.buf, path.len, mode, buffer, size); free(buffer); return err; } @@ -207,7 +209,9 @@ static void queue_directory(const struct object_id *oid, oidcpy(&d->oid, oid); } -static int write_directory(struct archiver_context *c) +static int write_directory( + struct repository *repo, + struct archiver_context *c) { struct directory *d = c->bottom; int ret; @@ -217,8 +221,8 @@ static int write_directory(struct archiver_context *c) c->bottom = d->up; d->path[d->len - 1] = '\0'; /* no trailing slash */ ret = - write_directory(c) || - write_archive_entry(&d->oid, d->path, d->baselen, + write_directory(repo, c) || + write_archive_entry(repo, &d->oid, d->path, d->baselen, d->path + d->baselen, d->mode, c) != READ_TREE_RECURSIVE; free(d); @@ -257,9 +261,9 @@ static int queue_or_write_archive_entry( return READ_TREE_RECURSIVE; } - if (write_directory(c)) + if (write_directory(r, c)) return -1; - return write_archive_entry(oid, base->buf, base->len, filename, mode, + return write_archive_entry(r, oid, base->buf, base->len, filename, mode, context); } @@ -269,7 +273,9 @@ struct extra_file_info { void *content; }; -int write_archive_entries(struct archiver_args *args, +int write_archive_entries( + struct repository *repo, + struct archiver_args *args, write_archive_entry_fn_t write_entry) { struct archiver_context context; @@ -290,7 +296,7 @@ int write_archive_entries(struct archiver_args *args, len--; if (args->verbose) fprintf(stderr, "%.*s\n", (int)len, args->base); - err = write_entry(args, &args->tree->object.oid, args->base, + err = write_entry(repo, args, &args->tree->object.oid, args->base, len, 040777, NULL, 0); if (err) return err; @@ -345,12 +351,12 @@ int write_archive_entries(struct archiver_args *args, if (strbuf_read_file(&content, path, info->stat.st_size) < 0) err = error_errno(_("cannot read '%s'"), path); else - err = write_entry(args, &fake_oid, path_in_archive.buf, + err = write_entry(repo, args, &fake_oid, path_in_archive.buf, path_in_archive.len, canon_mode(info->stat.st_mode), content.buf, content.len); } else { - err = write_entry(args, &fake_oid, + err = write_entry(repo, args, &fake_oid, path, strlen(path), canon_mode(info->stat.st_mode), info->content, info->stat.st_size); @@ -711,7 +717,7 @@ int write_archive(int argc, const char **argv, const char *prefix, parse_treeish_arg(argv, &args, prefix, remote); parse_pathspec_arg(argv + 1, &args); - rc = ar->write_archive(ar, &args); + rc = ar->write_archive(ar, repo, &args); string_list_clear_func(&args.extra_files, extra_file_info_clear); free(args.refname); diff --git a/archive.h b/archive.h index 08bed3ed3af..bfbbd3274bd 100644 --- a/archive.h +++ b/archive.h @@ -41,7 +41,10 @@ const char *archive_format_from_filename(const char *filename); #define ARCHIVER_HIGH_COMPRESSION_LEVELS 4 struct archiver { const char *name; - int (*write_archive)(const struct archiver *, struct archiver_args *); + int (*write_archive)( + const struct archiver *, + struct repository *, + struct archiver_args *); unsigned flags; char *filter_command; }; @@ -51,12 +54,17 @@ void init_tar_archiver(void); void init_zip_archiver(void); void init_archivers(void); -typedef int (*write_archive_entry_fn_t)(struct archiver_args *args, +typedef int (*write_archive_entry_fn_t)( + struct repository *repo, + struct archiver_args *args, const struct object_id *oid, const char *path, size_t pathlen, unsigned int mode, void *buffer, unsigned long size); -int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry); +int write_archive_entries( + struct repository *repo, + struct archiver_args *args, + write_archive_entry_fn_t write_entry); #endif /* ARCHIVE_H */ From patchwork Mon Oct 17 02:23:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008108 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36A1BC4332F for ; Mon, 17 Oct 2022 02:23:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbiJQCXx (ORCPT ); Sun, 16 Oct 2022 22:23:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbiJQCXd (ORCPT ); Sun, 16 Oct 2022 22:23:33 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 938E5444B4 for ; Sun, 16 Oct 2022 19:23:31 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id az22-20020a05600c601600b003c6b72797fdso8995415wmb.5 for ; Sun, 16 Oct 2022 19:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=FzkqgSkNQdq8N4dpFhyWqulPwP1qvPc/RRAdLMJF8cY=; b=n4okneeSG0cs6jJk0/7pA5McYudRFr+ZLPlUmPoueOnT55R7bo04xU08UJJ+lX/iGY RnVhNjZBK9lCYzGYYu0Sb5uTVmH60uWAXgLDi0WfJOaqxCwbs1Ub7GbpD+E2h+rdh6bF SqHdC6UcxVY2XE+KfBlaT71Mqf5oGnBR7gSc3LAFsu3VTZylCrebCHjjk1kbaec2x2qa 6vEgml21zHFGZtwAC7HYBonDUmI+p4M9YOidsxEtpFO/YYGSAJn2WQWrJ5yryhPGBgvw w9n+e1IsFHcJm7//Ug62wjP8vR3Q+L+EYjiAXiTlEDVE56wTmYtE2Dj4uUcfL+fzWNBh lZ7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzkqgSkNQdq8N4dpFhyWqulPwP1qvPc/RRAdLMJF8cY=; b=I7g4xcC0PjdqDnr20nBOnQG5NOesATJkQPrab/Tb/5Yr2Q++hlCC0c6G3GtUh4TRDt EUYcx5PjLX07R1qxm2v8T1xMpPa+aIokhkaaK28UXas6RRRgzhkbPjK+FrmVCVTBI2Un MXSVg8Lh8hmoD35vX7yB42Hwq617uK9i+6jwMFcfjw0B3QFD8sB6zqpRgC21Yf8Quq9l U00Zh7wY23ipUCzpmxIxFWLikj48ZGJVO2xrVNdNJlhpXjtnnwUA/J1bCImL+5alWQFj Yg0WHa2EXukTb4pUp/KJqjRt2GjgYmGcbhRvuiKmOdot8oL0+1uB2WHJIExm90aFnCnl dL5g== X-Gm-Message-State: ACrzQf07IDNHeo6YjaLuKcmKNtd+Pn28LXaMuvnXd/4FP6KfaKc5iIGj m60g5FARXlfs8STnVDiNHr3CE6Ms9E8= X-Google-Smtp-Source: AMsMyM7TJS7R8lxZJPTCYpggYiRLB6VWLhK86kInjVlZ4AQW/u7FUIM+Vo277lQASNCwmUiyuN9efQ== X-Received: by 2002:a05:600c:654f:b0:3c4:271b:6b35 with SMTP id dn15-20020a05600c654f00b003c4271b6b35mr5434987wmb.182.1665973409917; Sun, 16 Oct 2022 19:23:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x6-20020a5d54c6000000b0022e2c38f8basm7155822wrv.14.2022.10.16.19.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:29 -0700 (PDT) Message-Id: <2443c9b1b6efce4340f01930c179d2fafbc5bbb3.1665973401.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:19 +0000 Subject: [PATCH v3 7/9] archive: remove global repository from archive_args Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe Remove archive_args.repo to ensure all functions are using local repository instances. Since all functions now have access to repo, this access isn't needed anymore. The main issue is that submodules do not use the same repo as the subproject repo that is being passed around contextually. Signed-off-by: Heather Lapointe --- archive.c | 51 +++++++++++++++++++++++++++++---------------------- archive.h | 1 - 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/archive.c b/archive.c index 2cca7bc5c8a..34549d849f1 100644 --- a/archive.c +++ b/archive.c @@ -36,7 +36,9 @@ void init_archivers(void) init_zip_archiver(); } -static void format_subst(const struct commit *commit, +static void format_subst( + struct repository *repo, + const struct commit *commit, const char *src, size_t len, struct strbuf *buf, struct pretty_print_context *ctx) { @@ -59,7 +61,7 @@ static void format_subst(const struct commit *commit, strbuf_add(&fmt, b + 8, c - b - 8); strbuf_add(buf, src, b - src); - format_commit_message(commit, fmt.buf, buf, ctx); + repo_format_commit_message(repo, commit, fmt.buf, buf, ctx); len -= c + 1 - src; src = c + 1; } @@ -68,7 +70,9 @@ static void format_subst(const struct commit *commit, free(to_free); } -static void *object_file_to_archive(const struct archiver_args *args, +static void *object_file_to_archive( + struct repository *repo, + const struct archiver_args *args, const char *path, const struct object_id *oid, unsigned int mode, @@ -84,15 +88,15 @@ static void *object_file_to_archive(const struct archiver_args *args, (args->tree ? &args->tree->object.oid : NULL), oid); path += args->baselen; - buffer = read_object_file(oid, type, sizep); + buffer = repo_read_object_file(repo, oid, type, sizep); if (buffer && S_ISREG(mode)) { struct strbuf buf = STRBUF_INIT; size_t size = 0; strbuf_attach(&buf, buffer, *sizep, *sizep + 1); - convert_to_working_tree(args->repo->index, path, buf.buf, buf.len, &buf, &meta); + convert_to_working_tree(repo->index, path, buf.buf, buf.len, &buf, &meta); if (commit) - format_subst(commit, buf.buf, buf.len, &buf, args->pretty_ctx); + format_subst(repo, commit, buf.buf, buf.len, &buf, args->pretty_ctx); buffer = strbuf_detach(&buf, &size); *sizep = size; } @@ -186,7 +190,7 @@ static int write_archive_entry( size > big_file_threshold) return write_entry(repo, args, oid, path.buf, path.len, mode, NULL, size); - buffer = object_file_to_archive(args, path.buf, oid, mode, &type, &size); + buffer = object_file_to_archive(repo, args, path.buf, oid, mode, &type, &size); if (!buffer) return error(_("cannot read '%s'"), oid_to_hex(oid)); err = write_entry(repo, args, oid, path.buf, path.len, mode, buffer, size); @@ -313,8 +317,8 @@ int write_archive_entries( memset(&opts, 0, sizeof(opts)); opts.index_only = 1; opts.head_idx = -1; - opts.src_index = args->repo->index; - opts.dst_index = args->repo->index; + opts.src_index = repo->index; + opts.dst_index = repo->index; opts.fn = oneway_merge; init_tree_desc(&t, args->tree->buffer, args->tree->size); if (unpack_trees(1, &t, &opts)) @@ -322,7 +326,7 @@ int write_archive_entries( git_attr_set_direction(GIT_ATTR_INDEX); } - err = read_tree(args->repo, args->tree, + err = read_tree(repo, args->tree, &args->pathspec, queue_or_write_archive_entry, &context); @@ -412,7 +416,7 @@ static int reject_entry( return ret; } -static int path_exists(struct archiver_args *args, const char *path) +static int path_exists(struct repository *repo, struct archiver_args *args, const char *path) { const char *paths[] = { path, NULL }; struct path_exists_context ctx; @@ -421,14 +425,16 @@ static int path_exists(struct archiver_args *args, const char *path) ctx.args = args; parse_pathspec(&ctx.pathspec, 0, 0, "", paths); ctx.pathspec.recursive = 1; - ret = read_tree(args->repo, args->tree, + ret = read_tree(repo, args->tree, &ctx.pathspec, reject_entry, &ctx); clear_pathspec(&ctx.pathspec); return ret != 0; } -static void parse_pathspec_arg(const char **pathspec, +static void parse_pathspec_arg( + struct repository *repo, + const char **pathspec, struct archiver_args *ar_args) { /* @@ -442,14 +448,16 @@ static void parse_pathspec_arg(const char **pathspec, ar_args->pathspec.recursive = 1; if (pathspec) { while (*pathspec) { - if (**pathspec && !path_exists(ar_args, *pathspec)) + if (**pathspec && !path_exists(repo, ar_args, *pathspec)) die(_("pathspec '%s' did not match any files"), *pathspec); pathspec++; } } } -static void parse_treeish_arg(const char **argv, +static void parse_treeish_arg( + struct repository *repo, + const char **argv, struct archiver_args *ar_args, const char *prefix, int remote) { @@ -475,7 +483,7 @@ static void parse_treeish_arg(const char **argv, if (get_oid(name, &oid)) die(_("not a valid object name: %s"), name); - commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1); + commit = lookup_commit_reference_gently(repo, &oid, 1); if (commit) { commit_oid = &commit->object.oid; archive_time = commit->date; @@ -484,7 +492,7 @@ static void parse_treeish_arg(const char **argv, archive_time = time(NULL); } - tree = parse_tree_indirect(&oid); + tree = repo_parse_tree_indirect(repo, &oid); if (!tree) die(_("not a tree object: %s"), oid_to_hex(&oid)); @@ -493,14 +501,14 @@ static void parse_treeish_arg(const char **argv, unsigned short mode; int err; - err = get_tree_entry(ar_args->repo, + err = get_tree_entry(repo, &tree->object.oid, prefix, &tree_oid, &mode); if (err || !S_ISDIR(mode)) die(_("current working directory is untracked")); - tree = parse_tree_indirect(&tree_oid); + tree = repo_parse_tree_indirect(repo, &tree_oid); } ar_args->refname = ref; ar_args->tree = tree; @@ -701,7 +709,6 @@ int write_archive(int argc, const char **argv, const char *prefix, ctx.abbrev = DEFAULT_ABBREV; ctx.describe_status = &describe_status; args.pretty_ctx = &ctx; - args.repo = repo; args.prefix = prefix; string_list_init_dup(&args.extra_files); argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote); @@ -714,8 +721,8 @@ int write_archive(int argc, const char **argv, const char *prefix, setup_git_directory(); } - parse_treeish_arg(argv, &args, prefix, remote); - parse_pathspec_arg(argv + 1, &args); + parse_treeish_arg(repo, argv, &args, prefix, remote); + parse_pathspec_arg(repo, argv + 1, &args); rc = ar->write_archive(ar, repo, &args); diff --git a/archive.h b/archive.h index bfbbd3274bd..540a3b12130 100644 --- a/archive.h +++ b/archive.h @@ -8,7 +8,6 @@ struct repository; struct pretty_print_context; struct archiver_args { - struct repository *repo; char *refname; const char *prefix; const char *base; From patchwork Mon Oct 17 02:23:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008110 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 504C0C4332F for ; Mon, 17 Oct 2022 02:23:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230203AbiJQCX5 (ORCPT ); Sun, 16 Oct 2022 22:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbiJQCXe (ORCPT ); Sun, 16 Oct 2022 22:23:34 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8385C2C66A for ; Sun, 16 Oct 2022 19:23:32 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id bp11so16407819wrb.9 for ; Sun, 16 Oct 2022 19:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=hbHU69GkfyEQzRT4xm0Puy2ehVoFdYZ5dmmHFRr40ro=; b=SBEZu7SiyuEh3KXZ6PE7lcduLhASeb1w/J1rm1gCTMqk9FshoCvaYL8kSb668+bg9u xbQPSj/MpokF8TKajzE9I/exHHLyFiWsNnlgmsutmaa8i4vGcqcliaXDz5pF/SkAUN8t 7zCN7rsp8ppvk6Yf9O7v6DSN/2vZDXu5+rF5JBSbM0Tme+zYNMRzCd8753H5hetWd/r1 /HO6ei/0aajeenktk51ufzuLdOHfTx1Y0Bojmvs4CcScr864kpI5J8F90aS6zq6SKQ10 Pvaqr30M4cHYyzWQ5jFDFHeRfXp7+CgzuWFN1crnmzyYs3aE5RDhPgtHIXzt7rAtT0BW BG/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hbHU69GkfyEQzRT4xm0Puy2ehVoFdYZ5dmmHFRr40ro=; b=LUj159CKI8FCTwiqOFInM97OicvmOiLEaqjxPM4Hpr3nBFSaCfdIbS9nEr0S3PXDTl oQOkGZTRZdPYbfuBQQQG8lWEn0Iga53drKq01t0po54LEsaGd4IiGsqVfHcFf1XZeDfs A35OvmgA++O9zE6OUCTZ65gFGmT1EDokIQrh16CwOxXbEwa68+0Kr7vXNuJswlo8q+av rvMq10K6L0VO+3CFndvCrKKg3FrFgcny9bwErqaoBPJNVEbNwq7DQPA6San8pVZYbrWY t4uVRD4/TaIanS9aPvU5IBIFO7gqWBWCa1NDJHq6QkoFGp9/kC/irwoncA8+Qde1yTbB 7tPg== X-Gm-Message-State: ACrzQf0UL/PdVMSRywtj8QBr4X/xEM1PCS3W6mrk1RSDeBushOB8CZGa qMrHmdA6kyA9FsUjjN3NO51bXU27Jq4= X-Google-Smtp-Source: AMsMyM7Q9Ws1pwrj/5qw4phkHYLOjPyQN9CAUbnxXezMCMI3GrmxOvkTuafPVjiyMlSTbReUtdndhg== X-Received: by 2002:a05:6000:2c9:b0:22f:e7b5:bc26 with SMTP id o9-20020a05600002c900b0022fe7b5bc26mr4578668wry.149.1665973410833; Sun, 16 Oct 2022 19:23:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j28-20020a5d6e5c000000b0022cd27bc8c1sm8991852wrz.9.2022.10.16.19.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:30 -0700 (PDT) Message-Id: <4672e3d958625cd76eb8056ab434e9a37f52661e.1665973401.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:20 +0000 Subject: [PATCH v3 8/9] archive: add --recurse-submodules to git-archive command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe This makes it possible to include submodule contents in an archive command. The default behavior remains the same, do not write submodule contents to the resulting archive. Signed-off-by: Heather Lapointe --- Documentation/git-archive.txt | 6 +++++- archive.c | 36 +++++++++++++++++++++++++++++++++-- archive.h | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt index 60c040988bb..22f54428b98 100644 --- a/Documentation/git-archive.txt +++ b/Documentation/git-archive.txt @@ -10,7 +10,8 @@ SYNOPSIS -------- [verse] 'git archive' [--format=] [--list] [--prefix=/] [] - [-o | --output=] [--worktree-attributes] + [-o | --output=] + [--recurse-submodules] [--worktree-attributes] [--remote= [--exec=]] [...] @@ -82,6 +83,9 @@ The file mode is limited to a regular file, and the option may be subject to platform-dependent command-line limits. For non-trivial cases, write an untracked file and use `--add-file` instead. +--recurse-submodules + Include submodules recursively in archive. + --worktree-attributes:: Look for attributes in .gitattributes files in the working tree as well (see <>). diff --git a/archive.c b/archive.c index 34549d849f1..f81ef741487 100644 --- a/archive.c +++ b/archive.c @@ -10,6 +10,7 @@ #include "unpack-trees.h" #include "dir.h" #include "quote.h" +#include "submodule.h" static char const * const archive_usage[] = { N_("git archive [] [...]"), @@ -213,6 +214,25 @@ static void queue_directory(const struct object_id *oid, oidcpy(&d->oid, oid); } +static void queue_submodule( + struct repository *superproject, + const struct object_id *oid, + struct strbuf *base, const char *filename, + unsigned mode, struct archiver_context *c) +{ + struct repository subrepo; + + if (repo_submodule_init(&subrepo, superproject, filename, null_oid())) + return; + + if (repo_read_index(&subrepo) < 0) + die("index file corrupt"); + + queue_directory(oid, base, filename, mode, c); + + repo_clear(&subrepo); +} + static int write_directory( struct repository *repo, struct archiver_context *c) @@ -228,9 +248,11 @@ static int write_directory( write_directory(repo, c) || write_archive_entry(repo, &d->oid, d->path, d->baselen, d->path + d->baselen, d->mode, - c) != READ_TREE_RECURSIVE; + c); free(d); - return ret ? -1 : 0; + if (ret == READ_TREE_RECURSIVE) + return 0; + return ret; } static int queue_or_write_archive_entry( @@ -263,6 +285,11 @@ static int queue_or_write_archive_entry( return 0; queue_directory(oid, base, filename, mode, c); return READ_TREE_RECURSIVE; + } else if (c->args->recurse_submodules && S_ISGITLINK(mode)) { + if (is_submodule_active(r, filename)) { + queue_submodule(r, oid, base, filename, mode, c); + return READ_TREE_RECURSIVE; + } } if (write_directory(r, c)) @@ -446,6 +473,7 @@ static void parse_pathspec_arg( PATHSPEC_PREFER_FULL, "", pathspec); ar_args->pathspec.recursive = 1; + ar_args->pathspec.recurse_submodules = ar_args->recurse_submodules; if (pathspec) { while (*pathspec) { if (**pathspec && !path_exists(repo, ar_args, *pathspec)) @@ -609,6 +637,7 @@ static int parse_archive_args(int argc, const char **argv, int verbose = 0; int i; int list = 0; + int recurse_submodules = 0; int worktree_attributes = 0; struct option opts[] = { OPT_GROUP(""), @@ -623,6 +652,8 @@ static int parse_archive_args(int argc, const char **argv, add_file_cb, (intptr_t)&base }, OPT_STRING('o', "output", &output, N_("file"), N_("write the archive to this file")), + OPT_BOOL(0, "recurse-submodules", &recurse_submodules, + N_("include submodules in archive")), OPT_BOOL(0, "worktree-attributes", &worktree_attributes, N_("read .gitattributes in working directory")), OPT__VERBOSE(&verbose, N_("report archived files on stderr")), @@ -686,6 +717,7 @@ static int parse_archive_args(int argc, const char **argv, args->verbose = verbose; args->base = base; args->baselen = strlen(base); + args->recurse_submodules = recurse_submodules; args->worktree_attributes = worktree_attributes; return argc; diff --git a/archive.h b/archive.h index 540a3b12130..1b21484dda6 100644 --- a/archive.h +++ b/archive.h @@ -18,6 +18,7 @@ struct archiver_args { timestamp_t time; struct pathspec pathspec; unsigned int verbose : 1; + unsigned int recurse_submodules : 1; unsigned int worktree_attributes : 1; unsigned int convert : 1; int compression_level; From patchwork Mon Oct 17 02:23:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heather Lapointe X-Patchwork-Id: 13008109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90BE7C433FE for ; Mon, 17 Oct 2022 02:23:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbiJQCXy (ORCPT ); Sun, 16 Oct 2022 22:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbiJQCXe (ORCPT ); Sun, 16 Oct 2022 22:23:34 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EF3A4448F for ; Sun, 16 Oct 2022 19:23:32 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id j16so16438199wrh.5 for ; Sun, 16 Oct 2022 19:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=61z3BnFxwNixLm06cVJ5YahQgEauGr51Bc0NXdcN05U=; b=LJsPEpv/Pug0CQL0lw0yC82DUZC9OXluRc8T5jiLAGlAQl6NSb+M2eA0UUW4Yuzo4T ZaczVC84niM0OtWNT9wdRu2BAt/83OxN6BtvMOPEiGM1HBDu/0A5tkmBIFG3y8KRXWf8 JqVVuj0zmoXemOKJ6pGrGm342HFv8QTRn5qAdzGadxZgbWosUEd+3QrplHMDlTTWljbD sHPA2fdQVWeLJuKLcuxupOuMkEhz5HPYEjXa+QQUUw4Vm1blQ/pgUD0xiQ6drCbP/9NW pwav8CRKLyWi8qk9a3MXX61Lc6vIioaj08TKx24yJ87Ik3BK8wNBCnpiQpjnJtQl/2b2 EofQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=61z3BnFxwNixLm06cVJ5YahQgEauGr51Bc0NXdcN05U=; b=3UQZbHx9sI6/fOzY79BrslZIMv3rFJfHnyPyJ9/of4cLMvl1aJkfvgb30fbariWkuY UJW6Da1VrEbGG3cxbq6vqalhT1Gtw92Dffo85hx+ftTLDLAEBTy98MoDZ2d6X4k9VVzn 0HxTpGQDOQsiBYVxmkKZo3nTvKtOw+94YqHlGd3mELBZIzMPRPVB4sKsUznvhnWb8+2Q DJfqXLlVrpF97dt6v5D71eoZiddZA/GLKB1qzGXdQ8gNh+ZJnWC5Y6fpEDw/Y1HGNTBB rhluyLZD7xTMT/mDzgCcmP7hnxkYWHpq5CSlTJrJsBQvQz2F8wiyr2UsGFrov9S8zGLk Hn0g== X-Gm-Message-State: ACrzQf07oR9obWKkezHUuzzBHFsBL+DwwRKyGJbfD2ZZu/liYp55JQ5N 01EWrJrvYt96G1qUtOxyx9Tn3pEtGJs= X-Google-Smtp-Source: AMsMyM74H+lOHNaCMhImwCrA7DH99HIv1+FRm+z8uFQdD//C4ckyxN9bQCDjjrcO9qhwkElamBVXXQ== X-Received: by 2002:adf:f407:0:b0:22e:5848:f6b with SMTP id g7-20020adff407000000b0022e58480f6bmr4627101wro.46.1665973411894; Sun, 16 Oct 2022 19:23:31 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l32-20020a05600c1d2000b003b47b913901sm24960799wms.1.2022.10.16.19.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 19:23:31 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 17 Oct 2022 02:23:21 +0000 Subject: [PATCH v3 9/9] archive: add tests for git archive --recurse-submodules Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Heather Lapointe , Heather Lapointe Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Heather Lapointe From: Heather Lapointe Ensuring functionality works with and without submodules. We expect --recurse-submodules to fail if there are uninitialized submodules present. Signed-off-by: Heather Lapointe --- archive.c | 2 +- t/t5005-archive-submodules.sh | 83 +++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100755 t/t5005-archive-submodules.sh diff --git a/archive.c b/archive.c index f81ef741487..b0a3181f7f5 100644 --- a/archive.c +++ b/archive.c @@ -179,7 +179,7 @@ static int write_archive_entry( err = write_entry(repo, args, oid, path.buf, path.len, mode, NULL, 0); if (err) return err; - return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); + return READ_TREE_RECURSIVE; } if (args->verbose) diff --git a/t/t5005-archive-submodules.sh b/t/t5005-archive-submodules.sh new file mode 100755 index 00000000000..aad6cfd1082 --- /dev/null +++ b/t/t5005-archive-submodules.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +test_description='git archive --recurse-submodules test' + +. ./test-lib.sh + +check_tar() { + tarfile=$1.tar + listfile=$1.lst + dir=$1 + dir_with_prefix=$dir/$2 + + test_expect_success ' extract tar archive' ' + (mkdir $dir && cd $dir && "$TAR" xf -) <$tarfile + ' +} + +check_added() { + dir=$1 + path_in_fs=$2 + path_in_archive=$3 + + test_expect_success " validate extra file $path_in_archive" ' + test -f $dir/$path_in_archive && + diff -r $path_in_fs $dir/$path_in_archive + ' +} + +check_not_added() { + dir=$1 + path_in_archive=$2 + + test_expect_success " validate unpresent file $path_in_archive" ' + ! test -f $dir/$path_in_archive && + ! test -d $dir/$path_in_archive + ' +} + +test_expect_success 'setup' ' + rm -rf repo_with_submodules submodule1 uninited_repo_with_submodules && + git init repo_with_submodules && + git init submodule1 && + ( + cd submodule1 && + echo "dir1/sub1/file1.txt" > "file1.txt" && + git add file1.txt && + git commit -m "initialize with file1.txt" + ) && + ( + cd repo_with_submodules && + echo "file2" > file2.txt && + git add file2.txt && + git commit -m "initialize with file2.txt" && + mkdir -p dir1 && + git submodule add ../submodule1 dir1/sub1 && + git commit -m "add submodule1" + ) && + git clone repo_with_submodules uninited_repo_with_submodules +' + +test_expect_success 'archive without recurse, non-init' ' + git -C uninited_repo_with_submodules archive -v HEAD >b.tar +' + +check_tar b +check_added b uninited_repo_with_submodules/file2.txt file2.txt +check_not_added b uninited_repo_with_submodules/dir1/sub1/file1.txt + +# It is expected that --recurse-submodules will not work if submodules are not +# initialized. +test_expect_success 'archive with recurse, non-init' ' + ! git -C uninited_repo_with_submodules archive --recurse-submodules -v HEAD >b2-err.tar +' + +test_expect_success 'archive with recurse, init' ' + git -C repo_with_submodules archive --recurse-submodules -v HEAD >b3.tar +' + +check_tar b3 +check_added b3 repo_with_submodules/file2.txt file2.txt +check_added b3 repo_with_submodules/dir1/sub1/file1.txt dir1/sub1/file1.txt + +test_done