List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] ui-shared: restrict to 15 levels
       [not found] <Leu8zHu--3-1@tuta.io>
@ 2019-05-20 19:55 ` Jason
  2019-05-20 22:05   ` john
  0 siblings, 1 reply; 2+ messages in thread
From: Jason @ 2019-05-20 19:55 UTC (permalink / raw)


Perhaps a more ideal version of this would be to not print breadcrumbs
at all for paths that don't exist in the given repo at the given oid.

Signed-off-by: Jason A. Donenfeld <Jason at zx2c4.com>
Reported-by: Fydor Wire Snark <wsnark at tuta.io>
---
I've committed this, and it works. But if anyone would like to give the
implementation a stab, I think a better approach might be simply
skipping printing of breadcrumbs in cases where the path doesn't exist
in the repo. This way we're not limited to some reasonable constant such
as 15.

 ui-shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ui-shared.c b/ui-shared.c
index d27a5fd..d2358f2 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -945,12 +945,13 @@ static void cgit_print_path_crumbs(char *path)
 {
 	char *old_path = ctx.qry.path;
 	char *p = path, *q, *end = path + strlen(path);
+	int levels = 0;
 
 	ctx.qry.path = NULL;
 	cgit_self_link("root", NULL, NULL);
 	ctx.qry.path = p = path;
 	while (p < end) {
-		if (!(q = strchr(p, '/')))
+		if (!(q = strchr(p, '/')) || levels > 15)
 			q = end;
 		*q = '\0';
 		html_txt("/");
@@ -958,6 +959,7 @@ static void cgit_print_path_crumbs(char *path)
 		if (q < end)
 			*q = '/';
 		p = q + 1;
+		++levels;
 	}
 	ctx.qry.path = old_path;
 }
-- 
2.21.0



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

* [PATCH] ui-shared: restrict to 15 levels
  2019-05-20 19:55 ` [PATCH] ui-shared: restrict to 15 levels Jason
@ 2019-05-20 22:05   ` john
  0 siblings, 0 replies; 2+ messages in thread
From: john @ 2019-05-20 22:05 UTC (permalink / raw)


On Mon, May 20, 2019 at 09:55:06PM +0200, Jason A. Donenfeld wrote:
> Perhaps a more ideal version of this would be to not print breadcrumbs
> at all for paths that don't exist in the given repo at the given oid.
> 
> Signed-off-by: Jason A. Donenfeld <Jason at zx2c4.com>
> Reported-by: Fydor Wire Snark <wsnark at tuta.io>
> ---
> I've committed this, and it works. But if anyone would like to give the
> implementation a stab, I think a better approach might be simply
> skipping printing of breadcrumbs in cases where the path doesn't exist
> in the repo. This way we're not limited to some reasonable constant such
> as 15.

That works for some pages, but I'm not sure it works in general (or at
least it's not always trivial to figure out if the path exists).

One example is ui-log, where it's perfectly reasonably to ask for the
log restricted to a path which doesn't exist in HEAD, and I'm not sure
at what point we decide that checking if the path exists at any point in
the history is more expensive than printing a long path here.

>  ui-shared.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/ui-shared.c b/ui-shared.c
> index d27a5fd..d2358f2 100644
> --- a/ui-shared.c
> +++ b/ui-shared.c
> @@ -945,12 +945,13 @@ static void cgit_print_path_crumbs(char *path)
>  {
>  	char *old_path = ctx.qry.path;
>  	char *p = path, *q, *end = path + strlen(path);
> +	int levels = 0;
>  
>  	ctx.qry.path = NULL;
>  	cgit_self_link("root", NULL, NULL);
>  	ctx.qry.path = p = path;
>  	while (p < end) {
> -		if (!(q = strchr(p, '/')))
> +		if (!(q = strchr(p, '/')) || levels > 15)
>  			q = end;
>  		*q = '\0';
>  		html_txt("/");
> @@ -958,6 +959,7 @@ static void cgit_print_path_crumbs(char *path)
>  		if (q < end)
>  			*q = '/';
>  		p = q + 1;
> +		++levels;
>  	}
>  	ctx.qry.path = old_path;
>  }
> -- 
> 2.21.0


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

end of thread, other threads:[~2019-05-20 22:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Leu8zHu--3-1@tuta.io>
2019-05-20 19:55 ` [PATCH] ui-shared: restrict to 15 levels Jason
2019-05-20 22:05   ` john

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