Beispiel #1
0
func (ra *repoAccess) localChangesetId(rs revlog.RevisionSpec) (chgId revlog.FileRevSpec, err error) {
	r, err := ra.clRec(rs)
	if err == nil {
		chgId = revlog.FileRevSpec(r.FileRev())
	}
	return
}
Beispiel #2
0
func (m *Manifests) LookupRevision(linkrev int, wantId revlog.NodeId) (r *revlog.Rec, err error) {
	r, err = revlog.FileRevSpec(linkrev).Lookup(m.Index)
	if err != nil {
		r = m.Tip()
		err = nil
	}
	for int(r.Linkrev) > linkrev {
		r = r.Prev()
	}
	if !wantId.Eq(r.Id()) {
		err = errors.New("manifest node id does not match changelog entry")
	}
	return
}
Beispiel #3
0
func runRevlog(cmd *Command, w io.Writer, args []string) {
	if len(args) == 0 {
		fatalf("missing argument: revlog index file")
	}
	index, err := revlog.Open(storeName(args[0]))
	if err != nil {
		fatalf("%s", err)
	}

	if *revlogR == -1 {
		index.Dump(w)
		return
	}

	r, err := revlog.FileRevSpec(*revlogR).Lookup(index)
	if err != nil {
		fatalf("%s", err)
	}
	if !*revlogBuild {
		dh := &dataHelper{}
		d, err := r.GetData(dh)
		if dh.file != nil {
			dh.file.Close()
		}
		if err != nil {
			fatalf("%s", err)
		}
		if r.IsBase() {
			w.Write(d)
		} else {
			hunks, err := patch.Parse(d)
			if err != nil {
				fatalf("%s", err)
			}
			for _, h := range hunks {
				h.Dump(w)
			}
		}
	} else {
		fb := revlog.NewFileBuilder()
		err = fb.BuildWrite(w, r)
		if err != nil {
			fatalf("%s", err)
		}
	}
}
Beispiel #4
0
func (ra *repoAccess) manifestEntry(chgId int, fileName string) (me *store.ManifestEnt, err error) {
	r, err := ra.clRec(revlog.FileRevSpec(chgId))
	if err != nil {
		return
	}
	c, err := changelog.BuildEntry(r, ra.fb)
	if err != nil {
		return
	}
	m, err := getManifest(int(c.Linkrev), c.ManifestNode, ra.fb)
	if err != nil {
		return
	}
	me = m.Map()[fileName]
	if me == nil {
		err = errors.New("file does not exist in given revision")
	}
	return
}
Beispiel #5
0
func parseRevisionSpec(s, dflt string) revlog.RevisionSpec {
	if s == "" {
		s = dflt
	}
	if s == "tip" {
		return revlog.TipRevSpec{}
	}
	if s == "null" {
		return revlog.NullRevSpec{}
	}
	if id, ok := allTags.IdByName[s]; ok {
		s = id
	} else if id, ok := branchHeads.IdByName[s]; ok {
		s = id
	} else if i, err := strconv.Atoi(s); err == nil {
		return revlog.FileRevSpec(i)
	}

	return revlog.NodeIdRevSpec(s)
}
Beispiel #6
0
func runCat(cmd *Command, w io.Writer, args []string) {
	openRepository(args)
	rs := getRevisionSpec()
	fileArg := getFileArg(args)
	st := repo.NewStore()

	fileLog, err := st.OpenRevlog(fileArg)
	if err != nil {
		fatalf("%s", err)
	}

	ra := repoAccess{
		fb: revlog.NewFileBuilder(),
		st: st,
	}
	localId, ok := rs.(revlog.FileRevSpec)
	if !ok {
		localId, err = ra.localChangesetId(rs)
		if err != nil {
			return
		}
	}

	link := revlog.NewLinkRevSpec(int(localId))
	link.FindPresent = func(rlist []*revlog.Rec) (index int, err error) {
		if len(rlist) > 1 {
			// Does link.Rev refer to a changelog revision that is a
			// descendant of one of the revisions in rlist?
			for i, r := range rlist {
				cr, err1 := ra.clRec(revlog.FileRevSpec(r.Linkrev))
				if err1 != nil {
					err = err1
					return
				}
				if cr.IsDescendant(link.Rev) {
					index = i
					goto found
				}
			}
			err = fmt.Errorf("internal error: none of the given records is an ancestor of rev %v", link.Rev)
			return

		found:
			if !rlist[index].IsLeaf() {
				return
			}
		}

		// Check for the file's existence using the manifest.
		ent, err := ra.manifestEntry(link.Rev, fileArg)
		if err == nil {
			index, err = findPresentByNodeId(ent, rlist)
		}
		return
	}
	r, err := link.Lookup(fileLog)
	if err != nil {
		fatalf("%s", err)
	}

	fb := revlog.NewFileBuilder()
	err = fb.BuildWrite(w, r)
	if err != nil {
		fatalf("%s", err)
	}
}
Beispiel #7
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
}