fix * glob matching files in subdirectories

This commit is contained in:
Joey Hess 2013-02-26 13:49:22 -04:00
parent 1e3aa441f0
commit 7df2861d67
4 changed files with 18 additions and 16 deletions

View file

@ -12,12 +12,8 @@ module Limit where
import Data.Time.Clock.POSIX
import qualified Data.Set as S
import qualified Data.Map as M
#ifdef WITH_GLOB
import "Glob" System.FilePath.Glob (simplify, compile, match)
#else
import Text.Regex.PCRE.Light.Char8
import System.Path.WildMatch
#endif
import Text.Regex
import Common.Annex
import qualified Annex
@ -86,18 +82,14 @@ addExclude = addLimit . limitExclude
limitExclude :: MkLimit
limitExclude glob = Right $ const $ return . not . matchglob glob
{- Could just use wildCheckCase, but this way the regex is only compiled
- once. -}
matchglob :: String -> Annex.FileInfo -> Bool
matchglob glob (Annex.FileInfo { Annex.matchFile = f }) =
#ifdef WITH_GLOB
match pattern f
isJust $ matchRegex cregex f
where
pattern = simplify $ compile glob
#else
isJust $ match cregex f []
where
cregex = compile regex []
cregex = mkRegex regex
regex = '^':wildToRegex glob
#endif
{- Adds a limit to skip files not believed to be present
- in a specfied repository. -}

3
debian/changelog vendored
View file

@ -16,6 +16,9 @@ git-annex (3.20130217) UNRELEASED; urgency=low
* Additional GIT_DIR support bugfixes. May actually work now.
* webapp: Display any error message from git init if it fails to create
a repository.
* Fix a reversion in matching globs introduced in the last release,
where "*" did not match files inside subdirectories. No longer uses
the Glob library.
-- Joey Hess <joeyh@debian.org> Sun, 17 Feb 2013 16:42:16 -0400

View file

@ -60,14 +60,13 @@ Executable git-annex
extensible-exceptions, dataenc, SHA, process, json,
base (>= 4.5 && < 4.8), monad-control, transformers-base, lifted-base,
IfElse, text, QuickCheck >= 2.1, bloomfilter, edit-distance, process,
SafeSemaphore, uuid, random, Glob
SafeSemaphore, uuid, random
-- Need to list these because they're generated from .hsc files.
Other-Modules: Utility.Touch Utility.Mounts
Include-Dirs: Utility
C-Sources: Utility/libdiskfree.c Utility/libmounts.c
Extensions: CPP
GHC-Options: -threaded
CPP-Options: -DWITH_GLOB
if flag(S3)
Build-Depends: hS3
@ -127,7 +126,7 @@ Test-Suite test
old-locale, time, extensible-exceptions, dataenc, SHA,
process, json, base (>= 4.5 && < 4.7), monad-control,
transformers-base, lifted-base, IfElse, text, QuickCheck >= 2.1,
bloomfilter, edit-distance, process, SafeSemaphore, Glob, random, uuid
bloomfilter, edit-distance, process, SafeSemaphore, random, uuid
Other-Modules: Utility.Touch
Include-Dirs: Utility
C-Sources: Utility/libdiskfree.c

View file

@ -560,6 +560,14 @@ test_find = "git-annex find" ~: intmpclonerepo $ do
git_annex_expectoutput "find" ["--inbackend", "SHA1"] [sha1annexedfile]
git_annex_expectoutput "find" ["--inbackend", "WORM"] []
{- --include=* should match files in subdirectories too,
- and --exclude=* should exclude them. -}
createDirectory "dir"
writeFile "dir/subfile" "subfile"
git_annex "add" ["dir"] @? "add of subdir failed"
git_annex_expectoutput "find" ["--include", "*", "--exclude", annexedfile, "--exclude", sha1annexedfile] ["dir/subfile"]
git_annex_expectoutput "find" ["--exclude", "*"] []
test_merge :: Test
test_merge = "git-annex merge" ~: intmpclonerepo $ do
git_annex "merge" [] @? "merge failed"