Skip to content
  • Brad King's avatar
    refs: add update_refs for multiple simultaneous updates · 98aee92d
    Brad King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Add 'struct ref_update' to encode the information needed to update or
    delete a ref (name, new sha1, optional old sha1, no-deref flag).  Add
    function 'update_refs' accepting an array of updates to perform.  First
    sort the input array to order locks consistently everywhere and reject
    multiple updates to the same ref.  Then acquire locks on all refs with
    verified old values.  Then update or delete all refs accordingly.  Fail
    if any one lock cannot be obtained or any one old value does not match.
    
    Though the refs themselves cannot be modified together in a single
    atomic transaction, this function does enable some useful semantics.
    For example, a caller may create a new branch starting from the head of
    another branch and rewind the original branch at the same time.  This
    transfers ownership of commits between branches without risk of losing
    commits added to the original branch by a concurrent process, or risk of
    a concurrent process creating the new branch first.
    
    Signed-off-by: default avatarBrad King <brad.king@kitware.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    98aee92d