1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00

output the right paths in patch

This commit is contained in:
joshvera 2016-02-10 11:32:26 -08:00
parent 44578211ff
commit e008fda7d1
5 changed files with 8 additions and 7 deletions

View File

@ -26,7 +26,8 @@ main = do
let parse = DO.parserForFilepath sourceAPath
terms <- sequence $ parse <$> sources
let replaceLeaves = DO.breakDownLeavesByWord <$> sources
let sourceBlobs = runJoin $ (\s -> SourceBlob s mempty) <$> sources
let srcs = runJoin sources
let sourceBlobs = (SourceBlob (fst srcs) mempty sourceAPath, SourceBlob (snd srcs) mempty sourceBPath)
DO.printDiff (args arguments) (uncurry diffTerms . runJoin $ replaceLeaves <*> terms) sourceBlobs
where opts = info (helper <*> arguments)
(fullDesc <> progDesc "Diff some things" <> header "semantic-diff - diff semantically")

View File

@ -43,7 +43,7 @@ main = do
let parse = DO.parserForFilepath filepath
terms <- sequence $ parse <$> sources
let replaceLeaves = DO.breakDownLeavesByWord <$> sources
let sourceBlobs = ((SourceBlob (fst $ runJoin sources) *** SourceBlob (snd $ runJoin sources)) oids)
let sourceBlobs = (SourceBlob (fst $ runJoin sources) (fst oids) filepath, SourceBlob (snd $ runJoin sources) (snd oids) filepath)
DO.printDiff (args arguments filepath) (uncurry diffTerms . runJoin $ replaceLeaves <*> terms) sourceBlobs
where opts = info (helper <*> arguments)
(fullDesc <> progDesc "Diff some things" <> header "semantic-diff - diff semantically")

View File

@ -69,7 +69,7 @@ getRange (Free (Annotated (Info range _) _)) = range
getRange (Pure (Info range _ :< _)) = range
header :: (SourceBlob, SourceBlob) -> Hunk a -> String
header blobs hunk = "diff --git a/path.txt b/path.txt\n" ++
header blobs hunk = "diff --git a/" ++ path (fst blobs) ++ " b/" ++ path (snd blobs) ++ "\n" ++
"index " ++ oid (fst blobs) ++ ".." ++ oid (snd blobs) ++ "\n" ++
"@@ -" ++ show offsetA ++ "," ++ show lengthA ++ " +" ++ show offsetB ++ "," ++ show lengthB ++ " @@\n"
where (lengthA, lengthB) = join bimap getSum $ hunkLength hunk

View File

@ -5,7 +5,7 @@ import Range
import qualified Data.Vector as Vector
import qualified Data.Text as T
data SourceBlob = SourceBlob { source :: Source Char, oid :: String }
data SourceBlob = SourceBlob { source :: Source Char, oid :: String, path :: FilePath }
-- | The contents of a source file, backed by a vector for efficient slicing.
newtype Source a = Source { getVector :: Vector.Vector a }

View File

@ -9,7 +9,7 @@ import Control.Monad.Free
import Test.Hspec
spec :: Spec
spec = parallel $ do
describe "hunks" $ do
spec = parallel $
describe "hunks" $
it "empty diffs have no hunks" $
hunks (Free . Annotated (Info (Range 0 0) mempty, Info (Range 0 0) mempty) $ Leaf "") (fromList "", fromList "") `shouldBe` []
hunks (Free . Annotated (Info (Range 0 0) mempty, Info (Range 0 0) mempty) $ Leaf "") (SourceBlob (fromList "") "abcde" "path2.txt", SourceBlob (fromList "") "xyz" "path2.txt") `shouldBe` []