From 9b14290c97df62f6e7da91c90b8bd7bb6a4bec42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 1 Nov 2026 20:36:12 +0100 Subject: =?UTF-8?q?Add=20=E2=80=98upstream=E2=80=99=20revision=20expressio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Expression.hs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/Expression.hs') 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 -- cgit v1.2.3