[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-tar] exclude-vcs-ignores bug
From: |
Pavel Raiskup |
Subject: |
Re: [Bug-tar] exclude-vcs-ignores bug |
Date: |
Thu, 15 Dec 2016 11:09:39 +0100 |
User-agent: |
KMail/5.3.2 (Linux/4.8.13-300.fc25.x86_64; KDE/5.27.0; x86_64; ; ) |
On Wednesday, December 7, 2016 9:23:10 AM CET Serge Matveenko wrote:
> Hello everybody!
>
> It looks like I've found bug in tar.
>
> When used to create archive with option `--exclude-vcs-ignores` tar treats
> `.gitignore` patterns as shell patterns while they are not.
That's right [1], it is a bit more complicated, though the shell patterns are
closer to that syntax than regexps.
> Consider the following example.
>
> $ tar c --exclude-vcs-ignores -f ../tartest.tar .
> $ tar tf ../tartest.tar
> ./
> $ ls -1lA
> total 8
> 1
> .2
> .git
> .gitignore
> $ cat .gitignore
> .*
>
> Expected result is for `1` to be found in the archive.
>
> In this case git ignores `.2` and `.gitignore` files while tar ignores
> everything.
> `.*` means "ignore everything starting with .". This is not a regex.
>
> It is expected for `--exclude-vcs-ignores` to mimic VCS' ignore logic.
This is not that tar threats '.*' as regex, but I think tar tries to match
'.*' pattern with './1' string for example, and it succeeds (so the file
is excluded).
The pattern '.*' should be probably transformed into './.*' in tar,
somewhere around:
-> src/exclist.c:
106 >------- if (add_exclude_fp (vcsfile->addfn, ex, fp,
107 >------->------->------- EXCLUDE_WILDCARDS|EXCLUDE_ANCHORED, '\n',
108 >------->------->------- vcsfile->data))
109 >------- {
But add_exclude_fp seems to be gnulib call, and 'fp' is FILE* pointer, so
I'm not sure how easily prepend the leading part of the pattern (without diving
too deep) ... maybe tar should avoid using add_exclude_fp() call ... and add the
exclude pattern manually. Anyways, it looks like this deserves separate library
doing the right thing WRT .gitignore [1].
[1] https://git-scm.com/docs/gitignore
Pavel