summaryrefslogtreecommitdiff
path: root/cmd_comment.go
blob: d783ecc758890f2e1e7e3e09ac787d161ec96607 (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
package libfastimport

import (
	"strconv"

	"git.lukeshu.com/go/libfastimport/textproto"
)

type CmdComment struct {
	Comment string
}

func (c CmdComment) fiCmdClass() cmdClass { return cmdClassComment }
func (c CmdComment) fiCmdWrite(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("#" + c.Comment)
}

type CmdGetMark struct {
	Mark int
}

func (c CmdGetMark) fiCmdClass() cmdClass { return cmdClassComment }
func (c CmdGetMark) fiCmdWrite(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("get-mark", ":"+strconv.Itoa(c.Mark))
}

type CmdCatBlob struct {
	DataRef string
}

func (c CmdCatBlob) fiCmdClass() cmdClass { return cmdClassComment }
func (c CmdCatBlob) fiCmdWrite(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("cat-blob", c.DataRef)
}

type CmdLs struct {
	DataRef string // optional if inside of a commit
	Path    textproto.Path
}

func (c CmdLs) fiCmdClass() cmdClass {
	if c.DataRef == "" {
		return cmdClassCommit
	}
	return cmdClassComment
}
func (c CmdLs) fiCmdWrite(fiw *textproto.FIWriter) error {
	if c.DataRef == "" {
		return fiw.WriteLine("ls", c.Path)
	} else {
		return fiw.WriteLine("ls", c.DataRef, c.Path)
	}
}