aboutsummaryrefslogtreecommitdiffstats
path: root/identity
diff options
context:
space:
mode:
Diffstat (limited to 'identity')
-rw-r--r--identity/bare.go5
-rw-r--r--identity/identity.go17
-rw-r--r--identity/identity_stub.go4
-rw-r--r--identity/interface.go3
4 files changed, 29 insertions, 0 deletions
diff --git a/identity/bare.go b/identity/bare.go
index d3f7655a..b6cbe491 100644
--- a/identity/bare.go
+++ b/identity/bare.go
@@ -85,6 +85,11 @@ func (i *Bare) Id() string {
return i.id
}
+// HumanId return the Identity identifier truncated for human consumption
+func (i *Bare) HumanId() string {
+ return FormatHumanID(i.Id())
+}
+
// Name return the last version of the name
func (i *Bare) Name() string {
return i.name
diff --git a/identity/identity.go b/identity/identity.go
index 114b954e..d57e8ce0 100644
--- a/identity/identity.go
+++ b/identity/identity.go
@@ -20,6 +20,9 @@ const identityRemoteRefPattern = "refs/remotes/%s/identities/"
const versionEntryName = "version"
const identityConfigKey = "git-bug.identity"
+const idLength = 40
+const humanIdLength = 7
+
var ErrNonFastForwardMerge = errors.New("non fast-forward identity merge")
var ErrNoIdentitySet = errors.New("user identity first needs to be created using \"git bug user create\"")
var ErrMultipleIdentitiesSet = errors.New("multiple user identities set")
@@ -93,6 +96,10 @@ func read(repo repository.Repo, ref string) (*Identity, error) {
refSplit := strings.Split(ref, "/")
id := refSplit[len(refSplit)-1]
+ if len(id) != idLength {
+ return nil, fmt.Errorf("invalid ref length")
+ }
+
hashes, err := repo.ListCommits(ref)
// TODO: this is not perfect, it might be a command invoke error
@@ -461,6 +468,16 @@ func (i *Identity) Id() string {
return i.id
}
+// HumanId return the Identity identifier truncated for human consumption
+func (i *Identity) HumanId() string {
+ return FormatHumanID(i.Id())
+}
+
+func FormatHumanID(id string) string {
+ format := fmt.Sprintf("%%.%ds", humanIdLength)
+ return fmt.Sprintf(format, id)
+}
+
// Name return the last version of the name
func (i *Identity) Name() string {
return i.lastVersion().name
diff --git a/identity/identity_stub.go b/identity/identity_stub.go
index 830cfb99..1bfc18d0 100644
--- a/identity/identity_stub.go
+++ b/identity/identity_stub.go
@@ -44,6 +44,10 @@ func (i *IdentityStub) Id() string {
return i.id
}
+func (i *IdentityStub) HumanId() string {
+ return FormatHumanID(i.Id())
+}
+
func (IdentityStub) Name() string {
panic("identities needs to be properly loaded with identity.ReadLocal()")
}
diff --git a/identity/interface.go b/identity/interface.go
index 9fe4db4f..d5c80543 100644
--- a/identity/interface.go
+++ b/identity/interface.go
@@ -9,6 +9,9 @@ type Interface interface {
// Id return the Identity identifier
Id() string
+ // HumanId return the Identity identifier truncated for human consumption
+ HumanId() string
+
// Name return the last version of the name
Name() string
// Email return the last version of the email