summaryrefslogtreecommitdiff
path: root/fileactions.go
blob: 910fe5a867a07b5677892f0cecbdfd81e62bbc48 (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
92
93
94
package libfastimport

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

type FileAction interface {
	fiWriteFA(*textproto.FIWriter) error
}

type FileModify struct {
	Mode    textproto.Mode
	Path    textproto.Path
	DataRef string
}

func (o FileModify) fiWriteFA(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("M", o.Mode, o.DataRef, o.Path)
}

type FileModifyInline struct {
	Mode textproto.Mode
	Path textproto.Path
	Data string
}

func (o FileModifyInline) fiWriteFA(fiw *textproto.FIWriter) error {
	ez := &ezfiw{fiw: fiw}
	ez.WriteLine("M", o.Mode, "inline", o.Path)
	ez.WriteData(o.Data)
	return ez.err
}

type FileDelete struct {
	Path textproto.Path
}

func (o FileDelete) fiWriteFA(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("D", o.Path)
}

type FileCopy struct {
	Src textproto.Path
	Dst textproto.Path
}

func (o FileCopy) fiWriteFA(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("C", o.Src, o.Dst)
}

type FileRename struct {
	Src string
	Dst string
}

func (o FileRename) fiWriteFA(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("R", o.Src, o.Dst)
}

type FileDeleteAll struct{}

func (o FileDeleteAll) fiWriteFA(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("deleteall")
}

type NoteModify struct {
	CommitIsh string
	DataRef   string
}

func (o NoteModify) fiWriteFA(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("N", o.DataRef, o.CommitIsh)
}

type NoteModifyInline struct {
	CommitIsh string
	Data      string
}

func (o NoteModifyInline) fiWriteFA(fiw *textproto.FIWriter) error {
	ez := &ezfiw{fiw: fiw}
	ez.WriteLine("N", "inline", o.CommitIsh)
	ez.WriteData(o.Data)
	return ez.err
}

// See CmdLs for using ls outside of a commit
type FileLs struct {
	Path textproto.Path
}

func (o FileLs) fiWriteFA(fiw *textproto.FIWriter) error {
	return fiw.WriteLine("ls", o.Path)
}