From patchwork Sat Mar 6 19:34:52 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: 12120195 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,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 4461FC433DB for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BC9B650CF for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231522AbhCFTf0 (ORCPT ); Sat, 6 Mar 2021 14:35:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231529AbhCFTfP (ORCPT ); Sat, 6 Mar 2021 14:35:15 -0500 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 E53C5C06174A for ; Sat, 6 Mar 2021 11:35:14 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso1374951wma.4 for ; Sat, 06 Mar 2021 11:35:14 -0800 (PST) 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=l44t0kx9MTkP83vPd5vNxPvm69YH9r5x3db1VIahav4=; b=TGzUCBjBNIwD3ZdPdqevMQx7sQHvlNIy3dQOS4DxGhWwo+J73bYiI9JYXT+dIKALV9 UVPY5Qh9uOp1uYKMPY1EsWuWT/YnjuC5ot2wakD+2yYvdS6fIdhgoJH9wXhZ4HPZH++h crCWopDjyuHz+6vLnLdh59C1oQNxrM9jYXubDqHVVwyS7c2Cu8U1ONpF5uieboqdURku yE0kyMDtZ+EskEdSyT5NDIbr7aB4uWHbPJYgNGxMoyWqjfkfGn6gBKuzEQcho6qlZNK9 xcvW0caEfZ7JO6iISIuWjMCsqWkn2kGzAhY1uw3hgy2JlyP2XUQ4KJ+8IbXdV8Z5hY4V lsLg== 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=l44t0kx9MTkP83vPd5vNxPvm69YH9r5x3db1VIahav4=; b=lvvFUEumM9/mk2epvv59vVDQCgN7JKRXucmlbH1z8laH4bE0L/PL9ViJiZYnjn4tcr bkfxHak3+3mJdQf73fSWhCzms+mSBc3X2d8AkIApatSMy9tycJ8GzW9iKKK6+EgHPw2j S3B+l+P8FisjBvL8VpDzBZGh8viGk8wtcHK6ZMFKAbjsEw8wdSvXg9fro0lbap3nqg1i hIqLPHvX0sepVMXwssescOWPg02aj+b+cxMr5Fcg+5Jf0rZ565M9HXeFzClHvoQ0uc7z Vh4wVTLfGrVEh5MxEwZSsgJGpiLqB7/Cf5dAwKKIbQejnmhFD+NeZJltmiAVKBaxNwK1 Q6Dw== X-Gm-Message-State: AOAM530RK5iGaGp8oZ+RfgiIPCipbrMBuFlFTk7wKq2jwkeLo/ozB+6b gzwTqPk1XRttBfxCqq4bfGl+sdbE4HEFlw== X-Google-Smtp-Source: ABdhPJxijE3x1+VhIKo7sxDdGcbYaX5wysxBqrmfYcOvnax227c6aDAGAhyy/GLZrkvbHv314cWR4A== X-Received: by 2002:a1c:7901:: with SMTP id l1mr14986599wme.114.1615059313304; Sat, 06 Mar 2021 11:35:13 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a5sm9951578wrs.35.2021.03.06.11.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:35:12 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/7] tree.c API: move read_tree() into builtin/ls-files.c Date: Sat, 6 Mar 2021 20:34:52 +0100 Message-Id: <20210306193458.20633-2-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <1240014568-3675-1-git-send-email-pclouds@gmail.com> References: <1240014568-3675-1-git-send-email-pclouds@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 ++++++++++++++++++++++++++++++++++++++++++++++ tree.c | 89 --------------------------------------------- tree.h | 4 -- 3 files changed, 91 insertions(+), 93 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index f6f9e483b27..a4458622813 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/tree.c b/tree.c index a52479812ce..a6c12f2745a 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 3eb0484cbf2..84d66b45538 100644 --- a/tree.h +++ b/tree.h @@ -39,8 +39,4 @@ int read_tree_recursive(struct repository *r, 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 Sat Mar 6 19:34:53 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: 12120199 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,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 5C71FC433E6 for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 349FA650BC for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbhCFTf3 (ORCPT ); Sat, 6 Mar 2021 14:35:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231531AbhCFTfQ (ORCPT ); Sat, 6 Mar 2021 14:35:16 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE335C06174A for ; Sat, 6 Mar 2021 11:35:15 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id j2so6575579wrx.9 for ; Sat, 06 Mar 2021 11:35:15 -0800 (PST) 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=IPKfvej6w7tTutDJz8cAOO04Knc3C1maiRIg6hg7wGc=; b=j5Gcu35wZGaBt6dj4xcF4Zfjob5BzV7TNBDVbi0isvm2moEOSkdDNC5lzpZ1NrC9CD ZshiGA0WYhafeU4etKQ12AhUooxgd/GHWRRtjwdDASqxg9lvhPcJhdP40TnU2mlTvDr5 C0KdBabpYLyb+wBJN+jvJz6dLeUy7ghUbMXh+tKDvsUQvzL/c38iM3zQZ+hX7oYqijCO Pe0QYgzh1DckAWhDhCxSS+sxA/8EoqJ8xTDSsTMssnMVVwhebWE1R7Do7/a3gmJal1sW aTVXBH3cK7OswOHHqDT/YJtxIDxU05ANdcoQjgiRA894eZtF9fA0RRolMjVCV3AyNBHa 7ikg== 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=IPKfvej6w7tTutDJz8cAOO04Knc3C1maiRIg6hg7wGc=; b=q3rZL94Y7VVn9WfIiZI8oktk0NP5iDc1CQ6WIjkapZYAIQTgJVUgdGTidt67Zc30m5 u1AiwD5Q7oWb+F0wvD83i5xOhFmNVUYt4c1KLvTgeIRJ+SgmykJ0y/P7+TcxqNnJaJ5W ONDct5sgAPIjv6PhS0zOAsHAPnsIcz5AKC+L3TNhww2G87p14Wf/g0HEVTFFRumuR9Vq yHx0pqJhH17V8XeOyPh1ETUukV7vL3BPfTb9j7DSvcOjbMICDDBV5ZVA1YLMX8/aMv1V k4b69EWdYaiC88uqatuEEXAcRM1/SZKNbr6m4wLz/OvzFKEcpQg+sxeuSIedLcAz0qn5 wzyQ== X-Gm-Message-State: AOAM531JSViOpbZV8hRM5T256G1oLm6d8gJbhV4SFEnYA/fsvXc1UtSE C5+4bNekeraq84REpZ+/ZhaYAqfE3KZ/VQ== X-Google-Smtp-Source: ABdhPJxUGaqixtZ1DrOqgERJIoNqZmIMNP/SNRPc49dUAiQCbZtoQfMObl79Ch0Grsfo1s117uXYLg== X-Received: by 2002:adf:f144:: with SMTP id y4mr15401414wro.408.1615059314382; Sat, 06 Mar 2021 11:35:14 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a5sm9951578wrs.35.2021.03.06.11.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:35:13 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/7] ls-files: don't needlessly pass around stage variable Date: Sat, 6 Mar 2021 20:34:53 +0100 Message-Id: <20210306193458.20633-3-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <1240014568-3675-1-git-send-email-pclouds@gmail.com> References: <1240014568-3675-1-git-send-email-pclouds@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 a4458622813..74d572a3e4a 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 Sat Mar 6 19:34:54 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: 12120201 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,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 8A0A5C43381 for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56F05650E3 for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbhCFTf3 (ORCPT ); Sat, 6 Mar 2021 14:35:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231527AbhCFTfR (ORCPT ); Sat, 6 Mar 2021 14:35:17 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2D2AC06174A for ; Sat, 6 Mar 2021 11:35:16 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id 7so6618928wrz.0 for ; Sat, 06 Mar 2021 11:35:16 -0800 (PST) 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=s2SCpNqpvtyG6ZTXDnM+8KOZOD8tX2tX2pQPYZ2RGWA=; b=NuPSaiNn5WB4YYJICTxpSgpzbQ9dgc7r1WO3cGBPwaMFXAtgtDnybXFwU0mgzGIIgw VGy0GfPEAryRxIHgJG0MxK0tsYWkjL81bYJkO/E7jU/uFNAkkUqR5FlVWR2d+Zub8Dvo Js+sAGRRoqrfdA+cz7okm2XYd0ZWAZy9WEOpsFfZQ4FnQYOAMC6H9dPOqW1ku2BByeBi zzGE2jCTW10KqrcrsPOS5/5EpzL+/LI214LfLXpAF70glFxB/P3vTzeTLPq1ViaD6gUV vynJpzXdomVdMGlA2qznM6LnEhOUDmH0+OwxNaHADm1k7iAPl8H3SWDKp5ivHnGDmnne XniQ== 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=s2SCpNqpvtyG6ZTXDnM+8KOZOD8tX2tX2pQPYZ2RGWA=; b=aXMxz62pPG4YsRTTn74vcpllWOJMhwLk9iAxMWoyp9UOt4fkomak8udjIYz+qzP6HM l1V44iNqWla5nJM38KDJj/na7jkLJG5JrdPjQkNvKCfVM8UzFF7XJmYwPtxL7sR5yjej 9pwNLwkBfig7cJr3DFbECBAeQxvDhuY/ytcJxVRBfA4Osyj0RcuwZnEn5nPSWtl83H23 5H28jWsGyvfE2K5wK5WKfw7nYI1dA5lXIMVtCCc9Gw5Ucn7aORoyii5I7gRRDwTuG4MD zao5ewv2Te3cxulQKxiy+j67eMAUPjWyy8DpiKDa/mHFZos4m5oISHj2pCeZ4I/WecgI J5mg== X-Gm-Message-State: AOAM530hrRv2QdfpO8ZuFfQRIsQFWdpGb5fFWRVTsClzWOUCJVMzxHJm gs7q3TLNSaueZ1f8HN1YRKSyK/30++SPzg== X-Google-Smtp-Source: ABdhPJzDk91sViPgIonmw0KIPIJlhxYZ8rDDb2kttShNC2Pxyv39DrTqfWmnPHTh2fxOWm9XINFo4w== X-Received: by 2002:adf:ec46:: with SMTP id w6mr15045102wrn.213.1615059315282; Sat, 06 Mar 2021 11:35:15 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a5sm9951578wrs.35.2021.03.06.11.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:35:14 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/7] ls-files: remove cache juggling + sorting Date: Sat, 6 Mar 2021 20:34:54 +0100 Message-Id: <20210306193458.20633-4-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <1240014568-3675-1-git-send-email-pclouds@gmail.com> References: <1240014568-3675-1-git-send-email-pclouds@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the "ce_stage(ce) == 1" and "Sort the cache entry" code from read_tree(), which allows us to remove the function entirely and move over to read_tree_recursive(). I don't think the "Sort the cached entry" code was needed here, see af3785dc5a7 (Optimize "diff --cached" performance., 2007-08-09) for the use-case it was intended for. The only user of this code is "ls-files --with-tree", which isn't the sort of use-case that needs to care about "ce_stage(ce) != 0" or sorting tree entries. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 76 +++++++--------------------------------------- 1 file changed, 11 insertions(+), 65 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 74d572a3e4a..f5239437809 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -12,7 +12,6 @@ #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" @@ -421,12 +420,15 @@ 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) +static int read_one_entry_quick(const struct object_id *oid, + struct strbuf *basebuf, + const char *pathname, + unsigned mode, + int stage, void *context) { + struct index_state *istate = context; + const char *base = basebuf->buf; + const int baselen = basebuf->len; int len; struct cache_entry *ce; @@ -442,64 +444,7 @@ static int read_one_entry_opt(struct index_state *istate, 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, - 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; + return add_index_entry(istate, ce, ADD_CACHE_JUST_APPEND); } /* @@ -540,7 +485,8 @@ 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)) + if (read_tree_recursive(the_repository, tree, "", 0, 1, + &pathspec, read_one_entry_quick, istate)) die("unable to read tree entries %s", tree_name); for (i = 0; i < istate->cache_nr; i++) { From patchwork Sat Mar 6 19:34:55 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: 12120207 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,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 AF622C43331 for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D4B4650DA for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231558AbhCFTfb (ORCPT ); Sat, 6 Mar 2021 14:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231532AbhCFTfS (ORCPT ); Sat, 6 Mar 2021 14:35:18 -0500 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 B5074C06174A for ; Sat, 6 Mar 2021 11:35:17 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id y124-20020a1c32820000b029010c93864955so1383195wmy.5 for ; Sat, 06 Mar 2021 11:35:17 -0800 (PST) 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=H8fi1Lus64w77i6PGkYGPRUgqUGl8V27vNlrXTmX4M8=; b=HS/P6kIpFyOrF/ZY+SOl34P94TRzjsfAihrqCetqCzyDUYBX5q3cllseUlmqIEjdt5 sxDjFPc8jW8wfE3xnDJYED7w5FVa4Jsr7hCorfdiWaBn2xXs+juYhnUn1spM3RNKenil IAvSVyPg+4LZwpfCrOWcHdnxoCLxGn0n7kSrMztOUdxYD0Q4ekQ1+cK9g24WIyLRNebn xmfgkrbLXWOOtgqhfvcfw+MXsf4cAAqN7cjB9sZkmqTFwqHhI6g0MQPISD9JpEPtI6BZ yEv/A479mS974LpQzjore2T49Pp81m2qpuXssDhrGMtmtDsa5nn1nOjO4aLw78Y+kBLL +jTA== 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=H8fi1Lus64w77i6PGkYGPRUgqUGl8V27vNlrXTmX4M8=; b=FYi/4K3Eb4XARmpI1u9jwI3S5yVt4tfPLqukp80K4tL+pDEd02J1YF6skxAvZK1IcY mK17RcU0BJvfehzKFA+g++d+EfHIoylGrvRUF/ucyNhmwEPeAQfLsfyW/E/r+UqTFJs9 TKS3lg2bNv2fiUcZ9L8ZvceS+CnweWYpaStE9JKZimv01PcuUzGcBbnM2+eNoII0/wlv A5P5TQlD1JbK4pzp6Bo7LMb62FgB7qD2BU9QrVLMUsD2zHcGmmtsZhrS3epnUJU7noGa +3ar3hXN4WuV1gSiMPUFcHkOF2v5ICeluoQMxzIcuxr3947xQbaQJrYMXQOalH6g3NvB cNWQ== X-Gm-Message-State: AOAM533uLvQhW3oBGFepcLXuGuOqzj+XI6U+vVmcPVctXg6P77879Ktb nvSXr1NxA3mnepBh+XLoLDFO9hEv3j33iA== X-Google-Smtp-Source: ABdhPJx1J0CK1jwGU3ATm3SLzryJh5QIl7GM4DnHSNgBNadeE2iFT3xk/87RjT6mmDrOL3/RGIp5Dg== X-Received: by 2002:a05:600c:4f14:: with SMTP id l20mr13791917wmq.71.1615059316259; Sat, 06 Mar 2021 11:35:16 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a5sm9951578wrs.35.2021.03.06.11.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:35:15 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 4/7] merge-ort: move cmp_cache_name_compare() from tree.c Date: Sat, 6 Mar 2021 20:34:55 +0100 Message-Id: <20210306193458.20633-5-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <1240014568-3675-1-git-send-email-pclouds@gmail.com> References: <1240014568-3675-1-git-send-email-pclouds@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the cmp_cache_name_compare() function from tree.c. Now that we've stopped using it in builtin/ls-files.c the merge-ort.c code is its only user, let's just have it own it instead of having this API which straddles tree.h and cache-tree.h in tree.c itself. See these commits for its recent introduction in merge-ort.c:: - 70912f66de7 (tree: enable cmp_cache_name_compare() to be used elsewhere, 2020-12-13) - ef2b3693870 (merge-ort: add implementation of record_conflicted_index_entries(), 2020-12-13) Signed-off-by: Ævar Arnfjörð Bjarmason --- merge-ort.c | 10 ++++++++++ tree.c | 11 ----------- tree.h | 2 -- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 603d30c5217..d7b3ced1bec 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -3099,6 +3099,16 @@ static int checkout(struct merge_options *opt, return ret; } +static int cmp_cache_name_compare(const void *a_, const void *b_) +{ + const struct cache_entry *ce1, *ce2; + + ce1 = *((const struct cache_entry **)a_); + ce2 = *((const struct cache_entry **)b_); + return cache_name_stage_compare(ce1->name, ce1->ce_namelen, ce_stage(ce1), + ce2->name, ce2->ce_namelen, ce_stage(ce2)); +} + static int record_conflicted_index_entries(struct merge_options *opt, struct index_state *index, struct strmap *paths, diff --git a/tree.c b/tree.c index a6c12f2745a..c1bde9314d0 100644 --- a/tree.c +++ b/tree.c @@ -1,5 +1,4 @@ #include "cache.h" -#include "cache-tree.h" #include "tree.h" #include "object-store.h" #include "blob.h" @@ -96,16 +95,6 @@ int read_tree_recursive(struct repository *r, return ret; } -int cmp_cache_name_compare(const void *a_, const void *b_) -{ - const struct cache_entry *ce1, *ce2; - - ce1 = *((const struct cache_entry **)a_); - ce2 = *((const struct cache_entry **)b_); - return cache_name_stage_compare(ce1->name, ce1->ce_namelen, ce_stage(ce1), - ce2->name, ce2->ce_namelen, ce_stage(ce2)); -} - 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 84d66b45538..34549c86c9f 100644 --- a/tree.h +++ b/tree.h @@ -28,8 +28,6 @@ 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); -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 *); From patchwork Sat Mar 6 19:34:56 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: 12120197 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,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 6D39BC433E9 for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45AE8650DA for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231550AbhCFTfa (ORCPT ); Sat, 6 Mar 2021 14:35:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231534AbhCFTfS (ORCPT ); Sat, 6 Mar 2021 14:35:18 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60B21C06174A for ; Sat, 6 Mar 2021 11:35:18 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id h98so6557693wrh.11 for ; Sat, 06 Mar 2021 11:35:18 -0800 (PST) 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=wmAkSq8IagvE7+NAwHoAE0V4jW/rRsqaPepw1V8Hrfk=; b=rogK9AoTnpsGlNnDBJNm5tf+R8o7LH+8oAlV2poqdXwK48b0fG7iXZoEE4M/vJ+aam DVQ3eYNZSfrYSPKinwQSGG8nUR+0KNbT6Ub7AYJYw5YggheTjkCZYlGT9BaGEWnsnl9l Bnxucb31wVZb38+LOjPYLZHu6Sxdsrytwzz31aqgakpRliHqp9V3M0mf/Ue0CxnKIzVg 9I/Q7lR1RWPHpvW/pELCUIquvdDZWcnEVISUbdK6SdOIu400TPoaCLIum0YpOBwaEpxP DxrSTcdLRVv20j5smFhCXxG7xborSe3rwH2mtb88E+ucprYBC4eOAqUe5NicndvfHjxp Jajg== 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=wmAkSq8IagvE7+NAwHoAE0V4jW/rRsqaPepw1V8Hrfk=; b=C66fjfUNEQ3O1DegUP8god3f0dUXN0hCZWNAMZ012Q4Df22G52lQ9HQY5XkMc5hdxB T0XSnYkMn24D4xHpP3bkjBIwOXHTaXD1LhrPIen8QRbinWBV8TgqhEpOHH5MMa3bNaTa PuaK2PeVCq6FtkWt1srqBcNxNIUS5e6pJhjiMBaqmKHzZ/OPV6OoAtxU1YbqV89sAkFm a1TUTl4QJhfZdzGHz4f8+Dz+lLbypF+qhVm+UeX0xjeplooac0c7JxZav3JFr0AcNUBQ MrwhQJX9eLZHc/mVQZ8+UMvBROpm0YzhFnuLm5S6XfdARTl8T6xFE3hSfi7xkGUe667o K1Jw== X-Gm-Message-State: AOAM532PD4MjcQ8b0rVcp3JLnnSdfvTohHhaFVU/XB8Pv1dwdtbgUCgC 4hsB2bs9jQ3SQ78bWKbksJo6oQeD/Y/5cA== X-Google-Smtp-Source: ABdhPJwQolVj6ts8agfeTJ/U9yQt8TRp58IhN8qrNqgVTGR42O1A+6Ji9yQ26WH00V5kUF2dA/Ki5Q== X-Received: by 2002:adf:f411:: with SMTP id g17mr15024386wro.22.1615059316970; Sat, 06 Mar 2021 11:35:16 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a5sm9951578wrs.35.2021.03.06.11.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:35:16 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 5/7] ls-files: refactor read_one_entry_quick() to use a strbuf Date: Sat, 6 Mar 2021 20:34:56 +0100 Message-Id: <20210306193458.20633-6-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <1240014568-3675-1-git-send-email-pclouds@gmail.com> References: <1240014568-3675-1-git-send-email-pclouds@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the code in read_one_entry_quick() that used "base" and "baselen" to just use the "buf" and "len" fields in the "base" strbuf directly. Having the "basebuf" variable was a transitory step in moving away from the old read_tree() in tree.c. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index f5239437809..c0349a7b206 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -421,14 +421,12 @@ static int get_common_prefix_len(const char *common_prefix) } static int read_one_entry_quick(const struct object_id *oid, - struct strbuf *basebuf, + struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { struct index_state *istate = context; - const char *base = basebuf->buf; - const int baselen = basebuf->len; int len; struct cache_entry *ce; @@ -436,13 +434,13 @@ static int read_one_entry_quick(const struct object_id *oid, 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, ADD_CACHE_JUST_APPEND); } From patchwork Sat Mar 6 19:34:57 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: 12120203 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,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 9436DC4332B for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F481650BC for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbhCFTfc (ORCPT ); Sat, 6 Mar 2021 14:35:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbhCFTfT (ORCPT ); Sat, 6 Mar 2021 14:35:19 -0500 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 2EFA4C06174A for ; Sat, 6 Mar 2021 11:35:19 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id e10so6550192wro.12 for ; Sat, 06 Mar 2021 11:35:19 -0800 (PST) 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=mrcRlHe995DTbDvHo1KsHYJ867Bi456GltRcqJtXoME=; b=NvhnJbaFUTf0lFxnawzWW+lppIx5zhnmGZm+vZONujtrtGaGz8B4Zu3zQjcrpNSlvF O3JNh6UqtUwPlhPAnG4J62OYxlaJzWW58T4stSDhOfCWTjqomHr3/3IKy2QDZN/Rzf5w SpdS7OR3+fXxIAB8k8Sgq1ffgKNLU959IpoSfmVI74Sd16Qf2e00rcGmZsFJiR2rEAZy Y+Tlf5fggPKq6nIALosRz+eau6dWKve7jEVa3jfhlgL7nLbFRlI/xAZPVFFzzVm/AiHE Q31bD1c/7uuPc+ZPOZzbFwIIkdLGt7LY8diaSUrmmP9ZYErS8xC3+6IpcLFCwUGbHUbh 6QmA== 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=mrcRlHe995DTbDvHo1KsHYJ867Bi456GltRcqJtXoME=; b=OlRx7BitcKcC1+TT+cThndInJbnkjAsR5vdK3vhcsSz36fZHpufzWE5U5nXYjQJ92y QOs9uaVm0eRygJDhCrCXVhLoU8pQMeg1adhCVzkEQDRZGc7hNbHHFVpaQ3hE0ySfAl5f us4XwoItc73qt/6n0lqdNClER6tIinqPL2eXjZCRsHUDvLwZBtN1AWCjDqnXGBqDbofF N0zhEhMnwAOBRkQGB1ciGP2FL7XguFiLvUYy0JdJMaBD+zHRLboiHZb36OEolIkC5M0X SpqsaAZhnMTciIBQdccrvWWrq9GfXmFpMTak54DB2lRZr6baaq+/rJ1CimH1UKRYsviu NHTQ== X-Gm-Message-State: AOAM5327HjLPaWIfagSt3bjdE80QmIlf2bY69oFiWYPSFveowhv5qfSl SAxS/v8mN8QzXGausC1/TJtT3JKj2XqvPA== X-Google-Smtp-Source: ABdhPJzRvfa2RrMQ4lNhd9AmU03Z5fWNLJ+NZOWlkCKWxImQbprgxp/BSkEUg1yNNdkMQHC6WLo+Xw== X-Received: by 2002:a5d:4d0f:: with SMTP id z15mr15510015wrt.192.1615059317660; Sat, 06 Mar 2021 11:35:17 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a5sm9951578wrs.35.2021.03.06.11.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:35:17 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 6/7] tree.h API: remove support for starting at prefix != "" Date: Sat, 6 Mar 2021 20:34:57 +0100 Message-Id: <20210306193458.20633-7-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <1240014568-3675-1-git-send-email-pclouds@gmail.com> References: <1240014568-3675-1-git-send-email-pclouds@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Every caller or the read_tree_recursive() function hardcoded a starting point of "" in the tree. So let's simply remove that parameter. It might be useful in the future to get this functionality back, there's no reason we won't have a read_tree_recursive() use-case that would want to start in a subdirectory. But if and when that happens we can just add something like a read_tree_recursive_subdir() and have both read_tree_recursive() and that function be a thin wrapper for read_tree_1(). In the meantime there's no reason to keep around what amounts to dead code just in case we need it in the future. 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 5919d9e5050..9394f170f7f 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 2d6550bc3c8..21b742c0f07 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 f67b67d80ed..ffa3fb8c286 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 c0349a7b206..2c609428eea 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -483,7 +483,7 @@ void overlay_tree_on_index(struct index_state *istate, PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree_recursive(the_repository, tree, "", 0, 1, + if (read_tree_recursive(the_repository, tree, 1, &pathspec, read_one_entry_quick, istate)) die("unable to read tree entries %s", tree_name); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 7cad3f24ebd..7d3fb2e6d0f 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 b052974f191..fa7602ff0f2 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 c1bde9314d0..285633892c2 100644 --- a/tree.c +++ b/tree.c @@ -82,14 +82,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 34549c86c9f..9a0fd3221e3 100644 --- a/tree.h +++ b/tree.h @@ -33,7 +33,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); From patchwork Sat Mar 6 19:34:58 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: 12120205 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,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 A774EC4332D for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BF94650DE for ; Sat, 6 Mar 2021 19:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231572AbhCFTfd (ORCPT ); Sat, 6 Mar 2021 14:35:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbhCFTfU (ORCPT ); Sat, 6 Mar 2021 14:35:20 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E15D4C06174A for ; Sat, 6 Mar 2021 11:35:19 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id j2so6575757wrx.9 for ; Sat, 06 Mar 2021 11:35:19 -0800 (PST) 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=bFb9CFtDqICgZMCZH6QnByp+tZYf/351eAcZM3MIQMA=; b=jYZlT95N8UlLvbD5iBqxAAOynBrIxXsL2v0OL4+7IJGWclGn9xbiV/zRJIDx+tN1qt YJCZgwlVElqbMlO0/phx9JvtLOkuSBdqT/XurvYIGTesmhBDIzf4Q/dYpzTv00XoHuJh W5vHb9xb+RB7AIEu3AwS49gDJM4jdbwRWSguVn2BLvQXqe6aTOt89Bc1jyEalEWafWa0 UgWNdF5dbw+LYLoYw/qfSn3mbNqtbhU+MZAqhk2RBHME2vMODMHUCKFtb7TJGp2UQtVP ljFaACKMt7SZYMuYTJXzSPA9Yt/ik1fS5UvHPqBFkTHVHRr59xMYn7Dvj6YwKjtFIdXO ZzwA== 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=bFb9CFtDqICgZMCZH6QnByp+tZYf/351eAcZM3MIQMA=; b=VkdXCQUgl1uye13flCf0LtYw6MKQblr0MSXCuM/mpXw2frQFqjbcSS4SBZVP691AdR kpzmz2hGu5TRyNzg7RGZghHFG0lJKhiAYdfPd/Oj9Gl/2KzepdMhk9njdrRXTal41Qve knfg2K/lO+N90SnMw4bi8cMMWuRW+kehZSiScgJ0e552EwGiDlHzDqpxnkxOsb+A+Y4G yIhIJiabas2HZQl8SvoQSB/6Iv6IkoMD+s0KD/aQZ1ZgbGx/iWpodGi7wxLaDfLfkwdd JmOjoR8eZ7OYF+nVXluAVSp9Fhr+la8PCcFBHCT4aTayfMWLo9F50UL/6vlyGpd/KaO1 1DNw== X-Gm-Message-State: AOAM532xC6IlNdqjmJ2Aa3XKZXxaRzAnNZYVjrJ4Z+zUBE4hAkKkGLcQ p1EcZTGWeYuyOlQU2zU63z59hRBzuQ2Qlg== X-Google-Smtp-Source: ABdhPJzfb01hURoaz9rS2WD3B7niCHMq2CjGu0Mvr+0Hce7qllxlu53JKaj3vRPxhU6LNplGXJkCDg== X-Received: by 2002:adf:e74a:: with SMTP id c10mr15843627wrn.409.1615059318360; Sat, 06 Mar 2021 11:35:18 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a5sm9951578wrs.35.2021.03.06.11.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:35:17 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 7/7] tree.h API: remove "stage" parameter from read_tree_recursive() Date: Sat, 6 Mar 2021 20:34:58 +0100 Message-Id: <20210306193458.20633-8-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <1240014568-3675-1-git-send-email-pclouds@gmail.com> References: <1240014568-3675-1-git-send-email-pclouds@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 | 6 +++--- builtin/ls-tree.c | 4 ++-- merge-recursive.c | 4 ++-- tree.c | 10 +++++----- tree.h | 4 ++-- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/archive.c b/archive.c index 9394f170f7f..6669a4bd147 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 21b742c0f07..2c2d58a230f 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 ffa3fb8c286..58acb2b76ab 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 2c609428eea..8ba13b69c97 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -424,7 +424,7 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, - int stage, void *context) + void *context) { struct index_state *istate = context; int len; @@ -437,7 +437,7 @@ static int read_one_entry_quick(const struct object_id *oid, 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); @@ -483,7 +483,7 @@ void overlay_tree_on_index(struct index_state *istate, PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree_recursive(the_repository, tree, 1, + if (read_tree_recursive(the_repository, tree, &pathspec, read_one_entry_quick, istate)) die("unable to read tree entries %s", tree_name); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 7d3fb2e6d0f..dbb31217beb 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 fa7602ff0f2..1593f374495 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 285633892c2..3de41e37364 100644 --- a/tree.c +++ b/tree.c @@ -12,7 +12,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; @@ -37,7 +37,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: @@ -71,7 +71,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) @@ -82,13 +82,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 9a0fd3221e3..e7b851c6abd 100644 --- a/tree.h +++ b/tree.h @@ -29,11 +29,11 @@ void free_tree_buffer(struct tree *tree); struct tree *parse_tree_indirect(const struct object_id *oid); #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 */