package main
import (
"fmt"
"io"
"time"
)
type Commit struct {
Mark int
Committer string
Timestamp time.Time
Message string
}
func (c Commit) WriteTo(w io.Writer) error {
if _, err := fmt.Fprintln(w, "commit refs/heads/master"); err != nil {
return err
}
if c.Mark != 0 {
if _, err := fmt.Fprintf(w, "mark :%d\n", c.Mark); err != nil {
return err
}
}
if _, err := fmt.Fprintln(w, "committer", c.Committer, formatTime(c.Timestamp)); err != nil {
return err
}
if _, err := fmt.Fprintln(w, "data", len(c.Message)); err != nil {
return err
}
if _, err := fmt.Fprintln(w, c.Message); err != nil {
return err
}
if _, err := fmt.Fprintln(w); err != nil {
return err
}
return nil
}