aboutsummaryrefslogtreecommitdiff
path: root/reachability/walk_expand_commits.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 10:59:53 +0800
committerGravatar Runxi Yu2026-03-06 10:59:53 +0800
commit95f8f3d45fe077042df4fd4afa73d4e419bc9974 (patch)
tree1e650b788eb4fbe5fc61ad0df700de58ebba40c5 /reachability/walk_expand_commits.go
parentformat/commitgraph: Split layer files (diff)
signatureNo signature
reachability: Split walk files
Diffstat (limited to 'reachability/walk_expand_commits.go')
-rw-r--r--reachability/walk_expand_commits.go70
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)
+}