-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
CLI command for reflog #7032
Merged
Merged
CLI command for reflog #7032
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
adcf3c1
tests for dolt reflog
fccec02
basic dolt reflog implementation
d3e7c7d
add --all for reflog
37158e0
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
stephkyou 6ba1d09
change error test output
3e5c6b6
minor test updates
5d24edd
address PR comments
0f2e926
reflog doc update
e9c63ac
another description update
b47eeb4
PR comments
e2f18ee
Merge remote-tracking branch 'origin/main' into steph/reflog
a99b52d
small fix
d73c8fd
Merge branch 'main' into steph/reflog
stephkyou 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 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 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 |
---|---|---|
|
@@ -29,10 +29,11 @@ import ( | |
) | ||
|
||
type ReflogTableFunction struct { | ||
ctx *sql.Context | ||
database sql.Database | ||
refExpr sql.Expression | ||
showAll bool | ||
ctx *sql.Context | ||
database sql.Database | ||
refAndArgExprs []sql.Expression | ||
tabId sql.TableId | ||
colset sql.ColSet | ||
} | ||
|
||
var _ sql.TableFunction = (*ReflogTableFunction)(nil) | ||
|
@@ -86,17 +87,30 @@ func (rltf *ReflogTableFunction) RowIter(ctx *sql.Context, row sql.Row) (sql.Row | |
} | ||
|
||
var refName string | ||
if rltf.refExpr != nil { | ||
target, err := rltf.refExpr.Eval(ctx, row) | ||
showAll := false | ||
for _, expr := range rltf.refAndArgExprs { | ||
target, err := expr.Eval(ctx, row) | ||
if err != nil { | ||
return nil, fmt.Errorf("error evaluating expression (%s): %s", | ||
rltf.refExpr.String(), err.Error()) | ||
expr.String(), err.Error()) | ||
} | ||
|
||
refName, ok = target.(string) | ||
targetStr, ok := target.(string) | ||
if !ok { | ||
return nil, fmt.Errorf("argument (%v) is not a string value, but a %T", target, target) | ||
} | ||
|
||
if targetStr == "--all" { | ||
if showAll { | ||
return nil, fmt.Errorf("error: multiple values provided for `all`") | ||
} | ||
showAll = true | ||
} else { | ||
if refName != "" { | ||
return nil, fmt.Errorf("error: %s has too many positional arguments. Expected at most %d, found %d: %s", | ||
rltf.Name(), 1, 2, rltf.refAndArgExprs) | ||
} | ||
refName = targetStr | ||
} | ||
} | ||
|
||
ddb := sqlDb.DbData().Ddb | ||
|
@@ -132,7 +146,7 @@ func (rltf *ReflogTableFunction) RowIter(ctx *sql.Context, row sql.Row) (sql.Row | |
} | ||
// skip workspace refs by default | ||
if doltRef.GetType() == ref.WorkspaceRefType { | ||
if !rltf.showAll { | ||
if !showAll { | ||
return nil | ||
} | ||
} | ||
|
@@ -199,19 +213,17 @@ func (rltf *ReflogTableFunction) Schema() sql.Schema { | |
} | ||
|
||
func (rltf *ReflogTableFunction) Resolved() bool { | ||
if rltf.refExpr != nil { | ||
return rltf.refExpr.Resolved() | ||
for _, expr := range rltf.refAndArgExprs { | ||
return expr.Resolved() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't want to always return on the first expression – you need to check that all the expressions are resolved. You probably want something like |
||
} | ||
return true | ||
} | ||
|
||
func (rltf *ReflogTableFunction) String() string { | ||
var args []string | ||
if rltf.showAll { | ||
args = append(args, "'--all'") | ||
} | ||
if rltf.refExpr != nil { | ||
args = append(args, rltf.refExpr.String()) | ||
|
||
for _, expr := range rltf.refAndArgExprs { | ||
args = append(args, expr.String()) | ||
} | ||
return fmt.Sprintf("DOLT_REFLOG(%s)", strings.Join(args, ", ")) | ||
} | ||
|
@@ -238,10 +250,7 @@ func (rltf *ReflogTableFunction) IsReadOnly() bool { | |
} | ||
|
||
func (rltf *ReflogTableFunction) Expressions() []sql.Expression { | ||
if rltf.refExpr != nil { | ||
return []sql.Expression{rltf.refExpr} | ||
} | ||
return []sql.Expression{} | ||
return rltf.refAndArgExprs | ||
} | ||
|
||
func (rltf *ReflogTableFunction) WithExpressions(expression ...sql.Expression) (sql.Node, error) { | ||
|
@@ -250,22 +259,7 @@ func (rltf *ReflogTableFunction) WithExpressions(expression ...sql.Expression) ( | |
} | ||
|
||
new := *rltf | ||
|
||
if len(expression) == 2 { | ||
if expression[0].String() == "'--all'" && expression[1].String() == "'--all'" { | ||
return nil, fmt.Errorf("error: multiple values provided for `all`") | ||
} | ||
if expression[0].String() != "'--all'" && expression[1].String() != "'--all'" { | ||
return nil, fmt.Errorf("error: %s has too many positional arguments. Expected at most %d, found %d: %s", rltf.Name(), 1, 2, expression) | ||
} | ||
} | ||
for _, expr := range expression { | ||
if expr.String() != "'--all'" { | ||
new.refExpr = expr | ||
} else { | ||
new.showAll = true | ||
} | ||
} | ||
new.refAndArgExprs = expression | ||
|
||
return &new, nil | ||
} | ||
|
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two members don't seem to be used anywhere, so should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were added in a separate PR, looks like they're being used a couple lines down.