Пример #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
}
Пример #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
}
Пример #3
0
func (r *Repository) FileSystem(at vcs.CommitID) (vfs.FileSystem, error) {
	rec, err := r.getRec(at)
	if err != nil {
		return nil, err
	}

	return &hgFSNative{
		dir:  r.Dir,
		at:   hg_revlog.FileRevSpec(rec.FileRev()),
		repo: r.u,
		st:   r.st,
		cl:   r.cl,
		fb:   hg_revlog.NewFileBuilder(),
	}, nil
}
Пример #4
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)
		}
	}
}
Пример #5
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
}
Пример #6
0
func (r *Repository) parseRevisionSpec(s string) hg_revlog.RevisionSpec {
	if s == "" {
		s = "tip"
		// TODO(sqs): determine per-repository default branch name (not always "default"?)
	}
	if s == "tip" {
		return hg_revlog.TipRevSpec{}
	}
	if s == "null" {
		return hg_revlog.NullRevSpec{}
	}
	if id, ok := r.allTags.IdByName[s]; ok {
		s = id
	} else if i, err := strconv.Atoi(s); err == nil {
		return hg_revlog.FileRevSpec(i)
	}

	return hg_revlog.NodeIdRevSpec(s)
}
Пример #7
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)
}
Пример #8
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)
	}
}