diff options
Diffstat (limited to 'identity/identity.go')
-rw-r--r-- | identity/identity.go | 17 |
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 |