Skip to content

Commit

Permalink
go/store/datas: Database: Tag works on commit hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
reltuk committed Feb 16, 2022
1 parent e376e24 commit 6a419bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 2 additions & 3 deletions go/libraries/doltcore/doltdb/doltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,7 @@ func (ddb *DoltDB) NewTagAtCommit(ctx context.Context, tagRef ref.DoltRef, c *Co
return fmt.Errorf("dataset already exists for tag %s", tagRef.String())
}

r, err := types.NewRef(c.commitSt, ddb.Format())

commitAddr, err := c.commitSt.Hash(ddb.Format())
if err != nil {
return err
}
Expand All @@ -1044,7 +1043,7 @@ func (ddb *DoltDB) NewTagAtCommit(ctx context.Context, tagRef ref.DoltRef, c *Co

tag := datas.TagOptions{Meta: st}

ds, err = ddb.db.Tag(ctx, ds, r, tag)
ds, err = ddb.db.Tag(ctx, ds, commitAddr, tag)

return err
}
Expand Down
11 changes: 6 additions & 5 deletions go/store/datas/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ type Database interface {
// an 'ErrMergeNeeded' error.
Commit(ctx context.Context, ds Dataset, v types.Value, opts CommitOptions) (Dataset, error)

// Tag stores an immutable reference to a Commit. It takes a Ref and a
// Dataset whose head must be nil (ie a newly created Dataset). The
// new Tag struct is constructed with `ref` and metadata about the tag
// contained in the struct `opts.Meta`.
Tag(ctx context.Context, ds Dataset, ref types.Ref, opts TagOptions) (Dataset, error)
// Tag stores an immutable reference to a Commit. It takes a Hash to
// the Commit and a Dataset whose head must be nil (ie a newly created
// Dataset). The new Tag struct is constructed pointing at
// |commitAddr| and metadata about the tag contained in the struct
// `opts.Meta`.
Tag(ctx context.Context, ds Dataset, commitAddr hash.Hash, opts TagOptions) (Dataset, error)

// UpdateWorkingSet updates the dataset given, setting its value to a new
// working set value object with the ref and meta given. If the dataset given
Expand Down
11 changes: 9 additions & 2 deletions go/store/datas/database_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,20 @@ func mergeNeeded(currentHeadRef types.Ref, ancestorRef types.Ref, commitRef type
return currentHeadRef.TargetHash() != ancestorRef.TargetHash()
}

func (db *database) Tag(ctx context.Context, ds Dataset, ref types.Ref, opts TagOptions) (Dataset, error) {
func (db *database) Tag(ctx context.Context, ds Dataset, commitAddr hash.Hash, opts TagOptions) (Dataset, error) {
return db.doHeadUpdate(
ctx,
ds,
func(ds Dataset) error {
commitSt, err := db.ReadValue(ctx, commitAddr)
if err != nil {
return err
}
ref, err := types.NewRef(commitSt, db.Format())
if err != nil {
return err
}
st, err := NewTag(ctx, ref, opts.Meta)

if err != nil {
return err
}
Expand Down

0 comments on commit 6a419bd

Please sign in to comment.