List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] Regression fix: Make section-from-path=-1 work again
@ 2013-04-16 14:10 plenz
  2013-04-16 14:30 ` john
  0 siblings, 1 reply; 6+ messages in thread
From: plenz @ 2013-04-16 14:10 UTC (permalink / raw)


This fixes a regression introduced in commit fb3655df, "use struct
strbuf instead of static buffers":

> The pattern there is to append the filename, use it and then reset
> the buffer to its original length (retaining a trailing '/').

This makes the "count slashes from end of string" fail. My workaround is
to start counting only before the trailing slash.

Signed-off-by: Julius Plenz <plenz at cis.fu-berlin.de>
---
 scan-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scan-tree.c b/scan-tree.c
index beb584b..53f949b 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -158,7 +158,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
 			while (slash && n && (slash = strchr(slash, '/')))
 				n--;
 		} else {
-			slash = rel.buf + rel.len;
+			slash = rel.buf + rel.len - 2;
 			while (slash && n && (slash = xstrrchr(rel.buf, slash, '/')))
 				n++;
 		}
-- 
1.8.2.1-zedat





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

* [PATCH] Regression fix: Make section-from-path=-1 work again
  2013-04-16 14:10 [PATCH] Regression fix: Make section-from-path=-1 work again plenz
@ 2013-04-16 14:30 ` john
  2013-04-16 14:50   ` plenz
  0 siblings, 1 reply; 6+ messages in thread
From: john @ 2013-04-16 14:30 UTC (permalink / raw)


On Tue, Apr 16, 2013 at 04:10:46PM +0200, Julius Plenz wrote:
> This fixes a regression introduced in commit fb3655df, "use struct
> strbuf instead of static buffers":
> 
> > The pattern there is to append the filename, use it and then reset
> > the buffer to its original length (retaining a trailing '/').
> 
> This makes the "count slashes from end of string" fail. My workaround is
> to start counting only before the trailing slash.

This is the "rel" buffer, not "path" so I think it would be better to
just strip any trailing slash from "rel" when it is assigned.  This has
the benefit of also making sure we don't have a trailing '/' in the
section name.

What do you think?




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

* [PATCH] Regression fix: Make section-from-path=-1 work again
  2013-04-16 14:30 ` john
@ 2013-04-16 14:50   ` plenz
  2013-04-16 17:39     ` john
  0 siblings, 1 reply; 6+ messages in thread
From: plenz @ 2013-04-16 14:50 UTC (permalink / raw)


Hi, John!

* John Keeping <john at keeping.me.uk> [2013-04-16 16:30]:
> This is the "rel" buffer, not "path" so I think it would be better
> to just strip any trailing slash from "rel" when it is assigned.
> This has the benefit of also making sure we don't have a trailing
> '/' in the section name.

Sure, that sounds better. I didn't really spend much time with your
new code. If you supply a patch I'll try it in my installation.

Thanks,

Julius




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

* [PATCH] Regression fix: Make section-from-path=-1 work again
  2013-04-16 14:50   ` plenz
@ 2013-04-16 17:39     ` john
  2013-04-17 11:38       ` plenz
  0 siblings, 1 reply; 6+ messages in thread
From: john @ 2013-04-16 17:39 UTC (permalink / raw)


From 1e4ddf8174341e6caa281d007a7e269183b9aca8 Mon Sep 17 00:00:00 2001
Message-Id: <1e4ddf8174341e6caa281d007a7e269183b9aca8.1366133788.git.john at keeping.me.uk>
From: John Keeping <john at keeping.me.uk>
Date: Tue, 16 Apr 2013 18:33:25 +0100
Subject: [PATCH] scan-tree: fix "section-from-path = -N"

Commit fb3655d (use struct strbuf instead of static buffers -
2013-04-06) introduced a regression in the "section-from-path" handling
when the configured value is negative.  By changing the "rel" variable
so that it includes a trailing slash, counting slashes from the end of
the string no longer gives the same answer as it did before.

Fix this by ensuring that "rel" does not have a trailing slash.

Reported-by: Julius Plenz <plenz at cis.fu-berlin.de>
Signed-off-by: John Keeping <john at keeping.me.uk>
---
On Tue, Apr 16, 2013 at 04:50:32PM +0200, Julius Plenz wrote:
> * John Keeping <john at keeping.me.uk> [2013-04-16 16:30]:
> > This is the "rel" buffer, not "path" so I think it would be better
> > to just strip any trailing slash from "rel" when it is assigned.
> > This has the benefit of also making sure we don't have a trailing
> > '/' in the section name.
> 
> Sure, that sounds better. I didn't really spend much time with your
> new code. If you supply a patch I'll try it in my installation.

I was hoping you might want to re-roll your patch taking that
approach... ;-)

It would be nice to have a test covering this, but to do it well I think
we should built a bit more CGit-specific test infrastructure, which is
more work that I want to do at the moment.

 scan-tree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scan-tree.c b/scan-tree.c
index beb584b..a1ec8fb 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -113,6 +113,8 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
 
 	if (!strcmp(rel.buf + rel.len - 5, "/.git"))
 		strbuf_setlen(&rel, rel.len - 5);
+	else if (rel.len && rel.buf[rel.len - 1] == '/')
+		strbuf_setlen(&rel, rel.len - 1);
 
 	repo = cgit_add_repo(rel.buf);
 	config_fn = fn;
-- 
1.8.2.694.ga76e9c3.dirty





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

* [PATCH] Regression fix: Make section-from-path=-1 work again
  2013-04-16 17:39     ` john
@ 2013-04-17 11:38       ` plenz
  2013-04-17 11:41         ` Jason
  0 siblings, 1 reply; 6+ messages in thread
From: plenz @ 2013-04-17 11:38 UTC (permalink / raw)


Hi, John!

* John Keeping <john at keeping.me.uk> [2013-04-16 19:43]:
> I was hoping you might want to re-roll your patch taking that
> approach... ;-)

I was already wading through that code for some hours, trying to
rebase my twenty or so patches onto the wip branch, which gave me a
lot of merge conflicts... so... :-/

I tested your solution, and it works just as well and is much cleaner,
of course. Thanks!

Julius




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

* [PATCH] Regression fix: Make section-from-path=-1 work again
  2013-04-17 11:38       ` plenz
@ 2013-04-17 11:41         ` Jason
  0 siblings, 0 replies; 6+ messages in thread
From: Jason @ 2013-04-17 11:41 UTC (permalink / raw)


Applied to wip:

http://git.zx2c4.com/cgit/commit/?h=wip&id=9a725f4f0991710336584bb284a83dcf5fa5bf1e



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

end of thread, other threads:[~2013-04-17 11:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-16 14:10 [PATCH] Regression fix: Make section-from-path=-1 work again plenz
2013-04-16 14:30 ` john
2013-04-16 14:50   ` plenz
2013-04-16 17:39     ` john
2013-04-17 11:38       ` plenz
2013-04-17 11:41         ` 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).