Example #1
0
func mapLinkrevToFilerevRange(i *revlog.Index, rLo, rHi *revlog.Rec) (r1, r2 *revlog.Rec) {
	r1 = getRecord(i, revlog.NewLinkRevSpec(int(rLo.Linkrev)))
	r2 = getRecord(i, revlog.NewLinkRevSpec(int(rHi.Linkrev)))
	if r1.Linkrev < rLo.Linkrev {
		if r1.Linkrev == r2.Linkrev {
			goto emptyRange
		}
		r1 = r1.Next()
	}
	if r1.Linkrev == r2.Linkrev && r2.Linkrev < rHi.Linkrev {
		goto emptyRange
	}
	return

emptyRange:
	r1 = nil
	r2 = nil
	return
}
Example #2
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)
	}
}
Example #3
0
func runArchive(cmd *Command, w io.Writer, args []string) {
	openRepository(args)
	rs := getRevisionSpec()
	b := revlog.NewFileBuilder()
	c, err := getChangeset(rs, b)
	if err != nil {
		fatalf("%s", err)
	}

	var ent *store.ManifestEnt
	link := revlog.NewLinkRevSpec(int(c.Linkrev))
	link.FindPresent = func(rlist []*revlog.Rec) (index int, err error) {
		index, err = findPresentByNodeId(ent, rlist)
		return
	}

	mm, err := getManifest(link.Rev, c.ManifestNode, b)
	if err != nil {
		fatalf("%s", err)
	}
	st := repo.NewStore()

	fileArg := getFileArg(args)

	newArchive, ok := amap[*archiveType]
	if !ok {
		fatalf("unknown archive type: %s", *archiveType)
	}
	a, pathPfx, err := newArchive(fileArg)
	if err != nil {
		fatalf("%s", err)
	}

	err = createArchivalTxt(a, pathPfx, c)
	if err != nil {
		fatalf("%s", err)
	}
	pathPfx += "/"

	for i := range mm {
		ent = &mm[i]

		f, err := st.OpenRevlog(ent.FileName)
		if err != nil {
			fatalf("%s", err)
		}
		r, err := link.Lookup(f)
		if err != nil {
			fatalf("%s", err)
		}

		name := pathPfx + ent.FileName
		if ent.IsLink() {
			buf, err := b.Build(r)
			if err != nil {
				fatalf("%s", err)
			}
			err = a.symlink(name, string(buf), c.Date)
			if err != nil {
				fatalf("%s", err)
			}
		} else {
			var mode int
			if ent.IsExecutable() {
				mode = 0755
			} else {
				mode = 0644
			}
			p, err := b.PreparePatch(r)
			if err != nil {
				fatalf("%s", err)
			}

			w, err := a.createFile(name, mode, int64(r.FileLength)-int64(len(p.MetaData)), c.Date)
			if err != nil {
				fatalf("%s", err)
			}
			err = p.Apply(w)
			if err != nil {
				fatalf("%s", err)
			}
		}
	}
	err = a.Close()
	if err != nil {
		fatalf("%s", err)
	}
}