aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-13 15:28:16 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-13 15:28:47 +0200
commitdf144e727a858ed07e3c9328d91efe052c4781e1 (patch)
treebfbfeea70f97ab3d4274c8e5add2c3aeeac1423b /bug
parentf2f779c5a8b4efe67317bbffe110a9880c1f529a (diff)
downloadgit-bug-df144e727a858ed07e3c9328d91efe052c4781e1.tar.gz
fix some linting trouble
Diffstat (limited to 'bug')
-rw-r--r--bug/bug.go30
-rw-r--r--bug/bug_actions.go5
-rw-r--r--bug/clocks.go2
-rw-r--r--bug/comment.go2
-rw-r--r--bug/operation.go11
-rw-r--r--bug/operation_pack.go6
-rw-r--r--bug/operations/label_change.go6
7 files changed, 47 insertions, 15 deletions
diff --git a/bug/bug.go b/bug/bug.go
index 3c52adc8..7fa1dfb2 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -26,7 +26,7 @@ const humanIdLength = 7
// Bug hold the data of a bug thread, organized in a way close to
// how it will be persisted inside Git. This is the data structure
-// used for merge of two different version.
+// used to merge two different version of the same Bug.
type Bug struct {
// A Lamport clock is a logical clock that allow to order event
@@ -41,7 +41,7 @@ type Bug struct {
lastCommit util.Hash
rootPack util.Hash
- // all the commited operations
+ // all the committed operations
packs []OperationPack
// a temporary pack of operations used for convenience to pile up new operations
@@ -49,14 +49,14 @@ type Bug struct {
staging OperationPack
}
-// Create a new Bug
+// NewBug create a new Bug
func NewBug() *Bug {
// No id yet
// No logical clock yet
return &Bug{}
}
-// Find an existing Bug matching a prefix
+// FindLocalBug find an existing Bug matching a prefix
func FindLocalBug(repo repository.Repo, prefix string) (*Bug, error) {
ids, err := repo.ListIds(bugsRefPattern)
@@ -84,17 +84,19 @@ func FindLocalBug(repo repository.Repo, prefix string) (*Bug, error) {
return ReadLocalBug(repo, matching[0])
}
+// ReadLocalBug will read a local bug from its hash
func ReadLocalBug(repo repository.Repo, id string) (*Bug, error) {
ref := bugsRefPattern + id
return readBug(repo, ref)
}
+// ReadRemoteBug will read a remote bug from its hash
func ReadRemoteBug(repo repository.Repo, remote string, id string) (*Bug, error) {
ref := fmt.Sprintf(bugsRemoteRefPattern, remote) + id
return readBug(repo, ref)
}
-// Read and parse a Bug from git
+// readBug will read and parse a Bug from git
func readBug(repo repository.Repo, ref string) (*Bug, error) {
hashes, err := repo.ListCommits(ref)
@@ -212,12 +214,12 @@ type StreamedBug struct {
Err error
}
-// Read and parse all local bugs
+// ReadAllLocalBugs read and parse all local bugs
func ReadAllLocalBugs(repo repository.Repo) <-chan StreamedBug {
return readAllBugs(repo, bugsRefPattern)
}
-// Read and parse all remote bugs for a given remote
+// ReadAllRemoteBugs read and parse all remote bugs for a given remote
func ReadAllRemoteBugs(repo repository.Repo, remote string) <-chan StreamedBug {
refPrefix := fmt.Sprintf(bugsRemoteRefPattern, remote)
return readAllBugs(repo, refPrefix)
@@ -251,7 +253,7 @@ func readAllBugs(repo repository.Repo, refPrefix string) <-chan StreamedBug {
return out
}
-// List all the available local bug ids
+// ListLocalIds list all the available local bug ids
func ListLocalIds(repo repository.Repo) ([]string, error) {
return repo.ListIds(bugsRefPattern)
}
@@ -304,12 +306,12 @@ func (bug *Bug) Append(op Operation) {
bug.staging.Append(op)
}
-// Return if the bug need to be committed
+// HasPendingOp tell if the bug need to be committed
func (bug *Bug) HasPendingOp() bool {
return !bug.staging.IsEmpty()
}
-// Write the staging area in Git and move the operations to the packs
+// Commit write the staging area in Git and move the operations to the packs
func (bug *Bug) Commit(repo repository.Repo) error {
if bug.staging.IsEmpty() {
return fmt.Errorf("can't commit a bug with no pending operation")
@@ -515,6 +517,10 @@ func (bug *Bug) Merge(repo repository.Repo, other *Bug) (bool, error) {
// create a new commit with the correct ancestor
hash, err := repo.StoreCommitWithParent(treeHash, bug.lastCommit)
+ if err != nil {
+ return false, err
+ }
+
// replace the pack
newPack := pack.Clone()
newPack.commitHash = hash
@@ -533,7 +539,7 @@ func (bug *Bug) Merge(repo repository.Repo, other *Bug) (bool, error) {
return true, nil
}
-// Return the Bug identifier
+// Id return the Bug identifier
func (bug *Bug) Id() string {
if bug.id == "" {
// simply panic as it would be a coding error
@@ -543,7 +549,7 @@ func (bug *Bug) Id() string {
return bug.id
}
-// Return the Bug identifier truncated for human consumption
+// HumanId return the Bug identifier truncated for human consumption
func (bug *Bug) HumanId() string {
return formatHumanId(bug.Id())
}
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index 30fc9876..d4d5fe98 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -107,6 +107,11 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
localRef := bugsRefPattern + remoteBug.Id()
localExist, err := repo.RefExist(localRef)
+ if err != nil {
+ out <- newMergeError(id, err)
+ continue
+ }
+
// the bug is not local yet, simply create the reference
if !localExist {
err := repo.CopyRef(remoteRef, localRef)
diff --git a/bug/clocks.go b/bug/clocks.go
index 7b254746..5ffa094a 100644
--- a/bug/clocks.go
+++ b/bug/clocks.go
@@ -4,6 +4,8 @@ import (
"github.com/MichaelMure/git-bug/repository"
)
+// Witnesser will read all the available Bug to recreate the different logical
+// clocks
func Witnesser(repo *repository.GitRepo) error {
for b := range ReadAllLocalBugs(repo) {
if b.Err != nil {
diff --git a/bug/comment.go b/bug/comment.go
index 0b4fd6ad..ef5d9ef7 100644
--- a/bug/comment.go
+++ b/bug/comment.go
@@ -6,6 +6,7 @@ import (
"time"
)
+// Comment represent a comment in a Bug
type Comment struct {
Author Person
Message string
@@ -16,6 +17,7 @@ type Comment struct {
UnixTime int64
}
+// FormatTime format the UnixTime of the comment for human consumption
func (c Comment) FormatTime() string {
t := time.Unix(c.UnixTime, 0)
return humanize.Time(t)
diff --git a/bug/operation.go b/bug/operation.go
index 3949ac7b..cdf87931 100644
--- a/bug/operation.go
+++ b/bug/operation.go
@@ -5,6 +5,7 @@ import (
"time"
)
+// OperationType is an identifier
type OperationType int
const (
@@ -16,22 +17,29 @@ const (
LabelChangeOp
)
+// Operation define the interface to fulfill for an edit operation of a Bug
type Operation interface {
+ // OpType return the type of operation
OpType() OperationType
+ // Time return the time when the operation was added
Time() time.Time
+ // Apply the operation to a Snapshot to create the final state
Apply(snapshot Snapshot) Snapshot
+ // Files return the files needed by this operation
Files() []util.Hash
// TODO: data validation (ex: a title is a single line)
// Validate() bool
}
+// OpBase implement the common code for all operations
type OpBase struct {
OperationType OperationType
Author Person
UnixTime int64
}
+// NewOpBase is the constructor for an OpBase
func NewOpBase(opType OperationType, author Person) OpBase {
return OpBase{
OperationType: opType,
@@ -40,14 +48,17 @@ func NewOpBase(opType OperationType, author Person) OpBase {
}
}
+// OpType return the type of operation
func (op OpBase) OpType() OperationType {
return op.OperationType
}
+// Time return the time when the operation was added
func (op OpBase) Time() time.Time {
return time.Unix(op.UnixTime, 0)
}
+// Files return the files needed by this operation
func (op OpBase) Files() []util.Hash {
return nil
}
diff --git a/bug/operation_pack.go b/bug/operation_pack.go
index cce1845c..5de60bde 100644
--- a/bug/operation_pack.go
+++ b/bug/operation_pack.go
@@ -20,6 +20,7 @@ type OperationPack struct {
commitHash util.Hash
}
+// ParseOperationPack will deserialize an OperationPack from raw bytes
func ParseOperationPack(data []byte) (*OperationPack, error) {
reader := bytes.NewReader(data)
decoder := gob.NewDecoder(reader)
@@ -35,6 +36,7 @@ func ParseOperationPack(data []byte) (*OperationPack, error) {
return &opp, nil
}
+// Serialize will serialise an OperationPack into raw bytes
func (opp *OperationPack) Serialize() ([]byte, error) {
var data bytes.Buffer
@@ -53,14 +55,18 @@ func (opp *OperationPack) Append(op Operation) {
opp.Operations = append(opp.Operations, op)
}
+// IsEmpty tell if the OperationPack is empty
func (opp *OperationPack) IsEmpty() bool {
return len(opp.Operations) == 0
}
+// IsValid tell if the OperationPack is considered valid
func (opp *OperationPack) IsValid() bool {
return !opp.IsEmpty()
}
+// Write will serialize and store the OperationPack as a git blob and return
+// its hash
func (opp *OperationPack) Write(repo repository.Repo) (util.Hash, error) {
data, err := opp.Serialize()
diff --git a/bug/operations/label_change.go b/bug/operations/label_change.go
index 85bae595..8f608dbc 100644
--- a/bug/operations/label_change.go
+++ b/bug/operations/label_change.go
@@ -9,16 +9,16 @@ import (
"github.com/MichaelMure/git-bug/bug"
)
-// LabelChangeOperation will add or remove a set of labels
-
var _ bug.Operation = LabelChangeOperation{}
+// LabelChangeOperation define a Bug operation to add or remove labels
type LabelChangeOperation struct {
bug.OpBase
Added []bug.Label
Removed []bug.Label
}
+// Apply apply the operation
func (op LabelChangeOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
// Add in the set
AddLoop:
@@ -59,7 +59,7 @@ func NewLabelChangeOperation(author bug.Person, added, removed []bug.Label) Labe
}
}
-// Convenience function to apply the operation
+// ChangeLabels is a convenience function to apply the operation
func ChangeLabels(out io.Writer, b *bug.Bug, author bug.Person, add, remove []string) error {
var added, removed []bug.Label