From d614fb1b26f83f33c0d5c1be803c447afaed5bdb Mon Sep 17 00:00:00 2001 From: sterni Date: Mon, 27 Jan 2025 03:37:51 +0100 Subject: [PATCH] =?UTF-8?q?feat(sterni/bl=C3=ABrg):=20implement=20prototyp?= =?UTF-8?q?e=20git=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Markup conversion and metadata querying beyond date is not yet implemented. Currently, plain text is rendered in a
, but without
any escaping.

Change-Id: I74cd2f8a0eab23bea00ca15232e915c0a3c74138
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13109
Reviewed-by: sterni 
Tested-by: BuildkiteCI
Autosubmit: sterni 
---
 users/sterni/blërg/blërg.bqn | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/users/sterni/blërg/blërg.bqn b/users/sterni/blërg/blërg.bqn
index 2728ffbcb..593b3e29c 100755
--- a/users/sterni/blërg/blërg.bqn
+++ b/users/sterni/blërg/blërg.bqn
@@ -14,6 +14,10 @@ MkDirP ← •file.CreateDir⍟(¬•file.Exists)
 AsciiDown ← ('A'-'a')⊸(⊢-×⟜('A'⊸≤∧≤⟜'Z'))
 Slugify ← '-'⊸⊣⍟(¬(('A'⊸≤∧'z'⊸≥)∨<⊸(⊑∊)⟜"-_0123456789"))¨ AsciiDown
 
+DropPrefix ← {𝕩(≠/⊣)𝕨↑˜≠𝕩}
+StripLeft ← ((¬ ∧`∘=)/⊢)
+StripRight ← ⌽ StripLeft⟜⌽
+
 _join ← {(∾⟜(𝕗⊸∾))´𝕩;𝕨∾𝕗∾𝕩}
 
 nl ← @+10
@@ -45,9 +49,10 @@ j ← {
   # Update README.md if dependency discovery changes
   ⟨Parse⟩ ⇐ •Import (GetEnv "BQN_LIBS") •file.At "json.bqn"
 
-  # TODO(sterni): default value
   ObjGet ⇐ (⊏⊸(⊑∘⊐) ⊑ ⊏˜⟜1)⟜<
   ObjGetPath ⇐ ObjGet˜´⟜⌽
+
+  _objGetDef ⇐ {𝕨 (⊏⊸(⊑∘⊐) ⊑ (∾⟜(⋈𝕗))∘(⊏˜⟜1)) <𝕩}
 }
 
 # (Apple) Mail Notes Backend
@@ -72,7 +77,34 @@ MailNotesBackend ← {𝕊 config:
   }
 }
 
-backends ← ⍉>⟨"mail-notes"‿mailNotesBackend⟩
+# Git Backend
+
+GitBackend ← {𝕊 config:
+  repo ← RelPath •file.At config j.ObjGet "repository"
+  path ← ∾⟜'/' '/' StripRight config "." j._ObjGetDef "path"
+
+  # We use zero separated fields when dealing with paths, so quoting is unnecessary
+  Git ← {R "git"‿"-c"‿"core.quotePath=false"‿"-C"‿repo∾𝕩}
+  rev ← Git "rev-parse"‿"HEAD"
+  # Use the author date of the latest commit on the file to establish the date
+  # of the file. The author date is easier to arbitrarily change and survives
+  # history rewrites. It could be interesting to ignore commits that touch
+  # multiple files (especially treewide ones).
+  PathDate ← {ReadPosDec Git "log"‿"--date=unix"‿"--pretty=tformat:%ad"‿"-1"‿rev‿"--"‿𝕩}
+
+  Entries ⇐ {𝕤⋄
+    blobs ← ∘‿2⥊@ SplitChar Git "ls-tree"‿"-zr"‿"--format=%(path)%x00%(objectname)"‿rev‿path
+    {𝕊 p‿b:
+      id ⇐ Slugify path DropPrefix p
+      # TODO(sterni): extract from file if possible
+      title ⇐ •file.Name p
+      time ⇐ PathDate p
+      Render ⇐ {𝕤 ⋄ {"
"∾𝕩∾"
"} Git "cat-file"‿"blob"‿b} + }˘blobs + } +} + +backends ← ⍉>⟨"mail-notes"‿mailNotesBackend, "git"‿gitBackend⟩ # Rendering