From e7c09831bcfe0de1be2406ce64970fc29a4bb50c Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Tue, 11 Oct 2016 15:22:37 -0500 Subject: [PATCH 1/4] Add development mode When developing locally, especially when using break to look at structure, the timeout is too quick. Instead of manually updating the timeout to a long duration, I figure disabling it when needed in the context of ghci would be nicer. --- src/Arguments.hs | 4 ++++ src/SemanticDiff.hs | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Arguments.hs b/src/Arguments.hs index d8eabdcde..9ebe977d6 100644 --- a/src/Arguments.hs +++ b/src/Arguments.hs @@ -26,6 +26,7 @@ data CmdLineOptions = CmdLineOptions , outputFilePath :: Maybe FilePath , noIndex :: Bool , extraArgs :: [ExtraArg] + , developmentMode' :: Bool } -- | Arguments for the program (includes command line, environment, and defaults). @@ -38,6 +39,7 @@ data Arguments = Arguments , diffMode :: DiffMode , shaRange :: Both (Maybe String) , filePaths :: [FilePath] + , developmentMode :: Bool } deriving (Show) -- | Returns Arguments for the program from parsed command line arguments. @@ -62,6 +64,7 @@ programArguments CmdLineOptions{..} = do (_, _) -> CommitDiff , shaRange = fetchShas extraArgs , filePaths = filePaths + , developmentMode = developmentMode' } where fetchPaths :: [ExtraArg] -> [FilePath] @@ -85,6 +88,7 @@ args gitDir sha1 sha2 filePaths format = Arguments , diffMode = CommitDiff , shaRange = Just <$> both sha1 sha2 , filePaths = filePaths + , developmentMode = False } -- | 7 seconds diff --git a/src/SemanticDiff.hs b/src/SemanticDiff.hs index 3da4eb231..dc068b1ae 100644 --- a/src/SemanticDiff.hs +++ b/src/SemanticDiff.hs @@ -49,6 +49,7 @@ argumentsParser = info (version <*> helper <*> argumentsP) <*> optional (strOption (long "output" <> short 'o' <> help "output directory for split diffs, defaults to stdout if unspecified")) <*> switch (long "no-index" <> help "compare two paths on the filesystem") <*> some (argument (eitherReader parseShasAndFiles) (metavar "SHA_A..SHAB FILES...")) + <*> switch (long "development" <> short 'd' <> help "set development mode which prevents timeout behavior by default") where parseShasAndFiles :: String -> Either String ExtraArg parseShasAndFiles s = case matchRegex regex s of @@ -66,8 +67,12 @@ version = infoOption versionString (long "version" <> short 'V' <> help "output -- | Compare changes between two commits. diffCommits :: Arguments -> IO () diffCommits args@Arguments{..} = do - ts <- Timeout.timeout timeoutInMicroseconds (fetchDiffs args) + ts <- fetchTerms args writeToOutput output (maybe mempty R.concatOutputs ts) + where fetchTerms args = if developmentMode + then Just <$> fetchDiffs args + else Timeout.timeout timeoutInMicroseconds (fetchDiffs args) + -- | Compare two paths on the filesystem (compariable to git diff --no-index). diffPaths :: Arguments -> Both FilePath -> IO () @@ -99,14 +104,17 @@ fetchDiff' Arguments{..} filepath = do let sources = fromMaybe (Source.emptySourceBlob filepath) <$> sourcesAndOids let sourceBlobs = Source.idOrEmptySourceBlob <$> sources - let textDiff = D.textDiff (parserForFilepath filepath) diffArguments sourceBlobs - text <- liftIO $ Timeout.timeout timeoutInMicroseconds textDiff + text <- fetchText textDiff truncatedPatch <- liftIO $ D.truncatedDiff diffArguments sourceBlobs pure $ fromMaybe truncatedPatch text where diffArguments = R.DiffArguments { format = format, output = output } + fetchText textDiff = if developmentMode + then liftIO $ Timeout.timeout timeoutInMicroseconds textDiff + else liftIO $ Just <$> textDiff + pathsToDiff :: Arguments -> Both String -> IO [FilePath] pathsToDiff Arguments{..} shas = withRepository lgFactory gitDir $ do From d5d1a7fbab851f5298e3cc76690205ddd1b939c9 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Tue, 11 Oct 2016 15:33:38 -0500 Subject: [PATCH 2/4] ++javascript --- test/corpus/repos/javascript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/corpus/repos/javascript b/test/corpus/repos/javascript index 7e9421a0f..725a0ee6c 160000 --- a/test/corpus/repos/javascript +++ b/test/corpus/repos/javascript @@ -1 +1 @@ -Subproject commit 7e9421a0f261a2de196d05d153a86dc4c8340351 +Subproject commit 725a0ee6c4535512f82e53d65edf151cc8f724eb From 8e0cc3374d43536c2261116506f8997ce6cb2544 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Tue, 11 Oct 2016 16:41:53 -0500 Subject: [PATCH 3/4] ++javascript --- test/corpus/repos/javascript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/corpus/repos/javascript b/test/corpus/repos/javascript index 725a0ee6c..dce5b472e 160000 --- a/test/corpus/repos/javascript +++ b/test/corpus/repos/javascript @@ -1 +1 @@ -Subproject commit 725a0ee6c4535512f82e53d65edf151cc8f724eb +Subproject commit dce5b472e5bcc43861e65b412644c7931f12d313 From 5cfe719141f83f80a21ffb91b259ae8091876e7a Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Tue, 11 Oct 2016 17:06:51 -0500 Subject: [PATCH 4/4] Fix the order of the then else conditions --- src/SemanticDiff.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SemanticDiff.hs b/src/SemanticDiff.hs index dc068b1ae..4a33814eb 100644 --- a/src/SemanticDiff.hs +++ b/src/SemanticDiff.hs @@ -112,8 +112,8 @@ fetchDiff' Arguments{..} filepath = do where diffArguments = R.DiffArguments { format = format, output = output } fetchText textDiff = if developmentMode - then liftIO $ Timeout.timeout timeoutInMicroseconds textDiff - else liftIO $ Just <$> textDiff + then liftIO $ Just <$> textDiff + else liftIO $ Timeout.timeout timeoutInMicroseconds textDiff pathsToDiff :: Arguments -> Both String -> IO [FilePath]