summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-11-23 22:53:25 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-11-23 22:53:25 -0500
commite2353adb6369b9ce298d0ff6611967e86b256087 (patch)
tree0d617b728a51da6389e4df5c5616f1eaa8a07509
parent1e50bb66b9d70eecf642afba1c266a39a8cb23cf (diff)
add delete handling
-rw-r--r--filter.go64
1 files changed, 52 insertions, 12 deletions
diff --git a/filter.go b/filter.go
index b02924c..1410f09 100644
--- a/filter.go
+++ b/filter.go
@@ -7,10 +7,11 @@ import (
"io/ioutil"
"os"
"os/exec"
- "path"
+ "strconv"
"strings"
"git.lukeshu.com/go/libfastimport"
+ "git.lukeshu.com/go/libfastimport/textproto"
)
type fullcommit struct {
@@ -28,7 +29,7 @@ type Filter struct {
refs map[string]string
mark int
- curCommitIn *libfastimport.CmdCommit
+ curCommitIn libfastimport.CmdCommit
curCommitOut map[string]fullcommit
}
@@ -162,7 +163,7 @@ func (f *Filter) Run() error {
// This should only happen once, at the very
// beginning. I think I can ignore it.
case libfastimport.CmdCommit:
- f.curCommitIn = &cmdt
+ f.curCommitIn = cmdt
f.curCommitOut = map[string]fullcommit{}
case libfastimport.CmdCommitEnd:
for _, fc := range f.curCommitOut {
@@ -181,7 +182,8 @@ func (f *Filter) Run() error {
}
}
}
- f.curCommitIn = nil
+ // TODO: synthesize ABS-tree submodule commits
+ f.curCommitIn = libfastimport.CmdCommit{}
f.curCommitOut = nil
case libfastimport.FileModify:
branchname := filename2branchname(string(cmdt.Path))
@@ -197,6 +199,7 @@ func (f *Filter) Run() error {
return err
}
if file_mode == cmdt.Mode && file_dataref == cmdt.DataRef {
+ // the file hasn't changed; the action is a no-op; ignore it
continue
}
} else {
@@ -215,15 +218,52 @@ func (f *Filter) Run() error {
}}
}
- outcommit := &f.curCommitOut[branch_ref]
- outcommit.fileactions = append(outcommit.fileactions, libfastimport.FileModify{
- Mode: cmdt.Mode,
- Path: strings.TrimPrefix(string(cmdt.Path), branchname+"/"),
- DataRef: cmdt.DataRef,
- })
+ outcommit := f.curCommitOut[branch_ref]
+ outcommit.fileactions = append(outcommit.fileactions,
+ libfastimport.FileModify{
+ Mode: cmdt.Mode,
+ Path: textproto.Path(strings.TrimPrefix(string(cmdt.Path), branchname+"/")),
+ DataRef: cmdt.DataRef,
+ })
+ f.curCommitOut[branch_ref] = outcommit
case libfastimport.FileDelete:
- //ref := f.toPfx + "/" + path.Dir(string(cmdt.Path))
- // TODO
+ branchname := filename2branchname(string(cmdt.Path))
+ if branchname == "" {
+ continue
+ }
+
+ branch_ref := f.toPfx + "/" + branchname
+ from_dataref, from_dataref_ok := f.refs[branch_ref]
+ if !from_dataref_ok {
+ return fmt.Errorf("cannot delete file %q from branch %q, because that branch doesn't exist!", cmdt.Path, branchname)
+ }
+ file_mode, _, _, err := f.backend.Ls(libfastimport.CmdLs{DataRef: from_dataref, Path: cmdt.Path})
+ if err != nil {
+ return err
+ }
+ if file_mode == 0 {
+ // the file doesn't exist; the action is a no-op; ignore it
+ continue
+ }
+
+ if _, ok := f.curCommitOut[branch_ref]; !ok {
+ f.curCommitOut[branch_ref] = fullcommit{metadata: libfastimport.CmdCommit{
+ Ref: branch_ref,
+ Mark: f.newmark(),
+ Author: f.curCommitIn.Author,
+ Committer: f.curCommitIn.Committer,
+ Msg: f.curCommitIn.Msg,
+ From: from_dataref,
+ Merge: nil,
+ }}
+ }
+
+ outcommit := f.curCommitOut[branch_ref]
+ outcommit.fileactions = append(outcommit.fileactions,
+ libfastimport.FileDelete{
+ Path: textproto.Path(strings.TrimPrefix(string(cmdt.Path), branchname+"/")),
+ })
+ f.curCommitOut[branch_ref] = outcommit
}
}
return nil