Exemple #1
0
func BuildEntry(r *revlog.Rec, fb *revlog.FileBuilder) (e *Entry, err error) {
	err = fb.BuildWrite(nil, r)
	if err != nil {
		return
	}
	e, err = parseEntryData(fb.Bytes())
	if err == nil {
		e.Rec = r
		e.Id = r.Id().Node()
	}
	return
}
Exemple #2
0
func printChangelog(w io.Writer, rFrom, rTo *revlog.Rec, logIndex *revlog.Index, tags map[string][]string, wantDirPrefix, wantFile string) (err error) {
	var clr *revlog.Rec

	match := func([]string) bool { return true }
	if wantFile != "" {
		match = func(files []string) (ok bool) {
			for _, f := range files {
				if f == wantFile {
					ok = true
					return
				}
			}
			return
		}
	} else if wantDirPrefix != "" {
		match = func(files []string) (ok bool) {
			for _, f := range files {
				if strings.HasPrefix(f, wantDirPrefix) {
					ok = true
					return
				}
			}
			return
		}
	}

	fb := revlog.NewFileBuilder()
	fb.SetDataCache(&dc)
	fb.KeepDataOpen()
	defer fb.CloseData()
	t, err := setupLogTemplate(logTemplate, tags)
	if err != nil {
		return
	}
	ch := make(chan *changelog.Entry, 16)
	errch := make(chan error, 0)
	go func() {
		errch <- t.Execute(w, ch)
	}()
	r := rFrom
	target := rTo.FileRev()
	var next func()
	if rFrom.FileRev() > target {
		next = func() { r = r.Prev() }
	} else {
		next = func() { r = r.Next() }
	}
	i := 0
	for {
		if logIndex == nil {
			clr = r
		} else {
			clr, err = revlog.FileRevSpec(r.Linkrev).Lookup(logIndex)
			if err != nil {
				return
			}
		}
		c, err1 := changelog.BuildEntry(clr, fb)
		if err1 != nil {
			err = err1
			return
		}
		c.Rec = clr

		if match(c.Files) {
			select {
			case ch <- c:
				i++
			case err = <-errch:
				return
			}
		}
		if r.FileRev() == target {
			break
		}
		next()
		if r.FileRev() == -1 {
			break
		}
		if *logL != 0 && i == *logL {
			break
		}
	}
	close(ch)
	err = <-errch
	return
}