func runManifest(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) } mm, err := getManifest(int(c.Linkrev), c.ManifestNode, b) if err != nil { fatalf("%s", err) } for i := range mm { fmt.Fprintln(w, mm[i].FileName) } }
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) } } }
// Parse tags, and return one Tags structure containing only // global tags, another one containing both global and local tags. func (r *Repository) Tags() (tGlobal, tAll *Tags) { tGlobal, tAll = newTags(), newTags() st := r.NewStore() index, err := st.OpenRevlog(".hgtags") if err == nil { fb := revlog.NewFileBuilder() if err := fb.BuildWrite(nil, index.Tip()); err == nil { tAll.parseFile(bytes.NewReader(fb.Bytes())) } } f, err := r.open(".hg/localtags") if err == nil { tGlobal.copy(tAll) err = tAll.parseFile(f) f.Close() } else { tGlobal = tAll } return }
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) } }
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 }
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) } }