Skip to content

Commit

Permalink
/go/libraries/doltcore/env/actions/tag.go: reinstage iterresolved tag…
Browse files Browse the repository at this point in the history
…s for better deprecation process
  • Loading branch information
coffeegoddd committed Jan 30, 2025
1 parent cda466f commit 09dd814
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions go/libraries/doltcore/env/actions/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 09dd814

Please sign in to comment.