{"thread":{"id":"11934","subject":"[PATCH] gitattributes: fix relative path matching","startedAt":"2008-02-07T08:22:16Z","lastAt":"2008-02-07T08:22:16Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"67766","messageId":"7vodatp45j.fsf@gitster.siamese.dyndns.org","threadId":"11934","inReplyTo":null,"subject":"[PATCH] gitattributes: fix relative path matching","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-07T08:22:16Z","receivedAt":"2008-02-07T08:22:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"There was an embarrassing pair of off-by-one miscounting that\nfailed to match path \"a/b/c\" when \"a/.gitattributes\" tried to\nname it with relative path \"b/c\".\n\nThis fixes it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n attr.c                |    6 +++---\n t/t0003-attributes.sh |   49 +++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 52 insertions(+), 3 deletions(-)\n create mode 100755 t/t0003-attributes.sh\n\ndiff --git a/attr.c b/attr.c\nindex 741db3b..64b77b1 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -406,7 +406,7 @@ static void debug_info(const char *what, struct attr_stack *elem)\n {\n \tfprintf(stderr, \"%s: %s\\n\", what, elem->origin ? elem->origin : \"()\");\n }\n-static void debug_set(const char *what, const char *match, struct git_attr *attr, void *v)\n+static void debug_set(const char *what, const char *match, struct git_attr *attr, const void *v)\n {\n \tconst char *value = v;\n \n@@ -543,10 +543,10 @@ static int path_matches(const char *pathname, int pathlen,\n \tif (*pattern == '/')\n \t\tpattern++;\n \tif (pathlen < baselen ||\n-\t    (baselen && pathname[baselen - 1] != '/') ||\n+\t    (baselen && pathname[baselen] != '/') ||\n \t    strncmp(pathname, base, baselen))\n \t\treturn 0;\n-\treturn fnmatch(pattern, pathname + baselen, FNM_PATHNAME) == 0;\n+\treturn fnmatch(pattern, pathname + baselen + 1, FNM_PATHNAME) == 0;\n }\n \n static int fill_one(const char *what, struct match_attr *a, int rem)\ndiff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh\nnew file mode 100755\nindex 0000000..47f08a4\n--- /dev/null\n+++ b/t/t0003-attributes.sh\n@@ -0,0 +1,49 @@\n+#!/bin/sh\n+\n+test_description=gitattributes\n+\n+. ./test-lib.sh\n+\n+attr_check () {\n+\n+\tpath=\"$1\"\n+\texpect=\"$2\"\n+\n+\tgit check-attr test -- \"$path\" >actual &&\n+\techo \"$path: test: $2\" >expect &&\n+\tdiff -u expect actual\n+\n+}\n+\n+\n+test_expect_success 'setup' '\n+\n+\tmkdir -p a/b/d a/c &&\n+\t(\n+\t\techo \"f\ttest=f\"\n+\t) >.gitattributes &&\n+\t(\n+\t\techo \"g test=a/g\" &&\n+\t\techo \"b/g test=a/b/g\"\n+\t) >a/.gitattributes &&\n+\t(\n+\t\techo \"h test=a/b/h\" &&\n+\t\techo \"d/* test=a/b/d/*\"\n+\t) >a/b/.gitattributes\n+\n+'\n+\n+test_expect_success 'attribute test' '\n+\n+\tattr_check f f &&\n+\tattr_check a/f f &&\n+\tattr_check a/c/f f &&\n+\tattr_check a/g a/g &&\n+\tattr_check a/b/g a/b/g &&\n+\tattr_check b/g unspecified &&\n+\tattr_check a/b/h a/b/h &&\n+\tattr_check a/b/d/g \"a/b/d/*\"\n+\n+'\n+\n+test_done\n-- \n1.5.4.1213.g2bdeb\n"}]}