author | Lars Hjemli <hjemli@gmail.com> | 2008-02-16 20:16:53 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-02-16 20:48:19 (UTC) |
commit | b88fb016d0209f7041ac7d3b4d2c077318407a4d (patch) (unidiff) | |
tree | 777e9cd042c3da9caaefe1f63363a52b56601521 | |
parent | d1f3bbe9d22029f45a77bb938c176ccc0c827d46 (diff) | |
download | cgit-b88fb016d0209f7041ac7d3b4d2c077318407a4d.zip cgit-b88fb016d0209f7041ac7d3b4d2c077318407a4d.tar.gz cgit-b88fb016d0209f7041ac7d3b4d2c077318407a4d.tar.bz2 |
Improve initialization of git directory
Using the functions offered by libgit feels like the right thing to do. Also,
make sure that config errors gets properly reported.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 17 | ||||
-rw-r--r-- | ui-shared.c | 2 |
2 files changed, 9 insertions, 10 deletions
@@ -85,9 +85,13 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
85 | unsigned char sha1[20]; | 85 | unsigned char sha1[20]; |
86 | int nongit = 0; | ||
86 | 87 | ||
87 | if (chdir(ctx.repo->path)) { | 88 | setenv("GIT_DIR", ctx.repo->path, 1); |
88 | title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); | 89 | setup_git_directory_gently(&nongit); |
90 | if (nongit) { | ||
91 | title = fmt("%s - %s", ctx.cfg.root_title, "config error"); | ||
92 | tmp = fmt("Not a git repository: '%s'", ctx.repo->path); | ||
93 | ctx.repo = NULL; | ||
89 | cgit_print_docstart(title, item); | 94 | cgit_print_docstart(title, item); |
90 | cgit_print_pageheader(title, 0); | 95 | cgit_print_pageheader(title, 0); |
91 | cgit_print_error(fmt("Unable to scan repository: %s", | 96 | cgit_print_error(tmp); |
92 | strerror(errno))); | ||
93 | cgit_print_docend(); | 97 | cgit_print_docend(); |
@@ -98,3 +102,2 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
98 | show_search = 0; | 102 | show_search = 0; |
99 | setenv("GIT_DIR", ctx.repo->path, 1); | ||
100 | 103 | ||
@@ -181,6 +184,4 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) | |||
181 | { | 184 | { |
182 | static char buf[PATH_MAX]; | ||
183 | int stdout2; | 185 | int stdout2; |
184 | 186 | ||
185 | getcwd(buf, sizeof(buf)); | ||
186 | item->st.st_mtime = time(NULL); | 187 | item->st.st_mtime = time(NULL); |
@@ -205,4 +206,2 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) | |||
205 | } | 206 | } |
206 | |||
207 | chdir(buf); | ||
208 | } | 207 | } |
diff --git a/ui-shared.c b/ui-shared.c index b9f487a..cc1ab8b 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -478,3 +478,3 @@ void cgit_print_pageheader(char *title, int show_search) | |||
478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); | 478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); |
479 | if (ctx.qry.repo) { | 479 | if (ctx.repo) { |
480 | html("<h1 class='first'>"); | 480 | html("<h1 class='first'>"); |