Пример #1
0
func (r *Repository) makeCommit(rec *hg_revlog.Rec) (*vcs.Commit, error) {
	fb := hg_revlog.NewFileBuilder()
	ce, err := hg_changelog.BuildEntry(rec, fb)
	if err != nil {
		return nil, err
	}

	addr, err := mail.ParseAddress(ce.Committer)
	if err != nil {
		// This occurs when the commit author specifier is
		// malformed. Fall back to just using the whole committer
		// string as the name.
		addr = &mail.Address{
			Name:    ce.Committer,
			Address: "",
		}
	}

	var parents []vcs.CommitID
	if !rec.IsStartOfBranch() {
		if p := rec.Parent(); p != nil {
			parents = append(parents, vcs.CommitID(hex.EncodeToString(rec.Parent().Id())))
		}
		if rec.Parent2Present() {
			parents = append(parents, vcs.CommitID(hex.EncodeToString(rec.Parent2().Id())))
		}
	}

	return &vcs.Commit{
		ID:      vcs.CommitID(ce.Id),
		Author:  vcs.Signature{addr.Name, addr.Address, pbtypes.NewTimestamp(ce.Date)},
		Message: ce.Comment,
		Parents: parents,
	}, nil
}
Пример #2
0
func TestBuildEntry(t *testing.T) {
	defer removeTmpDirs(t)

	dir := createRepo(t, commands)

	repo, err := hgo.OpenRepository(dir)
	if err != nil {
		t.Fatal("Unable to open repository.")
	}

	s := repo.NewStore()
	if s == nil {
		t.Fatal("Unable to create new store")
	}

	cl, err := s.OpenChangeLog()
	if err != nil {
		t.Fatalf("Unable to open change log: %s", err)
	}

	rec, err := hg_revlog.NodeIdRevSpec(revision).Lookup(cl)
	if err != nil {
		t.Errorf("Unable to get revision spec: %s", err)
	}

	fb := hg_revlog.NewFileBuilder()
	_, err = hg_changelog.BuildEntry(rec, fb)
	if err != nil {
		t.Errorf("Unable to build entry: %s", err)
	}
}
Пример #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 TestBuildManifest(t *testing.T) {
	defer removeTmpDirs(t)

	dir := createRepo(t, commands)

	repo, err := hgo.OpenRepository(dir)
	if err != nil {
		t.Fatal("Unable to open repository.")
	}

	s := repo.NewStore()
	if s == nil {
		t.Fatal("Unable to create new store")
	}

	cl, err := s.OpenChangeLog()
	if err != nil {
		t.Fatalf("Unable to open change log: %s", err)
	}

	rec, err := hg_revlog.NodeIdRevSpec(revision).Lookup(cl)
	if err != nil {
		t.Errorf("Unable to get revision spec: %s", err)
	}

	fb := hg_revlog.NewFileBuilder()
	ce, err := hg_changelog.BuildEntry(rec, fb)
	if err != nil {
		t.Errorf("Unable to build entry: %s", err)
	}

	mlog, err := s.OpenManifests()
	if err != nil {
		t.Errorf("Unable to open manifest: %s", err)
	}

	rec2, err := mlog.LookupRevision(int(ce.Linkrev), ce.ManifestNode)
	if err != nil {
		t.Errorf("Unable to lookup revision: %s", err)
	}

	_, err = hg_store.BuildManifest(rec2, fb)
	if err != nil {
		t.Errorf("Unable to build manifest: %s", err)
	}
}
Пример #5
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)
		}
	}
}
Пример #6
0
// 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
}
Пример #7
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)
	}
}
Пример #8
0
func (fs *hgFSNative) readFile(rec *hg_revlog.Rec) ([]byte, error) {
	fb := hg_revlog.NewFileBuilder()
	return fb.Build(rec)
}