commit_ref_update(): new function, extracted from write_ref_sha1()