From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-6.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 455BC1FEB3 for ; Fri, 13 Jan 2017 00:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751019AbdAMACT (ORCPT ); Thu, 12 Jan 2017 19:02:19 -0500 Received: from mail-pf0-f180.google.com ([209.85.192.180]:36682 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750960AbdAMACS (ORCPT ); Thu, 12 Jan 2017 19:02:18 -0500 Received: by mail-pf0-f180.google.com with SMTP id 189so20729353pfu.3 for ; Thu, 12 Jan 2017 16:02:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TYPL0cggpyti3tO8UVmi0r8mshCPIj4h3C4vk7QSShA=; b=uXiGtWSW3csXj/08cabhmgB/KediGtMzr0EW+CDT2eS3H7ZOMklIJwnX6xKB0RSukz dvkGIFeMeQ1SY8zMh4u5cnLm62HI9l5TcMgcvm9Akx8f0gUnPISMtw+P7Ju7PtcoOdm5 DCqeM7H10PjgK7bHFOMT+YYnGa1ksM/LUhACoOZl9qwDKGP6bWqyaZROjVFyuIyti4BZ OV7TogefK8HLDlQcSNHdzpsVxlh1zHsRLxFUSoPeb4ldrHvkvZW4soLqeQJd1u2V2P87 0qJpZItFk6C8GSr1Y9xTyqbFH5SwQFJo5MMijV7R+lzWmfOzB7uMnPUrAKDZLWzRzFKz j0+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TYPL0cggpyti3tO8UVmi0r8mshCPIj4h3C4vk7QSShA=; b=XEJGKtgsH+rdlmFoN0kMKk0derFu8xJpiQcUWRSd/7rMiemwn4Zr46NVzC9Mj2RVki v8HAkCd4y8q6lH2x0XUkl8xRgWQuZ/T2u4SKzXSVt2mHlwhnPZHpw5qs74PW155ONY/x fGz1iBZ2GiWxtnJTTneO0uEZH2wA6h62JHF9DhtmMu8M1hig8ePN2o5y/GeUwCocVTlE w/F1l68VKoy1qQsau12TSUl+u/hKCi9twbUe92crxCgF0yhDhAP50AYqbFvYs0dVSJ17 jnuh/vqCAqo7LzDIc61CkQ+9aiieCnAJhRHaFg4iEo3GKJBVRHwJlSdIOgFpJ+u9uUXB g25g== X-Gm-Message-State: AIkVDXInXWFvPN5y96VY+oLMSrHLsG6KjAvgNZAtmb6xF/pU0x2FNbaL8IgKo1bYst3ZDYJH X-Received: by 10.99.177.73 with SMTP id g9mr20677040pgp.32.1484265257712; Thu, 12 Jan 2017 15:54:17 -0800 (PST) Received: from roshar.mtv.corp.google.com ([100.96.238.26]) by smtp.gmail.com with ESMTPSA id e6sm24312192pgf.4.2017.01.12.15.54.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Jan 2017 15:54:16 -0800 (PST) From: Brandon Williams To: git@vger.kernel.org Cc: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= , gitster@pobox.com, sbeller@google.com, Brandon Williams Subject: [PATCH 10/27] attr: support quoting pathname patterns in C style Date: Thu, 12 Jan 2017 15:53:37 -0800 Message-Id: <20170112235354.153403-11-bmwill@google.com> X-Mailer: git-send-email 2.11.0.390.gc69c2f50cf-goog In-Reply-To: <20170112235354.153403-1-bmwill@google.com> References: <20170112235354.153403-1-bmwill@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Nguyễn Thái Ngọc Duy Full pattern must be quoted. So 'pat"t"ern attr' will give exactly 'pat"t"ern', not 'pattern'. Also clarify that leading whitespaces are not part of the pattern and document comment syntax. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Stefan Beller Signed-off-by: Brandon Williams --- Documentation/gitattributes.txt | 8 +++++--- attr.c | 15 +++++++++++++-- t/t0003-attributes.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index e0b66c122..3173dee7e 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -21,9 +21,11 @@ Each line in `gitattributes` file is of form: pattern attr1 attr2 ... That is, a pattern followed by an attributes list, -separated by whitespaces. When the pattern matches the -path in question, the attributes listed on the line are given to -the path. +separated by whitespaces. Leading and trailing whitespaces are +ignored. Lines that begin with '#' are ignored. Patterns +that begin with a double quote are quoted in C style. +When the pattern matches the path in question, the attributes +listed on the line are given to the path. Each attribute can be in one of these states for a given path: diff --git a/attr.c b/attr.c index d180c7833..e1c630f79 100644 --- a/attr.c +++ b/attr.c @@ -13,6 +13,7 @@ #include "attr.h" #include "dir.h" #include "utf8.h" +#include "quote.h" const char git_attr__true[] = "(builtin)true"; const char git_attr__false[] = "\0(builtin)false"; @@ -212,12 +213,21 @@ static struct match_attr *parse_attr_line(const char *line, const char *src, const char *cp, *name, *states; struct match_attr *res = NULL; int is_macro; + struct strbuf pattern = STRBUF_INIT; cp = line + strspn(line, blank); if (!*cp || *cp == '#') return NULL; name = cp; - namelen = strcspn(name, blank); + + if (*cp == '"' && !unquote_c_style(&pattern, name, &states)) { + name = pattern.buf; + namelen = pattern.len; + } else { + namelen = strcspn(name, blank); + states = name + namelen; + } + if (strlen(ATTRIBUTE_MACRO_PREFIX) < namelen && starts_with(name, ATTRIBUTE_MACRO_PREFIX)) { if (!macro_ok) { @@ -239,7 +249,6 @@ static struct match_attr *parse_attr_line(const char *line, const char *src, else is_macro = 0; - states = name + namelen; states += strspn(states, blank); /* First pass to count the attr_states */ @@ -282,9 +291,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src, cannot_trust_maybe_real = 1; } + strbuf_release(&pattern); return res; fail_return: + strbuf_release(&pattern); free(res); return NULL; } diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index f0fbb4255..f19ae4f8c 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -13,10 +13,31 @@ attr_check () { test_line_count = 0 err } +attr_check_quote () { + + path="$1" + quoted_path="$2" + expect="$3" + + git check-attr test -- "$path" >actual && + echo "\"$quoted_path\": test: $expect" >expect && + test_cmp expect actual + +} + +test_expect_success 'open-quoted pathname' ' + echo "\"a test=a" >.gitattributes && + test_must_fail attr_check a a +' + + test_expect_success 'setup' ' mkdir -p a/b/d a/c b && ( echo "[attr]notest !test" + echo "\" d \" test=d" + echo " e test=e" + echo " e\" test=e" echo "f test=f" echo "a/i test=a/i" echo "onoff test -test" @@ -69,6 +90,11 @@ test_expect_success 'command line checks' ' ' test_expect_success 'attribute test' ' + + attr_check " d " d && + attr_check e e && + attr_check_quote e\" e\\\" e && + attr_check f f && attr_check a/f f && attr_check a/c/f f && -- 2.11.0.390.gc69c2f50cf-goog