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_graph.go | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 reachability/walk_expand_commits_graph.go (limited to 'reachability/walk_expand_commits_graph.go') 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, ¬Found) { + 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 +} -- cgit v1.3.1-10-gc9f91