From patchwork Mon Dec 9 20:47:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11280415 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99A541593 for ; Mon, 9 Dec 2019 20:47:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A9C52071E for ; Mon, 9 Dec 2019 20:47:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FexKu1kh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726926AbfLIUrx (ORCPT ); Mon, 9 Dec 2019 15:47:53 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:56019 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbfLIUrv (ORCPT ); Mon, 9 Dec 2019 15:47:51 -0500 Received: by mail-wm1-f66.google.com with SMTP id q9so801720wmj.5 for ; Mon, 09 Dec 2019 12:47:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IM8NXGxG48ELrMvEtU27DdAjZm+S48DBs3jTcX5uhok=; b=FexKu1kh5EOWKCtFetoafPI9P3zmdigVvkBPykfF0x5bv8DKkJYnZX9psE2PLZ2yv+ +7f2Zt7Not7N6W2NCVYRPAx1ZFm6+IftIHNihkFAIuMV4v1jZ9lfPIy0JqbDwXEDNKF/ p8V0K/NR4E3gJOWdYtYSYeXjmAkZYHLrOSMl/m3kip37lQ+RquHD98uWybHD/nqz22Qj sILo8EARj4Sp5h7rNW1LApIGo1hHMHb8/3nZnNAnDG1ut1Vs4fe4NuJi9Fh/XnqegXTS AVrdeZ4If5b3opevNY5yIkuRfdX+OrqET/KQg+pncIoZ8k3i47dWUYK5XgEI0MYiNDIO HPNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IM8NXGxG48ELrMvEtU27DdAjZm+S48DBs3jTcX5uhok=; b=m9xjz3iFUs2Jud+idMzD1HUvI8eHGIpK3izJO9B1uInLYtrNAUq1JgQdcKFJSXKElQ Uf1LgcC+JdusgrT1bxrfTWjmumPUOtKzfRs6Hh3Sxf+yl4ZlwY7ZlJrM8yDAE593WNag JLXepVQ+Aggx2dLARHnzE48kqBdzr/kJT3YW21L1euPlgMvsk2qP5rBlEzgNIetkzAds ODi9In54PYokx5sHhlnIClWgKdUQeRbwhu08IAt5W5VR60W3khI82THKkvwpL5lpRlCd lQ/LoUneRvtTieClCyRfPsZNREdY0FfBnCgUBTFhyUBMVy7CdCJnq78c9BzjKe5CLxyz U2kw== X-Gm-Message-State: APjAAAUimGh54uTyp7e+MLsaftrDHwvGBcN/kzpnRxxbiC+5CBrHFj25 Cii27UzXdUHXMwZVtR3TNp7rrFsg X-Google-Smtp-Source: APXvYqwJsAnjDksU8IE5hXpyu7PgwI1kSIvUyrYxxrSkuze69GNPQh/gABS03zLRVYkcuD+4wjfTXw== X-Received: by 2002:a05:600c:224a:: with SMTP id a10mr966609wmm.143.1575924469810; Mon, 09 Dec 2019 12:47:49 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s10sm745901wrw.12.2019.12.09.12.47.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Dec 2019 12:47:49 -0800 (PST) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Mon, 09 Dec 2019 20:47:41 +0000 Subject: [PATCH 4/8] dir: exit before wildcard fall-through if there is no wildcard Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren The DO_MATCH_LEADING_PATHSPEC had a fall-through case for if there was a wildcard, noting that we don't yet have enough information to determine if a further paths under the current directory might match due to the presence of wildcards. But if we have no wildcards in our pathspec, then we shouldn't get to that fall-through case. Signed-off-by: Elijah Newren --- dir.c | 7 +++++++ t/t3011-common-prefixes-and-directory-traversal.sh | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 5dacacd469..517a569e10 100644 --- a/dir.c +++ b/dir.c @@ -379,6 +379,13 @@ static int match_pathspec_item(const struct index_state *istate, item->nowildcard_len - prefix)) return 0; + /* + * name has no wildcard, and it didn't match as a leading + * pathspec so return. + */ + if (item->nowildcard_len == item->len) + return 0; + /* * Here is where we would perform a wildmatch to check if * "name" can be matched as a directory (or a prefix) against diff --git a/t/t3011-common-prefixes-and-directory-traversal.sh b/t/t3011-common-prefixes-and-directory-traversal.sh index 773d6038d1..d4c06fcd76 100755 --- a/t/t3011-common-prefixes-and-directory-traversal.sh +++ b/t/t3011-common-prefixes-and-directory-traversal.sh @@ -90,7 +90,7 @@ test_expect_failure 'git ls-files -o untracked_repo/ does not recurse' ' test_cmp expect actual ' -test_expect_failure 'git ls-files -o untracked_dir untracked_repo recurses into untracked_dir only' ' +test_expect_success 'git ls-files -o untracked_dir untracked_repo recurses into untracked_dir only' ' echo untracked_dir/empty >expect && echo untracked_repo/ >>expect && git ls-files -o untracked_dir untracked_repo >actual && @@ -104,7 +104,7 @@ test_expect_success 'git ls-files -o untracked_dir/ untracked_repo/ recurses int test_cmp expect actual ' -test_expect_failure 'git ls-files -o --directory untracked_dir untracked_repo does not recurse' ' +test_expect_success 'git ls-files -o --directory untracked_dir untracked_repo does not recurse' ' echo untracked_dir/ >expect && echo untracked_repo/ >>expect && git ls-files -o --directory untracked_dir untracked_repo >actual &&