bundle: split out ref writing from bundle_create