Ejemplo n.º 1
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)
	}
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
0
func (fs *hgFSNative) getModTime() (time.Time, error) {
	r, err := fs.at.Lookup(fs.cl)
	if err != nil {
		return time.Time{}, err
	}

	c, err := hg_changelog.BuildEntry(r, fs.fb)
	if err != nil {
		return time.Time{}, err
	}

	return c.Date, nil
}
Ejemplo n.º 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)
	}
}
Ejemplo n.º 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
}
Ejemplo n.º 6
0
func (fs *hgFSNative) getManifest(chgId hg_revlog.FileRevSpec) (m hg_store.Manifest, err error) {
	rec, err := chgId.Lookup(fs.cl)
	if err != nil {
		return
	}
	c, err := hg_changelog.BuildEntry(rec, fs.fb)
	if err != nil {
		return
	}

	// st := fs.repo.NewStore()
	mlog, err := fs.st.OpenManifests()
	if err != nil {
		return nil, err
	}

	rec2, err := mlog.LookupRevision(int(c.Linkrev), c.ManifestNode)
	if err != nil {
		return nil, err
	}

	return hg_store.BuildManifest(rec2, fs.fb)
}