-
-
Notifications
You must be signed in to change notification settings - Fork 603
implement dolt_branch_status()
#9122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
03a21be
small refactor for dolt merge
jycor 2dfe538
partial implementation and tests
jycor dfdcc17
implement and test dolt_diverge
jycor c9049e2
revert engine testg
jycor cac827c
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
jycor 9afbac8
more tests
jycor 370b202
more refactoring
jycor 49bbdaa
Merge branch 'james/diverge' of github.com:dolthub/dolt into james/di…
jycor aab5d67
rename and use commitwalk
e8f2325
more tests
9d8848c
adding more complicated test
729f528
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
jycor e6110aa
Addional test with complicated history
macneale4 9b65333
merge with main
5a40973
fix merge with main
d93e111
debugging
ed360e5
testing
d7aad36
Merge branch 'main' into james/diverge
deda322
fix
059ce83
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
jycor 493028d
restore test functions
c98d334
Merge branch 'james/diverge' of github.com:dolthub/dolt into james/di…
7da5aaa
Merge branch 'main' into james/diverge
0e4376e
fix and add tests
be07f60
merge with main
d5641d7
feedback
0cc520c
return correct error
6999fa4
use CommitClosure instead
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
go/libraries/doltcore/sqle/dtablefunctions/dolt_diverge_table_function.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| // Copyright 2025 Dolthub, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package dtablefunctions | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/dolthub/go-mysql-server/sql" | ||
| "github.com/dolthub/go-mysql-server/sql/types" | ||
|
|
||
| "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" | ||
| "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" | ||
| ) | ||
|
|
||
| var _ sql.TableFunction = (*DivergeTableFunction)(nil) | ||
|
|
||
| type DivergeTableFunction struct { | ||
| db sql.Database | ||
| exprs []sql.Expression | ||
| } | ||
|
|
||
| // NewInstance creates a new instance of TableFunction interface | ||
| func (d *DivergeTableFunction) NewInstance(ctx *sql.Context, db sql.Database, args []sql.Expression) (sql.Node, error) { | ||
| if len(args) < 1 { | ||
| return nil, sql.ErrInvalidArgumentNumber.New(d.Name(), "at least 2", len(args)) | ||
| } | ||
| return &DivergeTableFunction{ | ||
| db: db, | ||
| exprs: args, | ||
| }, nil | ||
| } | ||
|
|
||
| // Name implements the sql.Node interface | ||
| func (d *DivergeTableFunction) Name() string { | ||
| return "DOLT_DIVERGE" | ||
| } | ||
|
|
||
| // String implements the Stringer interface | ||
| func (d *DivergeTableFunction) String() string { | ||
| exprStrs := make([]string, len(d.exprs)) | ||
| for i, expr := range d.exprs { | ||
| exprStrs[i] = expr.String() | ||
| } | ||
| return fmt.Sprintf("%s(%s)", d.Name(), strings.Join(exprStrs, ", ")) | ||
| } | ||
|
|
||
| // Resolved implements the sql.Resolvable interface | ||
| func (d *DivergeTableFunction) Resolved() bool { | ||
| for _, expr := range d.exprs { | ||
| if !expr.Resolved() { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| // Expressions implements the sql.Expressioner interface | ||
| func (d *DivergeTableFunction) Expressions() []sql.Expression { | ||
| return d.exprs | ||
| } | ||
|
|
||
| // WithExpressions implements the sql.Expressioner interface | ||
| func (d *DivergeTableFunction) WithExpressions(exprs ...sql.Expression) (sql.Node, error) { | ||
| nd := *d | ||
| nd.exprs = exprs | ||
| return &nd, nil | ||
| } | ||
|
|
||
| // Database implements the sql.Databaser interface | ||
| func (d *DivergeTableFunction) Database() sql.Database { | ||
| return d.db | ||
| } | ||
|
|
||
| // WithDatabase implements the sql.Databaser interface | ||
| func (d *DivergeTableFunction) WithDatabase(db sql.Database) (sql.Node, error) { | ||
| nd := *d | ||
| nd.db = db | ||
| return &nd, nil | ||
| } | ||
|
|
||
| // IsReadOnly implements the sql.Node interface | ||
| func (d *DivergeTableFunction) IsReadOnly() bool { | ||
| return true | ||
| } | ||
|
|
||
| // Schema implements the sql.Node interface | ||
| func (d *DivergeTableFunction) Schema() sql.Schema { | ||
| return sql.Schema{ | ||
| &sql.Column{Name: "branch", Type: types.Text, Nullable: false}, | ||
| &sql.Column{Name: "commits_ahead", Type: types.Uint64, Nullable: false}, | ||
| &sql.Column{Name: "commits_behind", Type: types.Uint64, Nullable: false}, | ||
| } | ||
| } | ||
|
|
||
| // Children implements the sql.Node interface | ||
| func (d *DivergeTableFunction) Children() []sql.Node { | ||
| return nil | ||
| } | ||
|
|
||
| // WithChildren implements the sql.Node interface | ||
| func (d *DivergeTableFunction) WithChildren(children ...sql.Node) (sql.Node, error) { | ||
| return d, nil | ||
| } | ||
|
|
||
| // RowIter implements the sql.Node interface | ||
| func (d *DivergeTableFunction) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) { | ||
| sqlDb, ok := d.db.(dsess.SqlDatabase) | ||
| if !ok { | ||
| return nil, fmt.Errorf("unable to get dolt database") | ||
| } | ||
| ddb := sqlDb.DbData().Ddb | ||
|
|
||
| sess := dsess.DSessFromSess(ctx.Session) | ||
| dbName := sess.Session.GetCurrentDatabase() | ||
| headRef, err := sess.CWBHeadRef(ctx, dbName) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| specs, err := mustExpressionsToString(ctx, d.exprs) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if len(specs) == 1 { | ||
| return sql.RowsToRowIter(), nil | ||
| } | ||
|
|
||
| commits := make([]*doltdb.Commit, len(specs)) | ||
| for i, spec := range specs { | ||
| cs, cErr := doltdb.NewCommitSpec(spec) | ||
| if cErr != nil { | ||
| return nil, err | ||
| } | ||
| optCmt, oErr := ddb.Resolve(ctx, cs, headRef) | ||
| if oErr != nil { | ||
| return nil, oErr | ||
| } | ||
| commit, optCommitOk := optCmt.ToCommit() | ||
| if !optCommitOk { | ||
| return nil, doltdb.ErrGhostCommitEncountered | ||
| } | ||
| commits[i] = commit | ||
| } | ||
|
|
||
| baseCommit := commits[0] | ||
| branchCommits := commits[1:] | ||
| baseHeight, err := baseCommit.Height() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var rows []sql.Row | ||
| for i, branchCommit := range branchCommits { | ||
| branchHeight, bErr := branchCommit.Height() | ||
| if bErr != nil { | ||
| return nil, bErr | ||
| } | ||
|
|
||
| ancOptCommit, ancErr := doltdb.GetCommitAncestor(ctx, baseCommit, branchCommit) | ||
| if ancErr != nil { | ||
| return nil, err | ||
| } | ||
| ancCommit, ancCommitOk := ancOptCommit.ToCommit() | ||
| if !ancCommitOk { | ||
| return nil, doltdb.ErrGhostCommitEncountered | ||
| } | ||
| ancHeight, _ := ancCommit.Height() | ||
|
|
||
| ahead := branchHeight - ancHeight | ||
| behind := baseHeight - ancHeight | ||
| rows = append(rows, sql.Row{specs[i+1], ahead, behind}) | ||
| } | ||
|
|
||
| return sql.RowsToRowIter(rows...), nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.