git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 09/38] {lock,commit,rollback}_packed_refs(): add files_ref_store arguments

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Sep 4, 2016, 16:08 UTC
Message-ID
<d4f623a7fde1ccc7d3ab49f8f8bed8b1dddf1933.1473003903.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1473003902.git.mhagger@alum.mit.edu>

These functions currently only work in the main repository, so add an assert_main_repository() check to each function.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 refs/files-backend.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0c92ace..6913d45 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2215,14 +2215,14 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)
  * hold_lock_file_for_update(). Return 0 on success. On errors, set
  * errno appropriately and return a nonzero value.
  */
-static int lock_packed_refs(int flags)
+static int lock_packed_refs(struct files_ref_store *refs, int flags)
 {
-	struct files_ref_store *refs =
-		get_files_ref_store(NULL, "lock_packed_refs");
 	static int timeout_configured = 0;
 	static int timeout_value = 1000;
 	struct packed_ref_cache *packed_ref_cache;
 
+	assert_main_repository(&refs->base, "lock_packed_refs");
+
 	if (!timeout_configured) {
 		git_config_get_int("core.packedrefstimeout", &timeout_value);
 		timeout_configured = 1;
@@ -2251,16 +2251,16 @@ static int lock_packed_refs(int flags)
  * lock_packed_refs()). Return zero on success. On errors, set errno
  * and return a nonzero value
  */
-static int commit_packed_refs(void)
+static int commit_packed_refs(struct files_ref_store *refs)
 {
-	struct files_ref_store *refs =
-		get_files_ref_store(NULL, "commit_packed_refs");
 	struct packed_ref_cache *packed_ref_cache =
 		get_packed_ref_cache(refs);
 	int error = 0;
 	int save_errno = 0;
 	FILE *out;
 
+	assert_main_repository(&refs->base, "commit_packed_refs");
+
 	if (!packed_ref_cache->lock)
 		die("internal error: packed-refs not locked");
 
@@ -2287,13 +2287,13 @@ static int commit_packed_refs(void)
  * in-memory packed reference cache.  (The packed-refs file will be
  * read anew if it is needed again after this function is called.)
  */
-static void rollback_packed_refs(void)
+static void rollback_packed_refs(struct files_ref_store *refs)
 {
-	struct files_ref_store *refs =
-		get_files_ref_store(NULL, "rollback_packed_refs");
 	struct packed_ref_cache *packed_ref_cache =
 		get_packed_ref_cache(refs);
 
+	assert_main_repository(&refs->base, "rollback_packed_refs");
+
 	if (!packed_ref_cache->lock)
 		die("internal error: packed-refs not locked");
 	rollback_lock_file(packed_ref_cache->lock);
@@ -2439,13 +2439,13 @@ int pack_refs(unsigned int flags)
 	memset(&cbdata, 0, sizeof(cbdata));
 	cbdata.flags = flags;
 
-	lock_packed_refs(LOCK_DIE_ON_ERROR);
+	lock_packed_refs(refs, LOCK_DIE_ON_ERROR);
 	cbdata.packed_refs = get_packed_refs(refs);
 
 	do_for_each_entry_in_dir(get_loose_refs(refs), 0,
 				 pack_if_possible_fn, &cbdata);
 
-	if (commit_packed_refs())
+	if (commit_packed_refs(refs))
 		die_errno("unable to overwrite old ref-pack file");
 
 	prune_refs(cbdata.ref_to_prune);
@@ -2481,7 +2481,7 @@ static int repack_without_refs(struct string_list *refnames, struct strbuf *err)
 	if (!needs_repacking)
 		return 0; /* no refname exists in packed refs */
 
-	if (lock_packed_refs(0)) {
+	if (lock_packed_refs(refs, 0)) {
 		unable_to_lock_message(git_path("packed-refs"), errno, err);
 		return -1;
 	}
@@ -2496,12 +2496,12 @@ static int repack_without_refs(struct string_list *refnames, struct strbuf *err)
 		 * All packed entries disappeared while we were
 		 * acquiring the lock.
 		 */
-		rollback_packed_refs();
+		rollback_packed_refs(refs);
 		return 0;
 	}
 
 	/* Write what remains */
-	ret = commit_packed_refs();
+	ret = commit_packed_refs(refs);
 	if (ret)
 		strbuf_addf(err, "unable to overwrite old ref-pack file: %s",
 			    strerror(errno));
@@ -3929,7 +3929,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
 		}
 	}
 
-	if (lock_packed_refs(0)) {
+	if (lock_packed_refs(refs, 0)) {
 		strbuf_addf(err, "unable to lock packed-refs file: %s",
 			    strerror(errno));
 		ret = TRANSACTION_GENERIC_ERROR;
@@ -3944,7 +3944,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
 			add_packed_ref(refs, update->refname, update->new_sha1);
 	}
 
-	if (commit_packed_refs()) {
+	if (commit_packed_refs(refs)) {
 		strbuf_addf(err, "unable to commit packed-refs file: %s",
 			    strerror(errno));
 		ret = TRANSACTION_GENERIC_ERROR;
-- 
2.9.3
Previous: David TurnerNext: Michael Haggerty
Message 45 of 49 in “Virtualization of the refs API”
  1. 00/38 Virtualization of the refs APIMichael Haggerty, Sep 4, 2016
  2. 06/38 add_packed_ref(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  3. 02/38 rename_ref_available(): add docstringMichael Haggerty, Sep 4, 2016
  4. Jakub NarębskiSep 6, 2016
  5. Michael HaggertySep 7, 2016
  6. 01/38 resolve_gitlink_ref(): eliminate temporary variableMichael Haggerty, Sep 4, 2016
  7. 04/38 refs: add a backend method structureMichael Haggerty, Sep 4, 2016
  8. David TurnerSep 4, 2016
  9. 07/38 get_packed_ref(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  10. 14/38 read_raw_ref(): take a (struct ref_store *) argumentMichael Haggerty, Sep 4, 2016
  11. 10/38 refs: add a transaction_commit() methodMichael Haggerty, Sep 4, 2016
  12. 03/38 refs: rename struct ref_cache to files_ref_storeMichael Haggerty, Sep 4, 2016
  13. 16/38 resolve_gitlink_ref(): implement using resolve_ref_recursively()Michael Haggerty, Sep 4, 2016
  14. 18/38 resolve_gitlink_ref(): rename path parameter to submoduleMichael Haggerty, Sep 4, 2016
  15. 08/38 resolve_missing_loose_ref(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  16. 31/38 refs: add method iterator_beginMichael Haggerty, Sep 4, 2016
  17. 35/38 refs: add methods to init refs dbMichael Haggerty, Sep 4, 2016
  18. 38/38 refs: implement iteration over only per-worktree refsMichael Haggerty, Sep 4, 2016
  19. David TurnerSep 8, 2016
  20. 32/38 refs: add methods for reflogMichael Haggerty, Sep 4, 2016
  21. 33/38 refs: add method for initial ref transaction commitMichael Haggerty, Sep 4, 2016
  22. 29/38 split_symref_update(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  23. 37/38 refs: make lock genericMichael Haggerty, Sep 4, 2016
  24. 30/38 files_ref_iterator_begin(): take a ref_store argumentMichael Haggerty, Sep 4, 2016
  25. 22/38 refs: make create_symref() virtualMichael Haggerty, Sep 4, 2016
  26. 15/38 resolve_ref_recursively(): new functionMichael Haggerty, Sep 4, 2016
  27. 27/38 lock_ref_for_update(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  28. 36/38 refs: add method to rename refsMichael Haggerty, Sep 4, 2016
  29. 26/38 commit_ref_update(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  30. 28/38 lock_ref_sha1_basic(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  31. 34/38 refs: make delete_refs() virtualMichael Haggerty, Sep 4, 2016
  32. 12/38 resolve_packed_ref(): rename function from resolve_missing_loose_ref()Michael Haggerty, Sep 4, 2016
  33. 13/38 resolve_gitlink_packed_ref(): remove functionMichael Haggerty, Sep 4, 2016
  34. 19/38 refs: make read_raw_ref() virtualMichael Haggerty, Sep 4, 2016
  35. 25/38 lock_raw_ref(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  36. 11/38 refs: reorder definitionsMichael Haggerty, Sep 4, 2016
  37. 17/38 resolve_gitlink_ref(): avoid memory allocation in many casesMichael Haggerty, Sep 4, 2016
  38. 24/38 repack_without_refs(): add a files_ref_store argumentMichael Haggerty, Sep 4, 2016
  39. 20/38 refs: make verify_refname_available() virtualMichael Haggerty, Sep 4, 2016
  40. 05/38 refs: create a base class "ref_store" for files_ref_storeMichael Haggerty, Sep 4, 2016
  41. David TurnerSep 4, 2016
  42. Michael HaggertySep 5, 2016
  43. Stefan BellerSep 5, 2016
  44. David TurnerSep 5, 2016
  45. 09/38 {lock,commit,rollback}_packed_refs(): add files_ref_store argumentsMichael Haggerty, Sep 4, 2016
  46. 21/38 refs: make pack_refs() virtualMichael Haggerty, Sep 4, 2016
  47. 23/38 refs: make peel_ref() virtualMichael Haggerty, Sep 4, 2016
  48. Junio C HamanoSep 7, 2016
  49. Michael HaggertySep 8, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.