aboutsummaryrefslogtreecommitdiffstats
path: root/identity/identity.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-24 14:17:52 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:48:51 +0100
commit7a80d8f849861a6033cd0765e5d85a52b08a8854 (patch)
tree30a2b00bec3e871aa18ba75acac626f9e7e1f1b2 /identity/identity.go
parent8bba6d1493fdf064ac9fede0a5098b1abe969052 (diff)
downloadgit-bug-7a80d8f849861a6033cd0765e5d85a52b08a8854.tar.gz
commands: add a super-fast "user ls" command
Diffstat (limited to 'identity/identity.go')
-rw-r--r--identity/identity.go17
1 files changed, 17 insertions, 0 deletions
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