aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/History.hs30
-rw-r--r--app/Issue.hs14
2 files changed, 29 insertions, 15 deletions
diff --git a/app/History.hs b/app/History.hs
index c3b3699..fad911a 100644
--- a/app/History.hs
+++ b/app/History.hs
@@ -7,11 +7,11 @@ import Control.Exception (Exception, catch, handle, throw)
import Data.Aeson (eitherDecode)
import Data.ByteString.Lazy.Char8 qualified as L8
import Data.List (intercalate)
-import Data.Maybe (catMaybes)
+import Data.Maybe (catMaybes, mapMaybe)
import Data.String (fromString)
import Data.Text (Text, lines, unpack)
import Data.Text.Encoding (decodeUtf8)
-import Issue (Issue (..), fromMatch)
+import Issue (Issue (..), fromMatch, id)
import Issue.Filter (Filter, applyFilter)
import Process (quote, sh, sh_)
import System.Directory (getCurrentDirectory, setCurrentDirectory)
@@ -21,7 +21,7 @@ import System.IO.Temp (withSystemTempDirectory)
import Text.Printf (printf)
import TreeGrepper.Match qualified as G
import TreeGrepper.Result qualified as G
-import Prelude hiding (lines)
+import Prelude hiding (id, lines)
import Prelude qualified as Prelude
data UnknownFileExtension = UnknownFileExtension
@@ -41,7 +41,29 @@ instance Exception InvalidTreeGrepperResult
listIssues :: [Filter] -> [FilePath] -> IO [Issue]
listIssues filters files = do
commits <- fmap (lines . decodeUtf8 . L8.toStrict) $ sh ("git log --format=%H")
- fmap head $ mapM (\commit -> listIssuesOf commit filters files) commits
+ issueses <- mapM (\commit -> listIssuesOf commit filters files) commits
+ (currentIssues, historicalIssues) <-
+ case issueses of
+ currentIssues : historicalIssueses ->
+ pure (currentIssues, concat historicalIssueses)
+ [] ->
+ die "no commits"
+ pure (map (merge . pick historicalIssues) currentIssues)
+
+pick :: [Issue] -> Issue -> (Issue, [Issue])
+pick issues issue =
+ (issue, filter (isSameIssue) issues)
+ where
+ isSameIssue otherIssue =
+ id otherIssue == id issue
+
+merge :: (Issue, [Issue]) -> Issue
+merge (issue, issues) =
+ case (mapMaybe provenance (reverse issues)) of
+ [] ->
+ issue
+ provenance : _ ->
+ issue {provenance = Just provenance}
listIssuesOf :: Text -> [Filter] -> [FilePath] -> IO [Issue]
listIssuesOf commit filters files = do
diff --git a/app/Issue.hs b/app/Issue.hs
index fabd88f..847e014 100644
--- a/app/Issue.hs
+++ b/app/Issue.hs
@@ -54,20 +54,12 @@ id issue =
fromMatch :: G.Result -> G.Match -> IO (Maybe Issue)
fromMatch result match = do
rawProvenance <-
- fmap (map (T.splitOn "\NUL") . T.lines . decodeUtf8 . toStrict) $
+ fmap (T.splitOn "\NUL" . head . T.lines . decodeUtf8 . toStrict) $
sh $
- ( fromString
- ( printf
- "git --no-pager log --reverse -S\"$(cat %s | tail -n+%d | head -%d)\" --format='%%H%%x00%%ai%%x00%%ae%%x00%%an' -- %s"
- (quote result.file)
- match.start.row
- (match.end.row - match.start.row + 1)
- (quote result.file)
- )
- )
+ "git show --format='%H%x00%ai%x00%ae%x00%an'"
let provenance =
case rawProvenance of
- (firstCommit' : rawDate : authorEmail : authorName : _) : _ ->
+ firstCommit' : rawDate : authorEmail : authorName : _ ->
let date = read (T.unpack rawDate)
in Just
Provenance