code: func SaveBuild(c context.Context, b *buildbot.Build) (replaced bool, err error) {
  	bs, err := summarizeBuild(c, b)
  	if err != nil {
  		err = errors.Annotate(err, "summarizing build").Err()
  		return
  	}
  
  	err = datastore.RunInTransaction(c, func(c context.Context) error {
  		existingBS := &model.BuildSummary{
  			BuildKey: bs.BuildKey,
  		}
  		existing := &buildEntity{
  			Master:      b.Master,
  			Buildername: b.Buildername,
  			Number:      b.Number,
  		}
  
  		if err := datastore.Get(c, existing, existingBS); err == nil {
  			// they both exist
  			replaced = true
  
  			if bs.Version < existingBS.Version {
  				return errors.Reason("Imported version older than existing (%d < %d)", bs.Version, existingBS.Version).Tag(ImportRejectedTag).Err()
  			} else if bs.Version == existingBS.Version {
  				return nil // idempotency
  			}
  		} else {
  			me := err.(errors.MultiError)
  			// one of the errors was NSE; bail.
  			for _, ierr := range me {
  				if ierr != nil && ierr != datastore.ErrNoSuchEntity {
  					return errors.Annotate(ierr, "getting existing build summary").Err()
  				}
  			}
  
  			// One or the other was NES; don't care, just record both entries to get
  			// up to date.
  		}
  
  		if err := datastore.Put(c, (*buildEntity)(b), bs); err != nil {
  			return err
  		}
  
  		return model.UpdateBuilderForBuild(c, bs)
  	}, &datastore.TransactionOptions{XG: true})
  	return
  }
docs: // SaveBuild persists the build in the storage.
  //
  // This will also update the model.BuildSummary and model.BuilderSummary.