branch.c: use ref transaction for all ref updates
commitd43f990fac72264c1553beb7dbc6e8e795083d42
authorRonnie Sahlberg <sahlberg@google.com>
Wed, 16 Apr 2014 23:21:53 +0000 (16 16:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Sep 2014 17:04:13 +0000 (3 10:04 -0700)
tree50444f39e8722dce38c4b8961e4aac9c3de2933e
parentde7e86f522ea806ef40b3c9557e040d4109e55fb
branch.c: use ref transaction for all ref updates

Change create_branch to use a ref transaction when creating the new branch.

This also fixes a race condition in the old code where two concurrent
create_branch could race since the lock_any_ref_for_update/write_ref_sha1
did not protect against the ref already existing. I.e. one thread could end up
overwriting a branch even if the forcing flag is false.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c