[PATCH v2] Remove trailing slash after remove-suffix

Lukas Fleischer cgit at cryptocrack.de
Sat Dec 13 12:30:51 CET 2014


When removing the ".git" suffix of a non-bare repository, also remove
the trailing slash for compatibility with cgit_repobasename().

Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
The previous version had a flaw (bogus pointer if there is no ".git"
suffix). This one is much more readable add should be applied on top of
the Git 2.2.0 patch (which adds strip_suffix() and strip_suffix_mem()).

 scan-tree.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/scan-tree.c b/scan-tree.c
index 044bcdc..e900ad9 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -123,9 +123,12 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
 		strbuf_setlen(path, pathlen);
 	}
 
-	if (ctx.cfg.remove_suffix)
-		if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
-			*p = '\0';
+	if (ctx.cfg.remove_suffix) {
+		size_t urllen;
+		strip_suffix(repo->url, ".git", &urllen);
+		strip_suffix_mem(repo->url, &urllen, "/");
+		repo->url[urllen] = '\0';
+	}
 	repo->path = xstrdup(path->buf);
 	while (!repo->owner) {
 		if ((pwd = getpwuid(st.st_uid)) == NULL) {
-- 
2.1.3



More information about the CGit mailing list