packed_refs_unlock(), packed_refs_is_locked(): new functions
Add two new public functions, `packed_refs_unlock()` and `packed_refs_is_locked()`, with which callers can manage and query the `packed-refs` lock externally. Call `packed_refs_unlock()` from `commit_packed_refs()` and `rollback_packed_refs()`. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 23, 2017 at 09:01 UTC
49aebcf4328d96bb984672213de76cd4c45197f2
2 files changed
+28
-6
refs/packed-backend.c
+25
-6
@@ -563,6 +563,29 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
563
return 0;
564
}
565
566
+void packed_refs_unlock(struct ref_store *ref_store)
567
+{
568
+ struct packed_ref_store *refs = packed_downcast(
569
+ ref_store,
570
+ REF_STORE_READ | REF_STORE_WRITE,
571
+ "packed_refs_unlock");
572
+
573
+ if (!is_lock_file_locked(&refs->lock))
574
+ die("BUG: packed_refs_unlock() called when not locked");
575
+ rollback_lock_file(&refs->lock);
576
+ release_packed_ref_cache(refs->cache);
577
+}
578
+
579
+int packed_refs_is_locked(struct ref_store *ref_store)
580
+{
581
+ struct packed_ref_store *refs = packed_downcast(
582
+ ref_store,
583
+ REF_STORE_READ | REF_STORE_WRITE,
584
+ "packed_refs_is_locked");
585
+
586
+ return is_lock_file_locked(&refs->lock);
587
+}
588
+
589
/*
590
* The packed-refs header line that we write out. Perhaps other
591
* traits will be added later. The trailing space is required.
@@ -649,8 +672,7 @@ error:
672
delete_tempfile(&refs->tempfile);
673
674
out:
652
- rollback_lock_file(&refs->lock);
653
- release_packed_ref_cache(packed_ref_cache);
675
+ packed_refs_unlock(ref_store);
676
return ret;
677
}
678
@@ -661,14 +683,11 @@ out:
683
*/
684
static void rollback_packed_refs(struct packed_ref_store *refs)
685
{
664
- struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
665
-
686
packed_assert_main_repository(refs, "rollback_packed_refs");
687
688
if (!is_lock_file_locked(&refs->lock))
689
die("BUG: packed-refs not locked");
670
- rollback_lock_file(&refs->lock);
671
- release_packed_ref_cache(packed_ref_cache);
690
+ packed_refs_unlock(&refs->base);
691
clear_packed_ref_cache(refs);
692
}
693
refs/packed-backend.h
+3
@@ -11,6 +11,9 @@ struct ref_store *packed_ref_store_create(const char *path,
11
*/
12
int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err);
13
14
+void packed_refs_unlock(struct ref_store *ref_store);
15
+int packed_refs_is_locked(struct ref_store *ref_store);
16
+
17
void add_packed_ref(struct ref_store *ref_store,
18
const char *refname, const struct object_id *oid);
19