diff options
| author | 2026-03-10 13:30:48 +0800 | |
|---|---|---|
| committer | 2026-03-10 13:30:48 +0800 | |
| commit | 73e602a5c2c766caba59948e91c11122653705ec (patch) | |
| tree | 57951a4275dd90c2b3953e5b4bf3c9a7bd09b84a /commitgraph/read/position.go | |
| parent | *: Move sideband64k and pktline to protocol/ (diff) | |
| signature | No signature | |
commitgraph: Move out of format/
Diffstat (limited to 'commitgraph/read/position.go')
| -rw-r--r-- | commitgraph/read/position.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/commitgraph/read/position.go b/commitgraph/read/position.go new file mode 100644 index 00000000..b2e1138b --- /dev/null +++ b/commitgraph/read/position.go @@ -0,0 +1,38 @@ +package read + +import ( + "fmt" + + "codeberg.org/lindenii/furgit/internal/intconv" +) + +// Position identifies one commit record by layer and row index. +type Position struct { + Graph uint32 + Index uint32 +} + +func (reader *Reader) globalToPosition(global uint32) (Position, error) { + for i := range reader.layers { + layer := &reader.layers[i] + from := layer.globalFrom + + to := from + layer.numCommits + if global >= from && global < to { + graph, err := intconv.IntToUint32(i) + if err != nil { + return Position{}, err + } + + return Position{ + Graph: graph, + Index: global - from, + }, nil + } + } + + return Position{}, &MalformedError{ + Path: "commit-graph", + Reason: fmt.Sprintf("parent global position out of range: %d", global), + } +} |
