aboutsummaryrefslogtreecommitdiff
path: root/internal/commitquery/populate.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 21:19:56 +0800
committerGravatar Runxi Yu2026-03-07 00:34:30 +0800
commit01d15bccf3b1dcc51516b1f64d50950b31d7f8fb (patch)
treee491fcc762c67c1ef4ce54faafc5dafdb734ae8a /internal/commitquery/populate.go
parentobjectstored/refstore: Weird ireturn behavior (diff)
signatureNo signature
Urgh I made some wrong amends and I'm too tired to separate the commits out this time
ancestor: Split out of reachability mergebase: Add merge base routines internal/commitquery: Add commit query context engine thingy internal/peel: Shared tag peeling errors: Shared object query errors internal/testgit: Add rooted repo helpers; remove raw path access objectstore/memory: Add in-memory object store objectid: Add Compare helper
Diffstat (limited to 'internal/commitquery/populate.go')
-rw-r--r--internal/commitquery/populate.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/commitquery/populate.go b/internal/commitquery/populate.go
new file mode 100644
index 00000000..87d65bf8
--- /dev/null
+++ b/internal/commitquery/populate.go
@@ -0,0 +1,42 @@
+package commitquery
+
+import "fmt"
+
+// populateNode fills one node's metadata and resolves its parents.
+func (ctx *Context) populateNode(idx NodeIndex, commit Commit) error {
+ if ctx.nodes[idx].loaded {
+ if ctx.nodes[idx].id != commit.ID {
+ return fmt.Errorf("commitquery: node identity mismatch: have %s, got %s", ctx.nodes[idx].id, commit.ID)
+ }
+
+ return nil
+ }
+
+ ctx.nodes[idx].id = commit.ID
+ ctx.nodes[idx].commitTime = commit.CommitTime
+ ctx.nodes[idx].generation = commit.Generation
+ ctx.nodes[idx].hasGeneration = commit.HasGeneration
+
+ if commit.HasGraphPos {
+ ctx.nodes[idx].graphPos = commit.GraphPos
+ ctx.nodes[idx].hasGraphPos = true
+ ctx.byGraphPos[commit.GraphPos] = idx
+ }
+
+ ctx.nodes[idx].loaded = true
+ ctx.nodes[idx].parents = ctx.nodes[idx].parents[:0]
+
+ for _, parent := range commit.Parents {
+ parentIdx, err := ctx.resolveParent(parent)
+ if err != nil {
+ ctx.nodes[idx].loaded = false
+ ctx.nodes[idx].parents = nil
+
+ return err
+ }
+
+ ctx.nodes[idx].parents = append(ctx.nodes[idx].parents, parentIdx)
+ }
+
+ return nil
+}