From patchwork Tue Mar 16 15:52:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4761CC43331 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2233165113 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238113AbhCPPxY (ORCPT ); Tue, 16 Mar 2021 11:53:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232073AbhCPPwu (ORCPT ); Tue, 16 Mar 2021 11:52:50 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39E3C061756 for ; Tue, 16 Mar 2021 08:52:49 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id g8so10384908wmd.4 for ; Tue, 16 Mar 2021 08:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T2L0S2igmKi6FvEX0L358Snc+OKCCR/yehnzxL1/Mr4=; b=ocwMKuVHRsJjky3vylCZGakKAvgKULh8NIkkVk2o6RXrvly0u4kgTCGQsnCB3OcjNZ RkEVPQNO+pj1HiCBHIB4QKBatZtDFT4HJrtYytUhthKrQeRs7j800PCdSY4niMijJSmX Vk12CqSHfpqIly7esuf+Du9tDnulQuqwDEaKWBRyO0ymWSmXSrmdF6FnpEJDAUoEdsrA 4GvW1w4wLdRtXB+gTSlXIf05gL+mB+ySD8OMGwokImyAAAS8dSREeM6Bccd69ZqurN3E 5pX825ykF73uHRxevAAQvJVyJZK6WF886O99aVx88G8tqqfIgcE/g/5H9XQlICqodk7g a7ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T2L0S2igmKi6FvEX0L358Snc+OKCCR/yehnzxL1/Mr4=; b=bNepLjpzfVLIBrAJYVvZxLJY1HldkXR+tkVdz3sGEQDRTEK/l7uI0YPgfzI1C7+Yud MU2dG4PXtVGKQjlBpwhkkhFES/rdYXU3qb+O5x/RmhmioePmwfpukxhjiJQ7J23nqrZA mL5avCG55A6/g6RDDd+hij9LxOuFmdnVUHW5UzeK80f7Zgq+k5/QZA5M2gK+1+OpuNf+ 4VxiiDeSUEbGVnY+rJPQwclwZw/KCT/4JYLHDY6DnIPLV+U0ijsSdpR+S7MtlON8Rxkm 6cOknkVkXr6lVYTf0ustgmVBclihKUcYb2YIOZUrnjW3rRxcDkLAlHSFBn36LRB4ESj1 TVwg== X-Gm-Message-State: AOAM5333vMQ2fNrHiZiBqz3GV85f/Mh9044btEzqhEF2EYcsT7q0eL7r N19FoHV7lsDhGxTN0K97t4rs81RmklDD4Q== X-Google-Smtp-Source: ABdhPJxYvyUjrPyaUghd3TE2WdnnS76N+ARxPAE9jY97K3BtVKlznSGwyqcqq7e8Rz2oPOMbQVF5QQ== X-Received: by 2002:a1c:400b:: with SMTP id n11mr253382wma.167.1615909968388; Tue, 16 Mar 2021 08:52:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 1/9] ls-files tests: add meaningful --with-tree tests Date: Tue, 16 Mar 2021 16:52:36 +0100 Message-Id: <20210316155244.28328-2-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add tests for "ls-files --with-tree". There was effectively no coverage for any normal usage of this command, only the tests added in 54e1abce90e (Add test case for ls-files --with-tree, 2007-10-03) for an obscure bug. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3060-ls-files-with-tree.sh | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/t/t3060-ls-files-with-tree.sh b/t/t3060-ls-files-with-tree.sh index 52ed665fcd..b257c792a4 100755 --- a/t/t3060-ls-files-with-tree.sh +++ b/t/t3060-ls-files-with-tree.sh @@ -47,6 +47,12 @@ test_expect_success setup ' git add . ' +test_expect_success 'usage' ' + test_expect_code 128 git ls-files --with-tree=HEAD -u && + test_expect_code 128 git ls-files --with-tree=HEAD -s && + test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD +' + test_expect_success 'git ls-files --with-tree should succeed from subdir' ' # We have to run from a sub-directory to trigger prune_path # Then we finally get to run our --with-tree test @@ -60,4 +66,39 @@ test_expect_success \ 'git ls-files --with-tree should add entries from named tree.' \ 'test_cmp expected output' +test_expect_success 'no duplicates in --with-tree output' ' + git ls-files --with-tree=HEAD >actual && + sort -u actual >expected && + test_cmp expected actual +' + +test_expect_success 'setup: output in a conflict' ' + test_create_repo conflict && + test_commit -C conflict BASE file && + test_commit -C conflict A file foo && + git -C conflict reset --hard BASE && + test_commit -C conflict B file bar +' + +test_expect_success 'output in a conflict' ' + test_must_fail git -C conflict merge A B && + cat >expected <<-\EOF && + file + file + file + file + EOF + git -C conflict ls-files --with-tree=HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'output with removed .git/index' ' + cat >expected <<-\EOF && + file + EOF + rm conflict/.git/index && + git -C conflict ls-files --with-tree=HEAD >actual && + test_cmp expected actual +' + test_done From patchwork Tue Mar 16 15:52:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6710C4332E for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E54B65101 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232666AbhCPPxZ (ORCPT ); Tue, 16 Mar 2021 11:53:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232057AbhCPPwv (ORCPT ); Tue, 16 Mar 2021 11:52:51 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8CECC06175F for ; Tue, 16 Mar 2021 08:52:50 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id p19so1444723wmq.1 for ; Tue, 16 Mar 2021 08:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=743W/QEa8d/zq2m4gyKfupVsy7XyaAWgf8DgagVsVlA=; b=WkzWRfZK/1SK6uYbIFMM+mgE34ZMKd4lS9QRn2iQulMPo4EpDQVXDTTo6nAcTH8d/c PPZoXlARdZ4GmBWQJYqau8AWiezYvsxiuaHUXqsn8OlJRGalXIQxS9zPTATWHijrHvyg KrYGMqUOYnOFS+kNybF7vYdPg5Dq6trMcyQoWEcm3c9GJf0wl41S6rDH1Nywa+H2nknK mbItu9F2ZInlNIefbqtaMwEJRMqKxdHfvsAOA44oC85C0awfzbR2nBjD8et0LINLrJbq Yj8KP2g/qwqsKoY91FuAWYqZwszQVABNRtpgIX2N7M3r66Sj2BlVFXK5NqtQ7NveRfPr POdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=743W/QEa8d/zq2m4gyKfupVsy7XyaAWgf8DgagVsVlA=; b=LzR5YpO51BAIDnuHVbeUWqzQ2kUu7aSD3E3kLqHZ+meTn/ZU69KxFjjsdRO1gm576S fod53NNhxEMOEGI4AlRTzBW1HgKTg+d5GDMTD70vYZdVFAs2YzVqqBg+UcxJJtG3X4JX fxfgrqhg4c7fCkbw2fFmqYHtzgVU9eRHu6RTZtC/lIfxBU4ykthbzHP5bOvRde1MuQBt CSUHdPdlgKBd4ZAqpzSYD4qF6aqT1fGeDuD06NcFOlZZkA51sYajCrM43MRb17sGLMZh FzVYAh75ncunjlKxnWI5H7gTbIpm25VvIJ4IDp/2BR6xAH/RPR63NyuftvxCLIrcHJX3 CbfA== X-Gm-Message-State: AOAM531gBKQozo1e7O2a4aK4yEM2U9UvzLTGi14Pt+3n0I2Oy0uq3h2R fm6Y88jTcOuxzFD2E9UcNsNl9Smwo+xv7w== X-Google-Smtp-Source: ABdhPJzkPAeMeEOLeuzfj08p5XGp6hB+Ge6xO1rUwdCy6vZCMJKga589I08XoSNLKQ3+f0oUs25mtQ== X-Received: by 2002:a1c:6a05:: with SMTP id f5mr269774wmc.75.1615909969314; Tue, 16 Mar 2021 08:52:49 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 2/9] tree.c API: move read_tree() into builtin/ls-files.c Date: Tue, 16 Mar 2021 16:52:37 +0100 Message-Id: <20210316155244.28328-3-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since the read_tree() API was added around the same time as read_tree_recursive() in 94537c78a82 (Move "read_tree()" to "tree.c"[...], 2005-04-22) and b12ec373b8e ([PATCH] Teach read-tree about commit objects, 2005-04-20) things have gradually migrated over to the read_tree_recursive() version. Now builtin/ls-files.c is the last user of this code, let's move all the relevant code there. This allows for subsequent simplification of it, and an eventual move to read_tree_recursive(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ cache.h | 2 +- tree.c | 89 --------------------------------------------- tree.h | 5 --- 4 files changed, 92 insertions(+), 95 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index f6f9e483b2..a445862281 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -12,6 +12,7 @@ #include "dir.h" #include "builtin.h" #include "tree.h" +#include "cache-tree.h" #include "parse-options.h" #include "resolve-undo.h" #include "string-list.h" @@ -420,6 +421,96 @@ static int get_common_prefix_len(const char *common_prefix) return common_prefix_len; } +static int read_one_entry_opt(struct index_state *istate, + const struct object_id *oid, + const char *base, int baselen, + const char *pathname, + unsigned mode, int stage, int opt) +{ + int len; + struct cache_entry *ce; + + if (S_ISDIR(mode)) + return READ_TREE_RECURSIVE; + + len = strlen(pathname); + ce = make_empty_cache_entry(istate, baselen + len); + + ce->ce_mode = create_ce_mode(mode); + ce->ce_flags = create_ce_flags(stage); + ce->ce_namelen = baselen + len; + memcpy(ce->name, base, baselen); + memcpy(ce->name + baselen, pathname, len+1); + oidcpy(&ce->oid, oid); + return add_index_entry(istate, ce, opt); +} + +static int read_one_entry(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, int stage, + void *context) +{ + struct index_state *istate = context; + return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, + mode, stage, + ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); +} + +/* + * 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, + const char *pathname, unsigned mode, int stage, + void *context) +{ + struct index_state *istate = context; + return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, + mode, stage, + ADD_CACHE_JUST_APPEND); +} + + +static int read_tree(struct repository *r, struct tree *tree, int stage, + struct pathspec *match, struct index_state *istate) +{ + read_tree_fn_t fn = NULL; + int i, err; + + /* + * Currently the only existing callers of this function all + * call it with stage=1 and after making sure there is nothing + * at that stage; we could always use read_one_entry_quick(). + * + * But when we decide to straighten out git-read-tree not to + * use unpack_trees() in some cases, this will probably start + * to matter. + */ + + /* + * See if we have cache entry at the stage. If so, + * do it the original slow way, otherwise, append and then + * sort at the end. + */ + for (i = 0; !fn && i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; + if (ce_stage(ce) == stage) + fn = read_one_entry; + } + + if (!fn) + fn = read_one_entry_quick; + err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate); + if (fn == read_one_entry || err) + return err; + + /* + * Sort the cache entry -- we need to nuke the cache tree, though. + */ + cache_tree_free(&istate->cache_tree); + QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); + return 0; +} + /* * Read the tree specified with --with-tree option * (typically, HEAD) into stage #1 and then diff --git a/cache.h b/cache.h index 6fda8091f1..c2f8a8eadf 100644 --- a/cache.h +++ b/cache.h @@ -803,7 +803,7 @@ static inline int index_pos_to_insert_pos(uintmax_t pos) #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ -#define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */ +#define ADD_CACHE_JUST_APPEND 8 /* Append only */ #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */ #define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */ #define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */ diff --git a/tree.c b/tree.c index a52479812c..a6c12f2745 100644 --- a/tree.c +++ b/tree.c @@ -11,54 +11,6 @@ const char *tree_type = "tree"; -static int read_one_entry_opt(struct index_state *istate, - const struct object_id *oid, - const char *base, int baselen, - const char *pathname, - unsigned mode, int stage, int opt) -{ - int len; - struct cache_entry *ce; - - if (S_ISDIR(mode)) - return READ_TREE_RECURSIVE; - - len = strlen(pathname); - ce = make_empty_cache_entry(istate, baselen + len); - - ce->ce_mode = create_ce_mode(mode); - ce->ce_flags = create_ce_flags(stage); - ce->ce_namelen = baselen + len; - memcpy(ce->name, base, baselen); - memcpy(ce->name + baselen, pathname, len+1); - oidcpy(&ce->oid, oid); - return add_index_entry(istate, ce, opt); -} - -static int read_one_entry(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, - void *context) -{ - struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, - mode, stage, - ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); -} - -/* - * 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, - const char *pathname, unsigned mode, int stage, - void *context) -{ - struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, - mode, stage, - ADD_CACHE_JUST_APPEND); -} - static int read_tree_1(struct repository *r, struct tree *tree, struct strbuf *base, int stage, const struct pathspec *pathspec, @@ -154,47 +106,6 @@ int cmp_cache_name_compare(const void *a_, const void *b_) ce2->name, ce2->ce_namelen, ce_stage(ce2)); } -int read_tree(struct repository *r, struct tree *tree, int stage, - struct pathspec *match, struct index_state *istate) -{ - read_tree_fn_t fn = NULL; - int i, err; - - /* - * Currently the only existing callers of this function all - * call it with stage=1 and after making sure there is nothing - * at that stage; we could always use read_one_entry_quick(). - * - * But when we decide to straighten out git-read-tree not to - * use unpack_trees() in some cases, this will probably start - * to matter. - */ - - /* - * See if we have cache entry at the stage. If so, - * do it the original slow way, otherwise, append and then - * sort at the end. - */ - for (i = 0; !fn && i < istate->cache_nr; i++) { - const struct cache_entry *ce = istate->cache[i]; - if (ce_stage(ce) == stage) - fn = read_one_entry; - } - - if (!fn) - fn = read_one_entry_quick; - err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate); - if (fn == read_one_entry || err) - return err; - - /* - * Sort the cache entry -- we need to nuke the cache tree, though. - */ - cache_tree_free(&istate->cache_tree); - QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); - return 0; -} - struct tree *lookup_tree(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); diff --git a/tree.h b/tree.h index 3eb0484cbf..6b0b1dc211 100644 --- a/tree.h +++ b/tree.h @@ -38,9 +38,4 @@ int read_tree_recursive(struct repository *r, const char *base, int baselen, int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context); - -int read_tree(struct repository *r, struct tree *tree, - int stage, struct pathspec *pathspec, - struct index_state *istate); - #endif /* TREE_H */ From patchwork Tue Mar 16 15:52:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBE3FC432C3 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A809D6510E for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238162AbhCPPxa (ORCPT ); Tue, 16 Mar 2021 11:53:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231684AbhCPPww (ORCPT ); Tue, 16 Mar 2021 11:52:52 -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 3E9F3C06174A for ; Tue, 16 Mar 2021 08:52:52 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so1748182wml.2 for ; Tue, 16 Mar 2021 08:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6T/mQ34byf3L1EwgB9VIViPWZHfszFl1Xxt4IsCa9YA=; b=ABnsh4WEVtpIUUYKFV9//ozrPrE6g4+H9BXZao48TxA2J6qhrjf1gQB178vJCA00g4 74FTFh9t5EcwcboPNWY/BXpYBad++cBv9GYaYltfdjwH3lMRQqp4idSqT1WAuUjQxBJU 5EaHS8JNkOQX4YMI9MIsw5kQfiMZPnW+f1Efp17Q9OifosslG4Oyhc9jM0U1IDaADmHL h6g26hGH7AIbK8lC/l0xxUY0+tgD8QLjBSCuLh2h8O5FfnQXaiBVfN3c1KlD4kvU9uT7 zu+8HBm6kfaqiOIhjSzPuaSxB7gXc8HHvU0Qjre0GFU7sAIyYmS19XLur5Im22k8aRkp QZrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6T/mQ34byf3L1EwgB9VIViPWZHfszFl1Xxt4IsCa9YA=; b=C0UEZ/2XdxQuwKtphauTqUG8nd2f8/cRfzLtUFb5OQZGihOqSHt/WK+L1wYsQvHO+w 4OxWA0gQGD4xbIYl3FO8c99W5ziULliSx4jbfJoIeFJ0GRJ/ZRYHg5UkjntXK8GdOvQs vWNfAyY98tnnJ2FgCmyzjjW01S/7IOtRGyqM6IV4ZZIyE6vVZBcU1oiNXxxUHjK7KBgT Z/y03NMyQkEOLFukUxal+yfWXRsBThc+jkAajwycD45bfTOKWFxbxacA8PDvW0R0A01W bva1Hw57AHhrGaYNo/CwJTIEORGUnXjFG/JrXxPzouc3LdBtodLK3uDDs0sHdyMg8v55 WQBQ== X-Gm-Message-State: AOAM530W03OAAIZaxTvuyjsX+d2HsgaT9pjjbgQ1LQXACTmvmLsbiE7B D4yJwNjegr4cms9x6JXlrw+e6RfoMOWfKA== X-Google-Smtp-Source: ABdhPJyXmt4DkURuiBElzqlu5ItXiHlG8UPAas1lWKkfY2IkWIN0GvO3HlP5uL4IcDhp0mY3sv5q/A== X-Received: by 2002:a1c:c282:: with SMTP id s124mr271907wmf.99.1615909970346; Tue, 16 Mar 2021 08:52:50 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:49 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 3/9] ls-files: don't needlessly pass around stage variable Date: Tue, 16 Mar 2021 16:52:38 +0100 Message-Id: <20210316155244.28328-4-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that read_tree() has been moved to ls-files.c we can get rid of the stage != 1 case that'll never happen. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a445862281..74d572a3e4 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -470,21 +470,12 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base } -static int read_tree(struct repository *r, struct tree *tree, int stage, +static int read_tree(struct repository *r, struct tree *tree, struct pathspec *match, struct index_state *istate) { read_tree_fn_t fn = NULL; int i, err; - /* - * Currently the only existing callers of this function all - * call it with stage=1 and after making sure there is nothing - * at that stage; we could always use read_one_entry_quick(). - * - * But when we decide to straighten out git-read-tree not to - * use unpack_trees() in some cases, this will probably start - * to matter. - */ /* * See if we have cache entry at the stage. If so, @@ -493,13 +484,13 @@ static int read_tree(struct repository *r, struct tree *tree, int stage, */ for (i = 0; !fn && i < istate->cache_nr; i++) { const struct cache_entry *ce = istate->cache[i]; - if (ce_stage(ce) == stage) + if (ce_stage(ce) == 1) fn = read_one_entry; } if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate); + err = read_tree_recursive(r, tree, "", 0, 1, match, fn, istate); if (fn == read_one_entry || err) return err; @@ -549,7 +540,7 @@ void overlay_tree_on_index(struct index_state *istate, PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree(the_repository, tree, 1, &pathspec, istate)) + if (read_tree(the_repository, tree, &pathspec, istate)) die("unable to read tree entries %s", tree_name); for (i = 0; i < istate->cache_nr; i++) { From patchwork Tue Mar 16 15:52:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA44FC43332 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9777F65109 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238153AbhCPPx1 (ORCPT ); Tue, 16 Mar 2021 11:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232062AbhCPPwx (ORCPT ); Tue, 16 Mar 2021 11:52:53 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 901E4C061756 for ; Tue, 16 Mar 2021 08:52:52 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so1754194wmj.1 for ; Tue, 16 Mar 2021 08:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ug2zKxYEtldeotnzyh1Ut66jcpx/c0OJQkZYVtkBABE=; b=RNbCVRCNB+N2rCcwmv1UTiCAVtqV3E5+FQwlNTr/rHYcmwvvq4ukXvEB57JGCu3k0n 3yjmFbb4dOvEapcb4Mg5SBf/iUROsIWYG0jsepGkHu9LVnlV9kjFin60xbPKMg915har 8Ilfla/BXZk/7MfK8F6suljzDhvWgJMGrsR5JkA5LQXYukIPtbzoWzmuFY5gHQ6hRj8J Zc73A7b6EGfBOKHGTBTMs6wvB1FS2RNzAIRWRtXAljQS1kzeWH2b3lrp3jm6XE9NzFLI MH+pZeoaJrY3RvCVcCxU3NWiQt2iK8HAZ0n+p9m48+EZW723MGVKyGvug0/INaDqOCLX DVGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ug2zKxYEtldeotnzyh1Ut66jcpx/c0OJQkZYVtkBABE=; b=HSN4nWUGrxlVofCQmP36YhXeIeLCwFIcDdavzFYIj2zLjtVpvRITitGnVZiwrME1xW BjLbR/a079HyRLqTOdGU7YD7FiIelNN6qAeToPK+LgG+sTnAqlKvaRzoWuQOOzQTAyDL npp5c5OmGxgvsUH1X+K2KMIjEygb+uJZUioj18qSRmh1LoihPM5M6q4MUcAlFPfSFlLm dw6O3t8Dd4u0dQ1rzza+aOymrqr6/tkZKc3doOjbnXMlVuyL4BYOpY2/v0hyztn95OlI qrSTNQUU+pa+e/dcRMG2MYpDdzOpuQetwbnpRJ3w4nbFIVxdwW6vs26o602cSTG79+kp 4ucA== X-Gm-Message-State: AOAM533HXNHDOPl6A0e2njfOiSSYkCUDUvdpX+YR+eYl8zRKeckZP4yL p5xcGM74tG8R+s7cn5iEw0vZ0CIUgAtQdw== X-Google-Smtp-Source: ABdhPJxWNEGdnq9sFIoRoZpPTA/524mz09F+MwU7smOabdAXX1L4F+2PM+4A5SrzEzbl6hZJyPjnCA== X-Received: by 2002:a7b:c214:: with SMTP id x20mr290680wmi.186.1615909971034; Tue, 16 Mar 2021 08:52:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 4/9] ls-files: refactor away read_tree() Date: Tue, 16 Mar 2021 16:52:39 +0100 Message-Id: <20210316155244.28328-5-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor away the read_tree() function into its only user, overlay_tree_on_index(). First, change read_one_entry_opt() to use the strbuf parameter read_tree_recursive() passes down in place. This finishes up a partial refactoring started in 6a0b0b6de99 (tree.c: update read_tree_recursive callback to pass strbuf as base, 2014-11-30). Moving the rest into overlay_tree_on_index() makes this index juggling we're doing easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 74 +++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 74d572a3e4..db53e2c8e6 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -423,7 +423,7 @@ static int get_common_prefix_len(const char *common_prefix) static int read_one_entry_opt(struct index_state *istate, const struct object_id *oid, - const char *base, int baselen, + struct strbuf *base, const char *pathname, unsigned mode, int stage, int opt) { @@ -434,13 +434,13 @@ static int read_one_entry_opt(struct index_state *istate, return READ_TREE_RECURSIVE; len = strlen(pathname); - ce = make_empty_cache_entry(istate, baselen + len); + ce = make_empty_cache_entry(istate, base->len + len); ce->ce_mode = create_ce_mode(mode); ce->ce_flags = create_ce_flags(stage); - ce->ce_namelen = baselen + len; - memcpy(ce->name, base, baselen); - memcpy(ce->name + baselen, pathname, len+1); + ce->ce_namelen = base->len + len; + memcpy(ce->name, base->buf, base->len); + memcpy(ce->name + base->len, pathname, len+1); oidcpy(&ce->oid, oid); return add_index_entry(istate, ce, opt); } @@ -450,7 +450,7 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, void *context) { struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, + return read_one_entry_opt(istate, oid, base, pathname, mode, stage, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } @@ -464,44 +464,11 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base void *context) { struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, + return read_one_entry_opt(istate, oid, base, pathname, mode, stage, ADD_CACHE_JUST_APPEND); } - -static int read_tree(struct repository *r, struct tree *tree, - struct pathspec *match, struct index_state *istate) -{ - read_tree_fn_t fn = NULL; - int i, err; - - - /* - * See if we have cache entry at the stage. If so, - * do it the original slow way, otherwise, append and then - * sort at the end. - */ - for (i = 0; !fn && i < istate->cache_nr; i++) { - const struct cache_entry *ce = istate->cache[i]; - if (ce_stage(ce) == 1) - fn = read_one_entry; - } - - if (!fn) - fn = read_one_entry_quick; - err = read_tree_recursive(r, tree, "", 0, 1, match, fn, istate); - if (fn == read_one_entry || err) - return err; - - /* - * Sort the cache entry -- we need to nuke the cache tree, though. - */ - cache_tree_free(&istate->cache_tree); - QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); - return 0; -} - /* * Read the tree specified with --with-tree option * (typically, HEAD) into stage #1 and then @@ -518,6 +485,8 @@ void overlay_tree_on_index(struct index_state *istate, struct pathspec pathspec; struct cache_entry *last_stage0 = NULL; int i; + read_tree_fn_t fn = NULL; + int err; if (get_oid(tree_name, &oid)) die("tree-ish %s not found.", tree_name); @@ -540,9 +509,32 @@ void overlay_tree_on_index(struct index_state *istate, PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree(the_repository, tree, &pathspec, istate)) + + /* + * See if we have cache entry at the stage. If so, + * do it the original slow way, otherwise, append and then + * sort at the end. + */ + for (i = 0; !fn && i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; + if (ce_stage(ce) == 1) + fn = read_one_entry; + } + + if (!fn) + fn = read_one_entry_quick; + err = read_tree_recursive(the_repository, tree, "", 0, 1, &pathspec, fn, istate); + if (err) die("unable to read tree entries %s", tree_name); + /* + * Sort the cache entry -- we need to nuke the cache tree, though. + */ + if (fn == read_one_entry_quick) { + cache_tree_free(&istate->cache_tree); + QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); + } + for (i = 0; i < istate->cache_nr; i++) { struct cache_entry *ce = istate->cache[i]; switch (ce_stage(ce)) { From patchwork Tue Mar 16 15:52:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF115C4321A for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAAD9650F6 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238163AbhCPPxd (ORCPT ); Tue, 16 Mar 2021 11:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232412AbhCPPwy (ORCPT ); Tue, 16 Mar 2021 11:52:54 -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 A37B8C061756 for ; Tue, 16 Mar 2021 08:52:53 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso1729012wma.4 for ; Tue, 16 Mar 2021 08:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/prMgCcbuo/nVzaq0m9Vy13aeSZOMLvFjDdTWJufty4=; b=jnxD2QrpGp1+IqYyt+U8bEIP4bcBvQW2uYrtu5HD/+xUfzhPFlmQPErWjR1TUGVR7q cQoZtA4UwHBDKivkc5wtxUWxhHMxR2hIax0p4Eqte4wWQxolk/gpLT1V/Pf1Qhu1yyX4 zzVv2mcnNBEIWCpmhEe7F/YkNNZgaF2dALLo9PRnPDFNZl5jZ063Xz1sn05zu/V83UbZ gssK3wnJhrdkXkeqdm82QUfO25XOlHvJ7EJ4v324VLItUzChWcRSDsyiKVV+j1Qkm6Mv qKel2S1me89Xgb4Cl3he1GNgBlTkJHRCkPk9tAEPwIH8kwWd7t/dtEA+/zFzQwM/ESIN jXRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/prMgCcbuo/nVzaq0m9Vy13aeSZOMLvFjDdTWJufty4=; b=iuWZVc0nVrd70jvp4+MVE4NFrlFnvRC1/GZ++Blb3e90olZmvhuKc26pz7UByQGwgl k1952S5wCVf38jSd19fvNf9h989qB5NkT5/dyfr7oRfsoTD0vCm/xvU2yZ/FE6yEGQ5V H0aEmmXhouLf1QAf0GYFZ5AAWmgCp0rjQOgHzN8mMwAYm99VTi7BvjKZos3zzZqKeSrJ 3sJf+vSWI9e29Mqi75VJM4/zCnVPcGoePgUx7haIJex18BY/nj+bYj1PaHY05BPdUFaS 5zb7IQ+cG64ROovXbTpg6z2T4vov/P72Ct4RnKNWM7TaBa19cC4LOLo64tUoaEus5k61 ZEYg== X-Gm-Message-State: AOAM5318MCP8iSnuw7/U/Czm6AXQcoe+nFYK9NzIfcToxNjTkPS58vQx uIjDw6gpQlaXV5NWsnXVINn5g/2CJFqBog== X-Google-Smtp-Source: ABdhPJx4zskgY4OUoXkuQOAxgDC0uSItcUrqZ6ymlNh5GMsMMjCyfHwxrzoQVGMXhwVwt4h9vOZY6w== X-Received: by 2002:a7b:cb99:: with SMTP id m25mr320222wmi.64.1615909972114; Tue, 16 Mar 2021 08:52:52 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 5/9] tree.h API: remove support for starting at prefix != "" Date: Tue, 16 Mar 2021 16:52:40 +0100 Message-Id: <20210316155244.28328-6-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Every caller of the read_tree_recursive() function hardcoded a starting point of "" in the tree. So let's simply remove that parameter. The last function to call read_tree_recursive() with a non-"" path was read_tree_recursive() itself, but that was changed in ffd31f661d5 (Reimplement read_tree_recursive() using tree_entry_interesting(), 2011-03-25). As it turns out (Murphy's law and all) we're just about to gain a new in-tree user that would need this parameter[1]. Let's remove it anyway as the common case is going to be to not supply it, A later commit will bring back this functionality in different form. 1. https://lore.kernel.org/git/xmqqft106sok.fsf@gitster.g/ Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 8 ++++---- builtin/checkout.c | 2 +- builtin/log.c | 4 ++-- builtin/ls-files.c | 2 +- builtin/ls-tree.c | 2 +- merge-recursive.c | 2 +- tree.c | 2 -- tree.h | 1 - 8 files changed, 10 insertions(+), 13 deletions(-) diff --git a/archive.c b/archive.c index 5919d9e505..9394f170f7 100644 --- a/archive.c +++ b/archive.c @@ -316,8 +316,8 @@ int write_archive_entries(struct archiver_args *args, git_attr_set_direction(GIT_ATTR_INDEX); } - err = read_tree_recursive(args->repo, args->tree, "", - 0, 0, &args->pathspec, + err = read_tree_recursive(args->repo, args->tree, + 0, &args->pathspec, queue_or_write_archive_entry, &context); if (err == READ_TREE_RECURSIVE) @@ -405,8 +405,8 @@ 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_recursive(args->repo, args->tree, "", - 0, 0, &ctx.pathspec, + ret = read_tree_recursive(args->repo, args->tree, + 0, &ctx.pathspec, reject_entry, &ctx); clear_pathspec(&ctx.pathspec); return ret != 0; diff --git a/builtin/checkout.c b/builtin/checkout.c index 2d6550bc3c..21b742c0f0 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -155,7 +155,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base, static int read_tree_some(struct tree *tree, const struct pathspec *pathspec) { - read_tree_recursive(the_repository, tree, "", 0, 0, + read_tree_recursive(the_repository, tree, 0, pathspec, update_some, NULL); /* update the index with the given tree's info diff --git a/builtin/log.c b/builtin/log.c index f67b67d80e..ffa3fb8c28 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -681,8 +681,8 @@ int cmd_show(int argc, const char **argv, const char *prefix) diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), name, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); - read_tree_recursive(the_repository, (struct tree *)o, "", - 0, 0, &match_all, show_tree_object, + read_tree_recursive(the_repository, (struct tree *)o, + 0, &match_all, show_tree_object, rev.diffopt.file); rev.shown_one = 1; break; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index db53e2c8e6..cd432ac03c 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -523,7 +523,7 @@ void overlay_tree_on_index(struct index_state *istate, if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(the_repository, tree, "", 0, 1, &pathspec, fn, istate); + err = read_tree_recursive(the_repository, tree, 1, &pathspec, fn, istate); if (err) die("unable to read tree entries %s", tree_name); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 7cad3f24eb..7d3fb2e6d0 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -185,6 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) tree = parse_tree_indirect(&oid); if (!tree) die("not a tree object"); - return !!read_tree_recursive(the_repository, tree, "", 0, 0, + return !!read_tree_recursive(the_repository, tree, 0, &pathspec, show_tree, NULL); } diff --git a/merge-recursive.c b/merge-recursive.c index b052974f19..fa7602ff0f 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -473,7 +473,7 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree) { struct pathspec match_all; memset(&match_all, 0, sizeof(match_all)); - read_tree_recursive(opt->repo, tree, "", 0, 0, + read_tree_recursive(opt->repo, tree, 0, &match_all, save_files_dirs, opt); } diff --git a/tree.c b/tree.c index a6c12f2745..04eb11aed3 100644 --- a/tree.c +++ b/tree.c @@ -83,14 +83,12 @@ static int read_tree_1(struct repository *r, int read_tree_recursive(struct repository *r, struct tree *tree, - const char *base, int baselen, int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context) { struct strbuf sb = STRBUF_INIT; int ret; - strbuf_add(&sb, base, baselen); ret = read_tree_1(r, tree, &sb, stage, pathspec, fn, context); strbuf_release(&sb); return ret; diff --git a/tree.h b/tree.h index 6b0b1dc211..5252b5139d 100644 --- a/tree.h +++ b/tree.h @@ -35,7 +35,6 @@ typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const c int read_tree_recursive(struct repository *r, struct tree *tree, - const char *base, int baselen, int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context); #endif /* TREE_H */ From patchwork Tue Mar 16 15:52:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0B0CC43603 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC32B64DF3 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232511AbhCPPxh (ORCPT ); Tue, 16 Mar 2021 11:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231952AbhCPPwz (ORCPT ); Tue, 16 Mar 2021 11:52:55 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A278BC06174A for ; Tue, 16 Mar 2021 08:52:54 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id e9so7695334wrw.10 for ; Tue, 16 Mar 2021 08:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5P88KfnVokmmTh/bsuQITrHC5fhnMvifuCi+n1JzeFA=; b=DaCw/1h/cIiM1HWcCiiw37X9CWmWEDdJ75n/vTcKFPzRnYb/gTjuNikjH+KQjVfDlG qQc/YRct76yO7Bi6CzhoN0LcrRfnyJheY2e3pmszbNFlG/oUa9OZNaX1iM9+oAHA48k4 y5LfA1m3NzsUBPiVrZkRZbYNb3zjTr9zzMqxuL9AmejbKOWBq4aqO07GJLCdrDc0owXx nxBrpuw16iyF19sfoOtNYzUs9cQ6AjdBAiyZ2joUXpcOzjAVnYCNy/k/R68s7vLPV4sr K8ssZ9mulegtSfPsxd/yI/LQNMAh8e8EjLGjkVJYOchV0j1o93LiSatQOd8xA8g/Jv/a oTow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5P88KfnVokmmTh/bsuQITrHC5fhnMvifuCi+n1JzeFA=; b=g/+NdpjeLRplmFB8Bjvkl+SR3w8/agZ8T3wTbGBb9h3zRKqRhc1L3oMlTMGBRWhtSj MdZ1nUepTFbEOsXtpwKplRp0IdTdaBZGw2lWaTEQi1ypUxkQn4gnWLfy/eoE3y6oNNvu iKSBCa9/+UqheWCOtO9vWhaBueNuzIGgfKrW8Ph4QkkJm6cro/3Q/CHqrZxlURx/V7N9 05PHIyBf3PAACBTM8Lz59UCjpwINg324hwF/0OFgjDqSI5Fs4lhpu4ka+qGgZUsMc7Zt 9yp0EAtmweX7SW7gjxIZPpCiG0BWxWI4Zy3AlVS/ZLdp2EE/rrD3vFOrS52bDK7vkual zrlg== X-Gm-Message-State: AOAM5333VfEXS78ctjcxvm6Fw6X2O5aY+ObjMniihY21DXPt02pzc5p6 11ycEohV1MvUjE7mwM9QyL9tZPOX/IMbYw== X-Google-Smtp-Source: ABdhPJxuHJN3odzWJ1C2znB92lJmts7e0XnkXVcyJ7s5E6QJWWtvSjCEFTOkUvNtppUg3nW20oKKUA== X-Received: by 2002:a5d:4688:: with SMTP id u8mr5622003wrq.39.1615909973004; Tue, 16 Mar 2021 08:52:53 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:52 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 6/9] tree.h API: remove "stage" parameter from read_tree_recursive() Date: Tue, 16 Mar 2021 16:52:41 +0100 Message-Id: <20210316155244.28328-7-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The read_tree_recursive() function took a "stage" parameter that is passed through as-is. As it turns out nothing used this parameter in a way that they couldn't just move to the callback function they defined, so let's get rid of it. If anyone needs to pass such information in the future they can use the "void *context" parameter. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 9 +++++---- builtin/checkout.c | 4 ++-- builtin/log.c | 4 ++-- builtin/ls-files.c | 14 +++++++------- builtin/ls-tree.c | 4 ++-- merge-recursive.c | 4 ++-- tree.c | 10 +++++----- tree.h | 4 ++-- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/archive.c b/archive.c index 9394f170f7..6669a4bd14 100644 --- a/archive.c +++ b/archive.c @@ -231,9 +231,10 @@ static int write_directory(struct archiver_context *c) static int queue_or_write_archive_entry(const struct object_id *oid, struct strbuf *base, const char *filename, - unsigned mode, int stage, void *context) + unsigned mode, void *context) { struct archiver_context *c = context; + int stage = 0; while (c->bottom && !(base->len >= c->bottom->len && @@ -317,7 +318,7 @@ int write_archive_entries(struct archiver_args *args, } err = read_tree_recursive(args->repo, args->tree, - 0, &args->pathspec, + &args->pathspec, queue_or_write_archive_entry, &context); if (err == READ_TREE_RECURSIVE) @@ -378,7 +379,7 @@ struct path_exists_context { static int reject_entry(const struct object_id *oid, struct strbuf *base, const char *filename, unsigned mode, - int stage, void *context) + void *context) { int ret = -1; struct path_exists_context *ctx = context; @@ -406,7 +407,7 @@ static int path_exists(struct archiver_args *args, const char *path) parse_pathspec(&ctx.pathspec, 0, 0, "", paths); ctx.pathspec.recursive = 1; ret = read_tree_recursive(args->repo, args->tree, - 0, &ctx.pathspec, + &ctx.pathspec, reject_entry, &ctx); clear_pathspec(&ctx.pathspec); return ret != 0; diff --git a/builtin/checkout.c b/builtin/checkout.c index 21b742c0f0..2c2d58a230 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -114,7 +114,7 @@ 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, - const char *pathname, unsigned mode, int stage, void *context) + const char *pathname, unsigned mode, void *context) { int len; struct cache_entry *ce; @@ -155,7 +155,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base, static int read_tree_some(struct tree *tree, const struct pathspec *pathspec) { - read_tree_recursive(the_repository, tree, 0, + read_tree_recursive(the_repository, tree, pathspec, update_some, NULL); /* update the index with the given tree's info diff --git a/builtin/log.c b/builtin/log.c index ffa3fb8c28..58acb2b76a 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -599,7 +599,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) static int show_tree_object(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *context) + const char *pathname, unsigned mode, void *context) { FILE *file = context; fprintf(file, "%s%s\n", pathname, S_ISDIR(mode) ? "/" : ""); @@ -682,7 +682,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) name, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); read_tree_recursive(the_repository, (struct tree *)o, - 0, &match_all, show_tree_object, + &match_all, show_tree_object, rev.diffopt.file); rev.shown_one = 1; break; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index cd432ac03c..fa9b01b6cc 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -425,7 +425,7 @@ static int read_one_entry_opt(struct index_state *istate, const struct object_id *oid, struct strbuf *base, const char *pathname, - unsigned mode, int stage, int opt) + unsigned mode, int opt) { int len; struct cache_entry *ce; @@ -437,7 +437,7 @@ static int read_one_entry_opt(struct index_state *istate, ce = make_empty_cache_entry(istate, base->len + len); ce->ce_mode = create_ce_mode(mode); - ce->ce_flags = create_ce_flags(stage); + ce->ce_flags = create_ce_flags(1); ce->ce_namelen = base->len + len; memcpy(ce->name, base->buf, base->len); memcpy(ce->name + base->len, pathname, len+1); @@ -446,12 +446,12 @@ static int read_one_entry_opt(struct index_state *istate, } static int read_one_entry(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, + const char *pathname, unsigned mode, void *context) { struct index_state *istate = context; return read_one_entry_opt(istate, oid, base, pathname, - mode, stage, + mode, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } @@ -460,12 +460,12 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, * the stage that will conflict with the entry being added. */ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, + const char *pathname, unsigned mode, void *context) { struct index_state *istate = context; return read_one_entry_opt(istate, oid, base, pathname, - mode, stage, + mode, ADD_CACHE_JUST_APPEND); } @@ -523,7 +523,7 @@ void overlay_tree_on_index(struct index_state *istate, if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(the_repository, tree, 1, &pathspec, fn, istate); + err = read_tree_recursive(the_repository, tree, &pathspec, fn, istate); if (err) die("unable to read tree entries %s", tree_name); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 7d3fb2e6d0..dbb31217be 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -62,7 +62,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname) } static int show_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *context) + const char *pathname, unsigned mode, void *context) { int retval = 0; int baselen; @@ -185,6 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) tree = parse_tree_indirect(&oid); if (!tree) die("not a tree object"); - return !!read_tree_recursive(the_repository, tree, 0, + return !!read_tree_recursive(the_repository, tree, &pathspec, show_tree, NULL); } diff --git a/merge-recursive.c b/merge-recursive.c index fa7602ff0f..1593f37449 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -453,7 +453,7 @@ static void unpack_trees_finish(struct merge_options *opt) static int save_files_dirs(const struct object_id *oid, struct strbuf *base, const char *path, - unsigned int mode, int stage, void *context) + unsigned int mode, void *context) { struct path_hashmap_entry *entry; int baselen = base->len; @@ -473,7 +473,7 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree) { struct pathspec match_all; memset(&match_all, 0, sizeof(match_all)); - read_tree_recursive(opt->repo, tree, 0, + read_tree_recursive(opt->repo, tree, &match_all, save_files_dirs, opt); } diff --git a/tree.c b/tree.c index 04eb11aed3..fb4985f22c 100644 --- a/tree.c +++ b/tree.c @@ -13,7 +13,7 @@ const char *tree_type = "tree"; static int read_tree_1(struct repository *r, struct tree *tree, struct strbuf *base, - int stage, const struct pathspec *pathspec, + const struct pathspec *pathspec, read_tree_fn_t fn, void *context) { struct tree_desc desc; @@ -38,7 +38,7 @@ static int read_tree_1(struct repository *r, } switch (fn(&entry.oid, base, - entry.path, entry.mode, stage, context)) { + entry.path, entry.mode, context)) { case 0: continue; case READ_TREE_RECURSIVE: @@ -72,7 +72,7 @@ static int read_tree_1(struct repository *r, strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); retval = read_tree_1(r, lookup_tree(r, &oid), - base, stage, pathspec, + base, pathspec, fn, context); strbuf_setlen(base, oldlen); if (retval) @@ -83,13 +83,13 @@ static int read_tree_1(struct repository *r, int read_tree_recursive(struct repository *r, struct tree *tree, - int stage, const struct pathspec *pathspec, + const struct pathspec *pathspec, read_tree_fn_t fn, void *context) { struct strbuf sb = STRBUF_INIT; int ret; - ret = read_tree_1(r, tree, &sb, stage, pathspec, fn, context); + ret = read_tree_1(r, tree, &sb, pathspec, fn, context); strbuf_release(&sb); return ret; } diff --git a/tree.h b/tree.h index 5252b5139d..1309ab997e 100644 --- a/tree.h +++ b/tree.h @@ -31,10 +31,10 @@ struct tree *parse_tree_indirect(const struct object_id *oid); 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, int, void *); +typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, void *); int read_tree_recursive(struct repository *r, struct tree *tree, - int stage, const struct pathspec *pathspec, + const struct pathspec *pathspec, read_tree_fn_t fn, void *context); #endif /* TREE_H */ From patchwork Tue Mar 16 15:52:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12F56C43619 for ; Tue, 16 Mar 2021 15:53:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1001650F7 for ; Tue, 16 Mar 2021 15:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238170AbhCPPxi (ORCPT ); Tue, 16 Mar 2021 11:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237537AbhCPPw4 (ORCPT ); Tue, 16 Mar 2021 11:52:56 -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 A22CEC061756 for ; Tue, 16 Mar 2021 08:52:55 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id d139-20020a1c1d910000b029010b895cb6f2so1742003wmd.5 for ; Tue, 16 Mar 2021 08:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2mC2vPY1WZARbtdAd0KpULssHVilyZ7jU13ldEkP2aA=; b=qM8RJvh9rOvSGscmO2CQF9+YcBpADEXMbOl8q2l4aC8US+PEd8nJaQCVErHkYwvJ3T pe9Kctu+cUECGeqCLk6YF7Agtpest3fGKygGZLHigogc245dFxXmqT3FTO8/aGBDch2v UKfaP3UeHBAZNZcveSr24vH7PzIQxE5fV7zp5NJaJjVLwKE8oYkXppXrh8PM/K4y3Fwf gNssPrOo5NeHOaL3MgrK/UMHQWVPB4/Rz6HQdnl6j65uUiLaD8NlW3NquvcHZXQ2w5DY cmPtsepkfLVmNuPCmNXcrRyfSH9uYJfageOt5R13IfnLMwZxv7DK1h3+xu72MnIZ+8yV hUug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2mC2vPY1WZARbtdAd0KpULssHVilyZ7jU13ldEkP2aA=; b=r+1Mto9uriI0YxXaAycmgecEUhPiQWNtoMRIEcuCzdJKz/kImmfywaMnVBdzu9QhP9 iErox6FPexefqEjEj4fePrCvh9vQJKd0LlvsRzwyUXNKj+CdPqRapkb1V2dC3129Lkx3 1XmvgKc8lWXWCnYciK/QfV3tBTCAUA40eFXDaxdS3eqk5Qt9raU8h6myLiHbRmLKt8OA bdC8rUNmzcru7ZrAn5ehhG1kh78KEVkOXgQkzagefSvGWgZqV4hClKiU6t4+2GVhc5SR GEJILbBhiaABVDpSjcbYYN6JjTe1JM7zu1RrDK85+5bazIWU7GI1wuObwTX+t/N9BY8r k8kQ== X-Gm-Message-State: AOAM5311NoCPo/GFYRGHpN5kaxXCL/IJAitE9MapPb7vThXLcuGRCuOq 59f2l0JXPp//6xvltnxGvkRFNC0QZIdZzA== X-Google-Smtp-Source: ABdhPJw+cnls1yXB4dX7xiy7SQEaYvhSX07k5uuu+sY3etWKM9Dc64A5OuVx100zFFjD+I9fIeHURQ== X-Received: by 2002:a1c:1d14:: with SMTP id d20mr324398wmd.36.1615909974112; Tue, 16 Mar 2021 08:52:54 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:53 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 7/9] tree.h API: rename read_tree_recursive() to read_tree() Date: Tue, 16 Mar 2021 16:52:42 +0100 Message-Id: <20210316155244.28328-8-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the read_tree_recursive() function to just read_tree(). We had another read_tree() function that I've refactored away in preceding steps, since all in-tree users read trees recursively with a callback we can change the name to signify that this is the norm. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 14 +++++++------- builtin/checkout.c | 6 +++--- builtin/log.c | 6 +++--- builtin/ls-files.c | 2 +- builtin/ls-tree.c | 4 ++-- merge-recursive.c | 4 ++-- tree.c | 8 ++++---- tree.h | 8 ++++---- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/archive.c b/archive.c index 6669a4bd14..c19300ecb9 100644 --- a/archive.c +++ b/archive.c @@ -317,10 +317,10 @@ int write_archive_entries(struct archiver_args *args, git_attr_set_direction(GIT_ATTR_INDEX); } - err = read_tree_recursive(args->repo, args->tree, - &args->pathspec, - queue_or_write_archive_entry, - &context); + err = read_tree(args->repo, args->tree, + &args->pathspec, + queue_or_write_archive_entry, + &context); if (err == READ_TREE_RECURSIVE) err = 0; while (context.bottom) { @@ -406,9 +406,9 @@ 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_recursive(args->repo, args->tree, - &ctx.pathspec, - reject_entry, &ctx); + ret = read_tree(args->repo, args->tree, + &ctx.pathspec, + reject_entry, &ctx); clear_pathspec(&ctx.pathspec); return ret != 0; } diff --git a/builtin/checkout.c b/builtin/checkout.c index 2c2d58a230..0e66390520 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -155,8 +155,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base, static int read_tree_some(struct tree *tree, const struct pathspec *pathspec) { - read_tree_recursive(the_repository, tree, - pathspec, update_some, NULL); + read_tree(the_repository, tree, + pathspec, update_some, NULL); /* update the index with the given tree's info * for all args, expanding wildcards, and exit @@ -322,7 +322,7 @@ static void mark_ce_for_checkout_overlay(struct cache_entry *ce, * If it comes from the tree-ish, we already know it * matches the pathspec and could just stamp * CE_MATCHED to it from update_some(). But we still - * need ps_matched and read_tree_recursive (and + * need ps_matched and read_tree (and * eventually tree_entry_interesting) cannot fill * ps_matched yet. Once it can, we can avoid calling * match_pathspec() for _all_ entries when diff --git a/builtin/log.c b/builtin/log.c index 58acb2b76a..980de59063 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -681,9 +681,9 @@ int cmd_show(int argc, const char **argv, const char *prefix) diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), name, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); - read_tree_recursive(the_repository, (struct tree *)o, - &match_all, show_tree_object, - rev.diffopt.file); + read_tree(the_repository, (struct tree *)o, + &match_all, show_tree_object, + rev.diffopt.file); rev.shown_one = 1; break; case OBJ_COMMIT: diff --git a/builtin/ls-files.c b/builtin/ls-files.c index fa9b01b6cc..13bcc2d847 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -523,7 +523,7 @@ void overlay_tree_on_index(struct index_state *istate, if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(the_repository, tree, &pathspec, fn, istate); + err = read_tree(the_repository, tree, &pathspec, fn, istate); if (err) die("unable to read tree entries %s", tree_name); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index dbb31217be..3a442631c7 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -185,6 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) tree = parse_tree_indirect(&oid); if (!tree) die("not a tree object"); - return !!read_tree_recursive(the_repository, tree, - &pathspec, show_tree, NULL); + return !!read_tree(the_repository, tree, + &pathspec, show_tree, NULL); } diff --git a/merge-recursive.c b/merge-recursive.c index 1593f37449..3d9207455b 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -473,8 +473,8 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree) { struct pathspec match_all; memset(&match_all, 0, sizeof(match_all)); - read_tree_recursive(opt->repo, tree, - &match_all, save_files_dirs, opt); + read_tree(opt->repo, tree, + &match_all, save_files_dirs, opt); } static int get_tree_entry_if_blob(struct repository *r, diff --git a/tree.c b/tree.c index fb4985f22c..f6de250d7f 100644 --- a/tree.c +++ b/tree.c @@ -81,10 +81,10 @@ static int read_tree_1(struct repository *r, return 0; } -int read_tree_recursive(struct repository *r, - struct tree *tree, - const struct pathspec *pathspec, - read_tree_fn_t fn, void *context) +int read_tree(struct repository *r, + struct tree *tree, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context) { struct strbuf sb = STRBUF_INIT; int ret; diff --git a/tree.h b/tree.h index 1309ab997e..4fb713774a 100644 --- a/tree.h +++ b/tree.h @@ -33,8 +33,8 @@ 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 *); -int read_tree_recursive(struct repository *r, - struct tree *tree, - const struct pathspec *pathspec, - read_tree_fn_t fn, void *context); +int read_tree(struct repository *r, + struct tree *tree, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context); #endif /* TREE_H */ From patchwork Tue Mar 16 15:52:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3999AC4361B for ; Tue, 16 Mar 2021 15:53:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 220CE650F7 for ; Tue, 16 Mar 2021 15:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233128AbhCPPxk (ORCPT ); Tue, 16 Mar 2021 11:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237948AbhCPPxA (ORCPT ); Tue, 16 Mar 2021 11:53:00 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E250C061765 for ; Tue, 16 Mar 2021 08:52:56 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id y16so10751973wrw.3 for ; Tue, 16 Mar 2021 08:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sVCkc2L9MdJuhSkePx0IuyxRZyX7dqx0Hrl9GTag0H8=; b=nK1PlUCOXuLyFsAgGPuujGge1uk8DgKE0IHgWBczp8zWIsHgSfR1x3igfN7whvwkqh 7XV85WtdUaMvm2Tkyab7ab3VRDD2DJ11+b/0EkAt4ohSM54zitErlG/1WRlAKV4Pf3TN TDFY4SV3kHy3WrAwpkSn0J+Eor4qzITz7/Az7YV5Gn54Q1qJpFd+wrwpLMyvKEd8mOe+ Sp+jhblSgHt8kV8tIh4oanIXosQB/BkNyt3xcahYDZH2HqUv9S02hNySxwo2bEx93hyD WVy39RMYORdKo9tVR9IMgwAEnwk9PmuG+rEqJCRUo5gpv2AYRCxHxjZAgGaRVaqpBCSl Bj8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sVCkc2L9MdJuhSkePx0IuyxRZyX7dqx0Hrl9GTag0H8=; b=lWQcxbnCKZuVeX/v4shRltM090nvERiswGDYO3AsCpA9BEFXUSzGcVL3nRoSOF7svS Bigfd++BHD6TD8D8b4q3xRAgkh1dV/8PopZ0Xk2CEmxhc8X3gQGHVaIfHcCQ/ELhLnYK wlLgYTJsUek7oP5/Mdim0WTDUUJr1Huj3mdFgkv8AQN2Luav7o3dNN1BRfXJvlbXoWlQ mKzAHVt2kmpc+jEB7MYd38kdwTrqJ+RIDCQmgUARtpR/W7ndbc2r5W0/QFbb1jgxq95F 5wlVsX8hb91m7iVtNPGuclOfDkYYVzssK/0eOYS2X04gb07pObspPfG768aOdlBUS0d8 SNww== X-Gm-Message-State: AOAM533dCHSwJ7N0kvMFaip1xUoriU0uQ3eSwOmu1sLR4X+XN8XUV5IX ECs/Mk85/OYtHqrbsQonAMVguDPI2zFIDg== X-Google-Smtp-Source: ABdhPJzDgk6JwBJHxjFoTnYpPqOqxzFSeXHyp7GZ6Ag62HuKsVNMtGYCJcxtKET1syiIuFD9GPph9A== X-Received: by 2002:a5d:4ac4:: with SMTP id y4mr5612699wrs.86.1615909975002; Tue, 16 Mar 2021 08:52:55 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:54 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 8/9] show tests: add test for "git show " Date: Tue, 16 Mar 2021 16:52:43 +0100 Message-Id: <20210316155244.28328-9-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add missing tests for showing a tree with "git show". Let's test for showing a tree, two trees, and that doing so doesn't recurse. The only tests for this code added in 5d7eeee2ac6 (git-show: grok blobs, trees and tags, too, 2006-12-14) were the tests in t7701-repack-unpack-unreachable.sh added in ccc1297226b (repack: modify behavior of -A option to leave unreferenced objects unpacked, 2008-05-09). Let's add this common mode of operation to the "show" tests themselves. It's more obvious, and the tests in t7701-repack-unpack-unreachable.sh happily parse if we start buggily emitting trees recursively. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7007-show.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/t/t7007-show.sh b/t/t7007-show.sh index 42d3db6246..d6cc69e0f2 100755 --- a/t/t7007-show.sh +++ b/t/t7007-show.sh @@ -38,6 +38,45 @@ test_expect_success 'showing two commits' ' test_cmp expect actual.filtered ' +test_expect_success 'showing a tree' ' + cat >expected <<-EOF && + tree main1: + + main1.t + EOF + git show main1: >actual && + test_cmp expected actual +' + +test_expect_success 'showing two trees' ' + cat >expected <<-EOF && + tree main1^{tree} + + main1.t + + tree main2^{tree} + + main1.t + main2.t + EOF + git show main1^{tree} main2^{tree} >actual && + test_cmp expected actual +' + +test_expect_success 'showing a trees is not recursive' ' + git worktree add not-recursive main1 && + mkdir not-recursive/a && + test_commit -C not-recursive a/file && + cat >expected <<-EOF && + tree HEAD^{tree} + + a/ + main1.t + EOF + git -C not-recursive show HEAD^{tree} >actual && + test_cmp expected actual +' + test_expect_success 'showing a range walks (linear)' ' cat >expect <<-EOF && commit $(git rev-parse main3) From patchwork Tue Mar 16 15:52:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12142619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25634C4360C for ; Tue, 16 Mar 2021 15:53:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 121A36511D for ; Tue, 16 Mar 2021 15:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238172AbhCPPxk (ORCPT ); Tue, 16 Mar 2021 11:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238089AbhCPPxD (ORCPT ); Tue, 16 Mar 2021 11:53:03 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B4E4C0613D7 for ; Tue, 16 Mar 2021 08:52:57 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id e10so10719505wro.12 for ; Tue, 16 Mar 2021 08:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fx+jZmmd3ye+eq6ZLjonBFLDQMakFKrosuWsCcXVEJE=; b=H8FGztUC+JfStY0wYFzbrlM8LKDc5tCbh0WCuQ+To5xH+mqVTOgo3+b8IguVjfjrel BRTJVJX6MPwC4ulg798ZctToCyc6zpZm35MToJLxdXRMfuY5BGsr65Rkhn53mMHxFiuC u/JtRSFnByqWLarqQngnSlzaJtEVLiThnc3Pgez9HxVDEp/Di8sFsDTkzKqS+9/wIc5e IavouIqaAuu26VNS3yGgzgn7TYqWTTAgBRVJqZEksR0KRfWij263PTO+WzXNoJmYhrFw jRaP+FdvQ1/iOQWT56ykdhRRHEWqGBHVVq1zrp62ysVSqUEjPo15dDqn8OmQGsQU2UPe NeQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fx+jZmmd3ye+eq6ZLjonBFLDQMakFKrosuWsCcXVEJE=; b=qfSJ+/T0AEIdyxpFPHdhvs9OIztFkwRtFUYgsKlcXlPrcdv2cW6/k8JXJD48eKn0zV 3XfOV4dk0UnBtK4nz1C6zbSpKj/FgTcimBjcCDfOV2RMbBl9kqBrYfAVE3NoS9+LtNL/ VNmW19h9ZNZM6fAxgPgywvnyAFIfxy47Zr7Etq3fu5603/DwItVJWiHwLElJclHlKNeX HNiezHMrEpzWkYui+jXWGvFQ4cFM+Yd6ntyXEz8O5SiA/q7fS1/d9jScAi3L8p+WJgNJ TFYD+5q63pLVh9RAMFnjmhhYudzFGTbVW4jiSzuq5a+Bc0UgvLkj5G08fx7OkioGJyqQ qMqg== X-Gm-Message-State: AOAM533SmF69N7/shtvKGPtB2m1kZ8Eq7Zwj5ehZGC9Bf3RVevQYGpl1 XQ0NDxfodIFo33LwC4cMOaHzA+nDKcqumQ== X-Google-Smtp-Source: ABdhPJyKglLRA2go7kVKL744Dey16hvSiEQA4IZB4gLp7rALDv0XtCkOAEfma9F8inJ/KUq1C9uLfw== X-Received: by 2002:a5d:5411:: with SMTP id g17mr5643761wrv.194.1615909975743; Tue, 16 Mar 2021 08:52:55 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i11sm22224228wro.53.2021.03.16.08.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 08:52:55 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 9/9] tree.h API: expose read_tree_1() as read_tree_at() Date: Tue, 16 Mar 2021 16:52:44 +0100 Message-Id: <20210316155244.28328-10-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.256.gf0ddda3145 In-Reply-To: <20210315234344.28427-1-avarab@gmail.com> References: <20210315234344.28427-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the static read_tree_1() function to read_tree_at(). This will allow for the old read_tree_recursive() mode of operation where we start at a given path instead of "". See [1] for the discussion of one such future in-tree user, unlike the old read_tree_recursive() this function takes a strbuf. Since that's what read_tree_1() used internally this should allow us to avoid casting and/or reallocations in the future. 1. https://lore.kernel.org/git/xmqqft106sok.fsf@gitster.g/#t --- tree.c | 16 ++++++++-------- tree.h | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tree.c b/tree.c index f6de250d7f..6a2a52967e 100644 --- a/tree.c +++ b/tree.c @@ -11,10 +11,10 @@ const char *tree_type = "tree"; -static int read_tree_1(struct repository *r, - struct tree *tree, struct strbuf *base, - const struct pathspec *pathspec, - read_tree_fn_t fn, void *context) +int read_tree_at(struct repository *r, + struct tree *tree, struct strbuf *base, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context) { struct tree_desc desc; struct name_entry entry; @@ -71,9 +71,9 @@ static int read_tree_1(struct repository *r, len = tree_entry_len(&entry); strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); - retval = read_tree_1(r, lookup_tree(r, &oid), - base, pathspec, - fn, context); + retval = read_tree_at(r, lookup_tree(r, &oid), + base, pathspec, + fn, context); strbuf_setlen(base, oldlen); if (retval) return -1; @@ -89,7 +89,7 @@ int read_tree(struct repository *r, struct strbuf sb = STRBUF_INIT; int ret; - ret = read_tree_1(r, tree, &sb, pathspec, fn, context); + ret = read_tree_at(r, tree, &sb, pathspec, fn, context); strbuf_release(&sb); return ret; } diff --git a/tree.h b/tree.h index 4fb713774a..f0b079d2e9 100644 --- a/tree.h +++ b/tree.h @@ -33,6 +33,12 @@ 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 *); +int read_tree_at(struct repository *r, + struct tree *tree, + struct strbuf *at, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context); + int read_tree(struct repository *r, struct tree *tree, const struct pathspec *pathspec,