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}
18
19func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt {
20 return &IdentityExcerpt{
21 Id: i.Id(),
22 Name: i.Name(),
23 Login: i.Login(),
24 }
25}
26
27// Package initialisation used to register the type for (de)serialization
28func init() {
29 gob.Register(IdentityExcerpt{})
30}
31
32/*
33 * Sorting
34 */
35
36type IdentityById []*IdentityExcerpt
37
38func (b IdentityById) Len() int {
39 return len(b)
40}
41
42func (b IdentityById) Less(i, j int) bool {
43 return b[i].Id < b[j].Id
44}
45
46func (b IdentityById) Swap(i, j int) {
47 b[i], b[j] = b[j], b[i]
48}