From ed81f16df37ac556c10cc0f2a69ecd7d57b949ca Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Fri, 18 Sep 2026 01:08:39 +0900 Subject: [PATCH] knotfeed: handle pre-1.13 knot event stream Signed-off-by: Seongmin Lee --- knotfeed/legacy.go | 11 ++++++++--- knotfeed/legacy_test.go | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/knotfeed/legacy.go b/knotfeed/legacy.go index 5ca01a501..55d708b57 100644 --- a/knotfeed/legacy.go +++ b/knotfeed/legacy.go @@ -1,6 +1,7 @@ package knotfeed import ( + "cmp" "encoding/json" "fmt" "log/slog" @@ -39,6 +40,7 @@ type legacyFrame struct { type legacyRefUpdate struct { Repo syntax.DID `json:"repo"` + LegacyRepo syntax.DID `json:"repoDid"` // knots older than 1.14 name the repo this way Ref string `json:"ref"` OldSha string `json:"oldSha"` NewSha string `json:"newSha"` @@ -82,7 +84,10 @@ func legacyRefOp(payload json.RawMessage, commit *Commit) error { } rkey, short := EscapeRefname(event.Ref) newSha, isObject := ParseObjectID(event.NewSha) - if event.Ref == "" || event.Repo == "" || !short || !isObject { + // pre-1.13 knots put the owner's did in repoDid, so this can miss on lookup; + // the event still has to flow through so the host's cursor keeps moving + repo := cmp.Or(event.Repo, event.LegacyRepo) + if event.Ref == "" || repo == "" || !short || !isObject { return nil } op := RecordOp{ @@ -95,7 +100,7 @@ func legacyRefOp(payload json.RawMessage, commit *Commit) error { // old knots leave committerDid empty; attribute those pushes to the repo itself editor, err := syntax.ParseDID(event.CommitterDid) if err != nil { - editor = event.Repo + editor = repo } record, err := encodeRefRecord(RefRecord{ Sha: newSha, @@ -108,7 +113,7 @@ func legacyRefOp(payload json.RawMessage, commit *Commit) error { op.Action, op.Bytes = tapc.RecordCreateAction, record } - commit.Repo = event.Repo + commit.Repo = repo commit.Records = []RecordOp{op} return nil } diff --git a/knotfeed/legacy_test.go b/knotfeed/legacy_test.go index e81720ddc..60cafa7ae 100644 --- a/knotfeed/legacy_test.go +++ b/knotfeed/legacy_test.go @@ -131,6 +131,19 @@ func TestLegacyFrameReadsAsCommit(t *testing.T) { RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:scallop"})}, }, }, + { + name: "push from a pre-1.14 knot, which names the repo repoDid", + frame: `{"nsid":"sh.tangled.git.refUpdate","created":11,"event":{` + + `"ref":"refs/heads/main","ownerDid":"did:plc:clam","repoDid":"did:plc:scallop",` + + `"repoName":"shell","committerDid":"did:plc:clam",` + + `"oldSha":"` + legacyOldSha + `","newSha":"` + legacyNewSha + `"}}`, + want: Commit{ + Repo: "did:plc:scallop", + Seq: 11, + Records: []RecordOp{refOp(t, "refs/heads/main", legacyOldSha, + RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:clam"})}, + }, + }, { name: "push with an empty committerDid", frame: `{"nsid":"sh.tangled.git.refUpdate","created":11,` + -- 2.51.2