List for cgit developers and users
 help / color / mirror / Atom feed
From: cgit at cryptocrack.de (Lukas Fleischer)
Subject: [PATCH v2] Remove trailing slash after remove-suffix
Date: Sat, 13 Dec 2014 12:30:51 +0100	[thread overview]
Message-ID: <1418470251-7909-1-git-send-email-cgit@cryptocrack.de> (raw)
In-Reply-To: <1418468482-7056-1-git-send-email-cgit@cryptocrack.de>

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



  reply	other threads:[~2014-12-13 11:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-13  8:41 Should remove-suffix=1 and scan-path work with non-bare repos? cdrice
2014-12-13 10:59 ` cgit
2014-12-13 11:01 ` [PATCH] Remove trailing slash after remove-suffix cgit
2014-12-13 11:30   ` cgit [this message]
2014-12-13 19:28     ` [PATCH v2] " cdrice
2014-12-24  1:55       ` Jason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418470251-7909-1-git-send-email-cgit@cryptocrack.de \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).