public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH] clean cached refs when calling set_git_dir()
@ 2011-03-10 15:19 Julius Plenz
  2011-03-10 15:59 ` Nguyen Thai Ngoc Duy
  0 siblings, 1 reply; 4+ messages in thread
From: Julius Plenz @ 2011-03-10 15:19 UTC (permalink / raw)
  To: git; +Cc: Julius Plenz

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-10 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-10 15:19 [PATCH] clean cached refs when calling set_git_dir() Julius Plenz
2011-03-10 15:59 ` Nguyen Thai Ngoc Duy
2011-03-10 16:09   ` Julius Plenz
2011-03-10 17:14     ` Lars Hjemli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox