[utils] Refactor copy_attributes.