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: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 496281F466 for ; Wed, 15 Jan 2020 20:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729092AbgAOUVr (ORCPT ); Wed, 15 Jan 2020 15:21:47 -0500 Received: from cloud.peff.net ([104.130.231.41]:37284 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726018AbgAOUVr (ORCPT ); Wed, 15 Jan 2020 15:21:47 -0500 Received: (qmail 19089 invoked by uid 109); 15 Jan 2020 20:21:47 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Wed, 15 Jan 2020 20:21:47 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 32722 invoked by uid 111); 15 Jan 2020 20:28:07 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 15 Jan 2020 15:28:07 -0500 Authentication-Results: peff.net; auth=none Date: Wed, 15 Jan 2020 15:21:46 -0500 From: Jeff King To: Elijah Newren via GitGitGadget Cc: Junio C Hamano , git@vger.kernel.org, Johannes Schindelin , Elijah Newren Subject: [PATCH] dir: point treat_leading_path() warning to the right place Message-ID: <20200115202146.GA4091171@coredump.intra.peff.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Wed, Jan 15, 2020 at 02:21:18PM +0000, Elijah Newren via GitGitGadget wrote: > From: Jeff King > > Restructure the code slightly to avoid passing around a struct dirent > anywhere, which also enables us to avoid trying to manufacture one. > > Signed-off-by: Jeff King > Signed-off-by: Elijah Newren Thanks, this looks good. I wondered briefly whether this: > @@ -2374,12 +2362,13 @@ static int treat_leading_path(struct dir_struct *dir, > break; > strbuf_reset(&sb); > strbuf_add(&sb, path, prevlen); > - memcpy(de->d_name, path+prevlen, baselen-prevlen); > - de->d_name[baselen-prevlen] = '\0'; > + strbuf_reset(&subdir); > + strbuf_add(&subdir, path+prevlen, baselen-prevlen); > + cdir.d_name = subdir.buf; ...could avoid the extra strbuf by pointing into an existing string (since d_name is now a pointer, and not part of a dirent). But I think the answer is "no", because in a path like "a/b/c", the loop may see just "b" (so offsetting into path isn't sufficient, because we also have to cut off the trailing part). I did notice one other small thing while looking at this code: -- >8 -- Subject: [PATCH] dir: point treat_leading_path() warning to the right place Commit 777b420347 (dir: synchronize treat_leading_path() and read_directory_recursive(), 2019-12-19) tried to add two warning comments in those functions, pointing at each other. But the one in treat_leading_path() just points at itself. Let's fix that. Since the comment also redirects the reader for more details to "the commit that added this warning", and since we're now modifying the warning (creating a new commit without those details), let's mention the actual commit id. Signed-off-by: Jeff King --- dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dir.c b/dir.c index 7d255227b1..31e83d982a 100644 --- a/dir.c +++ b/dir.c @@ -2308,9 +2308,9 @@ static int treat_leading_path(struct dir_struct *dir, * WARNING WARNING WARNING: * * Any updates to the traversal logic here may need corresponding - * updates in treat_leading_path(). See the commit message for the - * commit adding this warning as well as the commit preceding it - * for details. + * updates in read_directory_recursive(). See 777b420347 (dir: + * synchronize treat_leading_path() and read_directory_recursive(), + * 2019-12-19) and its parent commit for details. */ struct strbuf sb = STRBUF_INIT; -- 2.25.0.639.gb9b1511416