[darcs-users] darcs patch: Refactor actual_boring_file_filter. (and 1 more)

Eric Kow kowey at darcs.net
Sun Mar 22 20:34:16 UTC 2009


On Sun, Mar 22, 2009 at 15:55:58 +1100, Trent W.Buck wrote:
> Sun Mar 22 14:16:38 EST 2009  Trent W. Buck <trentbuck at gmail.com>
>   * Refactor actual_boring_file_filter.
> 
> Sun Mar 22 15:52:38 EST 2009  Trent W. Buck <trentbuck at gmail.com>
>   * Refactor darcs_binaries.

They look good to me.  Applied, thanks!

Refactor actual_boring_file_filter.
-----------------------------------
> Trent W. Buck <trentbuck at gmail.com>**20090322031638
>  Ignore-this: 5edebc17df5b1812b36d2af01e8861c8
> ] hunk ./src/Darcs/Repository/Prefs.lhs 40
>  import Control.Monad ( unless, when, mplus )
>  import Text.Regex ( Regex, mkRegex, matchRegex, )
>  import Data.Char ( toUpper )
> -import Data.Maybe ( isNothing, isJust, catMaybes )
> +import Data.Maybe ( isJust, catMaybes )
>  import Data.List ( nub, isPrefixOf, union )
>  import System.Directory ( getAppUserDataDirectory, doesDirectoryExist )
>  import System.Environment( getEnv )
> hunk ./src/Darcs/Repository/Prefs.lhs 287
>            nc l | startswith "^ ^ ^ ^ ^ ^ ^" l = False
>            nc _ = True
>  
> +-- | From a list of paths, filter out any that are within @_darcs@ or
> +-- match a boring regexp.
>  actual_boring_file_filter :: [Regex] -> [FilePath] -> [FilePath]
> hunk ./src/Darcs/Repository/Prefs.lhs 290
> -actual_boring_file_filter regexps fs =
> -    filter (abf (not.is_darcsdir) regexps . normalize) fs
> -    where
> -    abf fi (r:rs) = abf (\f -> fi f && isNothing (matchRegex r f)) rs
> -    abf fi [] = fi
> +actual_boring_file_filter regexps files = filter (not . boring . normalize) files
> +    where boring file = is_darcsdir file ||
> +                        any (\regexp -> isJust $ matchRegex regexp file) regexps
>  
>  normalize :: FilePath -> FilePath
>  normalize ('.':'/':f) = normalize f

Refactor darcs_binaries.
------------------------
> Trent W. Buck <trentbuck at gmail.com>**20090322045238
>  Ignore-this: f69604c422ee22936efc0f7b682def37
>  
>  Combine the lowercase and uppercase forms of each extension onto a
>  single line.  Also merge some extension variants (e.g. .jpe?g instead
>  of two entries .jpg and .jpeg) and sort the extension list.
>  
>  I've elected NOT to use Emacs' regexp-opt to build a faster regexp,
>  because that would make it very hard for end users to find and remove
>  an extension from the default list.  I think merging .jpe?g is OK.
> ] hunk ./src/Darcs/Repository/Prefs.lhs 320
>                  deriving (Eq)
>  
>  {-# NOINLINE default_binaries #-}
> +-- | The lines that will be inserted into @_darcs/prefs/binaries@ when
> +-- @darcs init@ is run.  Hence, a list of comments, blank lines and
> +-- regular expressions (ERE dialect).
> +--
> +-- Note that while this matches .gz and .GZ, it will not match .gZ,
> +-- i.e. it is not truly case insensitive.
>  default_binaries :: [String]
> hunk ./src/Darcs/Repository/Prefs.lhs 327
> -default_binaries =
> -    "# Binary file regexps:" :
> -    ext_regexes ["png","gz","pdf","jpg","jpeg","gif","tif",
> -                 "tiff","pnm","pbm","pgm","ppm","bmp","mng",
> -                 "tar","bz2","z","zip","jar","so","a",
> -                 "tgz","mpg","mpeg","iso","exe","doc",
> -                 "elc", "pyc"]
> -    where ext_regexes exts = concat $ map ext_regex exts
> -          ext_regex e = ["\\."++e++"$", "\\."++map toUpper e++"$"]
> +default_binaries = "# Binary file regexps:" :
> +                   ["\\.(" ++ e ++ "|" ++ map toUpper e ++ ")$" | e <- extensions ]
> +    where extensions = ["a","bmp","bz2","doc","elc","exe","gif","gz","iso",
> +                        "jar","jpe?g","mng","mpe?g","p[nbgp]m","pdf","png",
> +                        "pyc","so","tar","tgz","tiff?","z","zip"]
>  
>  filetype_function :: IO (FilePath -> FileType)
>  filetype_function = do
> 

-- 
Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
PGP Key ID: 08AC04F9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20090322/c80d9200/attachment.pgp>


More information about the darcs-users mailing list