mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-04 18:49:00 -06:00
/go/libraries/doltcore/env/actions/tag.go: reinstage iterresolved tags for better deprecation process
This commit is contained in:
42
go/libraries/doltcore/env/actions/tag.go
vendored
42
go/libraries/doltcore/env/actions/tag.go
vendored
@@ -17,6 +17,7 @@ package actions
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
@@ -122,6 +123,47 @@ func IterUnresolvedTags(ctx context.Context, ddb *doltdb.DoltDB, cb func(tag *do
|
||||
return nil
|
||||
}
|
||||
|
||||
// IterResolvedTags iterates over tags in dEnv.DoltDB from newest to oldest, resolving the tag to a commit and calling cb().
|
||||
func IterResolvedTags(ctx context.Context, ddb *doltdb.DoltDB, cb func(tag *doltdb.Tag) (stop bool, err error)) error {
|
||||
tagRefs, err := ddb.GetTags(ctx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var resolved []*doltdb.Tag
|
||||
for _, r := range tagRefs {
|
||||
tr, ok := r.(ref.TagRef)
|
||||
if !ok {
|
||||
return fmt.Errorf("DoltDB.GetTags() returned non-tag DoltRef")
|
||||
}
|
||||
|
||||
tag, err := ddb.ResolveTag(ctx, tr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resolved = append(resolved, tag)
|
||||
}
|
||||
|
||||
// iterate newest to oldest
|
||||
sort.Slice(resolved, func(i, j int) bool {
|
||||
return resolved[i].Meta.Timestamp > resolved[j].Meta.Timestamp
|
||||
})
|
||||
|
||||
for _, tag := range resolved {
|
||||
stop, err := cb(tag)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if stop {
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IterResolvedTagsPaginated iterates over tags in dEnv.DoltDB in their default lexicographical order, resolving the tag to a commit and calling cb().
|
||||
// Returns the next tag name if there are more results available.
|
||||
func IterResolvedTagsPaginated(ctx context.Context, ddb *doltdb.DoltDB, startTag string, cb func(tag *doltdb.Tag) (stop bool, err error)) (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user