// merge combines the versioned secret account bundle and the visible account bundle into
// a stellar1.AccountBundle for local use.
544072
func merge(secret stellar1.BundleSecretV2, visible stellar1.BundleVisibleV2) (stellar1.Bundle, error) {
	if len(secret.Accounts) != len(visible.Accounts) {
		return stellar1.Bundle{}, errors.New("invalid bundle, mismatched number of visible and secret accounts")
	}
	accounts := convertVisibleAccounts(visible.Accounts)

	// these should be in the same order
	for i, secretAccount := range secret.Accounts {
		if accounts[i].AccountID != secretAccount.AccountID {
			return stellar1.Bundle{}, errors.New("invalid bundle, mismatched order of visible and secret accounts")
		}
		accounts[i].Name = secretAccount.Name
	}
	return stellar1.Bundle{
		Revision: visible.Revision,
		Prev:     visible.Prev,
		Accounts: accounts,
	}, nil
}
881579
func (e MapElement) Merge(v Strategy) (Result, error) {
	return v.MergeMap(e)
}
1176805
func Merge(values ...Value) (Value, error) {
	var args []string
	for _, value := range values {
		args = append(args, value.String())
	}
	return Parse(args...)
}
720748
func (s *StringValue) Merge(onto *string) {
	if s.v != nil {
		*onto = *(s.v)
	}
}
1060725
func (c *ServiceClient) merge(ops *operations) {
	for _, s := range ops.regServices {
		c.services[s.ID] = s
	}
	for _, check := range ops.regChecks {
		c.checks[check.ID] = check
	}
	for _, s := range ops.scripts {
		c.scripts[s.id] = s
	}
	for _, sid := range ops.deregServices {
		delete(c.services, sid)
	}
	for _, cid := range ops.deregChecks {
		if script, ok := c.runningScripts[cid]; ok {
			script.cancel()
			delete(c.scripts, cid)
			delete(c.runningScripts, cid)
		}
		delete(c.checks, cid)
	}
	metrics.SetGauge([]string{"client", "consul", "services"}, float32(len(c.services)))
	metrics.SetGauge([]string{"client", "consul", "checks"}, float32(len(c.checks)))
	metrics.SetGauge([]string{"client", "consul", "script_checks"}, float32(len(c.runningScripts)))
}
894482
func (state *ServicesState) Merge(otherState *ServicesState) {
	for _, server := range otherState.Servers {
		for _, service := range server.Services {
			state.ServiceMsgs <- *service
		}
	}
}
731805
func (iid *ImageID) Merge(new *ImageID) error {
	if new.Host != "" {
		iid.Host = new.Host
	}
	if new.Port != 0 {
		iid.Port = new.Port
	}
	if new.User != "" {
		iid.User = new.User
	}
	if new.Repo != "" {
		iid.Repo = new.Repo
	}
	if new.Tag != "" {
		iid.Tag = new.Tag
	}
	return nil
}
208209
func (d *DesiredTransition) Merge(o *DesiredTransition) {
	if o.Migrate != nil {
		d.Migrate = o.Migrate
	}

	if o.Reschedule != nil {
		d.Reschedule = o.Reschedule
	}

	if o.ForceReschedule != nil {
		d.ForceReschedule = o.ForceReschedule
	}
}
58025
func (nf *nonFatal) Merge(err error) (ok bool) {
	if err == nil {
		return true // not an error
	}
	if !isNonFatal(err) {
		return false // fatal error
	}
	if nf.E == nil {
		nf.E = err // store first instance of non-fatal error
	}
	return true
}
24515
func (h *Header) Merge(h2 *Header) (*Header, error) {
	if h2 == nil {
		return nil, errors.New("merge target is nil")
	}

	h3 := NewHeader()
	if err := h3.Copy(h); err != nil {
		return nil, errors.Wrap(err, "failed to copy header values")
	}

	h3.EssentialHeader.Merge(h2.EssentialHeader)

	for k, v := range h2.PrivateParams {
		h3.PrivateParams[k] = v
	}

	return h3, nil
}
136483
func (v *Values) Merge(key Key, other *Values) bool {
	v.lock.Lock()
	defer v.lock.Unlock()

	changed := false
	other.EachKeyValue(func(otherKey Key, value interface{}) {
		actualKey := key.Append(otherKey)
		changed = v.put(actualKey, value) || changed
	})
	return changed
}
873972
func (w *machineUnitsWatcher) merge(pending []string, unitName string) (new []string, err error) {
	doc := unitDoc{}
	newUnits, closer := w.db.GetCollection(unitsC)
	defer closer()
	err = newUnits.FindId(unitName).One(&doc)
	if err != nil && err != mgo.ErrNotFound {
		return nil, errors.Trace(err)
	}
	if err == mgo.ErrNotFound || doc.Principal == "" && (doc.MachineId == "" || doc.MachineId != w.machine.doc.Id) {
		// We always pass the unitName because the document may be deleted, and thus not have a name on the object
		pending, err := w.removeWatchedUnit(unitName, doc, pending)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return pending, nil
	}
	life, known := w.known[unitName]
	if !known {
		return nil, errors.Errorf("merge() called with an unknown document: %q", doc.DocID)
	}
	if life != doc.Life && !hasString(pending, doc.Name) {
		logger.Tracef("machineUnitsWatcher found life changed to %q => %q for %q", life, doc.Life, doc.Name)
		pending = append(pending, doc.Name)
	}
	w.known[doc.Name] = doc.Life
	unknownSubordinates := set.NewStrings()
	for _, subunitName := range doc.Subordinates {
		if _, ok := w.known[subunitName]; !ok {
			unknownSubordinates.Add(subunitName)
		}
	}
	if !unknownSubordinates.IsEmpty() {
		pending, err = w.watchNewUnits(unknownSubordinates.Values(), pending, nil)
		if err != nil {
			return nil, errors.Trace(err)
		}
	}
	return pending, nil
}
799112
func (entry *Entry) Merge(merge *Entry) {
	for name, value := range merge.fields {
		entry.SetField(name, value)
	}
}
635811
func (c *Cell) Merge(hcells, vcells int) {
	c.HMerge = hcells
	c.VMerge = vcells
}
400622
func Merge(e1, e2 interface{}) error {
	if e1 == nil && e2 == nil {
		return nil
	}
	if e1 != nil && e2 == nil {
		return newError(e1, 2)
	}
	if e1 == nil && e2 != nil {
		return newError(e2, 2)
	}
	switch val := e2.(type) {
	case *Error:
		if val == nil {
			return newm(e1)
		}
		prev := val
		for err := val.next; err != nil; err = err.next {
			prev = err
		}
		prev.next = newm(e1)
		return val
	case error:
		if val == nil {
			return newm(e1)
		}
		prev := newError(val, 2).(*Error)
		prev.next = newm(e1)
		return prev
	case string:
		if val == "" {
			return newm(e1)
		}
		prev := newError(val, 2).(*Error)
		prev.next = newm(e1)
		return prev
	default:
		panic("invalid type")
	}
	//panic("¯|_(ツ)_/¯")
}
639256
func (e *ErrorRate) Merge(rate *ErrorRate) {
	e.QueryTotal += rate.QueryTotal
	e.ErrorTotal += rate.ErrorTotal
}
226212
func (c Config) Merge(cfg []Config) (config Config) {

	if len(cfg) > 0 {
		config = cfg[0]
		mergo.Merge(&config, c)
	} else {
		_default := c
		config = _default
	}

	return
}