From 95f8f3d45fe077042df4fd4afa73d4e419bc9974 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 6 Mar 2026 10:59:53 +0800 Subject: reachability: Split walk files --- reachability/walk_expand_commits.go | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 reachability/walk_expand_commits.go (limited to 'reachability/walk_expand_commits.go') diff --git a/reachability/walk_expand_commits.go b/reachability/walk_expand_commits.go new file mode 100644 index 00000000..11c5c692 --- /dev/null +++ b/reachability/walk_expand_commits.go @@ -0,0 +1,70 @@ +package reachability + +import ( + "fmt" + + "codeberg.org/lindenii/furgit/object" + "codeberg.org/lindenii/furgit/objecttype" +) + +func (walk *Walk) expandCommits(item walkItem) ([]walkItem, error) { + if walk.reachability.graph != nil { //nolint:nestif + next, graphUsed, err := walk.expandCommitsFromGraph(item.id) + if err != nil { + return nil, err + } + + if graphUsed && walk.strict { + err = walk.validateCommitObject(item.id) + if err != nil { + return nil, err + } + } + + if graphUsed { + return next, nil + } + } + + ty, err := walk.readHeaderType(item.id) + if err != nil { + return nil, err + } + + switch ty { + case objecttype.TypeCommit: + content, err := walk.readBytesContent(item.id) + if err != nil { + return nil, err + } + + commit, err := object.ParseCommit(content, item.id.Algorithm()) + if err != nil { + return nil, err + } + + next := make([]walkItem, 0, len(commit.Parents)) + for _, parent := range commit.Parents { + next = append(next, walkItem{id: parent, want: objecttype.TypeInvalid}) + } + + return next, nil + case objecttype.TypeTag: + content, err := walk.readBytesContent(item.id) + if err != nil { + return nil, err + } + + tag, err := object.ParseTag(content, item.id.Algorithm()) + if err != nil { + return nil, err + } + + return []walkItem{{id: tag.Target, want: objecttype.TypeInvalid}}, nil + case objecttype.TypeTree, objecttype.TypeBlob, objecttype.TypeInvalid, + objecttype.TypeFuture, objecttype.TypeOfsDelta, objecttype.TypeRefDelta: + return nil, &ErrObjectType{OID: item.id, Got: ty, Want: objecttype.TypeCommit} + } + + return nil, fmt.Errorf("reachability: unreachable object type %d", ty) +} -- cgit v1.3.1-10-gc9f91