Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

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

types,appview,knotserver: replace object.Commit with types.Commit

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
b26a5eca da28eba8

+39 -136
+6 -45
appview/commitverify/verify.go
··· 3 3 import ( 4 4 "log" 5 5 6 - "github.com/go-git/go-git/v5/plumbing/object" 7 6 "tangled.org/core/appview/db" 8 7 "tangled.org/core/appview/models" 9 8 "tangled.org/core/crypto" ··· 34 35 return "" 35 36 } 36 37 37 - func GetVerifiedObjectCommits(e db.Execer, emailToDid map[string]string, commits []*object.Commit) (VerifiedCommits, error) { 38 - ndCommits := []types.NiceDiff{} 39 - for _, commit := range commits { 40 - ndCommits = append(ndCommits, ObjectCommitToNiceDiff(commit)) 41 - } 42 - return GetVerifiedCommits(e, emailToDid, ndCommits) 43 - } 44 - 45 - func GetVerifiedCommits(e db.Execer, emailToDid map[string]string, ndCommits []types.NiceDiff) (VerifiedCommits, error) { 38 + func GetVerifiedCommits(e db.Execer, emailToDid map[string]string, ndCommits []types.Commit) (VerifiedCommits, error) { 46 39 vcs := VerifiedCommits{} 47 40 48 41 didPubkeyCache := make(map[string][]models.PublicKey) 49 42 50 43 for _, commit := range ndCommits { 51 - c := commit.Commit 52 - 53 - committerEmail := c.Committer.Email 44 + committerEmail := commit.Committer.Email 54 45 if did, exists := emailToDid[committerEmail]; exists { 55 46 // check if we've already fetched public keys for this did 56 47 pubKeys, ok := didPubkeyCache[did] ··· 56 67 } 57 68 58 69 // try to verify with any associated pubkeys 70 + payload := commit.Payload() 71 + signature := commit.PGPSignature 59 72 for _, pk := range pubKeys { 60 - if _, ok := crypto.VerifyCommitSignature(pk.Key, commit); ok { 73 + if _, ok := crypto.VerifySignature([]byte(pk.Key), []byte(signature), []byte(payload)); ok { 61 74 62 75 fp, err := crypto.SSHFingerprint(pk.Key) 63 76 if err != nil { 64 77 log.Println("error computing ssh fingerprint:", err) 65 78 } 66 79 67 - vc := verifiedCommit{fingerprint: fp, hash: c.This} 80 + vc := verifiedCommit{fingerprint: fp, hash: commit.This} 68 81 vcs[vc] = struct{}{} 69 82 break 70 83 } ··· 76 85 } 77 86 78 87 return vcs, nil 79 - } 80 - 81 - // ObjectCommitToNiceDiff is a compatibility function to convert a 82 - // commit object into a NiceDiff structure. 83 - func ObjectCommitToNiceDiff(c *object.Commit) types.NiceDiff { 84 - var niceDiff types.NiceDiff 85 - 86 - // set commit information 87 - niceDiff.Commit.Message = c.Message 88 - niceDiff.Commit.Author = c.Author 89 - niceDiff.Commit.This = c.Hash.String() 90 - niceDiff.Commit.Committer = c.Committer 91 - niceDiff.Commit.Tree = c.TreeHash.String() 92 - niceDiff.Commit.PGPSignature = c.PGPSignature 93 - 94 - changeId, ok := c.ExtraHeaders["change-id"] 95 - if ok { 96 - niceDiff.Commit.ChangedId = string(changeId) 97 - } 98 - 99 - // set parent hash if available 100 - if len(c.ParentHashes) > 0 { 101 - niceDiff.Commit.Parent = c.ParentHashes[0].String() 102 - } 103 - 104 - // XXX: Stats and Diff fields are typically populated 105 - // after fetching the actual diff information, which isn't 106 - // directly available in the commit object itself. 107 - 108 - return niceDiff 109 88 }
+1 -2
appview/pages/pages.go
··· 31 31 "github.com/bluesky-social/indigo/atproto/identity" 32 32 "github.com/bluesky-social/indigo/atproto/syntax" 33 33 "github.com/go-git/go-git/v5/plumbing" 34 - "github.com/go-git/go-git/v5/plumbing/object" 35 34 ) 36 35 37 36 //go:embed templates/* static legal ··· 648 649 RepoInfo repoinfo.RepoInfo 649 650 Active string 650 651 TagMap map[string][]string 651 - CommitsTrunc []*object.Commit 652 + CommitsTrunc []types.Commit 652 653 TagsTrunc []*types.TagReference 653 654 BranchesTrunc []types.Branch 654 655 // ForkInfo *types.ForkInfo
+1 -1
appview/pages/templates/repo/commit.html
··· 35 35 {{ end }} 36 36 37 37 <span class="px-1 select-none before:content-['\00B7']"></span> 38 - {{ template "repo/fragments/time" $commit.Author.When }} 38 + {{ template "repo/fragments/time" $commit.Committer.When }} 39 39 <span class="px-1 select-none before:content-['\00B7']"></span> 40 40 41 41 <a href="/{{ $repo }}/commit/{{ $commit.This }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.This 0 8 }}</a>
+1 -1
appview/repo/index.go
··· 122 122 l.Error("failed to get email to did map", "err", err) 123 123 } 124 124 125 - vc, err := commitverify.GetVerifiedObjectCommits(rp.db, emailToDidMap, commitsTrunc) 125 + vc, err := commitverify.GetVerifiedCommits(rp.db, emailToDidMap, commitsTrunc) 126 126 if err != nil { 127 127 l.Error("failed to GetVerifiedObjectCommits", "err", err) 128 128 }
+2 -2
appview/repo/log.go
··· 116 116 l.Error("failed to fetch email to did mapping", "err", err) 117 117 } 118 118 119 - vc, err := commitverify.GetVerifiedObjectCommits(rp.db, emailToDidMap, xrpcResp.Commits) 119 + vc, err := commitverify.GetVerifiedCommits(rp.db, emailToDidMap, xrpcResp.Commits) 120 120 if err != nil { 121 121 l.Error("failed to GetVerifiedObjectCommits", "err", err) 122 122 } ··· 192 192 l.Error("failed to get email to did mapping", "err", err) 193 193 } 194 194 195 - vc, err := commitverify.GetVerifiedCommits(rp.db, emailToDidMap, []types.NiceDiff{*result.Diff}) 195 + vc, err := commitverify.GetVerifiedCommits(rp.db, emailToDidMap, []types.Commit{result.Diff.Commit}) 196 196 if err != nil { 197 197 l.Error("failed to GetVerifiedCommits", "err", err) 198 198 }
+1 -3
appview/repo/repo_util.go
··· 8 8 "tangled.org/core/appview/db" 9 9 "tangled.org/core/appview/models" 10 10 "tangled.org/core/types" 11 - 12 - "github.com/go-git/go-git/v5/plumbing/object" 13 11 ) 14 12 15 13 func sortFiles(files []types.NiceTree) { ··· 40 42 }) 41 43 } 42 44 43 - func uniqueEmails(commits []*object.Commit) []string { 45 + func uniqueEmails(commits []types.Commit) []string { 44 46 emails := make(map[string]struct{}) 45 47 for _, commit := range commits { 46 48 if commit.Author.Email != "" {
+1 -34
crypto/verify.go
··· 5 5 "crypto/sha256" 6 6 "encoding/base64" 7 7 "fmt" 8 - "strings" 9 8 10 9 "github.com/hiddeco/sshsig" 11 10 "golang.org/x/crypto/ssh" 12 - "tangled.org/core/types" 13 11 ) 14 12 15 13 func VerifySignature(pubKey, signature, payload []byte) (error, bool) { ··· 26 28 // multiple algorithms but sha-512 is most secure, and git's ssh signing defaults 27 29 // to sha-512 for all key types anyway. 28 30 err = sshsig.Verify(buf, sig, pub, sshsig.HashSHA512, "git") 31 + 29 32 return err, err == nil 30 - } 31 - 32 - // VerifyCommitSignature reconstructs the payload used to sign a commit. This is 33 - // essentially the git cat-file output but without the gpgsig header. 34 - // 35 - // Caveats: signature verification will fail on commits with more than one parent, 36 - // i.e. merge commits, because types.NiceDiff doesn't carry more than one Parent field 37 - // and we are unable to reconstruct the payload correctly. 38 - // 39 - // Ideally this should directly operate on an *object.Commit. 40 - func VerifyCommitSignature(pubKey string, commit types.NiceDiff) (error, bool) { 41 - signature := commit.Commit.PGPSignature 42 - 43 - author := bytes.NewBuffer([]byte{}) 44 - committer := bytes.NewBuffer([]byte{}) 45 - commit.Commit.Author.Encode(author) 46 - commit.Commit.Committer.Encode(committer) 47 - 48 - payload := strings.Builder{} 49 - 50 - fmt.Fprintf(&payload, "tree %s\n", commit.Commit.Tree) 51 - if commit.Commit.Parent != "" { 52 - fmt.Fprintf(&payload, "parent %s\n", commit.Commit.Parent) 53 - } 54 - fmt.Fprintf(&payload, "author %s\n", author.String()) 55 - fmt.Fprintf(&payload, "committer %s\n", committer.String()) 56 - if commit.Commit.ChangedId != "" { 57 - fmt.Fprintf(&payload, "change-id %s\n", commit.Commit.ChangedId) 58 - } 59 - fmt.Fprintf(&payload, "\n%s", commit.Commit.Message) 60 - 61 - return VerifySignature([]byte(pubKey), []byte(signature), []byte(payload.String())) 62 33 } 63 34 64 35 // SSHFingerprint computes the fingerprint of the supplied ssh pubkey.
+1 -17
knotserver/git/diff.go
··· 77 77 nd.Diff = append(nd.Diff, ndiff) 78 78 } 79 79 80 - nd.Stat.FilesChanged = len(diffs) 81 - nd.Commit.This = c.Hash.String() 82 - nd.Commit.PGPSignature = c.PGPSignature 83 - nd.Commit.Committer = c.Committer 84 - nd.Commit.Tree = c.TreeHash.String() 85 - 86 - if parent.Hash.IsZero() { 87 - nd.Commit.Parent = "" 88 - } else { 89 - nd.Commit.Parent = parent.Hash.String() 90 - } 91 - nd.Commit.Author = c.Author 92 - nd.Commit.Message = c.Message 93 - 94 - if v, ok := c.ExtraHeaders["change-id"]; ok { 95 - nd.Commit.ChangedId = string(v) 96 - } 80 + nd.Commit.FromGoGitCommit(c) 97 81 98 82 return &nd, nil 99 83 }
+6 -1
knotserver/xrpc/repo_log.go
··· 62 62 return 63 63 } 64 64 65 + tcommits := make([]types.Commit, len(commits)) 66 + for i, c := range commits { 67 + tcommits[i].FromGoGitCommit(c) 68 + } 69 + 65 70 // Create response using existing types.RepoLogResponse 66 71 response := types.RepoLogResponse{ 67 - Commits: commits, 72 + Commits: tcommits, 68 73 Ref: ref, 69 74 Page: (offset / limit) + 1, 70 75 PerPage: limit,
-1
patchutil/patchutil.go
··· 296 296 } 297 297 298 298 nd := types.NiceDiff{} 299 - nd.Commit.Parent = targetBranch 300 299 301 300 for _, d := range diffs { 302 301 ndiff := types.Diff{}
+2 -12
types/diff.go
··· 2 2 3 3 import ( 4 4 "github.com/bluekeyes/go-gitdiff/gitdiff" 5 - "github.com/go-git/go-git/v5/plumbing/object" 6 5 ) 7 6 8 7 type DiffOpts struct { ··· 42 43 43 44 // A nicer git diff representation. 44 45 type NiceDiff struct { 45 - Commit struct { 46 - Message string `json:"message"` 47 - Author object.Signature `json:"author"` 48 - This string `json:"this"` 49 - Parent string `json:"parent"` 50 - PGPSignature string `json:"pgp_signature"` 51 - Committer object.Signature `json:"committer"` 52 - Tree string `json:"tree"` 53 - ChangedId string `json:"change_id"` 54 - } `json:"commit"` 55 - Stat struct { 46 + Commit Commit `json:"commit"` 47 + Stat struct { 56 48 FilesChanged int `json:"files_changed"` 57 49 Insertions int `json:"insertions"` 58 50 Deletions int `json:"deletions"`
+17 -17
types/repo.go
··· 8 8 ) 9 9 10 10 type RepoIndexResponse struct { 11 - IsEmpty bool `json:"is_empty"` 12 - Ref string `json:"ref,omitempty"` 13 - Readme string `json:"readme,omitempty"` 14 - ReadmeFileName string `json:"readme_file_name,omitempty"` 15 - Commits []*object.Commit `json:"commits,omitempty"` 16 - Description string `json:"description,omitempty"` 17 - Files []NiceTree `json:"files,omitempty"` 18 - Branches []Branch `json:"branches,omitempty"` 19 - Tags []*TagReference `json:"tags,omitempty"` 20 - TotalCommits int `json:"total_commits,omitempty"` 11 + IsEmpty bool `json:"is_empty"` 12 + Ref string `json:"ref,omitempty"` 13 + Readme string `json:"readme,omitempty"` 14 + ReadmeFileName string `json:"readme_file_name,omitempty"` 15 + Commits []Commit `json:"commits,omitempty"` 16 + Description string `json:"description,omitempty"` 17 + Files []NiceTree `json:"files,omitempty"` 18 + Branches []Branch `json:"branches,omitempty"` 19 + Tags []*TagReference `json:"tags,omitempty"` 20 + TotalCommits int `json:"total_commits,omitempty"` 21 21 } 22 22 23 23 type RepoLogResponse struct { 24 - Commits []*object.Commit `json:"commits,omitempty"` 25 - Ref string `json:"ref,omitempty"` 26 - Description string `json:"description,omitempty"` 27 - Log bool `json:"log,omitempty"` 28 - Total int `json:"total,omitempty"` 29 - Page int `json:"page,omitempty"` 30 - PerPage int `json:"per_page,omitempty"` 24 + Commits []Commit `json:"commits,omitempty"` 25 + Ref string `json:"ref,omitempty"` 26 + Description string `json:"description,omitempty"` 27 + Log bool `json:"log,omitempty"` 28 + Total int `json:"total,omitempty"` 29 + Page int `json:"page,omitempty"` 30 + PerPage int `json:"per_page,omitempty"` 31 31 } 32 32 33 33 type RepoCommitResponse struct {