From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id E753A1F8C6 for ; Thu, 19 Aug 2021 18:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234546AbhHSS3w (ORCPT ); Thu, 19 Aug 2021 14:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234404AbhHSS3w (ORCPT ); Thu, 19 Aug 2021 14:29:52 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9707BC061575 for ; Thu, 19 Aug 2021 11:29:15 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id v33-20020a0568300921b0290517cd06302dso9800557ott.13 for ; Thu, 19 Aug 2021 11:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yrrC0zGme+GLeP2qVRi9Z+esyOIdmVnZhyy2l+a3IGc=; b=bNo4QOiSGUAhCMhHoWc/7KJNjg3gbmteMuAu3cLEY+twX7Hj2/xZMqSW7eh/cDqf2R ysW35gmxQxA+VqpMHFEIQHahjlvxFpGYkGbcbrH/x+fRNwHJ9dLD/CBMxh4Xs3pbNETZ BJPLJ77bW90t4dx14Zy/zcriTEM2dFkbPQ4zYbY/+EByF/asO8aBkY1/l/+0Zufvz53s yuXlTiNnwghdw8ksHT9H44g2jjLc1A7OXkT6BPfxxOw3xKmiBA/E8Z5tUeHmLRY8JY3d PYOUgoQbLrlcymq1iuJugK+iCY0VAyxX/3oabik4QCqqAo8ldXMOB0AsqOh6w/+P4LkU z34A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yrrC0zGme+GLeP2qVRi9Z+esyOIdmVnZhyy2l+a3IGc=; b=doUjncgk10iQpDUlvyMVAKa12cuqo+9AIS8nP9Ijh/OFnY8dFkY7LttNCQ37ucJU3N iPHum1S4m0IL9mnXBswscjTdTEZM2yod4uRB9W0eNYwpKvr5kXPGbo9e9CfklcLSN5+s JYrwiUflbz8/QkDnDsC46rzMCgBDboedLHJj4G4G443FgryamPjCy4uksdN1FY3/OjCX sSpqEdo7WXB0tpSBy937WFoF468jdE4+m5AuLFBHZsvEgWDoSrmF8VsXtXg2l2ux3Mxd NnexfVh+1pJomeM0gUsV7xksh7x5WS3kyXVVVkf+iVi+NKo0XyX0ZLkGUKu37s+tr3Fr CY0w== X-Gm-Message-State: AOAM530ZpKz+ofKYJab2P+yeBhQIBtwmJlLMU8RUvoRkWTsBT2Z4PgOj dJZKdFuBALqyDrPXeixhjuFDJdUpB/fq7TeFNEA= X-Google-Smtp-Source: ABdhPJyq13aPifCo4qd0da1pFZOwE+erjNUIiRkYHtUm6wD4yEBax7AUq0lptuKN74qjKKwSvnrG/tT9tq3L8AJODyA= X-Received: by 2002:a05:6830:1da:: with SMTP id r26mr12870981ota.162.1629397754973; Thu, 19 Aug 2021 11:29:14 -0700 (PDT) MIME-Version: 1.0 References: <10bcadb284e49419f9b4baf75e05f719ec395d98.1629206603.git.gitgitgadget@gmail.com> In-Reply-To: <10bcadb284e49419f9b4baf75e05f719ec395d98.1629206603.git.gitgitgadget@gmail.com> From: Elijah Newren Date: Thu, 19 Aug 2021 11:29:04 -0700 Message-ID: Subject: Re: [PATCH v3 4/8] unpack-trees: fix nested sparse-dir search To: Derrick Stolee via GitGitGadget Cc: Git Mailing List , Junio C Hamano , Matheus Tavares Bernardino , Derrick Stolee , Derrick Stolee , Derrick Stolee Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Tue, Aug 17, 2021 at 6:23 AM Derrick Stolee via GitGitGadget wrote: > > From: Derrick Stolee > > The iterated search in find_cache_entry() was recently modified to > include a loop that searches backwards for a sparse directory entry that > matches the given traverse_info and name_entry. However, the string > comparison failed to actually concatenate those two strings, so this > failed to find a sparse directory when it was not a top-level directory. > > This caused some errors in rare cases where a 'git checkout' spanned a > diff that modified files within the sparse directory entry, but we could > not correctly find the entry. Doh, sorry for missing that in my review of the earlier series. > > Signed-off-by: Derrick Stolee > --- > unpack-trees.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/unpack-trees.c b/unpack-trees.c > index 5786645f315..df1f4437723 100644 > --- a/unpack-trees.c > +++ b/unpack-trees.c > @@ -1255,9 +1255,10 @@ static int sparse_dir_matches_path(const struct cache_entry *ce, > static struct cache_entry *find_cache_entry(struct traverse_info *info, > const struct name_entry *p) > { > - struct cache_entry *ce; > + struct cache_entry *ce = NULL; > int pos = find_cache_pos(info, p->path, p->pathlen); > struct unpack_trees_options *o = info->data; > + struct strbuf full_path = STRBUF_INIT; > > if (0 <= pos) > return o->src_index->cache[pos]; > @@ -1273,6 +1274,10 @@ static struct cache_entry *find_cache_entry(struct traverse_info *info, > if (pos < 0 || pos >= o->src_index->cache_nr) > return NULL; > > + strbuf_addstr(&full_path, info->traverse_path); > + strbuf_add(&full_path, p->path, p->pathlen); > + strbuf_addch(&full_path, '/'); > + > /* > * Due to lexicographic sorting and sparse directory > * entries ending with a trailing slash, our path as a > @@ -1283,17 +1288,20 @@ static struct cache_entry *find_cache_entry(struct traverse_info *info, > while (pos >= 0) { > ce = o->src_index->cache[pos]; > > - if (strncmp(ce->name, p->path, p->pathlen)) > - return NULL; > + if (strncmp(ce->name, full_path.buf, full_path.len)) { > + ce = NULL; > + break; > + } > > if (S_ISSPARSEDIR(ce->ce_mode) && > sparse_dir_matches_path(ce, info, p)) > - return ce; > + break; > > pos--; > } > > - return NULL; > + strbuf_release(&full_path); > + return ce; > } > > static void debug_path(struct traverse_info *info) > -- > gitgitgadget Makes sense.