aboutsummaryrefslogtreecommitdiffstats
path: root/ui-repolist.c
diff options
context:
space:
mode:
authorGravatar John Keeping <john@keeping.me.uk>2013-04-06 18:28:57 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2013-04-08 23:12:52 (JST)
commitfb3655df3bf85bd405c5921bbd4b3a54c705c839 (patch)
tree419a962a0b82f5ba3023791549044ff462229250 /ui-repolist.c
parent42d5476f258e7909682f1b611da00d64507d45c6 (diff)
downloadcgit-fb3655df3bf85bd405c5921bbd4b3a54c705c839.zip
cgit-fb3655df3bf85bd405c5921bbd4b3a54c705c839.tar.gz
use struct strbuf instead of static buffers
Use "struct strbuf" from Git to remove the limit on file path length. Notes on scan-tree: This is slightly involved since I decided to pass the strbuf into add_repo() and modify if whenever a new file name is required, which should avoid any extra allocations within that function. The pattern there is to append the filename, use it and then reset the buffer to its original length (retaining a trailing '/'). Notes on ui-snapshot: Since write_archive modifies the argv array passed to it we copy the argv_array values into a new array of char* and then free the original argv_array structure and the new array without worrying about what the values now look like. Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'ui-repolist.c')
-rw-r--r--ui-repolist.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/ui-repolist.c b/ui-repolist.c
index 76fe71a..47ca997 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -33,7 +33,7 @@ static time_t read_agefile(char *path)
33 33
34static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) 34static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
35{ 35{
36 char *path; 36 struct strbuf path = STRBUF_INIT;
37 struct stat s; 37 struct stat s;
38 struct cgit_repo *r = (struct cgit_repo *)repo; 38 struct cgit_repo *r = (struct cgit_repo *)repo;
39 39
@@ -41,32 +41,36 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
41 *mtime = repo->mtime; 41 *mtime = repo->mtime;
42 return 1; 42 return 1;
43 } 43 }
44 path = fmt("%s/%s", repo->path, ctx.cfg.agefile); 44 strbuf_addf(&path, "%s/%s", repo->path, ctx.cfg.agefile);
45 if (stat(path, &s) == 0) { 45 if (stat(path.buf, &s) == 0) {
46 *mtime = read_agefile(path); 46 *mtime = read_agefile(path.buf);
47 if (*mtime) { 47 if (*mtime) {
48 r->mtime = *mtime; 48 r->mtime = *mtime;
49 return 1; 49 goto end;
50 } 50 }
51 } 51 }
52 52
53 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch ? 53 strbuf_reset(&path);
54 repo->defbranch : "master"); 54 strbuf_addf(&path, "%s/refs/heads/%s", repo->path,
55 if (stat(path, &s) == 0) { 55 repo->defbranch ? repo->defbranch : "master");
56 if (stat(path.buf, &s) == 0) {
56 *mtime = s.st_mtime; 57 *mtime = s.st_mtime;
57 r->mtime = *mtime; 58 r->mtime = *mtime;
58 return 1; 59 goto end;
59 } 60 }
60 61
61 path = fmt("%s/%s", repo->path, "packed-refs"); 62 strbuf_reset(&path);
62 if (stat(path, &s) == 0) { 63 strbuf_addf(&path, "%s/%s", repo->path, "packed-refs");
64 if (stat(path.buf, &s) == 0) {
63 *mtime = s.st_mtime; 65 *mtime = s.st_mtime;
64 r->mtime = *mtime; 66 r->mtime = *mtime;
65 return 1; 67 goto end;
66 } 68 }
67 69
68 *mtime = 0; 70 *mtime = 0;
69 r->mtime = *mtime; 71 r->mtime = *mtime;
72end:
73 strbuf_release(&path);
70 return (r->mtime != 0); 74 return (r->mtime != 0);
71} 75}
72 76