blob: 279de48a0507edb52a3d80e1561024394b4d7fed (
plain)
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
|
package todo
import (
"io"
"strings"
)
func Write(f io.Writer, todos []Todo, commentChar byte) error {
for _, todo := range todos {
if err := writeTodo(f, todo, commentChar); err != nil {
return err
}
}
return nil
}
func writeTodo(f io.Writer, todo Todo, commentChar byte) error {
var sb strings.Builder
if todo.Command != Comment {
sb.WriteString(todo.Command.String())
}
switch todo.Command {
case NoOp:
case Comment:
sb.WriteByte(commentChar)
sb.WriteString(todo.Comment)
case Break:
case Label:
fallthrough
case Reset:
sb.WriteByte(' ')
sb.WriteString(todo.Label)
case Exec:
sb.WriteByte(' ')
sb.WriteString(todo.ExecCommand)
case Merge:
sb.WriteByte(' ')
if todo.Commit != "" {
sb.WriteString(todo.Flag)
sb.WriteByte(' ')
sb.WriteString(todo.Commit)
sb.WriteByte(' ')
}
sb.WriteString(todo.Label)
if todo.Msg != "" {
sb.WriteString(" # ")
sb.WriteString(todo.Msg)
}
case Fixup:
sb.WriteByte(' ')
if todo.Flag != "" {
sb.WriteString(todo.Flag)
sb.WriteByte(' ')
}
sb.WriteString(todo.Commit)
case UpdateRef:
sb.WriteByte(' ')
sb.WriteString(todo.Ref)
case Pick:
fallthrough
case Revert:
fallthrough
case Edit:
fallthrough
case Reword:
fallthrough
case Squash:
fallthrough
case Drop:
sb.WriteByte(' ')
sb.WriteString(todo.Commit)
if todo.Msg != "" {
sb.WriteByte(' ')
sb.WriteString(todo.Msg)
}
}
sb.WriteByte('\n')
_, err := f.Write([]byte(sb.String()))
return err
}
|