mirror of
https://github.com/github/semantic.git
synced 2024-11-29 02:44:36 +03:00
Merge pull request #872 from github/development-mode
Add development mode
This commit is contained in:
commit
2e6ca19522
@ -26,6 +26,7 @@ data CmdLineOptions = CmdLineOptions
|
|||||||
, outputFilePath :: Maybe FilePath
|
, outputFilePath :: Maybe FilePath
|
||||||
, noIndex :: Bool
|
, noIndex :: Bool
|
||||||
, extraArgs :: [ExtraArg]
|
, extraArgs :: [ExtraArg]
|
||||||
|
, developmentMode' :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Arguments for the program (includes command line, environment, and defaults).
|
-- | Arguments for the program (includes command line, environment, and defaults).
|
||||||
@ -38,6 +39,7 @@ data Arguments = Arguments
|
|||||||
, diffMode :: DiffMode
|
, diffMode :: DiffMode
|
||||||
, shaRange :: Both (Maybe String)
|
, shaRange :: Both (Maybe String)
|
||||||
, filePaths :: [FilePath]
|
, filePaths :: [FilePath]
|
||||||
|
, developmentMode :: Bool
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
-- | Returns Arguments for the program from parsed command line arguments.
|
-- | Returns Arguments for the program from parsed command line arguments.
|
||||||
@ -62,6 +64,7 @@ programArguments CmdLineOptions{..} = do
|
|||||||
(_, _) -> CommitDiff
|
(_, _) -> CommitDiff
|
||||||
, shaRange = fetchShas extraArgs
|
, shaRange = fetchShas extraArgs
|
||||||
, filePaths = filePaths
|
, filePaths = filePaths
|
||||||
|
, developmentMode = developmentMode'
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
fetchPaths :: [ExtraArg] -> [FilePath]
|
fetchPaths :: [ExtraArg] -> [FilePath]
|
||||||
@ -85,6 +88,7 @@ args gitDir sha1 sha2 filePaths format = Arguments
|
|||||||
, diffMode = CommitDiff
|
, diffMode = CommitDiff
|
||||||
, shaRange = Just <$> both sha1 sha2
|
, shaRange = Just <$> both sha1 sha2
|
||||||
, filePaths = filePaths
|
, filePaths = filePaths
|
||||||
|
, developmentMode = False
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | 7 seconds
|
-- | 7 seconds
|
||||||
|
@ -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"))
|
<*> 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")
|
<*> switch (long "no-index" <> help "compare two paths on the filesystem")
|
||||||
<*> some (argument (eitherReader parseShasAndFiles) (metavar "SHA_A..SHAB FILES..."))
|
<*> 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
|
where
|
||||||
parseShasAndFiles :: String -> Either String ExtraArg
|
parseShasAndFiles :: String -> Either String ExtraArg
|
||||||
parseShasAndFiles s = case matchRegex regex s of
|
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.
|
-- | Compare changes between two commits.
|
||||||
diffCommits :: Arguments -> IO ()
|
diffCommits :: Arguments -> IO ()
|
||||||
diffCommits args@Arguments{..} = do
|
diffCommits args@Arguments{..} = do
|
||||||
ts <- Timeout.timeout timeoutInMicroseconds (fetchDiffs args)
|
ts <- fetchTerms args
|
||||||
writeToOutput output (maybe mempty R.concatOutputs ts)
|
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).
|
-- | Compare two paths on the filesystem (compariable to git diff --no-index).
|
||||||
diffPaths :: Arguments -> Both FilePath -> IO ()
|
diffPaths :: Arguments -> Both FilePath -> IO ()
|
||||||
@ -99,14 +104,17 @@ fetchDiff' Arguments{..} filepath = do
|
|||||||
|
|
||||||
let sources = fromMaybe (Source.emptySourceBlob filepath) <$> sourcesAndOids
|
let sources = fromMaybe (Source.emptySourceBlob filepath) <$> sourcesAndOids
|
||||||
let sourceBlobs = Source.idOrEmptySourceBlob <$> sources
|
let sourceBlobs = Source.idOrEmptySourceBlob <$> sources
|
||||||
|
|
||||||
let textDiff = D.textDiff (parserForFilepath filepath) diffArguments sourceBlobs
|
let textDiff = D.textDiff (parserForFilepath filepath) diffArguments sourceBlobs
|
||||||
text <- liftIO $ Timeout.timeout timeoutInMicroseconds textDiff
|
|
||||||
|
|
||||||
|
text <- fetchText textDiff
|
||||||
truncatedPatch <- liftIO $ D.truncatedDiff diffArguments sourceBlobs
|
truncatedPatch <- liftIO $ D.truncatedDiff diffArguments sourceBlobs
|
||||||
pure $ fromMaybe truncatedPatch text
|
pure $ fromMaybe truncatedPatch text
|
||||||
where
|
where
|
||||||
diffArguments = R.DiffArguments { format = format, output = output }
|
diffArguments = R.DiffArguments { format = format, output = output }
|
||||||
|
fetchText textDiff = if developmentMode
|
||||||
|
then liftIO $ Just <$> textDiff
|
||||||
|
else liftIO $ Timeout.timeout timeoutInMicroseconds textDiff
|
||||||
|
|
||||||
|
|
||||||
pathsToDiff :: Arguments -> Both String -> IO [FilePath]
|
pathsToDiff :: Arguments -> Both String -> IO [FilePath]
|
||||||
pathsToDiff Arguments{..} shas = withRepository lgFactory gitDir $ do
|
pathsToDiff Arguments{..} shas = withRepository lgFactory gitDir $ do
|
||||||
|
Loading…
Reference in New Issue
Block a user