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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
package libfastimport
import (
"strconv"
"git.lukeshu.com/go/libfastimport/textproto"
)
type Cmd interface {
fiWriteCmd(*textproto.FIWriter) error
}
type CmdCommit struct {
Ref string
Mark int // optional; < 1 for non-use
Author *textproto.UserTime
Committer textproto.UserTime
Msg []byte
Parents []string
Tree []FileAction
}
func (c CmdCommit) fiWriteCmd(fiw *textproto.FIWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("commit", c.Ref)
if c.Mark > 0 {
ez.WriteMark(c.Mark)
}
if c.Author != nil {
ez.WriteLine("author", *c.Author)
}
ez.WriteLine("committer", c.Committer)
ez.WriteData(c.Msg)
if len(c.Parents) > 0 {
ez.WriteLine("from", c.Parents[0])
if len(c.Parents) > 1 {
for _, parent := range c.Parents[1:] {
ez.WriteLine("merge", parent)
}
}
}
if ez.err != nil {
return ez.err
}
for _, action := range c.Tree {
err := action.fiWriteFA(fiw)
if err != nil {
return err
}
}
return nil
}
type CmdTag struct {
RefName string
CommitIsh string
Tagger textproto.UserTime
Data []byte
}
func (c CmdTag) fiWriteCmd(fiw *textproto.FIWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("tag", c.RefName)
ez.WriteLine("from", c.CommitIsh)
ez.WriteLine("tagger", c.Tagger)
ez.WriteData(c.Data)
return ez.err
}
type CmdReset struct {
RefName string
CommitIsh string // optional
}
func (c CmdReset) fiWriteCmd(fiw *textproto.FIWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("reset", c.RefName)
if c.CommitIsh != "" {
ez.WriteLine("from", c.CommitIsh)
}
return ez.err
}
type CmdBlob struct {
Mark int
Data []byte
}
func (c CmdBlob) fiWriteCmd(fiw *textproto.FIWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("blob")
if c.Mark > 0 {
ez.WriteMark(c.Mark)
}
ez.WriteData(c.Data)
return ez.err
}
type CmdCheckpoint struct{}
func (c CmdCheckpoint) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("checkpoint")
}
type CmdProgress struct {
Str string
}
func (c CmdProgress) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("progress", c.Str)
}
type CmdGetMark struct {
Mark int
}
func (c CmdGetMark) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("get-mark", ":"+strconv.Itoa(c.Mark))
}
type CmdCatBlob struct {
DataRef string
}
func (c CmdCatBlob) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("cat-blob", c.DataRef)
}
// See FileLs for using ls inside of a commit
type CmdLs struct {
DataRef string
Path textproto.Path
}
func (c CmdLs) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("ls", c.DataRef, c.Path)
}
type CmdFeature struct {
Feature string
Argument string
}
func (c CmdFeature) fiWriteCmd(fiw *textproto.FIWriter) error {
if c.Argument != "" {
return fiw.WriteLine("feature", c.Feature+"="+c.Argument)
} else {
return fiw.WriteLine("feature", c.Feature)
}
}
type CmdOption struct {
Option string
}
func (c CmdOption) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("option", c.Option)
}
type CmdDone struct{}
func (c CmdDone) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("done")
}
type CmdComment struct {
Comment string
}
func (c CmdComment) fiWriteCmd(fiw *textproto.FIWriter) error {
return fiw.WriteLine("#" + c.Comment)
}
|