summaryrefslogtreecommitdiff
path: root/src/Expression.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-11-01 20:36:12 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2026-11-04 20:56:18 +0100
commit9b14290c97df62f6e7da91c90b8bd7bb6a4bec42 (patch)
tree3c7541850da68ae9022706137b44cf1a67e0ad6b /src/Expression.hs
parent663a4fda12ab008a052c459902436d80c090fc4c (diff)
Add ‘upstream’ revision expression
Diffstat (limited to 'src/Expression.hs')
-rw-r--r--src/Expression.hs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/Expression.hs b/src/Expression.hs
index 49fb4c1..29b6ea0 100644
--- a/src/Expression.hs
+++ b/src/Expression.hs
@@ -47,6 +47,7 @@ import Repo
data DeclaredRef
= TextRef Text
+ | UpstreamRef Text
| TagRef Pattern (Tag Commit -> Tag Commit -> Tag Commit)
type family StaticRef' d :: Type where
@@ -131,6 +132,10 @@ textCommitRef (CommitRef suffix cid) = textCommitId cid <> suffix
evaluateDeclaredRevision :: (MonadIO m, MonadFail m, MonadOutput m) => Repo -> DeclaredRevisionExpression -> m RevisionExpression
evaluateDeclaredRevision repo = \case
StaticRef (TextRef ref) -> StaticRef <$> readCommit repo ref
+ StaticRef (UpstreamRef ref) ->
+ findUpstreamRef repo ref >>= \case
+ Just uref -> evaluateDeclaredRevision repo $ StaticRef (TextRef uref)
+ Nothing -> fail $ "no upstream ref found for ‘" <> T.unpack ref <> "’ in ‘" <> show repo <> "’"
StaticRef (TagRef pat sel) -> do
filter (Glob.match pat . T.unpack . tagTag) <$> listTags repo >>= \case
[] -> fail $ "no tag matching " <> show (decompile pat) <> " found"
@@ -145,6 +150,11 @@ evaluateDeclaredRevision repo = \case
Left commit -> do
return $ StaticRef commit
+ WatchedRef (UpstreamRef ref) ->
+ findUpstreamRef repo ref >>= \case
+ Just uref -> evaluateDeclaredRevision repo $ WatchedRef (TextRef uref)
+ Nothing -> fail $ "no upstream ref found for ‘" <> T.unpack ref <> "’ in ‘" <> show repo <> "’"
+
WatchedRef (TagRef wtPattern wtUpdate) -> do
wtChan <- watchTags repo
value <- filter (Glob.match wtPattern . T.unpack . tagTag) <$> listTags repo >>= \case
@@ -278,13 +288,17 @@ parseRangeExpression = bimap errorBundlePretty id . runParser parser ""
return range
]
- parseRevision :: ExprParser DeclaredRangeExpression
- parseRevision = do
- tok <- fmap T.concat $ some $ choice
+ parseTextRef :: ExprParser Text
+ parseTextRef = do
+ fmap T.concat $ some $ choice
[ takeWhile1P Nothing (\x -> isAlphaNum x || x `elem` [ '_', '-', '/' ])
, try $ string "." <* notFollowedBy (char '.')
]
+ parseRevision :: ExprParser DeclaredRangeExpression
+ parseRevision = do
+ tok <- parseTextRef
+
range <- choice
[ between (char '(') (char ')') $ do
case tok of
@@ -300,6 +314,9 @@ parseRangeExpression = bimap errorBundlePretty id . runParser parser ""
"lasttag" -> do
pat <- parseTagPattern
return $ SingleRevisionExpression $ StaticRef $ TagRef pat laterTag
+ "upstream" -> do
+ ref <- parseTextRef
+ return $ SingleRevisionExpression $ StaticRef $ UpstreamRef ref
_ -> unexpected $ Tokens $ NE.fromList $ chunkToTokens @Text Proxy tok
, do