aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-08 14:17:08 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-08 14:17:08 +0200
commit6d7e79a277fe6f3d137fc76588599c965fa5b2ee (patch)
tree7a392b6a12041fa8a1178980ba181c9ed5f5313c /bug
parent61a1173ec3f202b9dc71236205de785e2a454791 (diff)
downloadgit-bug-6d7e79a277fe6f3d137fc76588599c965fa5b2ee.tar.gz
cache: refactor to handle bug changes during Pull
Diffstat (limited to 'bug')
-rw-r--r--bug/bug.go6
-rw-r--r--bug/bug_actions.go43
2 files changed, 24 insertions, 25 deletions
diff --git a/bug/bug.go b/bug/bug.go
index c8b7ae61..ed4717bf 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -571,12 +571,8 @@ func (bug *Bug) Id() string {
// HumanId return the Bug identifier truncated for human consumption
func (bug *Bug) HumanId() string {
- return formatHumanId(bug.Id())
-}
-
-func formatHumanId(id string) string {
format := fmt.Sprintf("%%.%ds", humanIdLength)
- return fmt.Sprintf(format, id)
+ return fmt.Sprintf(format, bug.Id())
}
// CreateLamportTime return the Lamport time of creation
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index 37c3aa05..a51a1bf9 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -45,29 +45,32 @@ func Pull(repo repository.Repo, remote string) error {
}
type MergeResult struct {
+ // Err is set when a terminal error occur in the process
Err error
- Id string
- HumanId string
- Status string
+ Id string
+ Status string
+ Bug *Bug
}
-func newMergeError(id string, err error) MergeResult {
+func newMergeError(err error, id string) MergeResult {
return MergeResult{
- Id: id,
- HumanId: formatHumanId(id),
- Status: err.Error(),
+ Err: err,
+ Id: id,
}
}
-func newMergeStatus(id string, status string) MergeResult {
+func newMergeStatus(status string, id string, bug *Bug) MergeResult {
return MergeResult{
- Id: id,
- HumanId: formatHumanId(id),
- Status: status,
+ Id: id,
+ Status: status,
+
+ // Bug is not set for an invalid merge result
+ Bug: bug,
}
}
+// MergeAll will merge all the available remote bug
func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
out := make(chan MergeResult)
@@ -89,13 +92,13 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
remoteBug, err := readBug(repo, remoteRef)
if err != nil {
- out <- newMergeError(id, err)
+ out <- newMergeError(err, id)
continue
}
// Check for error in remote data
if !remoteBug.IsValid() {
- out <- newMergeStatus(id, MsgMergeInvalid)
+ out <- newMergeStatus(MsgMergeInvalid, id, nil)
continue
}
@@ -103,7 +106,7 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
localExist, err := repo.RefExist(localRef)
if err != nil {
- out <- newMergeError(id, err)
+ out <- newMergeError(err, id)
continue
}
@@ -112,32 +115,32 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
err := repo.CopyRef(remoteRef, localRef)
if err != nil {
- out <- newMergeError(id, err)
+ out <- newMergeError(err, id)
return
}
- out <- newMergeStatus(id, MsgMergeNew)
+ out <- newMergeStatus(MsgMergeNew, id, remoteBug)
continue
}
localBug, err := readBug(repo, localRef)
if err != nil {
- out <- newMergeError(id, err)
+ out <- newMergeError(err, id)
return
}
updated, err := localBug.Merge(repo, remoteBug)
if err != nil {
- out <- newMergeError(id, err)
+ out <- newMergeError(err, id)
return
}
if updated {
- out <- newMergeStatus(id, MsgMergeUpdated)
+ out <- newMergeStatus(MsgMergeUpdated, id, localBug)
} else {
- out <- newMergeStatus(id, MsgMergeNothing)
+ out <- newMergeStatus(MsgMergeNothing, id, localBug)
}
}
}()