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

[PATCH v2 08/29] get_packed_ref_cache(): take a `packed_ref_store *` parameter

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jun 23, 2017, 07:01 UTC
Message-ID
<9818ba3c290cafb21818a8fa2faee3aca08242c4.1498200513.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1498200513.git.mhagger@alum.mit.edu>
It only cares about the packed-refs part of the reference store.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs/files-backend.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index f061506bf0..b2ef7b3bb9 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -404,24 +404,22 @@ static void validate_packed_ref_cache(struct packed_ref_store *refs)
 }
 
 /*
- * Get the packed_ref_cache for the specified files_ref_store,
+ * Get the packed_ref_cache for the specified packed_ref_store,
  * creating and populating it if it hasn't been read before or if the
  * file has been changed (according to its `validity` field) since it
  * was last read. On the other hand, if we hold the lock, then assume
  * that the file hasn't been changed out from under us, so skip the
  * extra `stat()` call in `stat_validity_check()`.
  */
-static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
+static struct packed_ref_cache *get_packed_ref_cache(struct packed_ref_store *refs)
 {
-	const char *packed_refs_file = refs->packed_ref_store->path;
+	if (!is_lock_file_locked(&refs->lock))
+		validate_packed_ref_cache(refs);
 
-	if (!is_lock_file_locked(&refs->packed_ref_store->lock))
-		validate_packed_ref_cache(refs->packed_ref_store);
-
-	if (!refs->packed_ref_store->cache)
-		refs->packed_ref_store->cache = read_packed_refs(packed_refs_file);
+	if (!refs->cache)
+		refs->cache = read_packed_refs(refs->path);
 
-	return refs->packed_ref_store->cache;
+	return refs->cache;
 }
 
 static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_cache)
@@ -431,7 +429,7 @@ static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_ca
 
 static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
 {
-	return get_packed_ref_dir(get_packed_ref_cache(refs));
+	return get_packed_ref_dir(get_packed_ref_cache(refs->packed_ref_store));
 }
 
 /*
@@ -1151,7 +1149,7 @@ static struct ref_iterator *files_ref_iterator_begin(
 	loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
 					      prefix, 1);
 
-	iter->packed_ref_cache = get_packed_ref_cache(refs);
+	iter->packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
 	acquire_packed_ref_cache(iter->packed_ref_cache);
 	packed_iter = cache_ref_iterator_begin(iter->packed_ref_cache->cache,
 					       prefix, 0);
@@ -1365,7 +1363,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
 	 */
 	validate_packed_ref_cache(refs->packed_ref_store);
 
-	packed_ref_cache = get_packed_ref_cache(refs);
+	packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
 	/* Increment the reference count to prevent it from being freed: */
 	acquire_packed_ref_cache(packed_ref_cache);
 	return 0;
@@ -1380,7 +1378,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
 static int commit_packed_refs(struct files_ref_store *refs)
 {
 	struct packed_ref_cache *packed_ref_cache =
-		get_packed_ref_cache(refs);
+		get_packed_ref_cache(refs->packed_ref_store);
 	int ok, error = 0;
 	int save_errno = 0;
 	FILE *out;
@@ -1426,7 +1424,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
 static void rollback_packed_refs(struct files_ref_store *refs)
 {
 	struct packed_ref_cache *packed_ref_cache =
-		get_packed_ref_cache(refs);
+		get_packed_ref_cache(refs->packed_ref_store);
 
 	files_assert_main_repository(refs, "rollback_packed_refs");
 
-- 
2.11.0
Previous: Michael HaggertyNext: Jeff King
Message 46 of 52 in “Create a reference backend for packed refs”
  1. 00/29 Create a reference backend for packed refsMichael Haggerty, Jun 23, 2017
  2. 01/29 t1408: add a test of stale packed refs covered by loose refsMichael Haggerty, Jun 23, 2017
  3. Jeff KingJun 23, 2017
  4. Junio C HamanoJun 23, 2017
  5. 02/29 add_packed_ref(): teach function to overwrite existing refsMichael Haggerty, Jun 23, 2017
  6. 07/29 validate_packed_ref_cache(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  7. 05/29 packed_ref_store: move `packed_refs_lock` member hereMichael Haggerty, Jun 23, 2017
  8. 03/29 packed_ref_store: new structMichael Haggerty, Jun 23, 2017
  9. 09/29 get_packed_refs(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  10. 04/29 packed_ref_store: move `packed_refs_path` hereMichael Haggerty, Jun 23, 2017
  11. 13/29 rollback_packed_refs(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  12. 12/29 commit_packed_refs(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  13. 14/29 get_packed_ref(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  14. 06/29 clear_packed_ref_cache(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  15. 17/29 packed_ref_store: support iterationMichael Haggerty, Jun 23, 2017
  16. Jeff KingJun 23, 2017
  17. 16/29 packed_peel_ref(): new function, extracted from `files_peel_ref()`Michael Haggerty, Jun 23, 2017
  18. 19/29 packed-backend: new module for handling packed referencesMichael Haggerty, Jun 23, 2017
  19. Jeff KingJun 23, 2017
  20. Stefan BellerJun 23, 2017
  21. Junio C HamanoJun 23, 2017
  22. 20/29 packed_ref_store: make class into a subclass of `ref_store`Michael Haggerty, Jun 23, 2017
  23. Jeff KingJun 23, 2017
  24. 21/29 commit_packed_refs(): report errors rather than dyingMichael Haggerty, Jun 23, 2017
  25. 22/29 commit_packed_refs(): use a staging file separate from the lockfileMichael Haggerty, Jun 23, 2017
  26. Jeff KingJun 23, 2017
  27. Michael HaggertyJun 24, 2017
  28. Jeff KingJun 24, 2017
  29. 24/29 packed_refs_lock(): report errors via a `struct strbuf *err`Michael Haggerty, Jun 23, 2017
  30. 26/29 clear_packed_ref_cache(): don't protest if the lock is heldMichael Haggerty, Jun 23, 2017
  31. Jeff KingJun 23, 2017
  32. 25/29 packed_refs_unlock(), packed_refs_is_locked(): new functionsMichael Haggerty, Jun 23, 2017
  33. 23/29 packed_refs_lock(): function renamed from lock_packed_refs()Michael Haggerty, Jun 23, 2017
  34. 28/29 repack_without_refs(): don't lock or unlock the packed refsMichael Haggerty, Jun 23, 2017
  35. Jeff KingJun 23, 2017
  36. Michael HaggertyJul 1, 2017
  37. 27/29 commit_packed_refs(): remove call to `packed_refs_unlock()`Michael Haggerty, Jun 23, 2017
  38. Jeff KingJun 23, 2017
  39. 29/29 read_packed_refs(): die if `packed-refs` contains bogus dataMichael Haggerty, Jun 23, 2017
  40. Jeff KingJun 23, 2017
  41. Michael HaggertyJul 1, 2017
  42. 11/29 lock_packed_refs(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  43. 10/29 add_packed_ref(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  44. 15/29 repack_without_refs(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  45. 18/29 packed_read_raw_ref(): new function, replacing `resolve_packed_ref()`Michael Haggerty, Jun 23, 2017
  46. 08/29 get_packed_ref_cache(): take a `packed_ref_store *` parameterMichael Haggerty, Jun 23, 2017
  47. Jeff KingJun 23, 2017
  48. Jeff KingJun 23, 2017
  49. Junio C HamanoJun 23, 2017
  50. Jeff KingJun 24, 2017
  51. Michael HaggertyJun 24, 2017
  52. Junio C HamanoJun 23, 2017

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.