1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package models
import (
"fmt"
"strings"
)
const (
Untracked = "untracked"
)
func NewCommit(r RevisionController, id, tag string) Commit {
return Commit{
ID: id,
Subject: r.Subject(id),
Author: r.Author(id),
Date: r.Date(id),
MessageId: "",
Tag: tag,
}
}
func (c Commit) Untracked() bool {
return c.Tag == Untracked
}
func (c Commit) Info() string {
s := []string{}
if c.Subject == "" {
s = append(s, "(no subject)")
} else {
s = append(s, c.Subject)
}
if c.Author != "" {
s = append(s, c.Author)
}
if c.Date != "" {
s = append(s, c.Date)
}
if c.MessageId != "" {
s = append(s, "<"+c.MessageId+">")
}
return strings.Join(s, ", ")
}
func (c Commit) String() string {
return fmt.Sprintf("%-6.6s %s", c.ID, c.Info())
}
type Commits []Commit
func (h Commits) Tags() []string {
var tags []string
dedup := make(map[string]struct{})
for _, c := range h {
_, ok := dedup[c.Tag]
if ok {
continue
}
tags = append(tags, c.Tag)
dedup[c.Tag] = struct{}{}
}
return tags
}
func (h Commits) HasTag(t string) bool {
for _, c := range h {
if c.Tag == t {
return true
}
}
return false
}
func (h Commits) Lookup(id string) (Commit, bool) {
for _, c := range h {
if c.ID == id {
return c, true
}
}
return Commit{}, false
}
type CommitIDs []string
func (c CommitIDs) Has(id string) bool {
for _, cid := range c {
if cid == id {
return true
}
}
return false
}
|