2018-08-23 20:11:38 +03:00
|
|
|
package bug
|
|
|
|
|
|
|
|
import (
|
2019-08-11 15:08:03 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2018-08-23 20:11:38 +03:00
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2018-09-11 23:04:16 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/lamport"
|
2018-08-23 20:11:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Interface interface {
|
|
|
|
// Id return the Bug identifier
|
2019-08-11 15:08:03 +03:00
|
|
|
Id() entity.Id
|
2018-08-23 20:11:38 +03:00
|
|
|
|
2018-09-15 14:15:00 +03:00
|
|
|
// Validate check if the Bug data is valid
|
|
|
|
Validate() error
|
2018-08-23 20:11:38 +03:00
|
|
|
|
|
|
|
// Append an operation into the staging area, to be committed later
|
|
|
|
Append(op Operation)
|
|
|
|
|
2019-11-19 02:28:06 +03:00
|
|
|
// Indicate that the in-memory state changed and need to be commit in the repository
|
|
|
|
NeedCommit() bool
|
2018-08-23 20:11:38 +03:00
|
|
|
|
|
|
|
// Commit write the staging area in Git and move the operations to the packs
|
2018-09-21 19:18:51 +03:00
|
|
|
Commit(repo repository.ClockedRepo) error
|
2018-08-23 20:11:38 +03:00
|
|
|
|
|
|
|
// Merge a different version of the same bug by rebasing operations of this bug
|
|
|
|
// that are not present in the other on top of the chain of operations of the
|
|
|
|
// other version.
|
|
|
|
Merge(repo repository.Repo, other Interface) (bool, error)
|
|
|
|
|
|
|
|
// Lookup for the very first operation of the bug.
|
|
|
|
// For a valid Bug, this operation should be a CreateOp
|
|
|
|
FirstOp() Operation
|
|
|
|
|
|
|
|
// Lookup for the very last operation of the bug.
|
|
|
|
// For a valid Bug, should never be nil
|
|
|
|
LastOp() Operation
|
|
|
|
|
|
|
|
// Compile a bug in a easily usable snapshot
|
|
|
|
Compile() Snapshot
|
2018-08-23 20:19:16 +03:00
|
|
|
|
|
|
|
// CreateLamportTime return the Lamport time of creation
|
2018-09-11 23:04:16 +03:00
|
|
|
CreateLamportTime() lamport.Time
|
2018-08-23 20:19:16 +03:00
|
|
|
|
|
|
|
// EditLamportTime return the Lamport time of the last edit
|
2018-09-11 23:04:16 +03:00
|
|
|
EditLamportTime() lamport.Time
|
2018-08-23 20:11:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func bugFromInterface(bug Interface) *Bug {
|
2020-02-08 18:17:15 +03:00
|
|
|
switch bug := bug.(type) {
|
2018-08-23 20:11:38 +03:00
|
|
|
case *Bug:
|
2020-02-08 18:17:15 +03:00
|
|
|
return bug
|
2018-08-23 20:11:38 +03:00
|
|
|
case *WithSnapshot:
|
2020-02-08 18:17:15 +03:00
|
|
|
return bug.Bug
|
2018-08-23 20:11:38 +03:00
|
|
|
default:
|
|
|
|
panic("missing type case")
|
|
|
|
}
|
|
|
|
}
|