[PATCH] Regression fix: Make section-from-path=-1 work again
john at keeping.me.uk
Tue Apr 16 19:39:58 CEST 2013
>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
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
@@ -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;
More information about the CGit