From 0270083ded143fd49841e3d3d0cac5eb06081d2a Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 3 Jul 2006 22:48:03 +0200 Subject: Make it possible to set up libgit directly (instead of from the environment) This introduces a setup_git() function which is essentialy a (public) backend for setup_git_env() which lets anyone specify custom sources for the various paths instead of environment variables. Since the repositories may get switched on the fly, this also updates code that caches paths to invalidate them properly; I hope neither of those is a sweet spot. It is used by Git.xs' xs__call_gate() to set up per-repository data for libgit's consumption. No code actually takes advantage of it yet but get_object() will in the next patches. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- commit.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index e51ffa1c6c..17f51c2455 100644 --- a/commit.c +++ b/commit.c @@ -163,6 +163,14 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups) return 0; } +void free_commit_grafts(void) +{ + int pos = commit_graft_nr; + while (pos >= 0) + free(commit_graft[pos--]); + commit_graft_nr = 0; +} + struct commit_graft *read_graft_line(char *buf, int len) { /* The format is just "Commit Parent1 Parent2 ...\n" */ @@ -215,11 +223,18 @@ int read_graft_file(const char *graft_file) static void prepare_commit_graft(void) { static int commit_graft_prepared; - char *graft_file; + static char *last_graft_file; + char *graft_file = get_graft_file(); + + if (last_graft_file) { + if (!strcmp(graft_file, last_graft_file)) + return; + free_commit_grafts(); + } + if (last_graft_file) + free(last_graft_file); + last_graft_file = strdup(graft_file); - if (commit_graft_prepared) - return; - graft_file = get_graft_file(); read_graft_file(graft_file); commit_graft_prepared = 1; } -- cgit v1.2.3