func (m *MergeAdder) HandleToken(l *lex.Lexer, o io.Writer) error { switch l.Token() { case lex.CommitTok: parser := gitexport.NewLexerParser(l) commit, err := parser.Commit() if err != nil { return err } parentMark := int(0) ok := false if commit.Mark != 0 { if parentMark, ok = m.MarkToParentMark[commit.Mark]; ok { commit.Merge = append(commit.Merge, fmt.Sprintf(":%d", parentMark)) } } m.Commits = append(m.Commits, commit) case lex.ResetTok: if err := m.WriteCommits(o); err != nil { return err } io.WriteString(o, l.Line()) l.Consume() default: io.WriteString(o, l.Line()) l.Consume() } return nil }
func (t *TagHarvester) HandleToken(l *lex.Lexer, o io.Writer) error { switch l.Token() { case lex.TagTok: tag := l.Field(1) io.WriteString(o, l.Line()) l.Consume() var mark int _, err := fmt.Sscanf(l.Line(), "from :%d\n", &mark) if err != nil { return fmt.Errorf("invalid 'from' line: %s", l.Line()) } t.TagToMark[tag] = mark io.WriteString(o, l.Line()) l.Consume() default: io.WriteString(o, l.Line()) l.Consume() } return nil }
func filter(l *lex.Lexer, o io.Writer, handler TokenHandler) { for { switch l.Token() { case lex.EOFTok: return case lex.ErrTok: fmt.Fprintf(os.Stderr, "%d: error: %s\n", l.LineNumber(), l.Error()) os.Exit(1) case lex.InvalidTok: fmt.Fprintf(os.Stderr, "%d: invalid command: %s\n", l.LineNumber(), l.Line()) os.Exit(1) case lex.DataTok: passData(l, o) default: if err := handler.HandleToken(l, o); err != nil { fmt.Fprintf(os.Stderr, "%d: error: %s\n", l.LineNumber(), err) os.Exit(1) } } } }