aboutsummaryrefslogtreecommitdiffstats
path: root/identity/identity.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-16 17:32:30 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:24 +0100
commitd2483d83dd52365741f51eca106aa18c4e8d6420 (patch)
treeb1265d1874005952febe8d469435827a4947ba7b /identity/identity.go
parentcd7ed7ff9e3250c10e97fe16c934b5a6151527bb (diff)
downloadgit-bug-d2483d83dd52365741f51eca106aa18c4e8d6420.tar.gz
identity: I can compile again !!
Diffstat (limited to 'identity/identity.go')
-rw-r--r--identity/identity.go36
1 files changed, 27 insertions, 9 deletions
diff --git a/identity/identity.go b/identity/identity.go
index 725362f9..a0800bcd 100644
--- a/identity/identity.go
+++ b/identity/identity.go
@@ -241,15 +241,7 @@ func (i *Identity) AddVersion(version *Version) {
func (i *Identity) Commit(repo repository.Repo) error {
// Todo: check for mismatch between memory and commited data
- needCommit := false
- for _, v := range i.versions {
- if v.commitHash == "" {
- needCommit = true
- break
- }
- }
-
- if !needCommit {
+ if !i.NeedCommit() {
return fmt.Errorf("can't commit an identity with no pending version")
}
@@ -313,6 +305,23 @@ func (i *Identity) Commit(repo repository.Repo) error {
return nil
}
+func (i *Identity) CommitAsNeeded(repo repository.Repo) error {
+ if !i.NeedCommit() {
+ return nil
+ }
+ return i.Commit(repo)
+}
+
+func (i *Identity) NeedCommit() bool {
+ for _, v := range i.versions {
+ if v.commitHash == "" {
+ return true
+ }
+ }
+
+ return false
+}
+
// Merge will merge a different version of the same Identity
//
// To make sure that an Identity history can't be altered, a strict fast-forward
@@ -379,6 +388,10 @@ func (i *Identity) Merge(repo repository.Repo, other *Identity) (bool, error) {
func (i *Identity) Validate() error {
lastTime := lamport.Time(0)
+ if len(i.versions) == 0 {
+ return fmt.Errorf("no version")
+ }
+
for _, v := range i.versions {
if err := v.Validate(); err != nil {
return err
@@ -391,6 +404,11 @@ func (i *Identity) Validate() error {
lastTime = v.time
}
+ // The identity ID should be the hash of the first commit
+ if i.versions[0].commitHash != "" && string(i.versions[0].commitHash) != i.id {
+ return fmt.Errorf("identity id should be the first commit hash")
+ }
+
return nil
}