1package bug
2
3import (
4 "github.com/MichaelMure/git-bug/entity"
5 "github.com/MichaelMure/git-bug/repository"
6 "github.com/MichaelMure/git-bug/util/lamport"
7)
8
9type Interface interface {
10 // Id return the Bug identifier
11 Id() entity.Id
12
13 // Validate check if the Bug data is valid
14 Validate() error
15
16 // Append an operation into the staging area, to be committed later
17 Append(op Operation)
18
19 // Indicate that the in-memory state changed and need to be commit in the repository
20 NeedCommit() bool
21
22 // Commit write the staging area in Git and move the operations to the packs
23 Commit(repo repository.ClockedRepo) error
24
25 // Merge a different version of the same bug by rebasing operations of this bug
26 // that are not present in the other on top of the chain of operations of the
27 // other version.
28 Merge(repo repository.Repo, other Interface) (bool, error)
29
30 // Lookup for the very first operation of the bug.
31 // For a valid Bug, this operation should be a CreateOp
32 FirstOp() Operation
33
34 // Lookup for the very last operation of the bug.
35 // For a valid Bug, should never be nil
36 LastOp() Operation
37
38 // Compile a bug in a easily usable snapshot
39 Compile() Snapshot
40
41 // CreateLamportTime return the Lamport time of creation
42 CreateLamportTime() lamport.Time
43
44 // EditLamportTime return the Lamport time of the last edit
45 EditLamportTime() lamport.Time
46}
47
48func bugFromInterface(bug Interface) *Bug {
49 switch bug.(type) {
50 case *Bug:
51 return bug.(*Bug)
52 case *WithSnapshot:
53 return bug.(*WithSnapshot).Bug
54 default:
55 panic("missing type case")
56 }
57}