1package cache
2
3import (
4 "encoding/gob"
5
6 "github.com/MichaelMure/git-bug/identity"
7)
8
9// IdentityExcerpt hold a subset of the identity values to be able to sort and
10// filter identities efficiently without having to read and compile each raw
11// identity.
12type IdentityExcerpt struct {
13 Id string
14
15 Name string
16 Login string
17 ImmutableMetadata map[string]string
18}
19
20func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt {
21 return &IdentityExcerpt{
22 Id: i.Id(),
23 Name: i.Name(),
24 Login: i.Login(),
25 ImmutableMetadata: i.ImmutableMetadata(),
26 }
27}
28
29// Package initialisation used to register the type for (de)serialization
30func init() {
31 gob.Register(IdentityExcerpt{})
32}
33
34/*
35 * Sorting
36 */
37
38type IdentityById []*IdentityExcerpt
39
40func (b IdentityById) Len() int {
41 return len(b)
42}
43
44func (b IdentityById) Less(i, j int) bool {
45 return b[i].Id < b[j].Id
46}
47
48func (b IdentityById) Swap(i, j int) {
49 b[i], b[j] = b[j], b[i]
50}