List for cgit developers and users
 help / color / mirror / Atom feed
* Should remove-suffix=1 and scan-path work with non-bare repos?
@ 2014-12-13  8:41 cdrice
  2014-12-13 10:59 ` cgit
  2014-12-13 11:01 ` [PATCH] Remove trailing slash after remove-suffix cgit
  0 siblings, 2 replies; 6+ messages in thread
From: cdrice @ 2014-12-13  8:41 UTC (permalink / raw)


Hello!  New here to cgit.  Just built cgit-0.10.2 and was experimenting with features; noticed some unexpected behavior, and I believe I've narrowed it down to scan-path and remove-suffix with bare vs. non-bare repots. 

Given an /etc/cgitrc containing: 
remove-suffix=1 
scan-path=/tmp/testing 

and a non-bare repot /tmp/testing/blah/.git, I see unexpected behavior for the "blah" repot.  The repot is named "blah/" on the cgit index page (note trailing slash). The Summary page for "blah/" works as expected, but attempting to view any other data (refs, log, tree, etc), I receive a "No repositories found" error. 

If I disable remove-suffix in /etc/cgitrc, now I see "blah/.git" on the index page, and all subsequent pages work correctly (but of course the repot is named with the trailing .git, which I'd prefer to remove). 

If I re-enable remove-suffix, but now change the "blah" repo to a bare repo -- /tmp/testing/blah.git, I see the behavior I originally would have expected.  The index shows the repo as "blah", and all pages work when viewing blah. 

Should scanning + remove-suffix work with non-bare repots?  Please forgive me if I have missed something simple -- I've been scratching my head on this for a while.  Am I doing something silly or missing something in the documentation? 

Thanks - Chuck


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Should remove-suffix=1 and scan-path work with non-bare repos?
  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
  1 sibling, 0 replies; 6+ messages in thread
From: cgit @ 2014-12-13 10:59 UTC (permalink / raw)


On Sat, 13 Dec 2014 at 09:41:34, Charles Dee Rice wrote:
> [...]
> and a non-bare repot /tmp/testing/blah/.git, I see unexpected behavior for the "blah" repot.  The repot is named "blah/" on the cgit index page (note trailing slash). The Summary page for "blah/" works as expected, but attempting to view any other data (refs, log, tree, etc), I receive a "No repositories found" error. 
> [...]
> Should scanning + remove-suffix work with non-bare repots?  Please forgive me if I have missed something simple -- I've been scratching my head on this for a while.  Am I doing something silly or missing something in the documentation? 
> [...]

While the trailing slash is technically correct, it does not look nice
and does not match what we do in cgit_repobasename() -- so I consider
this a bug. Could be please try the patch I am going to send in a
second?

Regards,
Lukas


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Remove trailing slash after remove-suffix
  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 ` cgit
  2014-12-13 11:30   ` [PATCH v2] " cgit
  1 sibling, 1 reply; 6+ messages in thread
From: cgit @ 2014-12-13 11:01 UTC (permalink / raw)


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>
---
 scan-tree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scan-tree.c b/scan-tree.c
index 044bcdc..41e9264 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 (ctx.cfg.remove_suffix) {
 		if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
 			*p = '\0';
+		if (*(--p) == '/');
+			*p = '\0';
+	}
 	repo->path = xstrdup(path->buf);
 	while (!repo->owner) {
 		if ((pwd = getpwuid(st.st_uid)) == NULL) {
-- 
2.1.3



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Remove trailing slash after remove-suffix
  2014-12-13 11:01 ` [PATCH] Remove trailing slash after remove-suffix cgit
@ 2014-12-13 11:30   ` cgit
  2014-12-13 19:28     ` cdrice
  0 siblings, 1 reply; 6+ messages in thread
From: cgit @ 2014-12-13 11:30 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Remove trailing slash after remove-suffix
  2014-12-13 11:30   ` [PATCH v2] " cgit
@ 2014-12-13 19:28     ` cdrice
  2014-12-24  1:55       ` Jason
  0 siblings, 1 reply; 6+ messages in thread
From: cdrice @ 2014-12-13 19:28 UTC (permalink / raw)


Thank you so much for the quick reply!

> 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()). 

Version 1 would definitely cause some issues.  My brief testing confirmed it could cut off the last letter of the repot name for a bare repo -- "blah.git" became "bla".  It did work for non-bare repos, though -- "blah/.git" became "blah" and worked!  ;) 


Applying the latest version of Christian's git 2.2.0 patch from November + your version 2 looks like it works perfectly! 

I now see both bare and non-bare repos working with scanning and remove-suffix enabled.  All repo features (refs, log, tree, etc) work correctly in each case.


This really had me scratching my head -- I'm glad to see I wasn't doing something silly after all!   Thanks again! 


- Chuck


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Remove trailing slash after remove-suffix
  2014-12-13 19:28     ` cdrice
@ 2014-12-24  1:55       ` Jason
  0 siblings, 0 replies; 6+ messages in thread
From: Jason @ 2014-12-24  1:55 UTC (permalink / raw)


This is a good solution. Thanks for taking care of this Lukas. Merged.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20141223/b1d2b53e/attachment-0001.html>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-12-24  1:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` [PATCH v2] " cgit
2014-12-13 19:28     ` cdrice
2014-12-24  1:55       ` Jason

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).