Fast implementation of Git in pure Go codeberg.org/lindenii/furgit
git go
6
fork

Configure Feed

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

commitquery: Error handling cleanup after the fetcher port

Still a few weird parts, but I forgot what those helpers were for,
and the semantics were a bit awkward... will check later™

Runxi Yu 3ce59c32 23224b23

+12 -55
+6 -23
commitquery/query_load_by_oid.go
··· 3 3 import ( 4 4 stderrors "errors" 5 5 6 - giterrors "codeberg.org/lindenii/furgit/errors" 7 6 commitgraphread "codeberg.org/lindenii/furgit/format/commitgraph/read" 8 - "codeberg.org/lindenii/furgit/object/commit" 9 - objectstore "codeberg.org/lindenii/furgit/object/store" 10 - objecttype "codeberg.org/lindenii/furgit/object/type" 11 7 ) 12 8 13 9 // loadByOID populates one node from an object ID. ··· 25 21 } 26 22 } 27 23 28 - obj, err := query.fetcher.ExactObject(id) 24 + commit, err := query.fetcher.ExactCommit(id) 29 25 if err != nil { 30 - if stderrors.Is(err, objectstore.ErrObjectNotFound) { 31 - return &giterrors.ObjectMissingError{OID: id} 32 - } 33 - 34 26 return err 35 27 } 36 28 37 - commitObj, ok := obj.Object().(*commit.Commit) 38 - if !ok { 39 - return &giterrors.ObjectTypeError{ 40 - OID: id, 41 - Got: obj.Object().ObjectType(), 42 - Want: objecttype.TypeCommit, 43 - } 44 - } 45 - 46 - parents := make([]parentRef, 0, len(commitObj.Parents)) 47 - for _, parentID := range commitObj.Parents { 29 + parents := make([]parentRef, 0, len(commit.Object().Parents)) 30 + for _, parentID := range commit.Object().Parents { 48 31 parents = append(parents, parentRef{ID: parentID}) 49 32 } 50 33 51 - commit := commitData{ 34 + commitData := commitData{ 52 35 ID: id, 53 36 Parents: parents, 54 - CommitTime: commitObj.Committer.WhenUnix, 37 + CommitTime: commit.Object().Committer.WhenUnix, 55 38 } 56 39 57 - return query.populateNode(idx, commit) 40 + return query.populateNode(idx, commitData) 58 41 }
+6 -32
commitquery/query_resolve_commitish.go
··· 1 1 package commitquery 2 2 3 - import ( 4 - stderrors "errors" 5 - 6 - giterrors "codeberg.org/lindenii/furgit/errors" 7 - "codeberg.org/lindenii/furgit/object/commit" 8 - objectid "codeberg.org/lindenii/furgit/object/id" 9 - objectstore "codeberg.org/lindenii/furgit/object/store" 10 - "codeberg.org/lindenii/furgit/object/tag" 11 - objecttype "codeberg.org/lindenii/furgit/object/type" 12 - ) 3 + import objectid "codeberg.org/lindenii/furgit/object/id" 13 4 14 5 // resolveCommitish peels one commit-ish object ID and resolves the commit. 15 6 func (query *query) resolveCommitish(id objectid.ObjectID) (nodeIndex, error) { 16 - for { 17 - obj, err := query.fetcher.ExactObject(id) 18 - if err != nil { 19 - if stderrors.Is(err, objectstore.ErrObjectNotFound) { 20 - return 0, &giterrors.ObjectMissingError{OID: id} 21 - } 22 - 23 - return 0, err 24 - } 7 + id, err := query.fetcher.PeelToCommitID(id) 8 + if err != nil { 9 + return 0, err 10 + } 25 11 26 - switch parsed := obj.Object().(type) { 27 - case *commit.Commit: 28 - return query.resolveOID(id) 29 - case *tag.Tag: 30 - id = parsed.Target 31 - default: 32 - return 0, &giterrors.ObjectTypeError{ 33 - OID: id, 34 - Got: parsed.ObjectType(), 35 - Want: objecttype.TypeCommit, 36 - } 37 - } 38 - } 12 + return query.resolveOID(id) 39 13 }