diff options
Diffstat (limited to 'filter.go')
-rw-r--r-- | filter.go | 83 |
1 files changed, 46 insertions, 37 deletions
@@ -13,6 +13,11 @@ import ( "git.lukeshu.com/go/libfastimport" ) +type fullcommit struct { + metadata libfastimport.CmdCommit + fileactions []libfastimport.Cmd +} + type Filter struct { fromRef string toPfx string @@ -20,16 +25,25 @@ type Filter struct { frontend *libfastimport.Frontend backend *libfastimport.Backend + refs map[string]string mark int + + curCommitIn libfastimport.CmdCommit + curCommitOut map[string]fullcommit } -func NewFilter(fromRef string, toPfix string) (*Filter, error) { +func NewFilter(fromRef string, toPfx string) (*Filter, error) { var err error ret := &Filter{ - fromPfx: fromPfx, + fromRef: fromRef, toPfx: toPfx, } + ret.refs, err = gitRefs() + if err != nil { + return nil, err + } + ret.frontend, err = gitFastExport( "--use-done-feature", "--no-data", @@ -144,52 +158,47 @@ func (f *Filter) Run() error { return fmt.Errorf("git fast-export kept going after 'done': cmd=%v err=%v", cmd, err) } return nil + case libfastimport.CmdReset: + // TODO case libfastimport.CmdCommit: - err = f.handleCommit(cmdt) - if err != nil { - return err - } - default: - return fmt.Errorf("Unexpected command: %[1]T(%#[1]v)", cmd) - } - } -} - -func (f *Filter) handleCommit(commit libfastimport.CmdCommit) error { - out := make(map[string]libfastimport.CmdCommit) - for _, action := range commit.Tree { - switch actiont := action.(type) { + // TODO + case libfastimport.CmdCommitEnd: + // TODO case libfastimport.FileModify: - branch_ref := f.toPfx + "/" + path.Dir(string(actiont.Path)) - from_dataref, err := f.ref2dataref(branch_ref) - if err == nil { - file_mode, file_dataref, _, err := f.backend.Ls(libfastimport.CmdLs{DataRef: from_dataref, Path: actiont.Path}) + branchname := filename2branchname(string(cmdt.Path)) + if branchname == "" { + continue + } + branch_ref := f.toPfx + "/" + path.Dir(string(cmdt.Path)) + from_dataref, from_dataref_ok := f.refs[branch_ref] + if from_dataref_ok { + file_mode, file_dataref, _, err := f.backend.Ls(libfastimport.CmdLs{DataRef: from_dataref, Path: cmdt.Path}) if err != nil { return err } - if file_mode == actiont.Mode && file_dataref == actiont.DataRef { + if file_mode == cmdt.Mode && file_dataref == cmdt.DataRef { continue } + } else { + from_dataref = branch_ref + "^0" } - if _, ok := out[branch_ref]; !ok { - out[branch_ref] = libfastimport.CmdCommit{ - Ref: branch_ref, - Mark: f.newmark(), - Author: commit.Author, - Committer: commit.Committer, - Msg: commit.Msg, - From: from_dataref - Merge: nil - Tree: nil - } + 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 := out[branch_ref] - + //outcommit := f.curCommitOut[branch_ref] + // TODO case libfastimport.FileDelete: - ref := f.toPfx + "/" + path.Dir(string(actiont.Path)) - default: - return fmt.Errorf("Unexpected file action: %[1]T(%#[1]v)", action) + //ref := f.toPfx + "/" + path.Dir(string(cmdt.Path)) + // TODO } } return nil |