Skip to content

Commit 49aebcf

Browse files
mhaggergitster
authored andcommitted
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>
1 parent c8bed83 commit 49aebcf

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

refs/packed-backend.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,29 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
563563
return 0;
564564
}
565565

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+
566589
/*
567590
* The packed-refs header line that we write out. Perhaps other
568591
* traits will be added later. The trailing space is required.
@@ -649,8 +672,7 @@ int commit_packed_refs(struct ref_store *ref_store, struct strbuf *err)
649672
delete_tempfile(&refs->tempfile);
650673

651674
out:
652-
rollback_lock_file(&refs->lock);
653-
release_packed_ref_cache(packed_ref_cache);
675+
packed_refs_unlock(ref_store);
654676
return ret;
655677
}
656678

@@ -661,14 +683,11 @@ int commit_packed_refs(struct ref_store *ref_store, struct strbuf *err)
661683
*/
662684
static void rollback_packed_refs(struct packed_ref_store *refs)
663685
{
664-
struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
665-
666686
packed_assert_main_repository(refs, "rollback_packed_refs");
667687

668688
if (!is_lock_file_locked(&refs->lock))
669689
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);
672691
clear_packed_ref_cache(refs);
673692
}
674693

refs/packed-backend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ struct ref_store *packed_ref_store_create(const char *path,
1111
*/
1212
int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err);
1313

14+
void packed_refs_unlock(struct ref_store *ref_store);
15+
int packed_refs_is_locked(struct ref_store *ref_store);
16+
1417
void add_packed_ref(struct ref_store *ref_store,
1518
const char *refname, const struct object_id *oid);
1619

0 commit comments

Comments
 (0)