packages feed

filediff 0.1.0.3 → 0.1.0.4

raw patch · 5 files changed

+81/−25 lines, 5 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Filediff: diffDirectoriesWithIgnoredSubdirs :: FilePath -> FilePath -> [FilePath] -> [FilePath] -> IO Diff

Files

Tests/test-filediff.hs view
@@ -259,6 +259,49 @@         }     actualDiff @?= expectedDiff +testDirDiffIgnoreFiles :: Assertion+testDirDiffIgnoreFiles = do+    D.createDirectory "a"+    D.createDirectory "b"++    D.createDirectory "a/common"+    D.createDirectory "a/common2"+    D.createDirectory "b/common"+    D.createDirectory "b/common2"++    D.createDirectory "a/aonly"+    D.createDirectory "a/aonly2"+    D.createDirectory "b/bonly"+    D.createDirectory "b/bonly2"++    createFileWithContents "a/common/x" "x\na\nx"+    createFileWithContents "a/common2/x" "x\na\nx"+    createFileWithContents "b/common/x" "x\nb\nx"+    createFileWithContents "b/common2/x" "x\nb\nx"++    createFileWithContents "a/aonly/afile" "a\na\na"+    createFileWithContents "a/aonly2/afile" "a\na\na"+    createFileWithContents "b/bonly/bfile" "b\nb\nb"+    createFileWithContents "b/bonly2/bfile" "b\nb\nb"++    actualDiff <- F.diffDirectoriesWithIgnoredSubdirs "a" "b" ["aonly2", "common2"] ["bonly2", "common2"]+    let expectedDiff = F.Diff {+        F.filediffs =+            [ F.Filediff+                { F.base = "common/x"+                , F.comp = "common/x"+                , F.change = F.Mod $ SeqDiff [1] [(1, T.pack "b")] }+            , F.Filediff+                    { F.base = "aonly/afile"+                    , F.comp = "aonly/afile"+                    , F.change = F.Del $ SeqDiff [0,1,2] [] }+            , F.Filediff+                { F.base = "bonly/bfile"+                , F.comp = "bonly/bfile"+                , F.change = F.Add $ SeqDiff [] [(0, T.pack "b"),(1, T.pack "b"),(2, T.pack "b")] } ]+        }+    actualDiff @?= expectedDiff+ testDirDiffEmptyDirectories :: Assertion testDirDiffEmptyDirectories = do     D.createDirectory "a"@@ -488,10 +531,6 @@     directoriesEqual <- areDirectoriesEqual "a" "b"     (@?) directoriesEqual "Directories not equal after application" -testInMemoryDirApply :: Assertion-testInMemoryDirApply = do-    0 @?= 1- -- tests  tests :: TestTree@@ -536,6 +575,9 @@     , testCase         "Testing diffing for directories"         (runTest testDirDiff)+    , testCase+        "Testing diffing for directories, with ignoring subdirs"+        (runTest testDirDiffIgnoreFiles)      -- patching     , testCase@@ -565,9 +607,6 @@     , testCase         "Testing patching directories"         (runTest testDirApply)-    --, testCase-    --    "Testin in-memory patching directories"-    --    (runTest testInMemoryDirApply)      -- alg     -- edge cases
filediff.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                filediff-version:             0.1.0.3+version:             0.1.0.4 synopsis:            Diffing and patching module description:         `filediff` is a Haskell library for creating diffs, and applying diffs to files and directories. homepage:            https://github.com/bgwines/filediff
src/Filediff.hs view
@@ -6,6 +6,7 @@ ( -- * basic operations   diffFiles , diffDirectories+, diffDirectoriesWithIgnoredSubdirs , applyToFile , applyToDirectory ) where@@ -39,8 +40,9 @@     , removeDotDirs     , createFileWithContents     , dropUntil-    , removeFirstPathComponent -    , getDirectoryContentsRecursiveSafe )+    , removeFirstPathComponent+    , getDirectoryContentsRecursiveSafe+    , isPrefix)  -- * basic operations @@ -98,13 +100,21 @@ --   parameter into the second). Throws an exception if either or both of --   the parameters point to a file, not a directory. diffDirectories :: FilePath -> FilePath -> IO Diff-diffDirectories a b = do+diffDirectories a b = diffDirectoriesWithIgnoredSubdirs a b [] []++-- | Diff two directories, ignoring some subdirectories. The first+-- `[FilePath]` parameter refers to the first `FilePath` parameter,+-- and same for the second, respectively.+diffDirectoriesWithIgnoredSubdirs :: FilePath -> FilePath -> [FilePath] -> [FilePath] -> IO Diff+diffDirectoriesWithIgnoredSubdirs a b aToIgnore bToIgnore = do     aIsFile <- D.doesFileExist a     bIsFile <- D.doesFileExist b     when (aIsFile || bIsFile) $ error $ "One or both of " ++ a ++ " and " ++ b ++ "is not a directory, but a file." -    aContents <- getDirectoryContentsRecursiveSafe a-    bContents <- getDirectoryContentsRecursiveSafe b+    aContents' <- getDirectoryContentsRecursiveSafe a+    bContents' <- getDirectoryContentsRecursiveSafe b+    let aContents = filter (not . shouldIgnore aToIgnore) aContents'+    let bContents = filter (not . shouldIgnore bToIgnore) bContents'      intersectionDiffs <- getDiffs $ intersect aContents bContents @@ -127,12 +137,14 @@         isIdentityFileDiff = (==) mempty . change          removeFirstPathComponentFromDiff :: Filediff -> Filediff-        removeFirstPathComponentFromDiff-            (Filediff base comp change) =+        removeFirstPathComponentFromDiff (Filediff base comp change) =             Filediff                 (removeFirstPathComponent base)                 (removeFirstPathComponent comp)                 change++        shouldIgnore :: [FilePath] -> FilePath -> Bool+        shouldIgnore toIgnore filepath = any (flip isPrefix $ filepath) toIgnore  -- | /O(n)/. Apply a diff to a directory or file applyToFile :: Filediff -> FilePath -> IO [Line]--EitherT Error IO ()
src/Filediff/Types.hs view
@@ -124,17 +124,17 @@                 (Filediff bBase bComp _)                 = (aBase == bBase) && (aComp == bComp) -excludeBy  :: (a -> a -> Bool) -> [a] -> [a] -> [a]-excludeBy _ [] _ = []-excludeBy f (x:xs) ys =-    if any (f x) ys-        then excludeBy f xs ys-        else x : excludeBy f xs ys+            excludeBy  :: (a -> a -> Bool) -> [a] -> [a] -> [a]+            excludeBy _ [] _ = []+            excludeBy f (x:xs) ys =+                if any (f x) ys+                    then excludeBy f xs ys+                    else x : excludeBy f xs ys -intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [(a, a)]-intersectBy f a b-    = filter (uncurry f)-    $ (\x y -> (x,y)) <$> a <*> b+            intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [(a, a)]+            intersectBy f a b+                = filter (uncurry f)+                $ (\x y -> (x,y)) <$> a <*> b  -- | Data type for a line type Line = T.Text
src/Filediff/Utils.hs view
@@ -13,6 +13,7 @@  -- * list operations , dropUntil+, isPrefix ) where  import Data.List ((\\), inits)@@ -125,3 +126,7 @@     if f x         then (x:xs)         else dropUntil f xs++-- | (intended to be used infix)+isPrefix :: (Eq a) => [a] -> [a] -> Bool+a `isPrefix` b = (==) (length a) . length . takeWhile id $ zipWith (==) a b