* [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
* Re: [PATCH] clean cached refs when calling set_git_dir()
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
0 siblings, 1 reply; 4+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2011-03-10 15:59 UTC (permalink / raw)
To: Julius Plenz; +Cc: git
On Thu, Mar 10, 2011 at 10:19 PM, Julius Plenz <plenz@cis.fu-berlin.de> wrote:
> 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.
If you use libgit.a to do anything on more than one repository, you
get a lot more messed up that just that. Spawning a new process or
accessing with libgit2 may be safer. Why do you want to do that in the
first place?
--
Duy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] clean cached refs when calling set_git_dir()
2011-03-10 15:59 ` Nguyen Thai Ngoc Duy
@ 2011-03-10 16:09 ` Julius Plenz
2011-03-10 17:14 ` Lars Hjemli
0 siblings, 1 reply; 4+ messages in thread
From: Julius Plenz @ 2011-03-10 16:09 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: git
Hi!
* Nguyen Thai Ngoc Duy <pclouds@gmail.com> [2011-03-10 17:00]:
> On Thu, Mar 10, 2011 at 10:19 PM, Julius Plenz <plenz@cis.fu-berlin.de> wrote:
> > 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.
>
> If you use libgit.a to do anything on more than one repository, you
> get a lot more messed up that just that. Spawning a new process or
> accessing with libgit2 may be safer. Why do you want to do that in the
> first place?
I was working on the cgit repository browser, where you have to peek
into several repositories to create the overview page. Since cgit
links to libgit.a I fixed the bug there. Not sure if that's the proper
way to do it, though...
Julius
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] clean cached refs when calling set_git_dir()
2011-03-10 16:09 ` Julius Plenz
@ 2011-03-10 17:14 ` Lars Hjemli
0 siblings, 0 replies; 4+ messages in thread
From: Lars Hjemli @ 2011-03-10 17:14 UTC (permalink / raw)
To: Julius Plenz; +Cc: Nguyen Thai Ngoc Duy, git, cgit
On Thu, Mar 10, 2011 at 17:09, Julius Plenz <plenz@cis.fu-berlin.de> wrote:
> * Nguyen Thai Ngoc Duy <pclouds@gmail.com> [2011-03-10 17:00]:
>> On Thu, Mar 10, 2011 at 10:19 PM, Julius Plenz <plenz@cis.fu-berlin.de> wrote:
>> > 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.
>>
>> If you use libgit.a to do anything on more than one repository, you
>> get a lot more messed up that just that. Spawning a new process or
>> accessing with libgit2 may be safer. Why do you want to do that in the
>> first place?
>
> I was working on the cgit repository browser, where you have to peek
> into several repositories to create the overview page. Since cgit
> links to libgit.a I fixed the bug there. Not sure if that's the proper
> way to do it, though...
I never got around to answer your earlier email about this, but here
is what I would have said ;)
Since libgit.a doesn't work with multiple repos [1], cgit supports the
use of an "agefile" (that's the option name in cgitrc) to obtain the
last commit-date per repo.
The content of such an agefile can be generated by a command like the
following in one (or more) of your git hooks:
git for-each-ref --sort=-authordate --format='%(authordate:iso8601)' --count=1
Hth.
--
larsh
[1] Even if libgit.a did support working with multiple repos in a
single run, I probably would avoid this particular usage since it is
bound to perform badly when lots of repos are involved (like on
cgit.freedesktop.org), and even more so when the list is sorted by
idle-time. Simply reading a small textfile per repo is much faster.
^ permalink raw reply [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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.