Monorepo for Tangled tangled.org
766
fork

Configure Feed

Select the types of activity you want to include in your feed.

RFC: outside knotserver itself, define custom types instead of relying on go-git #387

open opened by runxiyu.tngl.sh

Rationale#

I am not familiar with XRPC, but it appears that our XRPC responses use types from types/, which are defined in terms of the types exposed by external Go libraries such as go-git.

This makes it difficult to experiment with switching individual knot servers to different Git libraries, as any hashes/refs must be converted into types specific to go-git, thereby causing the entire protocol to be go-git-centered.

Current status#

  • hook/setup.go
    SetupRepo uses git.PlainOpen to try to open the repo.
  • appview/pages/pages.go
    RepoTagsParams uses a map keyed by plumbing.Hashs and a slice of object.Commits.
  • appview/repo/tags.go
    Repo.Tags uses a map keyed by plumbing.Hashs.
  • appview/repo/log.go
    Repo.Commit uses plumbing.IsHash.
  • appview/repo/artifact.go
    Repo.DeleteArtifact uses plumbing.NewHash.
  • appview/repo/tree.go
    Repo.Tree uses plumbing.NewHash.
  • appview/repo/archive.go
    Repo.DownloadArchive uses plumbing.ReferenceName.
  • appview/repo/repo_util.go
    uniqueEmails uses object.Commit.
  • appview/repo/index.go
    Repo.buildIndexResponse uses plumbing.NewHash.
  • appview/ingester.go
    Ingester.ingestArtifact uses plumbing.Hash.
  • appview/commitverify/verify.go
    GetVerifiedObjectCommits and ObjectCommitToNiceDiff use object.Commit.
  • appview/models/pipeline.go
    Trigger.TargetRef uses plumbing.ReferenceName.
  • appview/models/artifact.go
    Artifact uses plumbing.Hash.
  • appview/db/artifact.go
    GetArtifact uses plumbing.Hash.
  • appview/state/knotstream.go
    updateRepoLanguages uses plumbing.ReferenceName.
  • workflow/def.go
    Constraint.MatchRef uses plumbing.ReferenceName.
  • types/diff.go
    NiceDiff uses object.Signature.
  • types/repo.go
    Many types here use object.Commit.
  • types/tree.go
    LastCommitInfo uses plumbing.Hash.

These are largely trivial and could be defined ourselves. However, it may be difficult to remain compatible with the existing protocol, unless we closely match go-git's types.

Note that, in particular, go-git's plumbing.Hash is a [20]byte, which means that protocols that use it as the hash could only really support SHA-1 hashes. This may be undesirable but perhaps necessary for compatibility with existing knot servers?

Some alternative libraries use schemes such as this:

type Hash struct {
	data [maxHashSize]byte
	size int
}

Thank you for your summary! I generally agree with that we should remove the go-git dependency on xrpc types. Some notes about the list:

  • hook/ is part of knot, so we can ignore it.
  • methods like plumbing.IsHash or plumbing.NewHash seems fine as they don't receive go-git types.

I think defining our own Hash, Commit, Signature, and ReferenceName types for types/ package is good place to start.

My opinion with this topic is that we shouldn't use xrpc to get git information at first place. Appview can fetch the entire repository on refUpdate events and directly gather informations from it. But this is long term goal and considering we would need types to represent git objects on appview anyway, I think defining custom types is definitely valuable.

methods like plumbing.IsHash or plumbing.NewHash seems fine as they don't receive go-git types.

I think IsHash is probably fine (other than its lack of support for SHA-256), but NewHash produces go-git types so... not sure?

im still quite unsure about plumbing.Hash. note that go-git v6 makes plumbing.hash an alias to plumbing.ObjectID, which is:

// ObjectID represents the ID of a Git object. The object data is kept
// in its hexadecimal form.
type ObjectID struct {
	hash   [format.SHA256Size]byte
	format format.ObjectFormat
}
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:oy6bo3cgc6erpohuxwscacbp/sh.tangled.repo.issue/3m6jalc3qfe22