Diff options
-rw-r--r--source/cache.c15
-rw-r--r--source/shared.c6
-rw-r--r--source/shared.h1
3 files changed, 12 insertions, 10 deletions
diff --git a/source/cache.c b/source/cache.c
index 004a84d..6317a12 100644
--- a/source/cache.c
+++ b/source/cache.c
@@ -12,7 +12,6 @@
#include "cache.h"
#include "cgit.h"
#include "html.h"
-#include "shared.h"
#include <sys/file.h>
#ifdef HAVE_LINUX_SENDFILE
#include <sys/sendfile.h>
@@ -493,6 +492,16 @@ unsigned long cache_hash_str(const char *str)
return h;
}
+/*
+ * Unlike git's strbuf_complete, an empty path gains the slash too, so an empty
+ * cache-root keeps its slots under / rather than in the working directory.
+ */
+static void end_with_slash(struct strbuf *path)
+{
+ if (!path->len || path->buf[path->len - 1] != '/')
+ strbuf_addch(path, '/');
+}
+
int cache_process(int size, const char *path, const char *key, int ttl, size_t max_bytes,
cache_fill_fn fn)
{
@@ -515,7 +524,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, size_t m
}
hash = cache_hash_str(key) % size;
strbuf_addstr(&slot_path, path);
- strbuf_ensure_end(&slot_path, '/');
+ end_with_slash(&slot_path);
for (i = 0; i < SLOT_NAME_LEN; i++) {
strbuf_addf(&slot_path, "%x", (unsigned char)(hash & 0xf));
hash >>= 4;
@@ -559,7 +568,7 @@ void cache_ls(const char *path)
return;
}
strbuf_addstr(&slot_path, path);
- strbuf_ensure_end(&slot_path, '/');
+ end_with_slash(&slot_path);
prefixlen = slot_path.len;
while ((ent = readdir(dir))) {
char mtime[64] = "-";
diff --git a/source/shared.c b/source/shared.c
index 72ec2d1..e3d2e58 100644
--- a/source/shared.c
+++ b/source/shared.c
@@ -204,12 +204,6 @@ char *cgit_trim_end(const char *str, char c)
return xstrndup(str, len);
}
-void strbuf_ensure_end(struct strbuf *sb, char c)
-{
- if (!sb->len || sb->buf[sb->len - 1] != c)
- strbuf_addch(sb, c);
-}
-
void cgit_free_taginfo(struct taginfo *info)
{
// NULL is accepted because cgit_parse_tag returns it for a tag object
diff --git a/source/shared.h b/source/shared.h
index 909f9f2..4f015e7 100644
--- a/source/shared.h
+++ b/source/shared.h
@@ -70,7 +70,6 @@ extern void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *
* Copy str without its trailing runs of c, returning NULL if nothing is left.
*/
extern char *cgit_trim_end(const char *str, char c);
-extern void strbuf_ensure_end(struct strbuf *sb, char c);
/*
* Read the first line of a file into a newly allocated, zero terminated