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

[PATCH] clean cached refs when calling set_git_dir()

From
JPJulius Plenz <plenz@cis.fu-berlin.de>
Date
Mar 10, 2011, 15:19 UTC
Message-ID
<1299770345-32055-1-git-send-email-plenz@cis.fu-berlin.de>

If you use libgit.a to perform reference resolutions on two or more repositories that contain packed refs, cached_refs will store the packed refs for the first repository to contain a packed-refs file only.

Subsequent calls to get_packed_refs() will return the *cached* list, even when you changed to a different repository with set_git_dir(). Thus, references will almost certainly resolve to non-existent commits.

The patch explicitly invalidates the cached list when calling set_git_dir() which calls setup_git_env().

Signed-off-by: Julius Plenz <plenz@cis.fu-berlin.de>
---
 cache.h       |    1 +
 environment.c |    1 +
 refs.c        |    2 +-
 3 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/cache.h b/cache.h
index 08a9022..95491fe 100644
--- a/cache.h
+++ b/cache.h
@@ -881,6 +881,7 @@ extern int check_leading_path(const char *name, int len);
 extern int has_dirs_only_path(const char *name, int len, int prefix_len);
 extern void schedule_dir_for_removal(const char *name, int len);
 extern void remove_scheduled_dirs(void);
+extern void invalidate_cached_refs(void);
 
 extern struct alternate_object_database {
 	struct alternate_object_database *next;
diff --git a/environment.c b/environment.c
index 9564475..3a7e1dc 100644
--- a/environment.c
+++ b/environment.c
@@ -110,6 +110,7 @@ static void setup_git_env(void)
 		git_graft_file = git_pathdup("info/grafts");
 	if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
 		read_replace_refs = 0;
+	invalidate_cached_refs();
 }
 
 int is_bare_repository(void)
diff --git a/refs.c b/refs.c
index e3c0511..bbe34fb 100644
--- a/refs.c
+++ b/refs.c
@@ -171,7 +171,7 @@ static void free_ref_list(struct ref_list *list)
 	}
 }
 
-static void invalidate_cached_refs(void)
+void invalidate_cached_refs(void)
 {
 	struct cached_refs *ca = &cached_refs;
 
-- 
1.7.3.1
Next: Nguyen Thai Ngoc Duy
Message 1 of 4 in “clean cached refs when calling set_git_dir()”
  1. clean cached refs when calling set_git_dir()Julius Plenz, Mar 10, 2011
  2. Nguyen Thai Ngoc DuyMar 10, 2011
  3. Julius PlenzMar 10, 2011
  4. Lars HjemliMar 10, 2011

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.