// Copyright 2019-2021 Luke Shumaker // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . package main import ( "regexp" "git.lukeshu.com/go/libfastimport" ) type Filter struct { backend *libfastimport.Backend filters []*regexp.Regexp writer *Writer } func (h *Filter) CmdProgress(cmd libfastimport.CmdProgress) error { for i := range h.filters { if h.filters[i].MatchString(cmd.Str) { h.writer.Write(i, "progress "+cmd.Str) return nil } } return h.backend.Do(cmd) } // pass through everything else func (h *Filter) CmdBlob(cmd libfastimport.CmdBlob) error { return h.backend.Do(cmd) } func (h *Filter) CmdAlias(cmd libfastimport.CmdAlias) error { return h.backend.Do(cmd) } func (h *Filter) CmdCheckpoint(cmd libfastimport.CmdCheckpoint) error { return h.backend.Do(cmd) } func (h *Filter) CmdComment(cmd libfastimport.CmdComment) error { return h.backend.Do(cmd) } func (h *Filter) CmdCommit(cmd libfastimport.CmdCommit) error { return h.backend.Do(cmd) } func (h *Filter) CmdCommitEnd(cmd libfastimport.CmdCommitEnd) error { return h.backend.Do(cmd) } func (h *Filter) CmdDone(cmd libfastimport.CmdDone) error { return h.backend.Do(cmd) } func (h *Filter) CmdFeature(cmd libfastimport.CmdFeature) error { return h.backend.Do(cmd) } func (h *Filter) CmdOption(cmd libfastimport.CmdOption) error { return h.backend.Do(cmd) } func (h *Filter) CmdReset(cmd libfastimport.CmdReset) error { return h.backend.Do(cmd) } func (h *Filter) CmdTag(cmd libfastimport.CmdTag) error { return h.backend.Do(cmd) } func (h *Filter) FileCopy(cmd libfastimport.FileCopy) error { return h.backend.Do(cmd) } func (h *Filter) FileDelete(cmd libfastimport.FileDelete) error { return h.backend.Do(cmd) } func (h *Filter) FileDeleteAll(cmd libfastimport.FileDeleteAll) error { return h.backend.Do(cmd) } func (h *Filter) FileModify(cmd libfastimport.FileModify) error { return h.backend.Do(cmd) } func (h *Filter) FileModifyInline(cmd libfastimport.FileModifyInline) error { return h.backend.Do(cmd) } func (h *Filter) FileRename(cmd libfastimport.FileRename) error { return h.backend.Do(cmd) } func (h *Filter) NoteModify(cmd libfastimport.NoteModify) error { return h.backend.Do(cmd) } func (h *Filter) NoteModifyInline(cmd libfastimport.NoteModifyInline) error { return h.backend.Do(cmd) } func (h *Filter) CmdCatBlob(cmd libfastimport.CmdCatBlob) (sha1 string, data string, err error) { return h.backend.CatBlob(cmd) } func (h *Filter) CmdGetMark(cmd libfastimport.CmdGetMark) (sha1 string, err error) { return h.backend.GetMark(cmd) } func (h *Filter) CmdLs(cmd libfastimport.CmdLs) (mode libfastimport.Mode, dataref string, path libfastimport.Path, err error) { return h.backend.Ls(cmd) } func (*Filter) HookEndOfStream() error { return nil }