// Create a new version from another version. This will duplicate the version’s records
354743
func (self *Version) New(zoneId, version int64) (int64, error) {
	var res int64

	params := []interface{}{self.Key, zoneId, version}
	if err := self.Call("domain.zone.version.new", params, &res); err != nil {
		return -1, err
	}
	return res, nil
}
1271756
func (s *releasesService) Create(ctx context.Context, db *gorm.DB, r *Release) (*Release, error) {
	// Lock all releases for the given application to ensure that the
	// release version is updated automically.
	if err := db.Exec(`select 1 from releases where app_id = ? for update`, r.App.ID).Error; err != nil {
		return r, err
	}

	// During rollbacks, we can just provide the existing Formation for the
	// old release. For new releases, we need to create a new formation by
	// merging the formation from the extracted Procfile, and the Formation
	// from the existing release.
	if r.Formation == nil {
		if err := buildFormation(db, r); err != nil {
			return r, err
		}
	}

	return releasesCreate(db, r)
}
448688
func (connector *Connector) Clone(url string, version repositories.Version, destPath string) (repo repositories.Repository, err error) {
	var (
		out  bytes.Buffer
		args []string
	)
	if version.Branch == "" {
		version.Branch = "master"
	}
	if strings.HasPrefix(url, "git+") {
		url = url[len("git+"):]
	}
	// clone
	args = []string{"clone", "--branch", version.Branch, url, destPath}
	cmd := exec.Command("git", args...)
	cmd.Stdout = &out
	cmd.Stderr = &out
	if err = cmd.Run(); err != nil {
		return nil, fmt.Errorf("external git app fail %v: %v %v", args, err, string(out.Bytes()))
	}
	// checkout
	if version.Revision == "" {
		return &Repository{
			path: destPath,
		}, nil
	}
	args = []string{"checkout", version.Branch}
	cmd = exec.Command("git", args...)
	cmd.Dir = destPath
	cmd.Stdout = &out
	cmd.Stderr = &out
	if err = cmd.Run(); err != nil {
		return nil, fmt.Errorf("external git app fail %v: %v %v", args, err, string(out.Bytes()))
	}
	return &Repository{
		path: destPath,
	}, nil
}
101723
func (g *Git) Version(context.Context) semver.Version {
	return semver.Version{
		Major: 4,
		Build: []string{"go-git"},
	}
}
13994
func (c Collector) Clone() Collector {
	col := make(Collector)
	col.Copy(c)
	return col
}
1099098
func (records *Records) Create(ctx context.Context, record *Record) (err error) {
	buffer := new(bytes.Buffer)
	err = json.NewEncoder(buffer).Encode(record)
	if err != nil {
		return
	}
	response, err := httpDo(ctx, records.Options, "POST", apiURL("/zones/%s/dns_records", record.ZoneID), buffer)
	if err != nil {
		return
	}
	defer response.Body.Close()
	result, err := readResponse(response.Body)
	if err != nil {
		return
	}
	res := new(Record)
	err = json.Unmarshal(result.Result, &res)
	if err != nil {
		return
	}
	record.ID = res.ID
	record.TTL = res.TTL
	record.Locked = res.Locked
	record.Proxied = res.Proxied
	record.Proxiable = res.Proxiable
	record.CreatedOn = res.CreatedOn
	record.ModifiedOn = res.ModifiedOn
	return
}
624789
func Clone(from, to string, opts CloneRepoOptions) (err error) {
	toDir := path.Dir(to)
	if err = os.MkdirAll(toDir, os.ModePerm); err != nil {
		return err
	}

	cmd := NewCommand("clone")
	if opts.Mirror {
		cmd.AddArguments("--mirror")
	}
	if opts.Bare {
		cmd.AddArguments("--bare")
	}
	if opts.Quiet {
		cmd.AddArguments("--quiet")
	}
	if len(opts.Branch) > 0 {
		cmd.AddArguments("-b", opts.Branch)
	}
	cmd.AddArguments(from, to)

	if opts.Timeout <= 0 {
		opts.Timeout = -1
	}
	_, err = cmd.RunTimeout(opts.Timeout)
	return err
}
281787
func (s *Store) Version(context.Context) semver.Version {
	return semver.Version{Minor: 1}
}
1171390
func (c *Client) copy(ctx context.Context, version string) error {
	backupDir := path.Join(path.Dir(c.Path), "backup")
	if _, err := os.Stat(backupDir); os.IsNotExist(err) {
		if err = os.Mkdir(backupDir, 0700); err != nil {
			return err
		}
	} else if err != nil {
		return err
	}

	fromFile, err := os.Open(c.Path)
	if err != nil {
		return err
	}
	defer fromFile.Close()

	toName := fmt.Sprintf("%s.%s", path.Base(c.Path), version)
	toPath := path.Join(backupDir, toName)
	toFile, err := os.OpenFile(toPath, os.O_RDWR|os.O_CREATE, 0600)
	if err != nil {
		return err
	}
	defer toFile.Close()

	_, err = io.Copy(toFile, fromFile)
	if err != nil {
		return err
	}

	c.logger.Info("Successfully created ", toPath)

	return nil
}
989721
func (tree *MutableTree) SaveVersion() ([]byte, int64, error) {
	version := tree.version + 1

	if tree.versions[version] {
		//version already exists, throw an error if attempting to overwrite
		// Same hash means idempotent.  Return success.
		existingHash := tree.ndb.getRoot(version)
		var newHash = tree.WorkingHash()
		if bytes.Equal(existingHash, newHash) {
			tree.version = version
			tree.ImmutableTree = tree.ImmutableTree.clone()
			tree.lastSaved = tree.ImmutableTree.clone()
			tree.orphans = map[string]int64{}
			return existingHash, version, nil
		}
		return nil, version, fmt.Errorf("version %d was already saved to different hash %X (existing hash %X)",
			version, newHash, existingHash)
	}

	if tree.root == nil {
		// There can still be orphans, for example if the root is the node being
		// removed.
		debug("SAVE EMPTY TREE %v\n", version)
		tree.ndb.SaveOrphans(version, tree.orphans)
		tree.ndb.SaveEmptyRoot(version)
	} else {
		debug("SAVE TREE %v\n", version)
		// Save the current tree.
		tree.ndb.SaveBranch(tree.root)
		tree.ndb.SaveOrphans(version, tree.orphans)
		tree.ndb.SaveRoot(tree.root, version)
	}
	tree.ndb.Commit()
	tree.version = version
	tree.versions[version] = true

	// Set new working tree.
	tree.ImmutableTree = tree.ImmutableTree.clone()
	tree.lastSaved = tree.ImmutableTree.clone()
	tree.orphans = map[string]int64{}

	return tree.Hash(), version, nil
}
653100
func NewVersion(parent *Versions) *Version {
	version := &Version{parent: parent}
	version.Init()

	return version
}
1224300
func (p *plugins) clone() *plugins {
	np := &plugins{
		plugins:  make(map[Kind][]Plugin, len(p.plugins)),
		versions: make(map[string]uint16, len(p.versions)),
	}
	for key, value := range p.plugins {
		np.plugins[key] = append([]Plugin(nil), value...)
	}
	for key, value := range p.versions {
		np.versions[key] = value
	}
	for key, value := range p.dyingPlugins {
		np.dyingPlugins[key] = value
	}
	return np
}
180985
func Version(buildVer, buildDate, commitHash string) Option {
	return func(o *Options) {
		BuildVersion = buildVer
		BuildDate = buildDate
		CommitHash = commitHash
	}
}
1085168
func makeVersionFile(relPath string, versionFile pkg.VersionFile) (fs.File, error) {
	if !fs.IsCleanSlashPath(relPath) {
		return nil, fmt.Errorf("invalid version_file: %s", relPath)
	}
	blob, err := json.MarshalIndent(versionFile, "", "  ")
	if err != nil {
		return nil, err
	}
	return &blobFile{
		name: relPath,
		blob: blob,
	}, nil
}
395301
func (versions *Versions) NewVersion(createFromVersion *Version, useEtagStrict bool) *Version {
	if createFromVersion == nil {
		var err error
		createFromVersion, err = versions.GetLatestVersion("")
		if err != nil {
			return nil
		}
	}

	version := NewVersion(versions)
	version.CreateFromVersion = createFromVersion.PropertyVersion

	versions.Versions.Items = append(versions.Versions.Items, version)

	if useEtagStrict {
		version.CreateFromVersionEtag = createFromVersion.Etag
	}

	return version
}
349573
func (db *Database) clone() *Database {
	clone := &Database{
		connection:       db.connection,
		db:               db.db,
		rawRows:          db.rawRows,
		logger:           db.logger,
		cte:              db.cte,
		selectFields:     db.selectFields,
		order:            db.order,
		limit:            db.limit,
		offset:           db.offset,
		varCount:         db.varCount,
		connectionString: db.connectionString,
		listener:         db.listener,
	}

	clone.tables = make([]string, len(db.tables))
	copy(clone.tables, db.tables)

	clone.joinTables = make([]string, len(db.joinTables))
	copy(clone.joinTables, db.joinTables)

	clone.models = make([]DBModel, len(db.models))
	copy(clone.models, db.models)

	clone.cteSelectValues = make([]interface{}, len(db.cteSelectValues))
	copy(clone.cteSelectValues, db.cteSelectValues)

	clone.updateCreateValues = make([]interface{}, len(db.updateCreateValues))
	copy(clone.updateCreateValues, db.updateCreateValues)

	clone.updateCreateFields = make([]string, len(db.updateCreateFields))
	copy(clone.updateCreateFields, db.updateCreateFields)

	clone.whereValues = make([]interface{}, len(db.whereValues))
	copy(clone.whereValues, db.whereValues)

	clone.whereFields = make([]string, len(db.whereFields))
	copy(clone.whereFields, db.whereFields)

	return clone
}
1306031
func (g *BuildGenerator) Clone(ctx context.Context, request *buildv1.BuildRequest) (*buildv1.Build, error) {
	var build *buildv1.Build
	var err error

	for i := 0; i < conflictRetries; i++ {
		build, err = g.clone(ctx, request)
		if err == nil || !errors.IsConflict(err) {
			break
		}
		klog.V(4).Infof("clone returned conflict, try %d/%d", i+1, conflictRetries)
	}

	return build, err
}