summaryrefslogtreecommitdiff
path: root/refs/packed-backend.h
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2017-09-08 13:51:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-09-08 18:18:04 (GMT)
commitdc39e099422b1d44f6230f557f94f7945c7521a7 (patch)
tree271d38ca5d049ce7a3976c875e577a2fd18c7bfb /refs/packed-backend.h
parent6a2a7736d867dac39f2c54833fd0a65107c7cc5b (diff)
downloadgit-dc39e099422b1d44f6230f557f94f7945c7521a7.zip
git-dc39e099422b1d44f6230f557f94f7945c7521a7.tar.gz
git-dc39e099422b1d44f6230f557f94f7945c7521a7.tar.bz2
files_ref_store: use a transaction to update packed refs
When processing a `files_ref_store` transaction, it is sometimes necessary to delete some references from the "packed-refs" file. Do that using a reference transaction conducted against the `packed_ref_store`. This change further decouples `files_ref_store` from `packed_ref_store`. It also fixes multiple problems, including the two revealed by test cases added in the previous commit. First, the old code didn't obtain the `packed-refs` lock until `files_transaction_finish()`. This means that a failure to acquire the `packed-refs` lock (e.g., due to contention with another process) wasn't detected until it was too late (problems like this are supposed to be detected in the "prepare" phase). The new code acquires the `packed-refs` lock in `files_transaction_prepare()`, the same stage of the processing when the loose reference locks are being acquired, removing another reason why the "prepare" phase might succeed and the "finish" phase might nevertheless fail. Second, the old code deleted the loose version of a reference before deleting any packed version of the same reference. This left a moment when another process might think that the packed version of the reference is current, which is incorrect. (Even worse, the packed version of the reference can be arbitrarily old, and might even point at an object that has since been garbage-collected.) Third, if a reference deletion fails to acquire the `packed-refs` lock altogether, then the old code might leave the repository in the incorrect state (possibly corrupt) described in the previous paragraph. Now we activate the new "packed-refs" file (sans any references that are being deleted) *before* deleting the corresponding loose references. But we hold the "packed-refs" lock until after the loose references have been finalized, thus preventing a simultaneous "pack-refs" process from packing the loose version of the reference in the time gap, which would otherwise defeat our attempt to delete it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs/packed-backend.h')
0 files changed, 0 insertions, 0 deletions