aboutsummaryrefslogtreecommitdiff
path: root/reachability/walk_expand_commits_graph.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_graph.go
parentformat/commitgraph: Split layer files (diff)
signatureNo signature
reachability: Split walk files
Diffstat (limited to 'reachability/walk_expand_commits_graph.go')
-rw-r--r--reachability/walk_expand_commits_graph.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/reachability/walk_expand_commits_graph.go b/reachability/walk_expand_commits_graph.go
new file mode 100644
index 00000000..15780c8e
--- /dev/null
+++ b/reachability/walk_expand_commits_graph.go
@@ -0,0 +1,57 @@
+package reachability
+
+import (
+ "errors"
+
+ "codeberg.org/lindenii/furgit/format/commitgraph"
+ "codeberg.org/lindenii/furgit/objectid"
+ "codeberg.org/lindenii/furgit/objecttype"
+)
+
+func (walk *Walk) expandCommitsFromGraph(id objectid.ObjectID) ([]walkItem, bool, error) {
+ pos, err := walk.reachability.graph.Lookup(id)
+ if err != nil {
+ var notFound *commitgraph.ErrNotFound
+ if errors.As(err, &notFound) {
+ return nil, false, nil
+ }
+
+ return nil, true, err
+ }
+
+ commit, err := walk.reachability.graph.CommitAt(pos)
+ if err != nil {
+ return nil, true, err
+ }
+
+ next := make([]walkItem, 0, 2+len(commit.ExtraParents))
+
+ if commit.Parent1.Valid {
+ parentOID, err := walk.reachability.graph.OIDAt(commit.Parent1.Pos)
+ if err != nil {
+ return nil, true, err
+ }
+
+ next = append(next, walkItem{id: parentOID, want: objecttype.TypeInvalid})
+ }
+
+ if commit.Parent2.Valid {
+ parentOID, err := walk.reachability.graph.OIDAt(commit.Parent2.Pos)
+ if err != nil {
+ return nil, true, err
+ }
+
+ next = append(next, walkItem{id: parentOID, want: objecttype.TypeInvalid})
+ }
+
+ for _, parentPos := range commit.ExtraParents {
+ parentOID, err := walk.reachability.graph.OIDAt(parentPos)
+ if err != nil {
+ return nil, true, err
+ }
+
+ next = append(next, walkItem{id: parentOID, want: objecttype.TypeInvalid})
+ }
+
+ return next, true, nil
+}