Artifact fcb4bd6886fb02e8f506dc1151b763d8713509bf1b6e59176c8406658d31986e:
- File
internal/merge/detect.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 1200) [annotate] [blame] [check-ins using]
package merge import ( libfossil "github.com/danmestas/libfossil/internal/fsltype" "github.com/danmestas/libfossil/internal/repo" ) // DetectForks finds divergent branches by querying the leaf table // (maintained by Fossil/manifest.Checkin) for checkins with no children. func DetectForks(r *repo.Repo) ([]Fork, error) { if r == nil { panic("merge.DetectForks: r must not be nil") } rows, err := r.DB().Query(` SELECT l.rid FROM leaf l JOIN event e ON e.objid=l.rid WHERE e.type='ci' ORDER BY e.mtime DESC`) if err != nil { return nil, err } defer rows.Close() var leaves []libfossil.FslID for rows.Next() { var rid int64 if err := rows.Scan(&rid); err != nil { continue } leaves = append(leaves, libfossil.FslID(rid)) } if err := rows.Err(); err != nil { return nil, err } if len(leaves) <= 1 { return nil, nil } var forks []Fork for i := 0; i < len(leaves); i++ { for j := i + 1; j < len(leaves); j++ { ancestor, err := FindCommonAncestor(r, leaves[i], leaves[j]) if err != nil { continue } forks = append(forks, Fork{ Ancestor: ancestor, LocalTip: leaves[i], RemoteTip: leaves[j], }) } } return forks, nil }