Beispiel #1
0
// WriteRevision implements a method of kcd.Writer.  This implementation stores
// revisions only in memory, they are not persisted in the indexpack.
func (db *DB) WriteRevision(_ context.Context, rev kcd.Revision, replace bool) error {
	if rev.Revision == "" {
		return errors.New("missing revision marker")
	} else if rev.Corpus == "" {
		return errors.New("missing corpus label")
	}
	if rev.Timestamp.IsZero() {
		rev.Timestamp = time.Now()
	}
	rev.Timestamp = rev.Timestamp.In(time.UTC)
	if replace {
		for i, old := range db.Revs {
			if old.Corpus == rev.Corpus && old.Revision == rev.Revision {
				db.Revs[i].Timestamp = rev.Timestamp
				return nil
			}
		}
	}
	db.Revs = append(db.Revs, rev)
	return nil
}