From patchwork Fri Jan 31 20:16:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360407 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 B3F901395 for ; Fri, 31 Jan 2020 20:16:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85BAD215A4 for ; Fri, 31 Jan 2020 20:16:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fEkfu3Q/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726213AbgAaUQT (ORCPT ); Fri, 31 Jan 2020 15:16:19 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45347 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbgAaUQT (ORCPT ); Fri, 31 Jan 2020 15:16:19 -0500 Received: by mail-wr1-f67.google.com with SMTP id a6so10081107wrx.12 for ; Fri, 31 Jan 2020 12:16:17 -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=PI7rAlWOADZX5nz+QBMgC5QO55bbe9huYYeZY+alby4=; b=fEkfu3Q/OvrAEoEI4zZjqJGGmuhPTNneXloKL3yC5xABZ4hnRe0xBCmQVoN64NxXWE Bhd1v2lg/UJhQHV1qm436sAOuQZKi58gSIZke5u8EFqwOV312LmWpwdiVduTLIGM/MMq eOhSDG2NQ73FAxBJ5g5SJRvP/O0GQc7x26R+rUFmfEwR4HIt8DI8EGsfXNMXPyANgDCE fyipqO2zwqxvNtf7BCiT3IkQtILZnw1V4WniRLSrYvt2TMukLd9VZKh8xBYOeYENj/1A TghKj9BuOK/+J9Nop3Yt84IoIzob2lcxpr7SXGh09ZiBoeEotwpTAWye1oZUQX3h1tJo BQlQ== 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=PI7rAlWOADZX5nz+QBMgC5QO55bbe9huYYeZY+alby4=; b=oWyNN97ebAFoO/gEPFua45ze3GrZOH+oexhdK6v3kUrkBmOc6Ykg5phR1SrbqwS0XW GJ45dQPLbDMreqclIpkLUcB5YmaJZEPJ6jGkFyTUVptSITUAlhwlw3ih+poHTU9tvgH+ Zb/YhoXH6egANzN1mZu24vhkaUjcd4QEEbmaKhzjuXu5A8ws2ei23jkY590ypqkXBEEt IvZD7I8v+sfm31crehbcjPgXqAfn8WKsg9HwtrMVZrCsN0ekQt03flicpYZgoOXy9l0T TRfrtwN8NAUZ38uEtmcu9Dt4ge66xDyIFRo9GJGbs6ZZHbqNN5mHHLj+BVw4+TUkbWgl arcA== X-Gm-Message-State: APjAAAX+na3tJSWSuD7XqRtYmS9k7F+vFA145jPSw0SNvpiVlpUKLQ5f EFaNPZ8MOpopdrGL0Fb6T7IGO0ak X-Google-Smtp-Source: APXvYqz6g4CpZPsCSjyaVVFOUYvK0Fgk2ep1iyXWkg2SLV+n0wDTIU8Pnyj7jLWvz7lecqgsov8Fkw== X-Received: by 2002:adf:ee43:: with SMTP id w3mr112068wro.339.1580501777146; Fri, 31 Jan 2020 12:16:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m3sm13445209wrs.53.2020.01.31.12.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:16 -0800 (PST) Message-Id: <1cc825412f0f2b66f7b89ed5ce33bcda937f4ee6.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:01 +0000 Subject: [PATCH v4 01/15] t1091: use check_files to reduce boilerplate Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When testing the sparse-checkout feature, we need to compare the contents of the working-directory against some expected output. Using here-docs was useful in the beginning, but became repetetive as the test script grew. Create a check_files helper to make the tests simpler and easier to extend. It also reduces instances of bad here-doc whitespace. Signed-off-by: Derrick Stolee --- t/t1091-sparse-checkout-builtin.sh | 117 ++++++----------------------- 1 file changed, 22 insertions(+), 95 deletions(-) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index ff7f8f7a1f..e058a20ad6 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -12,6 +12,13 @@ list_files() { (cd "$1" && printf '%s\n' *) } +check_files() { + list_files "$1" >actual && + shift && + printf "%s\n" $@ >expect && + test_cmp expect actual +} + test_expect_success 'setup' ' git init repo && ( @@ -58,9 +65,7 @@ test_expect_success 'git sparse-checkout init' ' EOF test_cmp expect repo/.git/info/sparse-checkout && test_cmp_config -C repo true core.sparsecheckout && - list_files repo >dir && - echo a >expect && - test_cmp expect dir + check_files repo a ' test_expect_success 'git sparse-checkout list after init' ' @@ -81,13 +86,7 @@ test_expect_success 'init with existing sparse-checkout' ' *folder* EOF test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'clone --sparse' ' @@ -98,9 +97,7 @@ test_expect_success 'clone --sparse' ' !/*/ EOF test_cmp expect actual && - list_files clone >dir && - echo a >expect && - test_cmp expect dir + check_files clone a ' test_expect_success 'set enables config' ' @@ -127,13 +124,7 @@ test_expect_success 'set sparse-checkout using builtin' ' git -C repo sparse-checkout list >actual && test_cmp expect actual && test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'set sparse-checkout using --stdin' ' @@ -147,13 +138,7 @@ test_expect_success 'set sparse-checkout using --stdin' ' git -C repo sparse-checkout list >actual && test_cmp expect actual && test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo "a folder1 folder2" ' test_expect_success 'cone mode: match patterns' ' @@ -162,13 +147,7 @@ test_expect_success 'cone mode: match patterns' ' git -C repo read-tree -mu HEAD 2>err && test_i18ngrep ! "disabling cone patterns" err && git -C repo reset --hard && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'cone mode: warn on bad pattern' ' @@ -185,14 +164,7 @@ test_expect_success 'sparse-checkout disable' ' test_path_is_file repo/.git/info/sparse-checkout && git -C repo config --list >config && test_must_fail git config core.sparseCheckout && - list_files repo >dir && - cat >expect <<-EOF && - a - deep - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a deep folder1 folder2 ' test_expect_success 'cone mode: init and set' ' @@ -204,24 +176,9 @@ test_expect_success 'cone mode: init and set' ' test_cmp expect dir && git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err && test_must_be_empty err && - list_files repo >dir && - cat >expect <<-EOF && - a - deep - EOF - test_cmp expect dir && - list_files repo/deep >dir && - cat >expect <<-EOF && - a - deeper1 - EOF - test_cmp expect dir && - list_files repo/deep/deeper1 >dir && - cat >expect <<-EOF && - a - deepest - EOF - test_cmp expect dir && + check_files repo a deep && + check_files repo/deep a deeper1 && + check_files repo/deep/deeper1 a deepest && cat >expect <<-EOF && /* !/*/ @@ -237,13 +194,7 @@ test_expect_success 'cone mode: init and set' ' folder2 EOF test_must_be_empty err && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - list_files repo >dir && - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'cone mode: list' ' @@ -275,13 +226,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' ' test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err && test_i18ngrep "cannot set sparse-checkout patterns" err && test_cmp repo/.git/info/sparse-checkout expect && - list_files repo/deep >dir && - cat >expect <<-EOF && - a - deeper1 - deeper2 - EOF - test_cmp dir expect + check_files repo/deep a deeper1 deeper2 ' test_expect_success 'revert to old sparse-checkout on empty update' ' @@ -332,12 +277,7 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' ' /folder1/ EOF test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - EOF - test_cmp expect dir + check_files repo a folder1 ' test_expect_success 'interaction with submodules' ' @@ -351,21 +291,8 @@ test_expect_success 'interaction with submodules' ' git sparse-checkout init --cone && git sparse-checkout set folder1 ) && - list_files super >dir && - cat >expect <<-\EOF && - a - folder1 - modules - EOF - test_cmp expect dir && - list_files super/modules/child >dir && - cat >expect <<-\EOF && - a - deep - folder1 - folder2 - EOF - test_cmp expect dir + check_files super a folder1 modules && + check_files super/modules/child a deep folder1 folder2 ' test_done From patchwork Fri Jan 31 20:16:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360409 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 2F94213B4 for ; Fri, 31 Jan 2020 20:16:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04748215A4 for ; Fri, 31 Jan 2020 20:16:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ef0UdP5v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726336AbgAaUQW (ORCPT ); Fri, 31 Jan 2020 15:16:22 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35197 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbgAaUQV (ORCPT ); Fri, 31 Jan 2020 15:16:21 -0500 Received: by mail-wr1-f67.google.com with SMTP id g17so10179770wro.2 for ; Fri, 31 Jan 2020 12:16:18 -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=FZrkWwoOV3NNkcvOwJlM7IbVcGOH3Js85ThSFj7lETA=; b=Ef0UdP5v4WQXXMz+ScNCcUuQc/gquBaW+UqTUn9nAndKhi+euqlvVeGQesJBu8C2r7 4chDoaOtDrk173rXn3OakEOK90b22gdo212ZBq7fGeDZezpjILprdcvFRljI7YINVgC0 NNvs/sRMotUuLR1r1f8lGo2cv73Es9wLZ30IgG91erM97EZgp0NJakYjDG0A3SJFzYzE c4rk8JXQxr7RbBJqD6iT3nLzLC9dXUYDrnFxL72RzU2zTpCBHw3m3/DriGoPxKIC0mGv pgS6ycQoi/MUnZT0FT1JIVGQlfjhvpWH2lfwBiE9gZswNGuLN7HYd6dxsYq6zx6hX/Wy twAg== 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=FZrkWwoOV3NNkcvOwJlM7IbVcGOH3Js85ThSFj7lETA=; b=I0rkv5/VeE75pjej9Tq3wCRqKm7xkjmw/LjPCRn39F7CEWQim2Z/rAJBFKVg/cbtoj RJ+8PQZND3C/gJqA3gMZ6k1hGOPlFn0wf1kM1a3sKetQElou69G0vEh1QBDNF9TLrU2e A5PhztnUxV+pj4qf21PdBOd+LiF+y4XOcnqSanR4AOKSMUXyT0G3Z3QMGxC5s6xbgZpH 2ZBQNNwrN1EmKy8HdVzfGQgsaFoQQvHghmMvoCNAbJ/mbevI8bqt+mC7HvZD44gA7GAO V7L/Z9VCLTiFrtFSJwPcVolwBo0IZRzA2VyrkjW0WoZziWVcswzly2qTfUDYJsaZq0Yo Kybg== X-Gm-Message-State: APjAAAVwCGuyNMxcDulpSAAPaHkuhjk3sP1YhjzwlBscqOGD5dVtaZN6 m9peWUoDxptT5BcqFvcvjLKwRBMQ X-Google-Smtp-Source: APXvYqxk6gcpmkuRb5bckPsc5stku04TEtlbq5AvE+dq8IVEgo/HZ3HuGnOq2v/akgKdbh6XioQszA== X-Received: by 2002:a5d:6802:: with SMTP id w2mr105310wru.353.1580501777944; Fri, 31 Jan 2020 12:16:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j5sm4119259wrb.33.2020.01.31.12.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:17 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:02 +0000 Subject: [PATCH v4 02/15] t1091: improve here-docs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee t1091-sparse-checkout-builtin.sh uses here-docs to populate the expected contents of the sparse-checkout file. These do not use shell interpolation, so use "-\EOF" instead of "-EOF". Also use proper tabbing. Signed-off-by: Derrick Stolee --- t/t1091-sparse-checkout-builtin.sh | 98 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index e058a20ad6..e28e1c797f 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -46,11 +46,11 @@ test_expect_success 'git sparse-checkout list (empty)' ' test_expect_success 'git sparse-checkout list (populated)' ' test_when_finished rm -f repo/.git/info/sparse-checkout && - cat >repo/.git/info/sparse-checkout <<-EOF && - /folder1/* - /deep/ - **/a - !*bin* + cat >repo/.git/info/sparse-checkout <<-\EOF && + /folder1/* + /deep/ + **/a + !*bin* EOF cp repo/.git/info/sparse-checkout expect && git -C repo sparse-checkout list >list && @@ -59,9 +59,9 @@ test_expect_success 'git sparse-checkout list (populated)' ' test_expect_success 'git sparse-checkout init' ' git -C repo sparse-checkout init && - cat >expect <<-EOF && - /* - !/*/ + cat >expect <<-\EOF && + /* + !/*/ EOF test_cmp expect repo/.git/info/sparse-checkout && test_cmp_config -C repo true core.sparsecheckout && @@ -70,9 +70,9 @@ test_expect_success 'git sparse-checkout init' ' test_expect_success 'git sparse-checkout list after init' ' git -C repo sparse-checkout list >actual && - cat >expect <<-EOF && - /* - !/*/ + cat >expect <<-\EOF && + /* + !/*/ EOF test_cmp expect actual ' @@ -80,10 +80,10 @@ test_expect_success 'git sparse-checkout list after init' ' test_expect_success 'init with existing sparse-checkout' ' echo "*folder*" >> repo/.git/info/sparse-checkout && git -C repo sparse-checkout init && - cat >expect <<-EOF && - /* - !/*/ - *folder* + cat >expect <<-\EOF && + /* + !/*/ + *folder* EOF test_cmp expect repo/.git/info/sparse-checkout && check_files repo a folder1 folder2 @@ -92,9 +92,9 @@ test_expect_success 'init with existing sparse-checkout' ' test_expect_success 'clone --sparse' ' git clone --sparse repo clone && git -C clone sparse-checkout list >actual && - cat >expect <<-EOF && - /* - !/*/ + cat >expect <<-\EOF && + /* + !/*/ EOF test_cmp expect actual && check_files clone a @@ -116,10 +116,10 @@ test_expect_success 'set enables config' ' test_expect_success 'set sparse-checkout using builtin' ' git -C repo sparse-checkout set "/*" "!/*/" "*folder*" && - cat >expect <<-EOF && - /* - !/*/ - *folder* + cat >expect <<-\EOF && + /* + !/*/ + *folder* EOF git -C repo sparse-checkout list >actual && test_cmp expect actual && @@ -128,11 +128,11 @@ test_expect_success 'set sparse-checkout using builtin' ' ' test_expect_success 'set sparse-checkout using --stdin' ' - cat >expect <<-EOF && - /* - !/*/ - /folder1/ - /folder2/ + cat >expect <<-\EOF && + /* + !/*/ + /folder1/ + /folder2/ EOF git -C repo sparse-checkout set --stdin actual && @@ -179,28 +179,28 @@ test_expect_success 'cone mode: init and set' ' check_files repo a deep && check_files repo/deep a deeper1 && check_files repo/deep/deeper1 a deepest && - cat >expect <<-EOF && - /* - !/*/ - /deep/ - !/deep/*/ - /deep/deeper1/ - !/deep/deeper1/*/ - /deep/deeper1/deepest/ + cat >expect <<-\EOF && + /* + !/*/ + /deep/ + !/deep/*/ + /deep/deeper1/ + !/deep/deeper1/*/ + /deep/deeper1/deepest/ EOF test_cmp expect repo/.git/info/sparse-checkout && - git -C repo sparse-checkout set --stdin 2>err <<-EOF && - folder1 - folder2 + git -C repo sparse-checkout set --stdin 2>err <<-\EOF && + folder1 + folder2 EOF test_must_be_empty err && check_files repo a folder1 folder2 ' test_expect_success 'cone mode: list' ' - cat >expect <<-EOF && - folder1 - folder2 + cat >expect <<-\EOF && + folder1 + folder2 EOF git -C repo sparse-checkout set --stdin actual 2>err && @@ -211,10 +211,10 @@ test_expect_success 'cone mode: list' ' test_expect_success 'cone mode: set with nested folders' ' git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && test_line_count = 0 err && - cat >expect <<-EOF && - /* - !/*/ - /deep/ + cat >expect <<-\EOF && + /* + !/*/ + /deep/ EOF test_cmp repo/.git/info/sparse-checkout expect ' @@ -271,10 +271,10 @@ test_expect_success 'sparse-checkout (init|set|disable) fails with dirty status' test_expect_success 'cone mode: set with core.ignoreCase=true' ' git -C repo sparse-checkout init --cone && git -C repo -c core.ignoreCase=true sparse-checkout set folder1 && - cat >expect <<-EOF && - /* - !/*/ - /folder1/ + cat >expect <<-\EOF && + /* + !/*/ + /folder1/ EOF test_cmp expect repo/.git/info/sparse-checkout && check_files repo a folder1 From patchwork Fri Jan 31 20:16:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360423 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 8129213B4 for ; Fri, 31 Jan 2020 20:16:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F082214D8 for ; Fri, 31 Jan 2020 20:16:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dHfmlrzo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726322AbgAaUQV (ORCPT ); Fri, 31 Jan 2020 15:16:21 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40961 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbgAaUQV (ORCPT ); Fri, 31 Jan 2020 15:16:21 -0500 Received: by mail-wr1-f68.google.com with SMTP id c9so10130035wrw.8 for ; Fri, 31 Jan 2020 12:16:19 -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=LHv3OUouiSWEjPl69LIDx7kK+8FoKtUJpN5eFvZqOEw=; b=dHfmlrzog6K/8nMiu3Q5J5gWThZhOB2T8hLXhgKlhLKRt5LRUVzQAft4wt77rU7mO/ JjweFVmqLe064tfEHyDPlR7MKN7hRGg2v9bWPLbc+zp4VI3vmFjH+FddRzey68ZLO9Q6 WeelVR22kGs5Gzq54JQYvr4imoyEbdq4eLFqnOYZ8S9CvG8rp/rMY3ghzCuXlhyUJvtq Hr9pie337jBiP4bh2vjZp3NfB2cSBdo+f4krDhZpEhsOYQzQmnrDHgsTfCOO5w9OakLS FGib6NqBBqeWnzJNhOTQHb3zfmxkz8MGH79O5GMBmVwJPJaxcb3o7fuRo547Vbt4yv4X 4vmw== 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=LHv3OUouiSWEjPl69LIDx7kK+8FoKtUJpN5eFvZqOEw=; b=geuAODISbnmfnIWryVpkatsJFu4+8rP4dLGsOmcX/R9611tY8NW7Zm7Dvao6jumReI 4Y7xFE4buE03A9V9W6ozFVaFhGhB4hU4xnAVnCS4bvvNmVyVm1qh4VDfG4mJIBjSD2D0 KsrFjOBVMRA8lBpbHHoNfpiPQzwtLxKALETsPefcupMl8Wbfo4Dm4iCqpa0RHqq7CFDC 6AAzl1dzcH09xxzZAlQemrX/fexIQJYkE1AixvNY6ANr2SGUBCDAPbo7xAJG21o/Ed2E q5lqZJBE9vWFDnapnI10OnXDxHAbccVJcGQC/docaXQ3wu3B7UO7C4RSo8FnEnXhY4RS Ncgg== X-Gm-Message-State: APjAAAVeyVtb1GZeFod8vkm52CfIe9ReltJ+qC+X2miCoJyq7aHpV3ZS b49NFbm1m8VztKW4mU5r/Ur5pP6S X-Google-Smtp-Source: APXvYqzV0AAduUDXy1XZwqVFA4avXolDhbOgMe+//daYaWdmraIdxmO6lHbt76ZJSU2ZlngDckX8gA== X-Received: by 2002:a05:6000:1252:: with SMTP id j18mr136105wrx.103.1580501778700; Fri, 31 Jan 2020 12:16:18 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e17sm324798wrn.62.2020.01.31.12.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:18 -0800 (PST) Message-Id: <5497ad8778c29ca936206d2ded6773758c236c12.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:03 +0000 Subject: [PATCH v4 03/15] sparse-checkout: create leading directories Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The 'git init' command creates the ".git/info" directory and fills it with some default files. However, 'git worktree add' does not create the info directory for that worktree. This causes a problem when running "git sparse-checkout init" inside a worktree. While care was taken to allow the sparse-checkout config to be specific to a worktree, this initialization was untested. Safely create the leading directories for the sparse-checkout file. This is the safest thing to do even without worktrees, as a user could delete their ".git/info" directory and expect Git to recover safely. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 4 ++++ t/t1091-sparse-checkout-builtin.sh | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index b3bed891cb..3cee8ab46e 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -199,6 +199,10 @@ static int write_patterns_and_update(struct pattern_list *pl) int result; sparse_filename = get_sparse_checkout_filename(); + + if (safe_create_leading_directories(sparse_filename)) + die(_("failed to create directory for sparse-checkout file")); + fd = hold_lock_file_for_update(&lk, sparse_filename, LOCK_DIE_ON_ERROR); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index e28e1c797f..43d1f7520c 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -295,4 +295,14 @@ test_expect_success 'interaction with submodules' ' check_files super/modules/child a deep folder1 folder2 ' +test_expect_success 'different sparse-checkouts with worktrees' ' + git -C repo worktree add --detach ../worktree && + check_files worktree "a deep folder1 folder2" && + git -C worktree sparse-checkout init --cone && + git -C repo sparse-checkout set folder1 && + git -C worktree sparse-checkout set deep/deeper1 && + check_files repo a folder1 && + check_files worktree a deep +' + test_done From patchwork Fri Jan 31 20:16:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360411 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 F3BAE13B4 for ; Fri, 31 Jan 2020 20:16:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2B5B215A4 for ; Fri, 31 Jan 2020 20:16:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SW8I0OcF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726385AbgAaUQW (ORCPT ); Fri, 31 Jan 2020 15:16:22 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37991 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbgAaUQV (ORCPT ); Fri, 31 Jan 2020 15:16:21 -0500 Received: by mail-wr1-f66.google.com with SMTP id y17so10150739wrh.5 for ; Fri, 31 Jan 2020 12:16:20 -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=KDhiP/nTsJtYltovU0qLNJhnLe1wUUQjqGoJo1gXOog=; b=SW8I0OcFZ/dg2WiYFfAyNraCKFLOBRBwKD7k7DIRwpAby8/DeqUk1+muB1Ox25mHjq Qf/pB/GGxoAMRgZXgGmJAs3v53UcLg7a76frjk83AIAyVLIz9ujNAZUN95/jxpzvlv5n 6hjNVdpqup7x9kUKc2KRVKnrRO5qwXnbI0Z7JjXLB1yAytRliDLTZbkJBkvxVlpe9fqa Rzazyi2tATFDyYhfb/TRM/LWecVf9A+wSOrovul8Gxtfn1S6IEaz5K6yOk8v5GWOd0im h8ZVPAz7WOsDbRxomFaG3RABDwusy/CGAxIhFWTzBj5cml5ySFl9CoH7AfWCtDZbWa8q uVZw== 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=KDhiP/nTsJtYltovU0qLNJhnLe1wUUQjqGoJo1gXOog=; b=HTV3iOP+AbfPLpV0GWNi/qTuNNnj+FgxzZeGt/O9BqHDPUhZ3jfKPBzoEdb/v4o6J4 Ag9x84BEC83LSwvXnLCU1w0kisZfW4eM5WwC+dKtPUVTzbNqLaiMcuzv/2/irMIwrKpN +e39ZkDljfWcxLFogRJCxLgxQUz5F824ZovIWVteXPoRMk1dp8FcTYCT1EPdW4zBhiPp mBXQCKaep2pn9DMZ559Lo0d7DnGLUhJHFDRbzhe4nxEVPc5F8Ef5nC67Z+nttK8fQFoh qebBESaUcGjEvVDXMZwynx7rU6a6SPJoPW7c97EDHWkrf6KsWlwEysoV1xS2PBsiRoBb b5Yw== X-Gm-Message-State: APjAAAWnsVB0Cy59BPb7tJjsklpB3fz4uSKS9+wbhMTMctFJpRUUv+yJ 4CfyLa5RFlr4ABz1qdpB8huCXLwM X-Google-Smtp-Source: APXvYqx2xjEFdtC4yaqWoWgy5g7aM8nAkxkD5yK8VFbSaC4XiIW9/oAnpP3MDGI32FIjm+TA2oNhSQ== X-Received: by 2002:adf:f0cb:: with SMTP id x11mr104091wro.421.1580501779443; Fri, 31 Jan 2020 12:16:19 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f1sm13349879wru.6.2020.01.31.12.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:18 -0800 (PST) Message-Id: <4991a51f6d5d840eaa3bb830e68f1530c2ee08e4.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:04 +0000 Subject: [PATCH v4 04/15] clone: fix --sparse option with URLs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The --sparse option was added to the clone builtin in d89f09c (clone: add --sparse mode, 2019-11-21) and was tested with a local path clone in t1091-sparse-checkout-builtin.sh. However, due to a difference in how local paths are handled versus URLs, this mechanism does not work with URLs. Modify the test to use a "file://" URL, which would output this error before the code change: Cloning into 'clone'... fatal: cannot change to 'file://.../repo': No such file or directory error: failed to initialize sparse-checkout These errors are due to using a "-C " option to call 'git -C sparse-checkout init' but the URL is being given instead of the target directory. Update that target directory to evaluate this correctly. I have also manually tested that https:// URLs are handled correctly as well. Acked-by: Taylor Blau Signed-off-by: Derrick Stolee --- builtin/clone.c | 2 +- t/t1091-sparse-checkout-builtin.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 4348d962c9..2caefc44fb 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1130,7 +1130,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_required_reference.nr || option_optional_reference.nr) setup_reference(); - if (option_sparse_checkout && git_sparse_checkout_init(repo)) + if (option_sparse_checkout && git_sparse_checkout_init(dir)) return 1; remote = remote_get(option_origin); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 43d1f7520c..cf4a595c86 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -90,7 +90,7 @@ test_expect_success 'init with existing sparse-checkout' ' ' test_expect_success 'clone --sparse' ' - git clone --sparse repo clone && + git clone --sparse "file://$(pwd)/repo" clone && git -C clone sparse-checkout list >actual && cat >expect <<-\EOF && /* From patchwork Fri Jan 31 20:16:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360419 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 D5E2613B4 for ; Fri, 31 Jan 2020 20:16:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B40BB21734 for ; Fri, 31 Jan 2020 20:16:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EEPZ8xeF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726505AbgAaUQ0 (ORCPT ); Fri, 31 Jan 2020 15:16:26 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37194 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbgAaUQW (ORCPT ); Fri, 31 Jan 2020 15:16:22 -0500 Received: by mail-wr1-f68.google.com with SMTP id w15so10156854wru.4 for ; Fri, 31 Jan 2020 12:16:20 -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=pl9kK0IVJdtZMHXu52/f8Sm0g3stqkcV9VxPh4NkuJo=; b=EEPZ8xeFyYou1KWb/VFQ2u2oo5MFcbwAoPvHKBT33WqtQ5mN7t8eaX6J9Xgt9+WULU jZhXA0Mte2zKqxOobG2IqvfLpXR0ruCsRuVwxMULh1svWPK8dRSOZ9hUTkPZXAgN4QX+ 0jL3RUWYa0QWwfBtJC8pt3w2VC76EYjcoqFWOv56C/hPYraazwkxUNf9kJK1Xjr8Ljy7 4KcFCu29EO0IC5FXTaCEuud6jP5cIrEFXiWzRwTjNq/P5qFN8GDr4gl65uFfXRWLyJx1 NITXadUWRm0WgtxQOqf0T7abevCzFV00xAKQOiMKdeUIW1ji2XbYMAuTyGNgT8ZMpf1I psoA== 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=pl9kK0IVJdtZMHXu52/f8Sm0g3stqkcV9VxPh4NkuJo=; b=QMLRr3KipTPf24E+X4WtFBjU/KZpAhy0Be2N4agIRyqfRBYfQ8NJyx574DMjephUCj Pb9tQ17ncrTTa0CJzlS6WKrlKVlfT3A/4KoYm6PU8eIRY4k8eLMhjE9Y/AoMvWKuWtDx VE5Wu9V0tE4kcfBdd/Hcke5miQq8w3tcxk3aGE5pg+4MKjraTn19u+JOsRZV5FzutnbB NscVwS7udatU3v9GsLOonBFUmydbL1eiI0vMA1gDeh3L4AvkAoq86uADMPqqlnkzVQ7x ScUV28AyZDp2VeF3BVoYPzqV/sQIPF1QR3Xutb0pdTFNMPrf8ck7I3F5q89fr/+0/S41 Ptpg== X-Gm-Message-State: APjAAAWQl8al2RhBA5rmkYzW0uaRYZkp9pg4KFFwfeQreUn2RR77S/xP Pnj+O576ytGaIt8VWW8C/U3g0/Gq X-Google-Smtp-Source: APXvYqxFekZlbH4BRvyGXGtCCBl8KkZuPRsIusEjDc/DGaEpI6ijWLWq6uLW0AjDJg6NAeZGAqJhQg== X-Received: by 2002:a5d:6b82:: with SMTP id n2mr136028wrx.153.1580501780131; Fri, 31 Jan 2020 12:16:20 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w20sm12141555wmk.34.2020.01.31.12.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:19 -0800 (PST) Message-Id: In-Reply-To: References: From: "Jeff King via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:05 +0000 Subject: [PATCH v4 05/15] sparse-checkout: fix documentation typo for core.sparseCheckoutCone Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Jeff King Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff King Signed-off-by: Jeff King Signed-off-by: Derrick Stolee --- Documentation/git-sparse-checkout.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt index 3b341cf0fc..4834fb434d 100644 --- a/Documentation/git-sparse-checkout.txt +++ b/Documentation/git-sparse-checkout.txt @@ -106,7 +106,7 @@ The full pattern set allows for arbitrary pattern matches and complicated inclusion/exclusion rules. These can result in O(N*M) pattern matches when updating the index, where N is the number of patterns and M is the number of paths in the index. To combat this performance issue, a more restricted -pattern set is allowed when `core.spareCheckoutCone` is enabled. +pattern set is allowed when `core.sparseCheckoutCone` is enabled. The accepted patterns in the cone pattern set are: From patchwork Fri Jan 31 20:16:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360413 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 54B0014D5 for ; Fri, 31 Jan 2020 20:16:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3068321734 for ; Fri, 31 Jan 2020 20:16:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VVI1d3xi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726469AbgAaUQY (ORCPT ); Fri, 31 Jan 2020 15:16:24 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38157 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbgAaUQX (ORCPT ); Fri, 31 Jan 2020 15:16:23 -0500 Received: by mail-wm1-f66.google.com with SMTP id a9so10148016wmj.3 for ; Fri, 31 Jan 2020 12:16:21 -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=pp+putYic/YPhOPXhgtuPLfFxxGHo2lzSEwyNyMGA0M=; b=VVI1d3xiMpLwIbREkgD6McZU/hwFDDQBJhhIgqjyREQfmUh3fbQqU/09aUJdbxNoZW ksFeaMzq9GM4jHMI4B477CMu+lLpAAv+HMHcx4EEN1W5ap21RvQFl2Dw8/0if4eXyH3i 9UDb0xPtX7UGYas46ubfIdlINa8jmqb9IeR5TzmcCr0LOgd7aDv8DJalt7DKxO3CZCNB F/l7nrC5Nxpxm0kE2HG7pSlZeAH14GQ9kdcBLmmfFqTKIqHjatx1/YLy26Hw/JqF8RXT A1iljbzfyWEiNXzSCMJT1gO+rDD0TnVMncVuVHls0ymcQaQXWa4cSPIfWH7cfYUhA8ec WEWA== 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=pp+putYic/YPhOPXhgtuPLfFxxGHo2lzSEwyNyMGA0M=; b=ZXd1cNarZX4qfe7pkKfS5BK53ZEj7J5FvwHQhYQ68RooS8ND6LMyStT3mN1IsVK3Qg zdlPyDYnzjSmKZIsEOM/tj2idSLbF6HOSB0/QLtVoUPnZDMBZTRuxd7PMgvP//wmGDpy uYNIgg3nI3oJD23gMB7N8/vsg8k5PVjcSeExDvFVAGk5998qx36Cpip0HshcTB+shvMe 37DhkJ0Hb1q64Le2mz0njoAbhf/bFab+EVnJsR9w69DHU5NS660/EejOS6UKocJASplZ DQxiCvVO7JK6eHxWpW7WFHW1d2Q6kdZtQ138Qub4GCshfpcPwat98vtk2Plu3gtHjFq7 HJtA== X-Gm-Message-State: APjAAAX2DASNG6FrUIQH0N74TLjbpWeDPU8RE+jhFD+bR+nfT2HCQjl7 xpc36CSrRyHejbwDhsTz0QYqRIP3 X-Google-Smtp-Source: APXvYqx2oNJFu0JmQ6yzDxSQdWHmBdomP7RRdRH7bwSAoLMFPfjBE9Z+G9KSP3j6eownDKMpJTfOnQ== X-Received: by 2002:a7b:c389:: with SMTP id s9mr13170402wmj.7.1580501780757; Fri, 31 Jan 2020 12:16:20 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p11sm1069774wrn.40.2020.01.31.12.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:20 -0800 (PST) Message-Id: <2ad4d3e467a7e2be679de4084e54f426aa242bd6.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:06 +0000 Subject: [PATCH v4 06/15] sparse-checkout: cone mode does not recognize "**" Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command creates a restricted set of possible patterns that are used by a custom algorithm to quickly match those patterns. If a user manually edits the sparse-checkout file, then they could create patterns that do not match these expectations. The cone-mode matching algorithm can return incorrect results. The solution is to detect these incorrect patterns, warn that we do not recognize them, and revert to the standard algorithm. Check each pattern for the "**" substring, and revert to the old logic if seen. While technically a "//**" pattern matches the meaning of "//", it is not one that would be written by the sparse-checkout builtin in cone mode. Attempting to accept that pattern change complicates the logic and instead we punt and do not accept any instance of "**". Signed-off-by: Derrick Stolee --- dir.c | 7 +++++- t/t1091-sparse-checkout-builtin.sh | 34 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 22d08e61c2..40fed73a94 100644 --- a/dir.c +++ b/dir.c @@ -651,11 +651,16 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern return; } + if (strstr(given->pattern, "**")) { + /* Not a cone pattern. */ + warning(_("unrecognized pattern: '%s'"), given->pattern); + goto clear_hashmaps; + } + if (given->patternlen > 2 && !strcmp(given->pattern + given->patternlen - 2, "/*")) { if (!(given->flags & PATTERN_FLAG_NEGATIVE)) { /* Not a cone pattern. */ - pl->use_cone_patterns = 0; warning(_("unrecognized pattern: '%s'"), given->pattern); goto clear_hashmaps; } diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index cf4a595c86..e2e45dc7fd 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -305,4 +305,38 @@ test_expect_success 'different sparse-checkouts with worktrees' ' check_files worktree a deep ' +check_read_tree_errors () { + REPO=$1 + FILES=$2 + ERRORS=$3 + git -C $REPO read-tree -mu HEAD 2>err && + if test -z "$ERRORS" + then + test_must_be_empty err + else + test_i18ngrep "$ERRORS" err + fi && + check_files $REPO $FILES +} + +test_expect_success 'pattern-checks: /A/**' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /folder1/** + EOF + check_read_tree_errors repo "a folder1" "disabling cone pattern matching" +' + +test_expect_success 'pattern-checks: /A/**/B/' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /deep/**/deepest + EOF + check_read_tree_errors repo "a deep" "disabling cone pattern matching" && + check_files repo/deep "deeper1" && + check_files repo/deep/deeper1 "deepest" +' + test_done From patchwork Fri Jan 31 20:16:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360417 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 0EC0013B4 for ; Fri, 31 Jan 2020 20:16:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1310215A4 for ; Fri, 31 Jan 2020 20:16:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R7kjvoMA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726494AbgAaUQ0 (ORCPT ); Fri, 31 Jan 2020 15:16:26 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53067 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbgAaUQX (ORCPT ); Fri, 31 Jan 2020 15:16:23 -0500 Received: by mail-wm1-f67.google.com with SMTP id p9so9356632wmc.2 for ; Fri, 31 Jan 2020 12:16:22 -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=7g3RInPRozRcqfiodm1wMBj88ZZT+XDAcmQ//AaX4/c=; b=R7kjvoMAip/CNnHoYJ968uAKkFX8YGo9QVm97qO3GDrrqX5e4gijzf4TyHCwkKxNDs aA0ZEKN1vkcU+sxx3HUKl08MhR5TNOdyQ/2fsNkyVqUyEJxOM0PjDouPke4m/T468BN/ SNg3lUTHIGLxBdzoXWCXOSnbNX4ATVBcFpdPdZkyjgZSbzD3hOM1IrU9itr76ZWUYV3g a/26agrYzKAJlccwkoajSMPSiLtDsIagT6xQ5GVs1GlZz4v9EmWHZtk00J5VC3s+PaP5 nRn0BqdCZuwNal1zBNm7h0slm+axT1QtmWzUYZu/BdAm8FgmlU5f0i3E2i94ySBGHSvk fMAQ== 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=7g3RInPRozRcqfiodm1wMBj88ZZT+XDAcmQ//AaX4/c=; b=BLWZ1MfNxvqWIVQje+YsPLEotkjSyHgj0fQkf4d2cqtPE5QkZKeevXakcABH2RPBdO v/wphMsemh8Og4N699Gka2EImRCRhbdXNVXVDMJdY1dpeOEF1qlxBP6HK8X4it9DsZoh xLeJFkx1juGUa0gj65UGcMEZI7PA740I2H0YayktapKM9o/Z/yuKaN+tmNuPghSAqltx EKyUdLlvy1ycV2/u6aM8/6TbUVtGMjxQKdYmXTinHa/w+zBCgpAQU8SSr9r4JN1IgtD5 UUyMnFlbYrBa5Jv9868F9HmFJ0U4a0iXN8yBJTEhRQ4q0qnn0xDcCggJp7ZKlpns9rRf +eaw== X-Gm-Message-State: APjAAAVJAsNRr71KXlCI8BdjAesIFJH5dAtPPT0+IcYFSS+VPhYWTpdP bbKubXCNxEqt0bz2jtajvjTSQ/yU X-Google-Smtp-Source: APXvYqzsY2J8Hxq+uH8oRKvC6guV+0M5xp01CoWlhpOgmOcRqqxccPgdbKHTxCMPMC90PE8xWeiZNA== X-Received: by 2002:a1c:a515:: with SMTP id o21mr13965923wme.85.1580501781558; Fri, 31 Jan 2020 12:16:21 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z4sm11833598wma.2.2020.01.31.12.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:21 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:07 +0000 Subject: [PATCH v4 07/15] sparse-checkout: detect short patterns Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee In cone mode, the shortest pattern the sparse-checkout command will write into the sparse-checkout file is "/*". This is handled carefully in add_pattern_to_hashsets(), so warn if any other pattern is this short. This will assist future pattern checks by allowing us to assume there are at least three characters in the pattern. Signed-off-by: Derrick Stolee --- dir.c | 3 ++- t/t1091-sparse-checkout-builtin.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 40fed73a94..c2e585607e 100644 --- a/dir.c +++ b/dir.c @@ -651,7 +651,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern return; } - if (strstr(given->pattern, "**")) { + if (given->patternlen <= 2 || + strstr(given->pattern, "**")) { /* Not a cone pattern. */ warning(_("unrecognized pattern: '%s'"), given->pattern); goto clear_hashmaps; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index e2e45dc7fd..2e57534799 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -339,4 +339,13 @@ test_expect_success 'pattern-checks: /A/**/B/' ' check_files repo/deep/deeper1 "deepest" ' +test_expect_success 'pattern-checks: too short' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /a + EOF + check_read_tree_errors repo "a" "disabling cone pattern matching" +' + test_done From patchwork Fri Jan 31 20:16:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360421 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 0D6EB1395 for ; Fri, 31 Jan 2020 20:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DFF6022522 for ; Fri, 31 Jan 2020 20:16:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JUTwIiqn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbgAaUQ1 (ORCPT ); Fri, 31 Jan 2020 15:16:27 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37754 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbgAaUQY (ORCPT ); Fri, 31 Jan 2020 15:16:24 -0500 Received: by mail-wm1-f68.google.com with SMTP id f129so10173262wmf.2 for ; Fri, 31 Jan 2020 12:16:23 -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=AtBqI6CCf+VMZOgmlvqj7UaYj+NRy62oNWe9942dw00=; b=JUTwIiqnLl4aDt+tACumX8r1RkY5P6lvJ1HdTWKVwsaOAs6X2kGW5q8LT3i9Mx/WVb sZOwvqYkvfEgRsTDxZPMzsjin1j/Y9Ml1RT8+1v7kyWcMtaN42KK+ysmlSPwBlRgMpNv mxR8Qotz8nqurtnm1wS/f8ev+ObGUQkdgTWiWfpsSOH5PrWV7s7xGK3cxvbw5mxjtPx/ pV7api1W2XDfTZ8p4uEypczbSPtsSJwFffvnOWMuN3OuI8qWKsY5yoXi4BIt31JmNauc A7vHtDZ4I0BYj3KdoBi9nVX7suzsUJGFGcIHk/OfsGdXSoNpgtnqHl1NgbFaf1swr+GJ 9DCw== 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=AtBqI6CCf+VMZOgmlvqj7UaYj+NRy62oNWe9942dw00=; b=Ogns9SZmGAI//6p0u9vZpdpU6mNYtWZ3k5QYN7CNUrLa9dcVrOhhULw6OG2L3Hl+8l 8KqadzBnoiJnfCU12xy55DFayR7NZynVM2Kf/qs9pLA3/QF0Zhz9VGz4EwfQ220mrIi7 fcvc7lRAYvWEalGONCFaInDBBvoD4N0rSCm/YuZcfRhFx2eJ+cSgjiaIrltBjKgf4bIl fqr5hxlVRsJwKhLfiwJ4M+xY0JLFMXCwGA7k//A8XBD0owNc1MPb3yGKRyJO2ADyzPOy 7TIEeY6peKbRm2YI5eS0uQLn0MjvvtN/dIB/CdTzoIfQIodzycHw++Hk/00iDZW39fZV pANw== X-Gm-Message-State: APjAAAUkSwIUhzwD4+t5haRT90w8c9jVbKTuskX1daeyRMM7f93zDhVQ E13L+AP554/UWd5b9xVH6G8x91bB X-Google-Smtp-Source: APXvYqySh1JGX7FCsXOzRY7l6RtQXIpzj1bNh7VkwUTjOaGIphYPw0JLUOKWn2stGc06nUE6tjr14Q== X-Received: by 2002:a05:600c:218b:: with SMTP id e11mr14016974wme.56.1580501782234; Fri, 31 Jan 2020 12:16:22 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a8sm12846934wmc.20.2020.01.31.12.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:21 -0800 (PST) Message-Id: <66caabef5f998e15cc564e91231590280892191b.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:08 +0000 Subject: [PATCH v4 08/15] sparse-checkout: warn on globs in cone patterns Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee In cone mode, the sparse-checkout commmand will write patterns that allow faster pattern matching. This matching only works if the patterns in the sparse-checkout file are those written by that command. Users can edit the sparse-checkout file and create patterns that cause the cone mode matching to fail. The cone mode patterns may end in "/*" but otherwise an un-escaped asterisk or other glob character is invalid. Add checks to disable cone mode when seeing these values. A later change will properly handle escaped globs. Signed-off-by: Derrick Stolee --- dir.c | 36 +++++++++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 39 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/dir.c b/dir.c index c2e585607e..71d28331f3 100644 --- a/dir.c +++ b/dir.c @@ -635,6 +635,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern struct pattern_entry *translated; char *truncated; char *data = NULL; + const char *prev, *cur, *next; if (!pl->use_cone_patterns) return; @@ -652,12 +653,47 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern } if (given->patternlen <= 2 || + *given->pattern == '*' || strstr(given->pattern, "**")) { /* Not a cone pattern. */ warning(_("unrecognized pattern: '%s'"), given->pattern); goto clear_hashmaps; } + prev = given->pattern; + cur = given->pattern + 1; + next = given->pattern + 2; + + while (*cur) { + /* Watch for glob characters '*', '\', '[', '?' */ + if (!is_glob_special(*cur)) + goto increment; + + /* But only if *prev != '\\' */ + if (*prev == '\\') + goto increment; + + /* But allow the initial '\' */ + if (*cur == '\\' && + is_glob_special(*next)) + goto increment; + + /* But a trailing '/' then '*' is fine */ + if (*prev == '/' && + *cur == '*' && + *next == 0) + goto increment; + + /* Not a cone pattern. */ + warning(_("unrecognized pattern: '%s'"), given->pattern); + goto clear_hashmaps; + + increment: + prev++; + cur++; + next++; + } + if (given->patternlen > 2 && !strcmp(given->pattern + given->patternlen - 2, "/*")) { if (!(given->flags & PATTERN_FLAG_NEGATIVE)) { diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 2e57534799..c732abeacd 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -348,4 +348,43 @@ test_expect_success 'pattern-checks: too short' ' check_read_tree_errors repo "a" "disabling cone pattern matching" ' +test_expect_success 'pattern-checks: trailing "*"' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /a* + EOF + check_read_tree_errors repo "a" "disabling cone pattern matching" +' + +test_expect_success 'pattern-checks: starting "*"' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + *eep/ + EOF + check_read_tree_errors repo "a deep" "disabling cone pattern matching" +' + +test_expect_success 'pattern-checks: contained glob characters' ' + for c in "[a]" "\\" "?" "*" + do + cat >repo/.git/info/sparse-checkout <<-EOF && + /* + !/*/ + something$c-else/ + EOF + check_read_tree_errors repo "a" "disabling cone pattern matching" + done +' + +test_expect_success 'pattern-checks: escaped "*"' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /does\*not\*exist/ + EOF + check_read_tree_errors repo "a" "" +' + test_done From patchwork Fri Jan 31 20:16:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360425 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 6DF8C13B4 for ; Fri, 31 Jan 2020 20:16:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D2C721734 for ; Fri, 31 Jan 2020 20:16:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uw3RsHqq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726593AbgAaUQ3 (ORCPT ); Fri, 31 Jan 2020 15:16:29 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36788 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726387AbgAaUQZ (ORCPT ); Fri, 31 Jan 2020 15:16:25 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so10172254wma.1 for ; Fri, 31 Jan 2020 12:16:23 -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=eZA3Y8V0DI7Y6OfhZpE3M38qZIRLUorKn3RyVp8rUpU=; b=Uw3RsHqqLceO7W6RxE8VwUSrV4QO1wljrlBouEb7g3FjZb9pYUezJdn0XBtE6zZxfh 3zn5+olsLV6FPCzM1PZgC0wpJHAr94IAbCC81QYtxJFje6y28skvQfG0q7JRIEGZS7do hoc28UTZVUmChosrQcrqAez6Z8h61NhA72rVmp7oBbF3RTzKHEnfKOOfrT9aH43JllFG dog3VCGUoCPXAP9DrCNzLe+Em4NLj6z/xFCfEprLdmcDrhDheC1UwkOe6FfOLaJNsFCQ /xpw4YvEELUTXZ/IjZ2wlyyzft+ZhiWQLumi4+91LSrTAyO1HrKaGL4kH3LAoqyVirt3 xarg== 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=eZA3Y8V0DI7Y6OfhZpE3M38qZIRLUorKn3RyVp8rUpU=; b=U6tbOcHdXvPazi4+Awxv2b6K8qBF4h4kjiubNiGqJUNmTvDyDLXuEN2SpJCbWaXZkc vtm3rrcYJbTyfsnLuFE+BvDWr84rVWIkcUenSL1EahjV95YMY8Cc2wdfx1imw/kL45Kk ewkhojJQPqFFjY00SuuMcsE3E3SK4HkWS0xDfCZodZGZKI0gKDONTNMrzyJsge2Zq2QC AAxAcfBOTGNpvyRAtjH04uZV+aMM7cJlPopzNBe2brzvQCq5iYZWjFyajdchFasNauXT AuL+saTz1HuTklmHiFaKNQQD28kaSUDYdHh+2sYzIiem/6D0LXmFgjMA5CIY0Ufr4oKH KSYw== X-Gm-Message-State: APjAAAXySxGyFDAndeUjS24w+pxl2zGiwU9ng7aXeTGxQAmpbyki65iG dYKNIeaySrYOTfoVVVY6lzs8XFAi X-Google-Smtp-Source: APXvYqwWOwZc4pUtzP4H7OVGL0qeklucrM+VKHyP/WnqPDQZUYeLdo73mITE40o+n6tousiCf78zeg== X-Received: by 2002:a7b:cc81:: with SMTP id p1mr13309501wma.62.1580501782977; Fri, 31 Jan 2020 12:16:22 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c141sm12318954wme.41.2020.01.31.12.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:22 -0800 (PST) Message-Id: <4c86d01f0e965db0285336a88f2dc34cbcd0c073.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:09 +0000 Subject: [PATCH v4 09/15] sparse-checkout: properly match escaped characters Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee In cone mode, the sparse-checkout feature uses hashset containment queries to match paths. Make this algorithm respect escaped asterisk (*) and backslash (\) characters. Create dup_and_filter_pattern() method to convert a pattern by removing escape characters and dropping an optional "/*" at the end. This method is available in dir.h as we will use it in builtin/sparse-checkout.c in a later change. Signed-off-by: Derrick Stolee --- dir.c | 35 +++++++++++++++++++++++++++--- t/t1091-sparse-checkout-builtin.sh | 23 ++++++++++++++++---- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/dir.c b/dir.c index 71d28331f3..7ac0920b71 100644 --- a/dir.c +++ b/dir.c @@ -630,6 +630,36 @@ int pl_hashmap_cmp(const void *unused_cmp_data, return strncmp(ee1->pattern, ee2->pattern, min_len); } +static char *dup_and_filter_pattern(const char *pattern) +{ + char *set, *read; + size_t count = 0; + char *result = xstrdup(pattern); + + set = result; + read = result; + + while (*read) { + /* skip escape characters (once) */ + if (*read == '\\') + read++; + + *set = *read; + + set++; + read++; + count++; + } + *set = 0; + + if (count > 2 && + *(set - 1) == '*' && + *(set - 2) == '/') + *(set - 2) = 0; + + return result; +} + static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern *given) { struct pattern_entry *translated; @@ -702,8 +732,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern goto clear_hashmaps; } - truncated = xstrdup(given->pattern); - truncated[given->patternlen - 2] = 0; + truncated = dup_and_filter_pattern(given->pattern); translated = xmalloc(sizeof(struct pattern_entry)); translated->pattern = truncated; @@ -737,7 +766,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern translated = xmalloc(sizeof(struct pattern_entry)); - translated->pattern = xstrdup(given->pattern); + translated->pattern = dup_and_filter_pattern(given->pattern); translated->patternlen = given->patternlen; hashmap_entry_init(&translated->ent, ignore_case ? diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index c732abeacd..9ea700896d 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -378,13 +378,28 @@ test_expect_success 'pattern-checks: contained glob characters' ' done ' -test_expect_success 'pattern-checks: escaped "*"' ' - cat >repo/.git/info/sparse-checkout <<-\EOF && +test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' + git clone repo escaped && + TREEOID=$(git -C escaped rev-parse HEAD:folder1) && + NEWTREE=$(git -C escaped mktree <<-EOF + $(git -C escaped ls-tree HEAD) + 040000 tree $TREEOID zbad\\dir + 040000 tree $TREEOID zdoes*exist + EOF + ) && + COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) && + git -C escaped reset --hard $COMMIT && + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && + git -C escaped sparse-checkout init --cone && + cat >escaped/.git/info/sparse-checkout <<-\EOF && /* !/*/ - /does\*not\*exist/ + /zbad\\dir/ + !/zbad\\dir/*/ + /zdoes\*not\*exist/ + /zdoes\*exist/ EOF - check_read_tree_errors repo "a" "" + check_read_tree_errors escaped "a zbad\\dir zdoes*exist" ' test_done From patchwork Fri Jan 31 20:16:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360429 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 CF13214D5 for ; Fri, 31 Jan 2020 20:16:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF82D21734 for ; Fri, 31 Jan 2020 20:16:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jthcIwlc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbgAaUQb (ORCPT ); Fri, 31 Jan 2020 15:16:31 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33989 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726475AbgAaUQZ (ORCPT ); Fri, 31 Jan 2020 15:16:25 -0500 Received: by mail-wr1-f65.google.com with SMTP id t2so10175459wrr.1 for ; Fri, 31 Jan 2020 12:16:24 -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=bWLb+llRKMp4j/agNI8PJG44bIIzb45hS/gZZJAh7Os=; b=jthcIwlcilZ6BZEocyH8VOcw+Jfy5yLNL9RBg5L1+TXrf1Pdcv2jrOj7obNXLl3NaD CDqDK73KPtjY2ZVEaOd5GAzdiIbLm0Wkf/yY0yLNKCDRbUuzDQsn/pq3TsoKGJ25UI/A rfUeaUfLOggtDJR9zK30y/nkHsv2hsdZVD4q+PIs18fnF+Fwd0IOyPb05VS6rfxOvodE U6grgoRXRobE0f1LjMVP0N1FR2Zn2bLGvY3wvwCh0yrb3po4nBshAgRisvH0rlPXuYVf ugoXl0fRGOuFBZeQ2SdYhTsb94hwEZDo+Nsrs2z/Pj0TRbVqaRYpw1hVuwwh4n+TYghb b1OQ== 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=bWLb+llRKMp4j/agNI8PJG44bIIzb45hS/gZZJAh7Os=; b=h/F/xmwCQKR3GhqOdOGvSjKmqtTeYvc3sr8sp6mBq6M9j4zRUHBjz90nil3tqfqmCR E/43y2dzDkWAtWq5e+Tu7z6TXPlNRupXU8gLZSIfuTv1UQeEenzGznYGu3venBzJaKM+ fDDLBJUsvTFDTEgoasVNutoebdgJJ61qWLd0pWIu1lrLBgSL1ispZlvVAs/UHbT477v3 Y++e3aMG8kui0OI/McE1LBZUkSZZo896X9pK/kza1FrLLR5H6tgY9+zxBN3nVx2eQpU6 N7hBMWv9JsK/s5w2HexxUjbSJUPk29fMKvHrJghgs4Upk8fdqAA15JRg5JLtwGT4sK6j KrhQ== X-Gm-Message-State: APjAAAVkjHcLCanKGlv/cDUv4E4S6xXHCZPHjfFcQlrLstGrKD+bozfF nKYfMcn5DmDFXRbOLmwNAkzc7r7i X-Google-Smtp-Source: APXvYqyAgrzIK2gTbpsOBXt7ekCxq7CueVCfba1FWNpRxmLlntNxhh8tW8dSDUmUDY5534slqQIJWw== X-Received: by 2002:adf:eb51:: with SMTP id u17mr143319wrn.29.1580501783753; Fri, 31 Jan 2020 12:16:23 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n28sm13496865wra.48.2020.01.31.12.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:23 -0800 (PST) Message-Id: <0b9346f67b207d9495ea5223bddf7b517291455e.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:10 +0000 Subject: [PATCH v4 10/15] sparse-checkout: write escaped patterns in cone mode Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee If a user somehow creates a directory with an asterisk (*) or backslash (\), then the "git sparse-checkout set" command will struggle to provide the correct pattern in the sparse-checkout file. When not in cone mode, the provided pattern is written directly into the sparse-checkout file. However, in cone mode we expect a list of paths to directories and then we convert those into patterns. However, there is some care needed for the timing of these escapes. The in-memory pattern list is used to update the working directory before writing the patterns to disk. Thus, we need the command to have the unescaped names in the hashsets for the cone comparisons, then escape the patterns later. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 23 +++++++++++++++++++++-- t/t1091-sparse-checkout-builtin.sh | 10 ++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 3cee8ab46e..cc86b8a014 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -13,6 +13,7 @@ #include "resolve-undo.h" #include "unpack-trees.h" #include "wt-status.h" +#include "quote.h" static const char *empty_base = ""; @@ -140,6 +141,22 @@ static int update_working_directory(struct pattern_list *pl) return result; } +static char *escaped_pattern(char *pattern) +{ + char *p = pattern; + struct strbuf final = STRBUF_INIT; + + while (*p) { + if (*p == '*' || *p == '\\') + strbuf_addch(&final, '\\'); + + strbuf_addch(&final, *p); + p++; + } + + return strbuf_detach(&final, NULL); +} + static void write_cone_to_file(FILE *fp, struct pattern_list *pl) { int i; @@ -164,10 +181,11 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl) fprintf(fp, "/*\n!/*/\n"); for (i = 0; i < sl.nr; i++) { - char *pattern = sl.items[i].string; + char *pattern = escaped_pattern(sl.items[i].string); if (strlen(pattern)) fprintf(fp, "%s/\n!%s/*/\n", pattern, pattern); + free(pattern); } string_list_clear(&sl, 0); @@ -185,8 +203,9 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl) string_list_remove_duplicates(&sl, 0); for (i = 0; i < sl.nr; i++) { - char *pattern = sl.items[i].string; + char *pattern = escaped_pattern(sl.items[i].string); fprintf(fp, "%s/\n", pattern); + free(pattern); } } diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 9ea700896d..fb8718e64a 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -309,6 +309,9 @@ check_read_tree_errors () { REPO=$1 FILES=$2 ERRORS=$3 + git -C $REPO -c core.sparseCheckoutCone=false read-tree -mu HEAD 2>err && + test_must_be_empty err && + check_files $REPO "$FILES" && git -C $REPO read-tree -mu HEAD 2>err && if test -z "$ERRORS" then @@ -391,14 +394,17 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' git -C escaped reset --hard $COMMIT && check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && git -C escaped sparse-checkout init --cone && - cat >escaped/.git/info/sparse-checkout <<-\EOF && + git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" && + cat >expect <<-\EOF && /* !/*/ /zbad\\dir/ !/zbad\\dir/*/ - /zdoes\*not\*exist/ + /zbad\\dir/bogus/ /zdoes\*exist/ + /zdoes\*not\*exist/ EOF + test_cmp expect escaped/.git/info/sparse-checkout && check_read_tree_errors escaped "a zbad\\dir zdoes*exist" ' From patchwork Fri Jan 31 20:16:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360427 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 7C23D1395 for ; Fri, 31 Jan 2020 20:16:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 59BF4214D8 for ; Fri, 31 Jan 2020 20:16:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nDL9k5jC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbgAaUQa (ORCPT ); Fri, 31 Jan 2020 15:16:30 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39514 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbgAaUQ0 (ORCPT ); Fri, 31 Jan 2020 15:16:26 -0500 Received: by mail-wm1-f66.google.com with SMTP id c84so10143869wme.4 for ; Fri, 31 Jan 2020 12:16:25 -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=qvJlsm6+87hUo/cW2GFKfhL+PDcSk/JMELMkiDzkh7k=; b=nDL9k5jCgzfFjA3+fFA6/JwSyzpqeMe5JZ3ng33k4lKYCnKX2VziaxKMpi0mPQ0+l9 KbV9u1t54pgN59Km+9C9xLKk0yJjId2NeJ3BVgNrcCvyuWXJZgc2IfcvgWXhORNnFk9D bI3ABrEe04gYuSQgVAr4DfQ27JM2nsOi2XP1hab7gkIccdjUg3J/uz7MTsHuFi1arkXb MLLFZqzVwxXcCr0Gnf6KUm2RGa5ZhEVCIkSUyMs3qBUUMLK3X8fgALBxkIHLBlpIYMSX 6ZmVVSPodK/lbrCABlmvo89MBgG9aWGXhYxRChrMj3TY6TQk3qgiEXOWvzIkzzHmDfhG kcRg== 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=qvJlsm6+87hUo/cW2GFKfhL+PDcSk/JMELMkiDzkh7k=; b=MCSFNJ4/d0SG9j3PNjQJPqi8MAgdd7fUynNx4/3UPwEaJKMiim3tZ6m7dgKlJLFMVw Wu9hwrXMtrR8C/OtAukr84FQRlNw37d+7SveILlKLdzs780j00+HiVYqDOoyWzk0FanO r8ZIQMODxEIU/lMapNuZU+aRUL9k1p5PBDh3SG/axidF8M5LYgnBfGu8wyMEu9Xiy/nD sp4NQ0Cf07bTXhMUfKgXVQsjO+Xx9I6Xnnn9XJz/CXjb9sdowGciRrXRlWfTrPBvnfmJ lGcqOBQUznR8OYps4cA1D4PEPCG67tdnbv6cj9pPN0SB5kp3AvVeN4QCFBG1dewBjERM 6LyA== X-Gm-Message-State: APjAAAXnNb1bxT1SIRcTN9Gzg3Zm/afgXacF5oZpuOG4niZcDJ24thfm 6wEriHQm1TF0PXQZrrMLf0cufBSn X-Google-Smtp-Source: APXvYqxt80rNz8lJwHoMaGAhsgf7d+bbwK/9zlKACme4Av+Nbq3EkudukO3CQoqPTKG7E6dBJg6Uyw== X-Received: by 2002:a05:600c:2147:: with SMTP id v7mr13218053wml.61.1580501784406; Fri, 31 Jan 2020 12:16:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m21sm12416873wmi.27.2020.01.31.12.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:24 -0800 (PST) Message-Id: <9f682e6076fd23491d51561ff2e9cf506cddbce6.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:11 +0000 Subject: [PATCH v4 11/15] sparse-checkout: unquote C-style strings over --stdin Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee If a user somehow creates a directory with an asterisk (*) or backslash (\), then the "git sparse-checkout set" command will struggle to provide the correct pattern in the sparse-checkout file. When not in cone mode, the provided pattern is written directly into the sparse-checkout file. However, in cone mode we expect a list of paths to directories and then we convert those into patterns. Even more specifically, the goal is to always allow the following from the root of a repo: git ls-tree --name-only -d HEAD | git sparse-checkout set --stdin The ls-tree command provides directory names with an unescaped asterisk. It also quotes the directories that contain an escaped backslash. We must remove these quotes, then keep the escaped backslashes. Use unquote_c_style() when parsing lines from stdin. Command-line arguments will be parsed as-is, assuming the user can do the correct level of escaping from their environment to match the exact directory names. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 15 ++++++++++++++- t/t1091-sparse-checkout-builtin.sh | 14 +++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index cc86b8a014..6083aa10f2 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -442,8 +442,21 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) pl.use_cone_patterns = 1; if (set_opts.use_stdin) { - while (!strbuf_getline(&line, stdin)) + struct strbuf unquoted = STRBUF_INIT; + while (!strbuf_getline(&line, stdin)) { + if (line.buf[0] == '"') { + strbuf_reset(&unquoted); + if (unquote_c_style(&unquoted, line.buf, NULL)) + die(_("unable to unquote C-style string '%s'"), + line.buf); + + strbuf_swap(&unquoted, &line); + } + strbuf_to_cone_pattern(&line, &pl); + } + + strbuf_release(&unquoted); } else { for (i = 0; i < argc; i++) { strbuf_setlen(&line, 0); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index fb8718e64a..a46a310740 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -405,7 +405,19 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' /zdoes\*not\*exist/ EOF test_cmp expect escaped/.git/info/sparse-checkout && - check_read_tree_errors escaped "a zbad\\dir zdoes*exist" + check_read_tree_errors escaped "a zbad\\dir zdoes*exist" && + git -C escaped ls-tree -d --name-only HEAD | git -C escaped sparse-checkout set --stdin && + cat >expect <<-\EOF && + /* + !/*/ + /deep/ + /folder1/ + /folder2/ + /zbad\\dir/ + /zdoes\*exist/ + EOF + test_cmp expect escaped/.git/info/sparse-checkout && + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" ' test_done From patchwork Fri Jan 31 20:16:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360435 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 817BE1395 for ; Fri, 31 Jan 2020 20:16:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60F9321734 for ; Fri, 31 Jan 2020 20:16:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sh8WFk1n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726670AbgAaUQf (ORCPT ); Fri, 31 Jan 2020 15:16:35 -0500 Received: from mail-wr1-f54.google.com ([209.85.221.54]:38426 "EHLO mail-wr1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbgAaUQ1 (ORCPT ); Fri, 31 Jan 2020 15:16:27 -0500 Received: by mail-wr1-f54.google.com with SMTP id y17so10151024wrh.5 for ; Fri, 31 Jan 2020 12:16:25 -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=SNXe42SXsr/Nmr5yTN07lWZrSqUv3TG4EiTph2yOymM=; b=Sh8WFk1n/8A30xKkqja57VM6uGm86SVENRxF8yc16pKXMARWd6MBnXt4VcVXLOur3R dHMtRSl7WsFwXp5JOlhvyiwoOOZ9HBPoe9+rKIpzXP/k0ft4BZ2HILAajPwQAlp50GYY macBxoUsOhDnf645MnS3VxnyxWhHzd0Nth9gU2NWT+8Batr+qIrEFXvAcUxI3+v1+81k meIfC4jT8C2EAc4i7EQmTqcEiyjjoA2xa0JN21IiTm14lAQr6vrybeV5T4bFjF3a6zOe LMGv275p1aDEKi7+OAoAEE7pS81DXm0TKq3KBg728ILfJNrQNHAThzOVPjRiTHurMHk0 Us7w== 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=SNXe42SXsr/Nmr5yTN07lWZrSqUv3TG4EiTph2yOymM=; b=ksC6qghcH1V9rwR6fL4TNTWlesgWtYbl4Iuztn4aDCrGQJ2Jxh9s3q+qiNqSUQ9W+O AvvMyo499ppAQhlk2IreWYXEO7r+L9zqSsrl08KQVonuaoX5aATXzHss9iTmW+FhVm7M p6seqZ/gLntVllzrEfVC8lVEphYdj8eC+9LZQwtZOlHM9UemOsDApCXH2qpJHD12dHvJ StCWZnbG5CNHoVRCbJR6a8/zpF9amWw5LVCTFUseKO1sPf+j+ajzHMmDGyH2IoD1MiXV PipD06ldD9vqt5t2DjO2ynELZbu7hWyA7AIsXVc9yFJjRuIIW7xUPCd7Dsj/LtdqnBQJ pjlA== X-Gm-Message-State: APjAAAUy6y+olweQBioU5COtKyC8YRal/DzzhQjJayarr2zucX6lCYuB lTHKcu3QNvwk590LdZ07xHcT+tp9 X-Google-Smtp-Source: APXvYqxZwwQCR5pW81Yvtequ5mQoNfOtpJpA/+JwEaLN5uVRLFpI5pJJRpJOS874jDzxr4xC7P8utw== X-Received: by 2002:adf:f182:: with SMTP id h2mr136731wro.364.1580501785152; Fri, 31 Jan 2020 12:16:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e8sm13030143wrt.7.2020.01.31.12.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:24 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:12 +0000 Subject: [PATCH v4 12/15] sparse-checkout: use C-style quotes in 'list' subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When in cone mode, the 'git sparse-checkout list' subcommand lists the directories included in the sparse cone. When these directories contain odd characters, such as a backslash, then we need to use C-style quotes similar to 'git ls-tree'. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 6 ++++-- t/t1091-sparse-checkout-builtin.sh | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 6083aa10f2..facdb6bda7 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -78,8 +78,10 @@ static int sparse_checkout_list(int argc, const char **argv) string_list_sort(&sl); - for (i = 0; i < sl.nr; i++) - printf("%s\n", sl.items[i].string); + for (i = 0; i < sl.nr; i++) { + quote_c_style(sl.items[i].string, NULL, stdout, 0); + printf("\n"); + } return 0; } diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index a46a310740..545e8d5ebe 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -406,7 +406,8 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' EOF test_cmp expect escaped/.git/info/sparse-checkout && check_read_tree_errors escaped "a zbad\\dir zdoes*exist" && - git -C escaped ls-tree -d --name-only HEAD | git -C escaped sparse-checkout set --stdin && + git -C escaped ls-tree -d --name-only HEAD >list-expect && + git -C escaped sparse-checkout set --stdin expect <<-\EOF && /* !/*/ @@ -417,7 +418,9 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' /zdoes\*exist/ EOF test_cmp expect escaped/.git/info/sparse-checkout && - check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && + git -C escaped sparse-checkout list >list-actual && + test_cmp list-expect list-actual ' test_done From patchwork Fri Jan 31 20:16:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360437 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 07F5513B4 for ; Fri, 31 Jan 2020 20:16:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DBFE321734 for ; Fri, 31 Jan 2020 20:16:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OhfkyXH/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726687AbgAaUQg (ORCPT ); Fri, 31 Jan 2020 15:16:36 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55560 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgAaUQ1 (ORCPT ); Fri, 31 Jan 2020 15:16:27 -0500 Received: by mail-wm1-f66.google.com with SMTP id q9so9337329wmj.5 for ; Fri, 31 Jan 2020 12:16:26 -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=UAdG0lzNzfH3h6z/Xyok/D1JO6NRnig6jTHOWkD+ijY=; b=OhfkyXH/3cE4HOMrm31eyAuwF1XviWOce6aNKs596R1ztmOXM6NPW8jW7Ml4yeX+4/ d13yQWf7zG9a19pc1PtDFmSmz58/6ZjiiliB8AFFL0J7gy2oIj8PoFGQID+/lYUdoMNe 9szOs6bDYfcj6edmLUlBtBqLdBam5gFQq4xSUnDpzFfl0VnljZ2xrPbUw0fBTbVpzcGU yIi9lhdz06NwHsVZP2ksWz2por7UOOQqp+eqBNLoVrgKAxzVulV3JLFLWcc9N6BEKmsJ ucXXl0JzgvZrTSwscKSEZ0N/sYF6k9bAN1ih/eYpbo9Bo/Eu6enCT9N14H5JhvNy21At 3JDg== 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=UAdG0lzNzfH3h6z/Xyok/D1JO6NRnig6jTHOWkD+ijY=; b=BWpq+TzBEKY0c+caQboFScmufwhGfgy0ugMt08EZjQwAd1Rb6wTqdHMNerCdCBMkmV lXP1RTND7Llf7d6i7TvzJHwlATg8eMWBCN7exXuSTGAEWW+S+3UVqTNCtukN8qtx+Ajo m2VUiB4epVS6AeYWD8E9ZNvs0cHZf/e4fghtAmKc7GeQno1Hf9WGWOSUjxAYGdsdrBtb E4gFzKnq70hHueGfqqg0asdAKh9bMXBaEsYchCErHmUFrel3zxairG7zA6EntoNzq739 GZ68/uzEySMwSy2nmHGJc0jmGU7T01MacXOHX+VIdJwMeKMV+ZRKSsxzld/qXWtuby55 JFKQ== X-Gm-Message-State: APjAAAVvxe5QUHX3qPJ/P2iTFxbANAvjZHe2cX2oPYHp+0xSOzT5vaw4 DnvKzohigz4N0gX/9Bxirgh5igqD X-Google-Smtp-Source: APXvYqzGfgvED4NGJfmbi7xh3/PvPg8py3xv67QIZ7RNsoQoQmzTT5KLDClAHzReycPV5MHlENnlUw== X-Received: by 2002:a7b:c183:: with SMTP id y3mr13103098wmi.45.1580501785803; Fri, 31 Jan 2020 12:16:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s8sm12379382wrt.57.2020.01.31.12.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:25 -0800 (PST) Message-Id: <54be8e89eb7ebad67ec18bfb871a13726f7c6769.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:13 +0000 Subject: [PATCH v4 13/15] sparse-checkout: escape all glob characters on write Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The sparse-checkout patterns allow special globs according to fnmatch(3). When writing cone-mode patterns for paths containing these characters, they must be escaped. Use is_glob_special() to check which characters must be escaped this way, and add a path to the tests that contains all glob characters at once. Note that ']' is not special, since the initial bracket '[' is escaped. Reported-by: Jeff King Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 2 +- t/t1091-sparse-checkout-builtin.sh | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index facdb6bda7..7aeb384362 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -149,7 +149,7 @@ static char *escaped_pattern(char *pattern) struct strbuf final = STRBUF_INIT; while (*p) { - if (*p == '*' || *p == '\\') + if (is_glob_special(*p)) strbuf_addch(&final, '\\'); strbuf_addch(&final, *p); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 545e8d5ebe..37e9304ef3 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -381,20 +381,21 @@ test_expect_success 'pattern-checks: contained glob characters' ' done ' -test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' +test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' ' git clone repo escaped && TREEOID=$(git -C escaped rev-parse HEAD:folder1) && NEWTREE=$(git -C escaped mktree <<-EOF $(git -C escaped ls-tree HEAD) 040000 tree $TREEOID zbad\\dir 040000 tree $TREEOID zdoes*exist + 040000 tree $TREEOID zglob[!a]? EOF ) && COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) && git -C escaped reset --hard $COMMIT && - check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? && git -C escaped sparse-checkout init --cone && - git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" && + git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" && cat >expect <<-\EOF && /* !/*/ @@ -403,9 +404,10 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' /zbad\\dir/bogus/ /zdoes\*exist/ /zdoes\*not\*exist/ + /zglob\[!a]\?/ EOF test_cmp expect escaped/.git/info/sparse-checkout && - check_read_tree_errors escaped "a zbad\\dir zdoes*exist" && + check_read_tree_errors escaped "a zbad\\dir zdoes*exist zglob[!a]?" && git -C escaped ls-tree -d --name-only HEAD >list-expect && git -C escaped sparse-checkout set --stdin expect <<-\EOF && @@ -416,9 +418,10 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' /folder2/ /zbad\\dir/ /zdoes\*exist/ + /zglob\[!a]\?/ EOF test_cmp expect escaped/.git/info/sparse-checkout && - check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? && git -C escaped sparse-checkout list >list-actual && test_cmp list-expect list-actual ' From patchwork Fri Jan 31 20:16:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360433 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 94B4A13B4 for ; Fri, 31 Jan 2020 20:16:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72B17215A4 for ; Fri, 31 Jan 2020 20:16:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ki0flzkU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726664AbgAaUQe (ORCPT ); Fri, 31 Jan 2020 15:16:34 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34435 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbgAaUQ2 (ORCPT ); Fri, 31 Jan 2020 15:16:28 -0500 Received: by mail-wm1-f67.google.com with SMTP id s144so9564389wme.1 for ; Fri, 31 Jan 2020 12:16:27 -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=7OIxkWhiTuACvbhbr0mgY5mdi0HMxPaJU+8Iq5N0peE=; b=ki0flzkU0FHshsd5Hc0BAAIaYWrt11A0TCwWtUtrsoenmgT+GdKh1V5Jw6vvVlJ/G8 qjwkRCY2wOMf977beom977iCu9SvgKMIw9EnhfTgrjluRlJcSA7i5gFCWSC6x0hwz2Yd tH0J8v7RfR3aJ4Rt+hp9+D0R7hyHwcYWO59G/zj+85vf7QQ6xfp5is3ojjh2XtRCLAgN LZ8512YoUhYH1TvHjvAKu3D4teRAQYr2CejQZzP6tjY/2ZVvTpqnKHq1FclU9Vb4fbdS 3x5XMRTe+u1zb91nIHrZ38BnwzC89MMQZzrxK0EO8/CtOEvhQZRU+YlLvQ8PgcEUFak8 k5UQ== 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=7OIxkWhiTuACvbhbr0mgY5mdi0HMxPaJU+8Iq5N0peE=; b=pFPkNRND2jAFlP3KQWGr/lNpRMtIBNIVHBCFWb4F71X7yrc5jej8RsnuclBGb3D7yE WHThxGLsYrEsmCCA+GLuoSPSbdD3VED4WWccQOv+C0n0D8a58bVwRk89K4S3PYrfTrm1 Nxh/a2bVJf44tLTUKRSRH+1rfYulGP4K/33R4qit4PUMlOv5jDRpgfu8VSwp6BVvJ+LC tb0uXDLZ1Kx3dHnIjPLBTwvozUPD8ER7CgIGcc/uN3sAMmHl9itu6Oa3+jKLAjK1LorE JcZsYYbrnVWNVkelVOSfXpSLFdRTj9PghDz1vnkoiTBeDjPlGYYBvr4sApmwww8ViBhv ezmQ== X-Gm-Message-State: APjAAAUylH0Tp5aQO59EpYdk+TbRR9d+zyzXAbsssrjfUK9+kRX/ZA9g 471G5rX2CE0aifTpOHxxc+RnIbRk X-Google-Smtp-Source: APXvYqyvxNFnIgU6Ua63V5Y4x9zcf6fEHcfTUaEZtPMP5O8WByw8wRCfaA+vZT+D0MHAP7sulpmwfA== X-Received: by 2002:a7b:cf12:: with SMTP id l18mr14404297wmg.66.1580501786527; Fri, 31 Jan 2020 12:16:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b67sm12622022wmc.38.2020.01.31.12.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:26 -0800 (PST) Message-Id: <3dd8f97b3a7c301955aba7dd5778549d1b49b0fd.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:14 +0000 Subject: [PATCH v4 14/15] sparse-checkout: improve docs around 'set' in cone mode Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The existing documentation does not clarify how the 'set' subcommand changes when core.sparseCheckoutCone is enabled. Correct this by changing some language around the "A/B/C" example. Also include a description of the input format matching the output of 'git ls-tree --name-only'. Helped-by: Jeff King Signed-off-by: Derrick Stolee --- Documentation/git-sparse-checkout.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt index 4834fb434d..0914619881 100644 --- a/Documentation/git-sparse-checkout.txt +++ b/Documentation/git-sparse-checkout.txt @@ -50,6 +50,14 @@ To avoid interfering with other worktrees, it first enables the + When the `--stdin` option is provided, the patterns are read from standard in as a newline-delimited list instead of from the arguments. ++ +When `core.sparseCheckoutCone` is enabled, the input list is considered a +list of directories instead of sparse-checkout patterns. The command writes +patterns to the sparse-checkout file to include all files contained in those +directories (recursively) as well as files that are siblings of ancestor +directories. The input format matches the output of `git ls-tree --name-only`. +This includes interpreting pathnames that begin with a double quote (") as +C-style quoted strings. 'disable':: Disable the `core.sparseCheckout` config setting, and restore the @@ -128,9 +136,12 @@ the following patterns: ---------------- This says "include everything in root, but nothing two levels below root." -If we then add the folder `A/B/C` as a recursive pattern, the folders `A` and -`A/B` are added as parent patterns. The resulting sparse-checkout file is -now + +When in cone mode, the `git sparse-checkout set` subcommand takes a list of +directories instead of a list of sparse-checkout patterns. In this mode, +the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as +a recursive pattern, the directories `A` and `A/B` are added as parent +patterns. The resulting sparse-checkout file is now ---------------- /* From patchwork Fri Jan 31 20:16:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 11360431 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 7BE8414D5 for ; Fri, 31 Jan 2020 20:16:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5AE5C21734 for ; Fri, 31 Jan 2020 20:16:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gySGl6JQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726637AbgAaUQc (ORCPT ); Fri, 31 Jan 2020 15:16:32 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36200 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726561AbgAaUQ3 (ORCPT ); Fri, 31 Jan 2020 15:16:29 -0500 Received: by mail-wr1-f66.google.com with SMTP id z3so10171417wru.3 for ; Fri, 31 Jan 2020 12:16:27 -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=NOixNBC7fdzNZ0Vh4Z4S7u1S7FIf/h5PVqWmfQdvx7U=; b=gySGl6JQBRlNp5DbysyOGCjgazaVqH2Gv6tCZlyoykgtJFDUIcdJnQECJyH06/60Lf BG4x82PjfrUCC46ocCFZxR0Fgoyz76kZYCR26mz5RMcWCwIZbN/ZeU2Wet6xrhDidHLM 9NGb+KyO5rBVyRt72iemGgnfhRUv4iN1aLqg5zvw0AFZbVKDs22/lNvRrTC47B5zoxZA 0l+pGc0NpGGA6T/WbAWNdmaO8QXIer1Lmna49JHXaWwUpfPbY5nwX9r9KoE1OtVxajJf gndqzlxncM9ewL8Ss0tF7FS7z7XBFqsG2k79cuNkELAiYTweT0hadj9dha3olDGSNAx5 CCqQ== 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=NOixNBC7fdzNZ0Vh4Z4S7u1S7FIf/h5PVqWmfQdvx7U=; b=FbYD9+UqWOLIc6I9IJLS1XhLDk2qNnThQtcVIiykQILZBJzUqyuAacHqmjnxRLxLY/ cHswgMwHwhXSJTv83bJsTg4+FxiWVjEt6xh64xnx2ze159ndIEDUWrlhvvca/lMDCthB xEEraOpUNsAEB4iE1ILEuVOYVjmyVHnl7V4XB/uORK1ojchZJiuLyzJHi8GiG2Wanb6Z tUwvrya6WWaEPU2omwlEpnCnCNkSbnedZasmGuqM0JU9aLsbes8CzHNwBZUQC5Ud24aP dWeMEdAYUXLx4UlNYQmsuYoJgReOY9SxZxo0A8WD13HJujnW+9+pQ4GvhMiEV6WV9ZDh amSw== X-Gm-Message-State: APjAAAUrH7Q33QY6gpNb6F/oGJtkiZ/HOkY/SvMP1SrO8EXXGHB3J8C+ 7MMkLUVYYoTdw1QeJGRrnekcveH/ X-Google-Smtp-Source: APXvYqyFKjWGRMniKg+FJbV/3wwZUyshM+O9zwgIktsxgj/Oa1n4UbyX2M2No+HFSEkKMw6ZsJeDnA== X-Received: by 2002:adf:978a:: with SMTP id s10mr124365wrb.69.1580501787251; Fri, 31 Jan 2020 12:16:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c141sm12319215wme.41.2020.01.31.12.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:16:26 -0800 (PST) Message-Id: <5e9fcce75f37676613f6cb919249ce8afd51c825.1580501775.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 31 Jan 2020 20:16:15 +0000 Subject: [PATCH v4 15/15] sparse-checkout: fix cone mode behavior mismatch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The intention of the special "cone mode" in the sparse-checkout feature is to always match the same patterns that are matched by the same sparse-checkout file as when cone mode is disabled. When a file path is given to "git sparse-checkout set" in cone mode, then the cone mode improperly matches the file as a recursive path. When setting the skip-worktree bits, files were not expecting the MATCHED_RECURSIVE response, and hence these were left out of the matched cone. Fix this bug by checking for MATCHED_RECURSIVE in addition to MATCHED and add a test that prevents regression. Reported-by: Finn Bryant Signed-off-by: Derrick Stolee --- t/t1091-sparse-checkout-builtin.sh | 12 ++++++++++++ unpack-trees.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 37e9304ef3..7d982096fb 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -305,6 +305,18 @@ test_expect_success 'different sparse-checkouts with worktrees' ' check_files worktree a deep ' +test_expect_success 'set using filename keeps file on-disk' ' + git -C repo sparse-checkout set a deep && + cat >expect <<-\EOF && + /* + !/*/ + /a/ + /deep/ + EOF + test_cmp expect repo/.git/info/sparse-checkout && + check_files repo a deep +' + check_read_tree_errors () { REPO=$1 FILES=$2 diff --git a/unpack-trees.c b/unpack-trees.c index 3789a22cf0..78425ce74b 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1416,7 +1416,7 @@ static int clear_ce_flags_1(struct index_state *istate, name, &dtype, pl, istate); if (ret == UNDECIDED) ret = default_match; - if (ret == MATCHED) + if (ret == MATCHED || ret == MATCHED_RECURSIVE) ce->ce_flags &= ~clear_mask; cache++; progress_nr++;