packages feed

nix-diff 1.0.19 → 1.0.20

raw patch · 9 files changed

+73/−41 lines, 9 filesdep ~bytestringdep ~containersdep ~mtl

Dependency ranges changed: bytestring, containers, mtl, optparse-applicative, tasty, text, typed-process, unix, vector

Files

CHANGELOG.md view
@@ -1,3 +1,10 @@+1.0.20++* [Add `--context` flag](https://github.com/Gabriella439/nix-diff/pull/81)+  * This limits the context to the specified number of characters/words/lines+* [Bump upper bounds](https://github.com/Gabriella439/nix-diff/pull/79)+  * Allow `unix-2.8` and few more+ 1.0.19  * [New Haskell API](https://github.com/Gabriella439/nix-diff/pull/60)
README.md view
@@ -1,5 +1,9 @@ # `nix-diff` +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Gabriella439/nix-diff/ci.yaml?branch=main)](https://github.com/Gabriella439/nix-diff/actions/workflows/ci.yaml)+[![Hackage version](https://img.shields.io/hackage/v/nix-diff.svg?color=success)](https://hackage.haskell.org/package/nix-diff)+[![Dependencies](https://img.shields.io/hackage-deps/v/nix-diff?label=Dependencies)](https://packdeps.haskellers.com/feed?needle=nix-diff)+ This package provides a `nix-diff` executable which explains why two Nix derivations differ.  The most common use cases for this are: @@ -90,8 +94,6 @@ You need to have nix installed in your PC.  ## Development status--[![Build Status](https://travis-ci.org/Gabriella439/nix-diff.png)](https://travis-ci.org/Gabriella439/nix-diff)  I don't currently plan to add any new features, but I do welcome feature requests.  Just open an issue on the issue tracker if you would like to request
app/Main.hs view
@@ -10,20 +10,21 @@  module Main where -import Control.Applicative ((<|>))+import Control.Applicative ((<|>), optional) import Data.Text (Text) import Options.Applicative (Parser, ParserInfo)+import Numeric.Natural (Natural)  import qualified Control.Monad.Reader import qualified Control.Monad.State+import qualified Data.Aeson+import qualified Data.ByteString.Lazy.Char8 import qualified Data.Set+import qualified Data.Text.IO as Text.IO import qualified GHC.IO.Encoding import qualified Options.Applicative import qualified System.Posix.IO import qualified System.Posix.Terminal-import qualified Data.Aeson-import qualified Data.ByteString.Lazy.Char8-import qualified Data.Text.IO as Text.IO  import Nix.Diff import Nix.Diff.Types@@ -71,6 +72,14 @@             <>  Options.Applicative.help ("Display textual differences on a per-" <> x <> " basis")             ) +parseContext :: Parser Natural+parseContext =+    Options.Applicative.option+        Options.Applicative.auto+        (   Options.Applicative.long "context"+        <>  Options.Applicative.help "Limit context to N lines/words/characters (depending on mode)"+        )+ parseEnvironment :: Parser Bool parseEnvironment =     Options.Applicative.switch@@ -115,17 +124,19 @@     , environment      :: Bool     , renderRunner     :: RenderRunner     , transformOptions :: TransformOptions+    , context          :: Maybe Natural     }  parseOptions :: Parser Options parseOptions = do-    left        <- parseLeft-    right       <- parseRight-    color       <- parseColor-    orientation <- parseLineOriented-    environment <- parseEnvironment-    renderRunner <- parseRenderRunner+    left             <- parseLeft+    right            <- parseRight+    color            <- parseColor+    orientation      <- parseLineOriented+    environment      <- parseEnvironment+    renderRunner     <- parseRenderRunner     transformOptions <- parseTransformOptions+    context          <- optional parseContext      return (Options { .. })   where
nix-diff.cabal view
@@ -1,5 +1,5 @@ name:                nix-diff-version:             1.0.19+version:             1.0.20 synopsis:            Explain why two Nix derivations differ description:         This package provides a @nix-diff@ executable which                      explains why two Nix derivations (i.e. @*.drv@ files)@@ -12,7 +12,7 @@ copyright:           2017 Gabriella Gonzalez category:            System build-type:          Simple-tested-with:         GHC == 8.0.2, GHC == 8.2.2, GHC == 8.8.3+tested-with:         GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.5, GHC == 9.4.4 cabal-version:       >= 1.10 extra-source-files:  README.md                      CHANGELOG.md@@ -26,15 +26,15 @@   build-depends:       base                 >= 4.9      && < 5                      , attoparsec           >= 0.13     && < 0.15                      , aeson-                     , bytestring           >= 0.9      && < 0.12-                     , containers           >= 0.5      && < 0.7+                     , bytestring           >= 0.9      && < 0.13+                     , containers           >= 0.5      && < 0.8                      , directory                           < 1.4-                     , mtl                  >= 2.2      && < 2.3+                     , mtl                  >= 2.2      && < 2.4                      , nix-derivation       >= 1.1      && < 1.2-                     , optparse-applicative >= 0.14.0.0 && < 0.18+                     , optparse-applicative >= 0.14.0.0 && < 0.19                      , patience             >= 0.3      && < 0.4-                     , text                 >= 1.2      && < 1.3-                     , vector               >= 0.12     && < 0.13+                     , text                 >= 1.2      && < 2.2+                     , vector               >= 0.12     && < 0.14                      , process                             < 1.7                      , filepath                            < 1.5                      , QuickCheck                          < 2.15@@ -52,9 +52,9 @@                      , nix-diff                      , aeson                      , bytestring-                     , optparse-applicative >= 0.14.0.0 && < 0.17+                     , optparse-applicative >= 0.14.0.0 && < 0.18                      , text-                     , unix                                < 2.8+                     , unix                                < 2.9                      , containers                      , mtl   hs-source-dirs:      app@@ -78,8 +78,8 @@                      , text                      , containers                      , mtl-                     , typed-process     < 0.2.11-                     , tasty             < 1.5+                     , typed-process     < 0.2.12+                     , tasty             < 1.6                      , tasty-quickcheck  < 0.11                      , tasty-silver      < 3.4 
src/Nix/Diff.hs view
@@ -179,9 +179,7 @@         let (fs, rest) = goNews xs          in Patience.New (x : fs) : go rest       Patience.Both x y : xs ->-        let (fs, rest) = goBoth xs-            (fxs, fys) = unzip fs-         in Patience.Both (x : fxs) (y : fys) : go rest+        Patience.Both [x] [y] : go xs       [] -> []      goOlds = \case@@ -194,12 +192,6 @@       Patience.New x : xs ->         let (fs, rest) = goNews xs          in (x : fs, rest)-      xs -> ([], xs)--    goBoth = \case-      Patience.Both x y : xs ->-        let (fs, rest) = goBoth xs-         in ((x, y) : fs, rest)       xs -> ([], xs)  -- | Diff two outputs
src/Nix/Diff/Render/HumanReadable.hs view
@@ -35,6 +35,7 @@   { orientation :: Orientation   , tty         :: TTY   , indent      :: Natural+  , context     :: Maybe Natural   }  newtype Render a = Render { unRender :: ReaderT RenderContext (Writer Text) a}@@ -253,7 +254,7 @@      renderText :: TextDiff -> Render Text     renderText (TextDiff chunks) = do-      RenderContext{ indent, orientation, tty } <- ask+      RenderContext{ indent, orientation, tty, context } <- ask        let n = fromIntegral indent @@ -276,6 +277,25 @@           renderChunk (Patience.Both l _) =               grey            orientation tty l -      return (format (Text.concat (fmap renderChunk chunks)))+      let windowedChunks = case context of+              Nothing -> chunks+              Just m  -> fmap middle (filter predicate (zippers chunks))+                where+                  notBoth (Patience.Both _ _) = False+                  notBoth  _                  = True +                  nat = fromIntegral m++                  predicate (before, line, after) =+                      any notBoth (line : take nat before ++ take nat after)++                  middle (_, line, _) = line+      return (format (Text.concat (fmap renderChunk windowedChunks)))+     ifExist m l = maybe (pure ()) l m++zippers :: [a] -> [([a], a, [a])]+zippers = go []+  where+    go _           []  = []+    go prefix (x : xs) = (prefix, x, xs) : go (x : prefix) xs
src/Nix/Diff/Types.hs view
@@ -6,10 +6,10 @@ {-# LANGUAGE DeriveTraversable     #-} {-# LANGUAGE BlockArguments        #-} {-# LANGUAGE DerivingVia           #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE StandaloneDeriving #-}-{-# LANGUAGE FlexibleInstances #-}-{-# OPTIONS_GHC -Wno-orphans #-}+{-# LANGUAGE DeriveDataTypeable    #-}+{-# LANGUAGE StandaloneDeriving    #-}+{-# LANGUAGE FlexibleInstances     #-}+{-# OPTIONS_GHC -Wno-orphans -fconstraint-solver-iterations=0 #-}  module Nix.Diff.Types where 
test/Golden/Tests.hs view
@@ -36,7 +36,7 @@   where     toJson drv = (<> "\n") . decodeUtf8 . BS.toStrict $ (Data.Aeson.encode drv) -    humanReadable_words = toHumanReadable (renderContext Word)+    humanReadable_words = toHumanReadable (renderContext Word Nothing)     toHumanReadable ctx drv = runRender' (renderDiffHumanReadable drv) ctx      simple_env_words = mkDTSimple (diffContextEnv Word)
test/Golden/Utils.hs view
@@ -44,7 +44,7 @@ nixInstantiate fp = shell ("nix-instantiate " <> fp)  nixPathInfo :: FilePath -> ProcessConfig () () ()-nixPathInfo fp = shell ("nix path-info --experimental-features 'nix-command flakes' --derivation " <> fp)+nixPathInfo fp = shell ("nix path-info --experimental-features 'nix-command flakes' --derivation " <> fp <> "#packages.x86_64-linux.default")  makeDiffTree :: TestableDerivations -> DiffContext -> IO DerivationDiff makeDiffTree TestableDerivations{..} diffContext = do