diff options
| author | 2026-03-06 10:59:53 +0800 | |
|---|---|---|
| committer | 2026-03-06 10:59:53 +0800 | |
| commit | 95f8f3d45fe077042df4fd4afa73d4e419bc9974 (patch) | |
| tree | 1e650b788eb4fbe5fc61ad0df700de58ebba40c5 /reachability/walk_expand_commits.go | |
| parent | format/commitgraph: Split layer files (diff) | |
| signature | No signature | |
reachability: Split walk files
Diffstat (limited to 'reachability/walk_expand_commits.go')
| -rw-r--r-- | reachability/walk_expand_commits.go | 70 |
1 files changed, 70 insertions, 0 deletions
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) +} |
