summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2008-02-16 20:16:53 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-02-16 20:48:19 (UTC)
commitb88fb016d0209f7041ac7d3b4d2c077318407a4d (patch) (unidiff)
tree777e9cd042c3da9caaefe1f63363a52b56601521
parentd1f3bbe9d22029f45a77bb938c176ccc0c827d46 (diff)
downloadcgit-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>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c17
-rw-r--r--ui-shared.c2
2 files changed, 9 insertions, 10 deletions
diff --git a/cgit.c b/cgit.c
index b270fdc..2c933dc 100644
--- a/cgit.c
+++ b/cgit.c
@@ -80,26 +80,29 @@ char *find_default_branch(struct cgit_repo *repo)
80 80
81static void cgit_print_repo_page(struct cacheitem *item) 81static void cgit_print_repo_page(struct cacheitem *item)
82{ 82{
83 char *title, *tmp; 83 char *title, *tmp;
84 int show_search; 84 int show_search;
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();
94 return; 98 return;
95 } 99 }
96 100
97 title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); 101 title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc);
98 show_search = 0; 102 show_search = 0;
99 setenv("GIT_DIR", ctx.repo->path, 1);
100 103
101 if (!ctx.qry.head) { 104 if (!ctx.qry.head) {
102 ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); 105 ctx.qry.head = xstrdup(find_default_branch(ctx.repo));
103 ctx.repo->defbranch = ctx.qry.head; 106 ctx.repo->defbranch = ctx.qry.head;
104 } 107 }
105 108
@@ -176,16 +179,14 @@ static void cgit_print_repo_page(struct cacheitem *item)
176 } 179 }
177 cgit_print_docend(); 180 cgit_print_docend();
178} 181}
179 182
180static void cgit_fill_cache(struct cacheitem *item, int use_cache) 183static 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);
187 188
188 if (use_cache) { 189 if (use_cache) {
189 stdout2 = chk_positive(dup(STDOUT_FILENO), 190 stdout2 = chk_positive(dup(STDOUT_FILENO),
190 "Preserving STDOUT"); 191 "Preserving STDOUT");
191 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 192 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
@@ -200,14 +201,12 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache)
200 if (use_cache) { 201 if (use_cache) {
201 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); 202 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT");
202 chk_positive(dup2(stdout2, STDOUT_FILENO), 203 chk_positive(dup2(stdout2, STDOUT_FILENO),
203 "Restoring original STDOUT"); 204 "Restoring original STDOUT");
204 chk_zero(close(stdout2), "Closing temporary STDOUT"); 205 chk_zero(close(stdout2), "Closing temporary STDOUT");
205 } 206 }
206
207 chdir(buf);
208} 207}
209 208
210static void cgit_check_cache(struct cacheitem *item) 209static void cgit_check_cache(struct cacheitem *item)
211{ 210{
212 int i = 0; 211 int i = 0;
213 212
diff --git a/ui-shared.c b/ui-shared.c
index b9f487a..cc1ab8b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -473,13 +473,13 @@ void cgit_print_pageheader(char *title, int show_search)
473 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 473 html("<table class='sidebar' cellspacing='0' summary=''>\n");
474 html("<tr><td class='sidebar'>\n<a href='"); 474 html("<tr><td class='sidebar'>\n<a href='");
475 html_attr(cgit_rooturl()); 475 html_attr(cgit_rooturl());
476 htmlf("'><img src='%s' alt='cgit'/></a>\n", 476 htmlf("'><img src='%s' alt='cgit'/></a>\n",
477 ctx.cfg.logo); 477 ctx.cfg.logo);
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'>");
481 html_txt(strrpart(ctx.repo->name, 20)); 481 html_txt(strrpart(ctx.repo->name, 20));
482 html("</h1>\n"); 482 html("</h1>\n");
483 html_txt(ctx.repo->desc); 483 html_txt(ctx.repo->desc);
484 if (ctx.repo->owner) { 484 if (ctx.repo->owner) {
485 html("<h1>owner</h1>\n"); 485 html("<h1>owner</h1>\n");