Re: [PATCH 1/1] ui-repolist: remove unused variable

2017-07-26 Thread Lukas Fleischer
On Tue, 06 Jun 2017 at 16:14:47, Christian Hesse wrote:
> From: Christian Hesse 
> 
> Signed-off-by: Christian Hesse 
> ---
>  ui-repolist.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/ui-repolist.c b/ui-repolist.c
> index 20a4f56..7272e87 100644
> --- a/ui-repolist.c
> +++ b/ui-repolist.c
> @@ -225,7 +225,6 @@ static int sort_section(const void *a, const void *b)
> const struct cgit_repo *r1 = a;
> const struct cgit_repo *r2 = b;
> int result;
> -   time_t t;
> [...]

Looks good to me. I already posted pretty much the same patch (and
queued it on lf/for-jason) back in April, though [1].

Jason, any chance you can go through our for-jason branches and merge
them anytime soon?

Regards,
Lukas

[1] https://lists.zx2c4.com/pipermail/cgit/2017-April/003532.html
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Remove unused variable from sort_section()

2017-04-08 Thread Lukas Fleischer
On Wed, 05 Apr 2017 at 12:28:28, Jason A. Donenfeld wrote:
> Looks good to me.

Queued on lf/for-jason.
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Remove unused variable from sort_section()

2017-04-04 Thread Lukas Fleischer
Signed-off-by: Lukas Fleischer <lfleisc...@lfos.de>
---
 ui-repolist.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/ui-repolist.c b/ui-repolist.c
index 20a4f56..7272e87 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -225,7 +225,6 @@ static int sort_section(const void *a, const void *b)
const struct cgit_repo *r1 = a;
const struct cgit_repo *r2 = b;
int result;
-   time_t t;
 
result = cmp(r1->section, r2->section);
if (!result) {
-- 
2.12.2

___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] ui-patch: fix segfault when a path prefix is passed

2017-01-23 Thread Lukas Fleischer
On Sun, 22 Jan 2017 at 23:45:01, Jason A. Donenfeld wrote:
> Nice catch, thanks.
> 
> Merged.

Note that I had a similar patch submitted to the mailing list about two
months ago [1] and queued up in lf/for-jason as you told me back then.

Could you check whether the additional changes I have in my version of
the patch are worth applying on top of what we now have in master?

Regards,
Lukas

[1] https://lists.zx2c4.com/pipermail/cgit/2016-November/003431.html
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Fix crash when using path limit

2016-11-24 Thread Lukas Fleischer
The array passed to setup_revisions() must be NULL-terminated. Fixes a
regression introduced in 455b598 (ui-patch.c: Use log_tree_commit() to
generate diffs, 2013-08-20).

Reported-by: Florian Pritz <bluew...@xinu.at>
Signed-off-by: Lukas Fleischer <lfleisc...@lfos.de>
---
 ui-patch.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/ui-patch.c b/ui-patch.c
index ec7f352..047e2f9 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -18,8 +18,8 @@ void cgit_print_patch(const char *new_rev, const char 
*old_rev,
struct commit *commit;
struct object_id new_rev_oid, old_rev_oid;
char rev_range[2 * 40 + 3];
-   const char *rev_argv[] = { NULL, "--reverse", "--format=email", 
rev_range, "--", prefix };
-   int rev_argc = ARRAY_SIZE(rev_argv);
+   const char *rev_argv[] = { NULL, "--reverse", "--format=email", 
rev_range, "--", prefix, NULL };
+   int rev_argc = ARRAY_SIZE(rev_argv) - 1;
char *patchname;
 
if (!prefix)
@@ -85,8 +85,7 @@ void cgit_print_patch(const char *new_rev, const char 
*old_rev,
DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY;
if (prefix)
rev.diffopt.stat_sep = fmt("(limited to '%s')\n\n", prefix);
-   setup_revisions(ARRAY_SIZE(rev_argv), rev_argv, ,
-   NULL);
+   setup_revisions(rev_argc, rev_argv, , NULL);
prepare_revision_walk();
 
while ((commit = get_revision()) != NULL) {
-- 
2.10.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: RFC: don't cache objects larger than X

2016-10-17 Thread Lukas Fleischer
On Wed, 12 Oct 2016 at 13:22:34, Jason A. Donenfeld wrote:
> I face this same problem, in fact. Unless somebody beats me to it, I'd
> be interested in giving this a stab.
> 
> One issue is that cache entries are currently "streamed" into the
> cache files, as they're produced. It's not trivially possible to know
> how big it's going to be beforehand. This means that the best we could
> do would be to just immediately unlink it after creation and printing.
> Would this be acceptable?

It is not easy to compute the exact size of the generated page but we
are able to detect huge objects before streaming -- the size of the
object is already returned by read_sha1_file().

I wonder whether the max-blob-size setting already does what you want,
though? It does not only affect the cached version but it seems better
to prevent from generating such huge pages in the first place. If you
really want to offer such files to your users, the max_blob_size check
in print_object() might be a good place to add the "print but do not
cache large files" functionality.

Regards,
Lukas
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Use skip_prefix() to get rid of magic constants

2016-10-08 Thread Lukas Fleischer
Signed-off-by: Lukas Fleischer <lfleisc...@lfos.de>
---
 cgit.c  | 56 ++--
 scan-tree.c |  6 --
 2 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/cgit.c b/cgit.c
index 2f29aa6..bc05f1e 100644
--- a/cgit.c
+++ b/cgit.c
@@ -31,6 +31,7 @@ static void process_cached_repolist(const char *path);
 
 static void repo_config(struct cgit_repo *repo, const char *name, const char 
*value)
 {
+   const char *path;
struct string_list_item *item;
 
if (!strcmp(name, "name"))
@@ -73,8 +74,8 @@ static void repo_config(struct cgit_repo *repo, const char 
*name, const char *va
repo->max_stats = cgit_find_stats_period(value, NULL);
else if (!strcmp(name, "module-link"))
repo->module_link= xstrdup(value);
-   else if (starts_with(name, "module-link.")) {
-   item = string_list_append(>submodules, xstrdup(name + 
12));
+   else if (skip_prefix(name, "module-link.", )) {
+   item = string_list_append(>submodules, xstrdup(path));
item->util = xstrdup(value);
} else if (!strcmp(name, "section"))
repo->section = xstrdup(value);
@@ -106,14 +107,16 @@ static void repo_config(struct cgit_repo *repo, const 
char *name, const char *va
 
 static void config_cb(const char *name, const char *value)
 {
+   const char *arg;
+
if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
ctx.cfg.section = xstrdup(value);
else if (!strcmp(name, "repo.url"))
ctx.repo = cgit_add_repo(value);
else if (ctx.repo && !strcmp(name, "repo.path"))
ctx.repo->path = trim_end(value, '/');
-   else if (ctx.repo && starts_with(name, "repo."))
-   repo_config(ctx.repo, name + 5, value);
+   else if (ctx.repo && skip_prefix(name, "repo.", ))
+   repo_config(ctx.repo, arg, value);
else if (!strcmp(name, "readme"))
string_list_append(, xstrdup(value));
else if (!strcmp(name, "root-title"))
@@ -280,8 +283,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.branch_sort = 1;
if (!strcmp(value, "name"))
ctx.cfg.branch_sort = 0;
-   } else if (starts_with(name, "mimetype."))
-   add_mimetype(name + 9, value);
+   } else if (skip_prefix(name, "mimetype.", ))
+   add_mimetype(arg, value);
else if (!strcmp(name, "include"))
parse_configfile(expand_macros(value), config_cb);
 }
@@ -470,13 +473,13 @@ static char *find_default_branch(struct cgit_repo *repo)
 
 static char *guess_defbranch(void)
 {
-   const char *ref;
+   const char *ref, *refname;
unsigned char sha1[20];
 
ref = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
-   if (!ref || !starts_with(ref, "refs/heads/"))
+   if (!ref || !skip_prefix(ref, "refs/heads/", ))
return "master";
-   return xstrdup(ref + 11);
+   return xstrdup(refname);
 }
 /* The caller must free filename and ref after calling this. */
 static inline void parse_readme(const char *readme, char **filename, char 
**ref, struct cgit_repo *repo)
@@ -937,6 +940,7 @@ out:
 static void cgit_parse_args(int argc, const char **argv)
 {
int i;
+   const char *arg;
int scan = 0;
 
for (i = 1; i < argc; i++) {
@@ -957,28 +961,28 @@ static void cgit_parse_args(int argc, const char **argv)
 
exit(0);
}
-   if (starts_with(argv[i], "--cache=")) {
-   ctx.cfg.cache_root = xstrdup(argv[i] + 8);
+   if (skip_prefix(argv[i], "--cache=", )) {
+   ctx.cfg.cache_root = xstrdup(arg);
} else if (!strcmp(argv[i], "--nocache")) {
ctx.cfg.nocache = 1;
} else if (!strcmp(argv[i], "--nohttp")) {
ctx.env.no_http = "1";
-   } else if (starts_with(argv[i], "--query=")) {
-   ctx.qry.raw = xstrdup(argv[i] + 8);
-   } else if (starts_with(argv[i], "--repo=")) {
-   ctx.qry.repo = xstrdup(argv[i] + 7);
-   } else if (starts_with(argv[i], "--page=")) {
-   ctx.qry.page = xstrdup(argv[i] + 7);
-   } else if (starts_with(argv[i], "--head=")) {
-   ctx.qry.head = xstrdup(argv[i] + 7);
+   } else if (skip_prefix(argv[i], &quo

Re: [PATCH] Avoid ambiguities when prettifying snapshot names

2016-07-02 Thread Lukas Fleischer
On Tue, 24 May 2016 at 18:15:18, Lukas Fleischer wrote:
> When composing snapshot file names for a tag with a prefix of the form
> v[0-9] (resp. V[0-9]), the leading "v" (resp. "V") is stripped. This
> leads to conflicts if a tag with the stripped name already exists or if
> there are tags only differing in the capitalization of the leading "v".
> Make sure we do not strip the "v" in these cases.
> 
> Reported-by: Juuso Lapinlampi <w...@partyvan.eu>
> Signed-off-by: Lukas Fleischer <lfleisc...@lfos.de>
> ---
> Note: The code that actually generates the snapshots works fine as it
> always tries an exact match first.
> 
>  ui-refs.c   | 24 +---
>  ui-shared.c | 26 +-
>  ui-shared.h |  2 ++
>  3 files changed, 32 insertions(+), 20 deletions(-)

Any comments on this?
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: Snapshot: Customize filename and remove obligatory folder

2015-11-13 Thread Lukas Fleischer
On Mon, 09 Nov 2015 at 13:11:51, Alexander Nitsche - e-pixler NEW MEDIA GmbH 
wrote:
> It would be nice to be able to
> 
> a) customize the automatically generated snapshot filename. In general
> it is {repository_name}-{branch}.zip. I - for integrity reasons - need
> to be able to say that the filename should be {filename_xy}.zip without
> the branch and a different name than the repo name. In my particular
> case this is for constraints of the CMS system Typo3.
> [...]

You should be able to achieve this by telling your web server to
redirect the URI to the path that cgit uses.

> b) remove the obligatory parent folder from the snapshot: e.g. if the
> tree structure of the git project "my_typo3_extension" is
> ---
> /classes/
> /resources/
> /configuration/
> ext_emconf.php
> ext_tables.php
> ..
> ---
> then the snapshot zip file looks like
> ---
> /my_typo3_extension
>   /classes/
>   /resources/
>   /configuration/
>   ext_emconf.php
>   ext_tables.php
>   ..
> ---
> but i need the snapshot to be without the parent folder
> "my_typo3_extension" - for Typo3 constraints again.
> [...]

I don't think this is currently possible but patching cgit to support
that should be fairly easy. Have a look at the prefix variable/parameter
in ui-snapshot.c.

Regards,
Lukas
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Customize cgit for the AUR

2015-06-04 Thread Lukas Fleischer
On Thu, 04 Jun 2015 at 13:32:41, Lukas Fleischer wrote:
 From: Lukas Fleischer lfleisc...@archlinux.org
 
 * Mention AUR and the package base in the title.
 * Remove the branch switch form.
 * Do not show any commit decorations.
 * Do not show branches on the summary page.
 * Drop link to the refs page.
 * Use proper Git clone URLs.
 
 Signed-off-by: Lukas Fleischer lfleisc...@archlinux.org
 ---
  ui-commit.c  |  1 -
  ui-log.c |  1 -
  ui-shared.c  | 28 +++-
  ui-summary.c |  2 --
  4 files changed, 7 insertions(+), 25 deletions(-)
 [...]

Sorry for submitting this here. This is obviously the wrong mailing
list...
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Add an option to disable the branch switch form

2015-05-31 Thread Lukas Fleischer
On Sat, 07 Feb 2015 at 17:33:36, Lukas Fleischer wrote:
 Introduce a configuration option enable-switch-form that is enabled by
 default and can be used to disable the branch quick switch form in the
 top-right corner of repository pages.
 
 Rationale: For repositories with a huge number of branches, the code
 generated for the switch form might become so large that it dominates
 the size of the HTTP response. For example, at the time of writing this
 commit message, the HTTP body of the Arch Linux community.git cgit index
 at https://projects.archlinux.org/svntogit/community.git/ has a size of
 228KB. Removing the form shrinks the size to only 12KB.
 
 Signed-off-by: Lukas Fleischer c...@cryptocrack.de
 ---
 I am not totally happy with the name but I did not come up with anything
 more expressive that is short enough at the same time. Suggestions
 welcome!
 [...]

Starting from next week, I am going to maintain another cgit setup where
this patch is needed. Any chance this will make it into mainline?

I am also open to other suggestions. Maybe a (configurable) limit for
the number of entries in the branch switcher?

Right now, cgit is unusable with a huge number of branches.

Regards,
Lukas
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Check SHA256 sum of git-$VER.tar.gz after downloading

2015-03-07 Thread Lukas Fleischer
On Sat, 07 Mar 2015 at 18:02:59, John Keeping wrote:
 [...]
 I'm not sure what benefit it has if it's optional.  Will anyone check?
 
 Maybe we could do something like:
 
 if type sha256sum /dev/null 21
 then
 sha256sum --check git.sha256sum $(GIT_FILE)
 else
 echo 2 'WARNING: sha256sum not found so we cannot verify'
 echo 2 'WARNING: the integrity of the Git archive!'
 fi
 

That is exactly what I meant by suggesting to make it optional. Sorry
for being vague...

  On a related note, can we download a signature and use `gpg --verify`
  instead (should probably be optional as well, to avoid a dependency on
  GnuPG)?
 
 I thought about that, but we'd have to embed a key with CGit for it to
 work reliably and how do we choose what key to use (given that
 individual Git archives are not signed - the list of SHA256 checksums
 is)?
 

Huh? This works fine for me:

$ gpg --recv-keys 96AFE6CB 
gpg: key 713660A7: public key Junio C Hamano gits...@pobox.com imported
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: Total number processed: 1
gpg:   imported: 1
$ curl -OO 
https://www.kernel.org/pub/software/scm/git/git-2.3.2.tar.{xz,sign} 
  % Total% Received % Xferd  Average Speed   TimeTime Time  
Current
 Dload  Upload   Total   SpentLeft  
Speed
100 3529k  100 3529k0 0  1133k  0  0:00:03  0:00:03 --:--:-- 
1133k
100   543  100   5430 0   3404  0 --:--:-- --:--:-- --:--:--  
3404
$ unxz git-2.3.2.tar.xz
$ gpg --verify git-2.3.2.tar.sign 
gpg: assuming signed data in 'git-2.3.2.tar'
gpg: Signature made Sat 07 Mar 2015 12:10:41 AM CET using RSA key ID 
96AFE6CB
gpg: Good signature from Junio C Hamano gits...@pobox.com [unknown]
gpg: aka Junio C Hamano j...@google.com [unknown]
gpg: aka Junio C Hamano ju...@pobox.com [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:  There is no indication that the signature belongs to the 
owner.
Primary key fingerprint: 96E0 7AF2 5771 9559 80DA  D100 20D0 4E5A 7136 60A7
 Subkey fingerprint: E1F0 36B1 FEE7 221F C778  ECEF B0B5 E886 96AF E6CB
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Check SHA256 sum of git-$VER.tar.gz after downloading

2015-03-07 Thread Lukas Fleischer
On Sat, 07 Mar 2015 at 15:46:41, John Keeping wrote:
 This requires that we save the downloaded file explicitly rather than
 piping it straight to tar, but that is advisable anyway since it allows
 us to check the exit status of curl and make sure that we have
 downloaded the file successfully.
 
 Also add a test to make sure we don't forget to update the file when
 updating our Git version in the future.
 
 Signed-off-by: John Keeping j...@keeping.me.uk
 ---
  Makefile |  8 ++--
  git.sha256sum|  1 +
  tests/t0001-validate-git-versions.sh | 11 +++
  3 files changed, 18 insertions(+), 2 deletions(-)
  create mode 100644 git.sha256sum
 [...]

I like the idea, however, sha256sum is not available on all platforms.
This breaks `make get-git` under OpenBSD, for example (OpenBSD has a
utility called sha256 with a different command line interface). Maybe we
can make the check optional, though?

On a related note, can we download a signature and use `gpg --verify`
instead (should probably be optional as well, to avoid a dependency on
GnuPG)?
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Remove no-op link from submodule entries

2015-03-05 Thread Lukas Fleischer
Instead of linking to the current page (href='#'), do not add a link
to a submodule entry at all if the module-link setting is not used.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 cgit.css|  2 +-
 ui-shared.c | 41 -
 2 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/cgit.css b/cgit.css
index 6888cde..82c755c 100644
--- a/cgit.css
+++ b/cgit.css
@@ -254,7 +254,7 @@ div#cgit div.error {
margin: 1em 2em;
 }
 
-div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit a.ls-mod {
+div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit .ls-mod {
font-family: monospace;
 }
 
diff --git a/ui-shared.c b/ui-shared.c
index ff03cb2..c8c1ae0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -555,25 +555,32 @@ void cgit_submodule_link(const char *class, char *path, 
const char *rev)
item = lookup_path(list, path);
}
}
-   html(a );
-   if (class)
-   htmlf(class='%s' , class);
-   html(href=');
-   if (item) {
-   html_attrf(item-util, rev);
-   } else if (ctx.repo-module_link) {
-   dir = strrchr(path, '/');
-   if (dir)
-   dir++;
-   else
-   dir = path;
-   html_attrf(ctx.repo-module_link, dir, rev);
+   if (item || ctx.repo-module_link) {
+   html(a );
+   if (class)
+   htmlf(class='%s' , class);
+   html(href=');
+   if (item) {
+   html_attrf(item-util, rev);
+   } else {
+   dir = strrchr(path, '/');
+   if (dir)
+   dir++;
+   else
+   dir = path;
+   html_attrf(ctx.repo-module_link, dir, rev);
+   }
+   html(');
+   html_txt(path);
+   html(/a);
} else {
-   html(#);
+   html(span);
+   if (class)
+   htmlf( class='%s', class);
+   html();
+   html_txt(path);
+   html(/span);
}
-   html(');
-   html_txt(path);
-   html(/a);
html_txtf( @ %.7s, rev);
if (item  tail)
path[len - 1] = tail;
-- 
2.3.1

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Support .git/category files

2015-03-05 Thread Lukas Fleischer
On Thu, 05 Mar 2015 at 18:15:04, Jan-Marek Glogowski wrote:
 Gitweb reads .git/category to set a repository section for
 grouping. This handles the file in the same way a .git/description
 file is handled.
 
 The file section takes precedence over the ctx.cfg.section_from_path
 setting.
 ---
  cgit.c  |  2 +-
  cgit.h  |  1 +
  scan-tree.c | 20 +++-
  shared.c|  1 +
  4 files changed, 22 insertions(+), 2 deletions(-)
 [...]

There already are at least two ways to achieve the same thing (using the
Git configuration variables gitweb.category or cgit.section and
repository-specific cgitrc files). Do we really need another
alternative? Is this just for GitWeb compatibility or does this have any
advantages over the existing options?
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: Support for submodules in tree view?

2015-03-05 Thread Lukas Fleischer
On Thu, 05 Mar 2015 at 19:25:53, John Keeping wrote:
 On Thu, Mar 05, 2015 at 06:19:31PM +, Dunnigan, Terrence J wrote:
  We are using cgit 0.10.1. Some of our repos have submodules, and when
  I look at a tree view I see the name of the submodule with its current
  hash, e.g.
  
  m-  Utilities @ 350bc94
  
  The submodule names are all hyperlinks, but the actual link is just a
  #. So clicking on it doesn't do anything.
  
  Is this the correct behavior? Or something on my system improperly
  configured to support submodules?
 
 You probably need to set the module-link configuration variable in
 your cgitrc file.
 
 Since it's possible for submodules to link to a different server, there
 isn't really much CGit can do in the general case.  Note that there's
 also repo.module-link.path in case your submodule paths don't match
 up to their URLs, although I'm quite surprised we don't support a filter
 to map submodule URLs to links - something to go on the TODO list
 perhaps...

What do you think about hiding the # link, though? I don't think it is
a good idea to pretend there is a link when there isn't...

-- 8 --
diff --git a/ui-shared.c b/ui-shared.c
index ff03cb2..0eeab6f 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -555,25 +555,27 @@ void cgit_submodule_link(const char *class, char *path, 
const char *rev)
item = lookup_path(list, path);
}
}
-   html(a );
-   if (class)
-   htmlf(class='%s' , class);
-   html(href=');
-   if (item) {
-   html_attrf(item-util, rev);
-   } else if (ctx.repo-module_link) {
-   dir = strrchr(path, '/');
-   if (dir)
-   dir++;
-   else
-   dir = path;
-   html_attrf(ctx.repo-module_link, dir, rev);
+   if (item || ctx.repo-module_link) {
+   html(a );
+   if (class)
+   htmlf(class='%s' , class);
+   html(href=');
+   if (item) {
+   html_attrf(item-util, rev);
+   } else {
+   dir = strrchr(path, '/');
+   if (dir)
+   dir++;
+   else
+   dir = path;
+   html_attrf(ctx.repo-module_link, dir, rev);
+   }
+   html(');
+   html_txt(path);
+   html(/a);
} else {
-   html(#);
+   html_txt(path);
}
-   html(');
-   html_txt(path);
-   html(/a);
html_txtf( @ %.7s, rev);
if (item  tail)
path[len - 1] = tail;
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 2/2] Drop return value from parse_user()

2015-03-05 Thread Lukas Fleischer
In commit 936295c (Simplify commit and tag parsing, 2015-03-03), the
commit and tag parsing code was refactored. This broke tag messages in
ui-tag since the line after the tagger header was erroneously skipped.
Rework parse_user() and skip the line manually outside parse_user().

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 parsing.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/parsing.c b/parsing.c
index dcaf2b3..f903c7c 100644
--- a/parsing.c
+++ b/parsing.c
@@ -69,13 +69,12 @@ static char *substr(const char *head, const char *tail)
return buf;
 }
 
-static const char *parse_user(const char *t, char **name, char **email, 
unsigned long *date)
+static void parse_user(const char *t, char **name, char **email, unsigned long 
*date)
 {
-   const char *line_end = strchrnul(t, '\n');
struct ident_split ident;
unsigned email_len;
 
-   if (!split_ident_line(ident, t, line_end - t)) {
+   if (!split_ident_line(ident, t, strchrnul(t, '\n') - t)) {
*name = substr(ident.name_begin, ident.name_end);
 
email_len = ident.mail_end - ident.mail_begin;
@@ -85,11 +84,6 @@ static const char *parse_user(const char *t, char **name, 
char **email, unsigned
if (ident.date_begin)
*date = strtoul(ident.date_begin, NULL, 10);
}
-
-   if (*line_end)
-   return line_end + 1;
-   else
-   return line_end;
 }
 
 #ifdef NO_ICONV
@@ -152,13 +146,15 @@ struct commitinfo *cgit_parse_commit(struct commit 
*commit)
p += sha1hex_len + 1;
 
if (p  skip_prefix(p, author , p)) {
-   p = parse_user(p, ret-author, ret-author_email,
+   parse_user(p, ret-author, ret-author_email,
ret-author_date);
+   p = next_header_line(p);
}
 
if (p  skip_prefix(p, committer , p)) {
-   p = parse_user(p, ret-committer, ret-committer_email,
+   parse_user(p, ret-committer, ret-committer_email,
ret-committer_date);
+   p = next_header_line(p);
}
 
if (p  skip_prefix(p, encoding , p)) {
@@ -211,7 +207,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag)
 
for (p = data; !end_of_header(p); p = next_header_line(p)) {
if (skip_prefix(p, tagger , p)) {
-   p = parse_user(p, ret-tagger, ret-tagger_email,
+   parse_user(p, ret-tagger, ret-tagger_email,
ret-tagger_date);
}
}
-- 
2.3.1

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 1/2] Remove leading newline characters from tag messages

2015-03-05 Thread Lukas Fleischer
Fixes a regression introduced in commit 936295c (Simplify commit and tag
parsing, 2015-03-03).

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 parsing.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/parsing.c b/parsing.c
index 0db181b..dcaf2b3 100644
--- a/parsing.c
+++ b/parsing.c
@@ -216,6 +216,9 @@ struct taginfo *cgit_parse_tag(struct tag *tag)
}
}
 
+   while (p  *p == '\n')
+   p++;
+
if (p  *p)
ret-msg = xstrdup(p);
 
-- 
2.3.1

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Simplify commit and tag parsing

2015-03-03 Thread Lukas Fleischer
* Use skip_prefix to avoid magic numbers in the code.
* Use xcalloc() instead of xmalloc(), followed by manual initialization.
* Split out line splitting.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 parsing.c | 114 +++---
 1 file changed, 42 insertions(+), 72 deletions(-)

diff --git a/parsing.c b/parsing.c
index 53c29bb..0db181b 100644
--- a/parsing.c
+++ b/parsing.c
@@ -118,45 +118,50 @@ static const char *reencode(char **txt, const char 
*src_enc, const char *dst_enc
 }
 #endif
 
+static const char *next_header_line(const char *p)
+{
+   p = strchr(p, '\n');
+   if (!p)
+   return NULL;
+   return p + 1;
+}
+
+static int end_of_header(const char *p)
+{
+   return !p || (*p == '\n');
+}
+
 struct commitinfo *cgit_parse_commit(struct commit *commit)
 {
+   const int sha1hex_len = 40;
struct commitinfo *ret;
const char *p = get_cached_commit_buffer(commit, NULL);
const char *t;
 
-   ret = xmalloc(sizeof(*ret));
+   ret = xcalloc(1, sizeof(struct commitinfo));
ret-commit = commit;
-   ret-author = NULL;
-   ret-author_email = NULL;
-   ret-committer = NULL;
-   ret-committer_email = NULL;
-   ret-subject = NULL;
-   ret-msg = NULL;
-   ret-msg_encoding = NULL;
-
-   if (p == NULL)
+
+   if (!p)
return ret;
 
-   if (!starts_with(p, tree ))
+   if (!skip_prefix(p, tree , p))
die(Bad commit: %s, sha1_to_hex(commit-object.sha1));
-   else
-   p += 46; // tree  + hex[40] + \n
+   p += sha1hex_len + 1;
 
-   while (starts_with(p, parent ))
-   p += 48; // parent  + hex[40] + \n
+   while (skip_prefix(p, parent , p))
+   p += sha1hex_len + 1;
 
-   if (p  starts_with(p, author )) {
-   p = parse_user(p + 7, ret-author, ret-author_email,
+   if (p  skip_prefix(p, author , p)) {
+   p = parse_user(p, ret-author, ret-author_email,
ret-author_date);
}
 
-   if (p  starts_with(p, committer )) {
-   p = parse_user(p + 10, ret-committer, ret-committer_email,
+   if (p  skip_prefix(p, committer , p)) {
+   p = parse_user(p, ret-committer, ret-committer_email,
ret-committer_date);
}
 
-   if (p  starts_with(p, encoding )) {
-   p += 9;
+   if (p  skip_prefix(p, encoding , p)) {
t = strchr(p, '\n');
if (t) {
ret-msg_encoding = substr(p, t + 1);
@@ -164,38 +169,21 @@ struct commitinfo *cgit_parse_commit(struct commit 
*commit)
}
}
 
-   /* if no special encoding is found, assume UTF-8 */
if (!ret-msg_encoding)
ret-msg_encoding = xstrdup(UTF-8);
 
-   // skip unknown header fields
-   while (p  *p  (*p != '\n')) {
-   p = strchr(p, '\n');
-   if (p)
-   p++;
-   }
-
-   // skip empty lines between headers and message
+   while (!end_of_header(p))
+   p = next_header_line(p);
while (p  *p == '\n')
p++;
-
if (!p)
return ret;
 
-   t = strchr(p, '\n');
-   if (t) {
-   ret-subject = substr(p, t);
-   p = t + 1;
-
-   while (p  *p == '\n') {
-   p = strchr(p, '\n');
-   if (p)
-   p++;
-   }
-   if (p)
-   ret-msg = xstrdup(p);
-   } else
-   ret-subject = xstrdup(p);
+   t = strchrnul(p, '\n');
+   ret-subject = substr(p, t);
+   while (*t == '\n')
+   t++;
+   ret-msg = xstrdup(t);
 
reencode(ret-author, ret-msg_encoding, PAGE_ENCODING);
reencode(ret-author_email, ret-msg_encoding, PAGE_ENCODING);
@@ -207,49 +195,31 @@ struct commitinfo *cgit_parse_commit(struct commit 
*commit)
return ret;
 }
 
-
 struct taginfo *cgit_parse_tag(struct tag *tag)
 {
void *data;
enum object_type type;
unsigned long size;
const char *p;
-   struct taginfo *ret;
+   struct taginfo *ret = NULL;
 
data = read_sha1_file(tag-object.sha1, type, size);
-   if (!data || type != OBJ_TAG) {
-   free(data);
-   return 0;
-   }
+   if (!data || type != OBJ_TAG)
+   goto cleanup;
 
-   ret = xmalloc(sizeof(*ret));
-   ret-tagger = NULL;
-   ret-tagger_email = NULL;
-   ret-tagger_date = 0;
-   ret-msg = NULL;
+   ret = xcalloc(1, sizeof(struct taginfo));
 
-   p = data;
-
-   while (p  *p) {
-   if (*p == '\n')
-   break;
-
-   if (starts_with(p, tagger )) {
-   p = parse_user(p + 7, ret-tagger, ret-tagger_email

[PATCH] ui-clone.c: Fix starts_with() path check

2015-02-08 Thread Lukas Fleischer
The check was broken in two ways: For one thing, the parameters were
passed in the wrong order, for another thing, starts_with() returns 1 if
the string starts with the prefix (not 0).

Note that this bug existed since commit 02a545e (Add support for cloning
over http, 2008-08-06) but only pops in in corner cases.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
Jason, I stumbled across this when trying to reproduce the bug you
reported earlier. Not sure if it is related but it's clearly a bug. One
reason why we haven't seen this occur earlier is that it only manifests
in a few rare cases (no packed refs, special requirements to repository
paths).

 ui-clone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-clone.c b/ui-clone.c
index 50569d6..9b93459 100644
--- a/ui-clone.c
+++ b/ui-clone.c
@@ -63,7 +63,7 @@ static void send_file(char *path)
}
ctx.page.mimetype = application/octet-stream;
ctx.page.filename = path;
-   if (!starts_with(ctx.repo-path, path))
+   if (starts_with(path, ctx.repo-path))
ctx.page.filename += strlen(ctx.repo-path) + 1;
cgit_print_http_headers();
html_include(path);
-- 
2.3.0

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH v2] ui-clone.c: Fix path check

2015-02-08 Thread Lukas Fleischer
The starts_with() check was broken in two ways: For one thing, the
parameters were passed in the wrong order, for another thing,
starts_with() returns 1 if the string starts with the prefix (not 0).

Note that this bug existed since commit 02a545e (Add support for cloning
over http, 2008-08-06) but only pops in in corner cases.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
Using skip_prefix() might be even better here :)

 ui-clone.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ui-clone.c b/ui-clone.c
index 50569d6..1e6238d 100644
--- a/ui-clone.c
+++ b/ui-clone.c
@@ -63,8 +63,8 @@ static void send_file(char *path)
}
ctx.page.mimetype = application/octet-stream;
ctx.page.filename = path;
-   if (!starts_with(ctx.repo-path, path))
-   ctx.page.filename += strlen(ctx.repo-path) + 1;
+   skip_prefix(path, ctx.repo-path, ctx.page.filename);
+   skip_prefix(ctx.page.filename, /, ctx.page.filename);
cgit_print_http_headers();
html_include(path);
 }
-- 
2.3.0

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Add an option to disable the branch switch form

2015-02-07 Thread Lukas Fleischer
Introduce a configuration option enable-switch-form that is enabled by
default and can be used to disable the branch quick switch form in the
top-right corner of repository pages.

Rationale: For repositories with a huge number of branches, the code
generated for the switch form might become so large that it dominates
the size of the HTTP response. For example, at the time of writing this
commit message, the HTTP body of the Arch Linux community.git cgit index
at https://projects.archlinux.org/svntogit/community.git/ has a size of
228KB. Removing the form shrinks the size to only 12KB.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
I am not totally happy with the name but I did not come up with anything
more expressive that is short enough at the same time. Suggestions
welcome!

 cgit.c   | 6 ++
 cgit.h   | 2 ++
 cgitrc.5.txt | 9 +
 shared.c | 1 +
 ui-shared.c  | 2 +-
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/cgit.c b/cgit.c
index 431e325..58dd200 100644
--- a/cgit.c
+++ b/cgit.c
@@ -55,6 +55,8 @@ static void repo_config(struct cgit_repo *repo, const char 
*name, const char *va
repo-enable_remote_branches = atoi(value);
else if (!strcmp(name, enable-subject-links))
repo-enable_subject_links = atoi(value);
+   else if (!strcmp(name, enable-switch-form))
+   repo-enable_switch_form = atoi(value);
else if (!strcmp(name, branch-sort)) {
if (!strcmp(value, age))
repo-branch_sort = 1;
@@ -168,6 +170,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.enable_remote_branches = atoi(value);
else if (!strcmp(name, enable-subject-links))
ctx.cfg.enable_subject_links = atoi(value);
+   else if (!strcmp(name, enable-switch-form))
+   ctx.cfg.enable_switch_form = atoi(value);
else if (!strcmp(name, enable-tree-linenumbers))
ctx.cfg.enable_tree_linenumbers = atoi(value);
else if (!strcmp(name, enable-git-config))
@@ -362,6 +366,7 @@ static void prepare_context(void)
ctx.cfg.enable_index_owner = 1;
ctx.cfg.enable_tree_linenumbers = 1;
ctx.cfg.enable_git_config = 0;
+   ctx.cfg.enable_switch_form = 1;
ctx.cfg.max_repo_count = 50;
ctx.cfg.max_commit_count = 50;
ctx.cfg.max_lock_attempts = 5;
@@ -824,6 +829,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
fprintf(f, repo.logo-link=%s\n, repo-logo_link);
fprintf(f, repo.enable-remote-branches=%d\n, 
repo-enable_remote_branches);
fprintf(f, repo.enable-subject-links=%d\n, 
repo-enable_subject_links);
+   fprintf(f, repo.enable-switch-form=%d\n, repo-enable_switch_form);
if (repo-branch_sort == 1)
fprintf(f, repo.branch-sort=age\n);
if (repo-commit_sort) {
diff --git a/cgit.h b/cgit.h
index 16f8092..c3c56dd 100644
--- a/cgit.h
+++ b/cgit.h
@@ -96,6 +96,7 @@ struct cgit_repo {
int enable_log_linecount;
int enable_remote_branches;
int enable_subject_links;
+   int enable_switch_form;
int max_stats;
int branch_sort;
int commit_sort;
@@ -229,6 +230,7 @@ struct cgit_config {
int enable_log_linecount;
int enable_remote_branches;
int enable_subject_links;
+   int enable_switch_form;
int enable_tree_linenumbers;
int enable_git_config;
int local_time;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index e21ece9..b99b787 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -186,6 +186,11 @@ enable-subject-links::
in commit view. Default value: 0. See also:
repo.enable-subject-links.
 
+enable-switch-form::
+   Flag which, when set to 1, will make cgit add a form to the top right
+   of each repository page that allows for quickly switching branches.
+   Default value: 1. See also: repo.enable-switch-form.
+
 enable-tree-linenumbers::
Flag which, when set to 1, will make cgit generate linenumber links
for plaintext blobs printed in the tree view. Default value: 1.
@@ -509,6 +514,10 @@ repo.enable-subject-links::
A flag which can be used to override the global setting
`enable-subject-links'. Default value: none.
 
+repo.enable-switch-form::
+   A flag which can be used to override the global setting
+   `enable-switch-form'. Default value: none.
+
 repo.hide::
Flag which, when set to 1, hides the repository from the repository
index. The repository can still be accessed by providing a direct path.
diff --git a/shared.c b/shared.c
index ae17d78..ad38c88 100644
--- a/shared.c
+++ b/shared.c
@@ -62,6 +62,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret-enable_log_linecount = ctx.cfg.enable_log_linecount;
ret-enable_remote_branches = ctx.cfg.enable_remote_branches;
ret-enable_subject_links

[PATCH] Add repo.hide and repo.ignore

2015-01-29 Thread Lukas Fleischer
These options can be used to hide a repository from the index or
completely ignore a repository, respectively. They are particularly
useful when used in combination with scan-path.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 cgit.c|  6 ++
 cgit.h|  2 ++
 cgitrc.5.txt  | 10 ++
 shared.c  |  3 +++
 ui-repolist.c |  2 ++
 5 files changed, 23 insertions(+)

diff --git a/cgit.c b/cgit.c
index 79019c2..431e325 100644
--- a/cgit.c
+++ b/cgit.c
@@ -93,6 +93,10 @@ static void repo_config(struct cgit_repo *repo, const char 
*name, const char *va
repo-email_filter = cgit_new_filter(value, EMAIL);
else if (!strcmp(name, owner-filter))
repo-owner_filter = cgit_new_filter(value, OWNER);
+   } else if (!strcmp(name, hide)) {
+   repo-hide = atoi(value);
+   } else if (!strcmp(name, ignore)) {
+   repo-ignore = atoi(value);
}
 }
 
@@ -828,6 +832,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
else if (repo-commit_sort == 2)
fprintf(f, repo.commit-sort=topo\n);
}
+   fprintf(f, repo.hide=%d\n, repo-hide);
+   fprintf(f, repo.ignore=%d\n, repo-ignore);
fprintf(f, \n);
 }
 
diff --git a/cgit.h b/cgit.h
index 42140ac..16f8092 100644
--- a/cgit.h
+++ b/cgit.h
@@ -106,6 +106,8 @@ struct cgit_repo {
struct cgit_filter *email_filter;
struct cgit_filter *owner_filter;
struct string_list submodules;
+   int hide;
+   int ignore;
 };
 
 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index be6703f..e21ece9 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -509,6 +509,16 @@ repo.enable-subject-links::
A flag which can be used to override the global setting
`enable-subject-links'. Default value: none.
 
+repo.hide::
+   Flag which, when set to 1, hides the repository from the repository
+   index. The repository can still be accessed by providing a direct path.
+   Default value: 0. See also: repo.ignore.
+
+repo.ignore::
+   Flag which, when set to 1, ignores the repository. The repository
+   is not shown in the index and cannot be accessed by providing a direct
+   path. Default value: 0. See also: repo.hide.
+
 repo.logo::
Url which specifies the source of an image which will be used as a logo
on this repo's pages. Default value: global logo.
diff --git a/shared.c b/shared.c
index 6e91857..ae17d78 100644
--- a/shared.c
+++ b/shared.c
@@ -75,6 +75,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret-owner_filter = ctx.cfg.owner_filter;
ret-clone_url = ctx.cfg.clone_url;
ret-submodules.strdup_strings = 1;
+   ret-hide = ret-ignore = 0;
return ret;
 }
 
@@ -85,6 +86,8 @@ struct cgit_repo *cgit_get_repoinfo(const char *url)
 
for (i = 0; i  cgit_repolist.count; i++) {
repo = cgit_repolist.repos[i];
+   if (repo-ignore)
+   continue;
if (!strcmp(repo-url, url))
return repo;
}
diff --git a/ui-repolist.c b/ui-repolist.c
index f929cb7..91911e0 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -275,6 +275,8 @@ void cgit_print_repolist()
html(table summary='repository list' class='list nowrap');
for (i = 0; i  cgit_repolist.count; i++) {
ctx.repo = cgit_repolist.repos[i];
+   if (ctx.repo-hide || ctx.repo-ignore)
+   continue;
if (!(is_match(ctx.repo)  is_in_url(ctx.repo)))
continue;
hits++;
-- 
2.2.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH v2] Support Git over HTTP using git-http-backend

2014-12-29 Thread Lukas Fleischer
On Mon, 29 Dec 2014 at 17:56:05, Florian Pritz wrote:
 This saves users from the hassle of setting up git-http-backend when
 they already run cgit.
 
 References: man git-http-backend
 
 Signed-off-by: Florian Pritz bluew...@xinu.at
 ---
 
 v2:
  - git_root allocation was too small by 1
  - change comment style to c89
 
  cgit.c   |  3 +++
  cgit.h   |  1 +
  cgitrc.5.txt |  8 
  cmd.c| 12 
  ui-clone.c   | 61 
 
  ui-clone.h   |  2 ++
  6 files changed, 87 insertions(+)
 [...]

Note that directly invoking http-backend from cgit without the overhead
of execl() seems to be a bit more involved -- almost everything in
http-backend.c is marked static:

Acked-by: Lukas Fleischer c...@cryptocrack.de
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Use split_ident_line() in parse_user()

2014-12-23 Thread Lukas Fleischer
On Wed, 24 Dec 2014 at 02:57:45, Jason A. Donenfeld wrote:
 On Wed, Dec 17, 2014 at 5:19 AM, Lukas Fleischer c...@cryptocrack.de
 wrote:
 
  Use Git's built-in ident line splitting algorithm instead of
  reimplementing it. This does not only simplify the code but also makes
  sure that cgit is consistent with Git when it comes to author parsing.
 
 
 Thank heavens!
 
  +   email_len = ident.mail_end - ident.mail_begin;
  +   *email = xmalloc(strlen() + email_len + strlen(\0));
  +   sprintf(*email, %.*s, email_len, ident.mail_begin);
  +
 
 
 strlen(\0) -- isn't the null superfluous? Cleanup and resubmit?

I think this is even wrong because it means the buffer won't be large
enough to hold the terminating null character. Will resubmit.
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Remove trailing slash after remove-suffix

2014-12-13 Thread Lukas Fleischer
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 c...@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

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH v2] Remove trailing slash after remove-suffix

2014-12-13 Thread Lukas Fleischer
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 c...@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

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: Integration with Bugzilla?

2014-10-26 Thread Lukas Fleischer
On Fri, 24 Oct 2014 at 22:25:01, Joey Reid wrote:
 Yes,  rewording the scan-path section of cgitrc.5 and adding an entry to
 the FAQ would be immensely helpful.
 
 The commit-links.sh and the trac script appear to spawn extra process. With
 servers like FreeDesktop's cgit  under a heavy load, is there a way
 to minimize CPU usage?
 [...]

You can use Lua filters, check [1] for details.

[1] http://git.zx2c4.com/cgit/tree/cgitrc.5.txt#n582
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: Integration with Bugzilla?

2014-09-29 Thread Lukas Fleischer
On Mon, 29 Sep 2014 at 20:33:28, Ferry Huberts wrote:
 [...]
 my server is guaranteed to have bash, so no need to change it.
 but thanks for the hint anyway :-)
 

I am not (only) talking about portability here. My main concern is the
current spate of bash vulnerabilities. As John pointed out earlier [1],
these can be used to remotely exploit any cgit setup that uses a bash
filter. We currently have at least five CVEs, some of which are very
critical. So if you really want to use bash, you should at least closely
follow the developments and always update your bash binary when there's
a new security patch.

 also, this script is a very minor modification of the script that's in 
 the source tree.
 
 -- 
 Ferry Huberts
 

[1] http://lists.zx2c4.com/pipermail/cgit/2014-September/002236.html
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 1/1] git: update for git 2.0

2014-05-04 Thread Lukas Fleischer
On Sun, 04 May 2014 at 21:31:39, Christian Hesse wrote:
 prefixcmp() and suffixcmp() have been remove, functionality is now
 provided by starts_with() and ends_with(). Retrurn values have been
 changed, so instead of just renaming we have to fix logic.
 Everything else looks just fine.
 ---
  Makefile  |  4 ++--
  cgit.c| 26 +-
  git   |  2 +-
  parsing.c | 12 ++--
  scan-tree.c   | 10 +++---
  ui-clone.c|  2 +-
  ui-log.c  |  8 
  ui-refs.c |  6 +++---
  ui-repolist.c |  2 +-
  ui-shared.c   |  2 +-
  ui-snapshot.c |  4 ++--
  ui-summary.c  |  2 +-
  12 files changed, 42 insertions(+), 38 deletions(-)
 
 [...]
 -   else if (!prefixcmp(name, module-link.)) {
 +   else if (starts_with(name, module-link.)) {
 item = string_list_append(repo-submodules, xstrdup(name + 
 12));

My original intention was to replace most of these with skip_prefix()
(well, I actually wanted to wait for strip_prefix() to replace
skip_prefix() but that didn't make it into Git 2.0). It would be great
to see most of the starts_with() invocations (followed by hardcoded
lengths) replaced by skip_prefix() but if you don't want to do it, I
guess this change is okay for now.

 item-util = xstrdup(value);
 } else if (!strcmp(name, section))
 @@ -102,7 +102,7 @@ static void config_cb(const char *name, const char *value)
 ctx.repo = cgit_add_repo(value);
 else if (ctx.repo  !strcmp(name, repo.path))
 ctx.repo-path = trim_end(value, '/');
 -   else if (ctx.repo  !prefixcmp(name, repo.))
 +   else if (ctx.repo  starts_with(name, repo.))
 repo_config(ctx.repo, name + 5, value);
 else if (!strcmp(name, readme)  value != NULL)
 string_list_append(ctx.cfg.readme, xstrdup(value));
 @@ -264,7 +264,7 @@ static void config_cb(const char *name, const char *value)
 [...]
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 2/2] Add a cache-snapshot-ttl configuration variable

2014-02-08 Thread Lukas Fleischer
On Wed, 05 Feb 2014 at 16:09:14, Lukas Fleischer wrote:
 On Wed, 05 Feb 2014 at 15:44:36, Jason A. Donenfeld wrote:
 [...]
  Currently it defaults to cache_repo_ttl, which is 5. I'd be willing to
  compromise for 15 if you prefer.
 
 I'm fine with either one. Whatever you prefer.

Changed the default value to 5 in lf/staging.
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Remove unused parameter from cgit_print_snapshot()

2014-02-08 Thread Lukas Fleischer
Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 cmd.c | 2 +-
 ui-snapshot.c | 2 +-
 ui-snapshot.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmd.c b/cmd.c
index cbd235c..188cd56 100644
--- a/cmd.c
+++ b/cmd.c
@@ -113,7 +113,7 @@ static void refs_fn(void)
 static void snapshot_fn(void)
 {
cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, ctx.qry.path,
-   ctx.repo-snapshots, ctx.qry.nohead);
+   ctx.qry.nohead);
 }
 
 static void stats_fn(void)
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 582dc31..3107b05 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -193,7 +193,7 @@ static void show_error(char *fmt, ...)
 }
 
 void cgit_print_snapshot(const char *head, const char *hex,
-const char *filename, int snapshots, int dwim)
+const char *filename, int dwim)
 {
const struct cgit_snapshot_format* f;
char *prefix = NULL;
diff --git a/ui-snapshot.h b/ui-snapshot.h
index b6ede52..a8deec3 100644
--- a/ui-snapshot.h
+++ b/ui-snapshot.h
@@ -2,6 +2,6 @@
 #define UI_SNAPSHOT_H
 
 extern void cgit_print_snapshot(const char *head, const char *hex,
-   const char *filename, int snapshot, int dwim);
+   const char *filename, int dwim);
 
 #endif /* UI_SNAPSHOT_H */
-- 
1.8.5.4

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 1/2] Skip cache slot when time-to-live is zero

2014-02-08 Thread Lukas Fleischer
On Sat, 08 Feb 2014 at 14:41:56, Jason A. Donenfeld wrote:
  On Feb 6, 2014 10:07 PM, Lukas Fleischer c...@cryptocrack.de wrote:
 
  This is different. -1 means never expire. 0 means always expire.
 
 Ahh perfect -- this is exactly the type of distinction I was looking for.
 Do we have this documented?

Yes, -1 is documented in the man page and it is quite clear that 0 means
always expire (directly follows from the general description of what
the *-ttl variables do).
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 1/2] Skip cache slot when time-to-live is zero

2014-02-06 Thread Lukas Fleischer
On Thu, 06 Feb 2014 at 20:52:46, Jason A. Donenfeld wrote:
 On Wed, Feb 5, 2014 at 10:46 AM, Lukas Fleischer c...@cryptocrack.dewrote:
 
  /* If the cache is disabled, just generate the content */
  -   if (size = 0) {
  +   if (size = 0 || ttl == 0) {
  fn();
  return 0;
  }
 
 
 Apparently we already special case ttl for  0:
 
 /* Check if the slot has expired */
 static int is_expired(struct cache_slot *slot)
 {
 if (slot-ttl  0)
 return 0;
 else
 return slot-cache_st.st_mtime + slot-ttl * 60 
 time(NULL);
 }
 
 What should our behavior be for consistency?

This is different. -1 means never expire. 0 means always expire. We
cannot add the 0 special case to is_expired(), though, because that
would mean we would update and write the cache file to disk on every
request which seems to be a bad idea (actually, that is what already
happens now without having a special case).
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 1/2] Skip cache slot when time-to-live is zero

2014-02-05 Thread Lukas Fleischer
If time-to-live is set to zero, we don't need to regenerate the cache
slots on every request. Instead, just skip the caching process and
immediately provide the dynamically generated version of the page.
Setting time-to-live to zero is useful when you want to disable caching
for certain pages.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cache.c b/cache.c
index 9e7eeb0..801e63f 100644
--- a/cache.c
+++ b/cache.c
@@ -343,7 +343,7 @@ int cache_process(int size, const char *path, const char 
*key, int ttl,
int result;
 
/* If the cache is disabled, just generate the content */
-   if (size = 0) {
+   if (size = 0 || ttl == 0) {
fn();
return 0;
}
-- 
1.8.5.3

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Intelligent caching

2014-02-05 Thread Lukas Fleischer
Hi,

Reading through our caching code, I wondered why we don't make it a bit
more clever. For every dynamically created page, we could just store a
fingerprint that can be computed quite fast and indicates whether the
cache slot is still up-to-date or not.

For example, on the log pages, we could save the commit the
corresponding ref points to and invalidate the cache slot when the ref
has changed. Using that, we could use the power of caching and never
deliver outdated pages at the same time.

What do you think about that?

Regards,
Lukas
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 2/4] Remove context parameter from all commands

2014-01-15 Thread Lukas Fleischer
Drop the context parameter from the following functions (and all static
helpers used by them) and use the global context instead:

* cgit_get_cmd()
* All cgit command functions.
* cgit_clone_info()
* cgit_clone_objects()
* cgit_clone_head()
* cgit_print_plain()
* cgit_show_stats()

Fix all invocations of these functions accordingly.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 cgit.c |   4 +--
 cmd.c  | 100 ++---
 cmd.h  |   4 +--
 ui-clone.c |  42 +-
 ui-clone.h |   6 ++--
 ui-plain.c |  10 +++
 ui-plain.h |   2 +-
 ui-stats.c |  29 +-
 ui-stats.h |   2 +-
 9 files changed, 99 insertions(+), 100 deletions(-)

diff --git a/cgit.c b/cgit.c
index 512ef56..54efd59 100644
--- a/cgit.c
+++ b/cgit.c
@@ -598,7 +598,7 @@ static void process_request(void *cbdata)
struct cgit_context *ctx = cbdata;
struct cgit_cmd *cmd;
 
-   cmd = cgit_get_cmd(ctx);
+   cmd = cgit_get_cmd();
if (!cmd) {
ctx-page.title = cgit error;
ctx-page.status = 404;
@@ -640,7 +640,7 @@ static void process_request(void *cbdata)
cgit_print_pageheader();
}
 
-   cmd-fn(ctx);
+   cmd-fn();
 
if (cmd-want_layout)
cgit_print_docend();
diff --git a/cmd.c b/cmd.c
index 3022452..cbd235c 100644
--- a/cmd.c
+++ b/cmd.c
@@ -26,120 +26,120 @@
 #include ui-tag.h
 #include ui-tree.h
 
-static void HEAD_fn(struct cgit_context *ctx)
+static void HEAD_fn(void)
 {
-   cgit_clone_head(ctx);
+   cgit_clone_head();
 }
 
-static void atom_fn(struct cgit_context *ctx)
+static void atom_fn(void)
 {
-   cgit_print_atom(ctx-qry.head, ctx-qry.path, ctx-cfg.max_atom_items);
+   cgit_print_atom(ctx.qry.head, ctx.qry.path, ctx.cfg.max_atom_items);
 }
 
-static void about_fn(struct cgit_context *ctx)
+static void about_fn(void)
 {
-   if (ctx-repo)
-   cgit_print_repo_readme(ctx-qry.path);
+   if (ctx.repo)
+   cgit_print_repo_readme(ctx.qry.path);
else
cgit_print_site_readme();
 }
 
-static void blob_fn(struct cgit_context *ctx)
+static void blob_fn(void)
 {
-   cgit_print_blob(ctx-qry.sha1, ctx-qry.path, ctx-qry.head, 0);
+   cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0);
 }
 
-static void commit_fn(struct cgit_context *ctx)
+static void commit_fn(void)
 {
-   cgit_print_commit(ctx-qry.sha1, ctx-qry.path);
+   cgit_print_commit(ctx.qry.sha1, ctx.qry.path);
 }
 
-static void diff_fn(struct cgit_context *ctx)
+static void diff_fn(void)
 {
-   cgit_print_diff(ctx-qry.sha1, ctx-qry.sha2, ctx-qry.path, 1, 0);
+   cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 0);
 }
 
-static void rawdiff_fn(struct cgit_context *ctx)
+static void rawdiff_fn(void)
 {
-   cgit_print_diff(ctx-qry.sha1, ctx-qry.sha2, ctx-qry.path, 1, 1);
+   cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 1);
 }
 
-static void info_fn(struct cgit_context *ctx)
+static void info_fn(void)
 {
-   cgit_clone_info(ctx);
+   cgit_clone_info();
 }
 
-static void log_fn(struct cgit_context *ctx)
+static void log_fn(void)
 {
-   cgit_print_log(ctx-qry.sha1, ctx-qry.ofs, ctx-cfg.max_commit_count,
-  ctx-qry.grep, ctx-qry.search, ctx-qry.path, 1,
-  ctx-repo-enable_commit_graph,
-  ctx-repo-commit_sort);
+   cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, ctx.cfg.max_commit_count,
+  ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1,
+  ctx.repo-enable_commit_graph,
+  ctx.repo-commit_sort);
 }
 
-static void ls_cache_fn(struct cgit_context *ctx)
+static void ls_cache_fn(void)
 {
-   ctx-page.mimetype = text/plain;
-   ctx-page.filename = ls-cache.txt;
+   ctx.page.mimetype = text/plain;
+   ctx.page.filename = ls-cache.txt;
cgit_print_http_headers();
-   cache_ls(ctx-cfg.cache_root);
+   cache_ls(ctx.cfg.cache_root);
 }
 
-static void objects_fn(struct cgit_context *ctx)
+static void objects_fn(void)
 {
-   cgit_clone_objects(ctx);
+   cgit_clone_objects();
 }
 
-static void repolist_fn(struct cgit_context *ctx)
+static void repolist_fn(void)
 {
cgit_print_repolist();
 }
 
-static void patch_fn(struct cgit_context *ctx)
+static void patch_fn(void)
 {
-   cgit_print_patch(ctx-qry.sha1, ctx-qry.sha2, ctx-qry.path);
+   cgit_print_patch(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path);
 }
 
-static void plain_fn(struct cgit_context *ctx)
+static void plain_fn(void)
 {
-   cgit_print_plain(ctx);
+   cgit_print_plain();
 }
 
-static void refs_fn(struct cgit_context *ctx)
+static void refs_fn(void)
 {
cgit_print_refs();
 }
 
-static void snapshot_fn(struct cgit_context *ctx)
+static void snapshot_fn(void)
 {
-   cgit_print_snapshot(ctx-qry.head, ctx

[PATCH 0/4] Remove references to the global context variable

2014-01-15 Thread Lukas Fleischer
Jason noticed that sometimes, we pass a reference (pointer) to the
global context variable. This series removes all such references and
replaces them with direct use of the global variable.

Most of the patches are much easier to review with the following
options:

--word-diff=color --word-diff-regex='[a-zA-Z_]+|-|\.'

Comments welcome!

Lukas Fleischer (4):
  Remove context parameter from cgit_print_*()
  Remove context parameter from all commands
  cgit.c: Remove context parameter from initializations
  Remove callback data parameter for cache slots

 cache.c   |  14 ++-
 cache.h   |   5 +-
 cgit.c| 249 
 cmd.c | 102 ++--
 cmd.h |   4 +-
 ui-atom.c |   2 +-
 ui-blob.c |   2 +-
 ui-clone.c|  48 +-
 ui-clone.h|   6 +-
 ui-diff.c |   2 +-
 ui-patch.c|   2 +-
 ui-plain.c|  14 +--
 ui-plain.h|   2 +-
 ui-repolist.c |   6 +-
 ui-shared.c   | 297 +-
 ui-shared.h   |   6 +-
 ui-snapshot.c |   8 +-
 ui-stats.c|  29 +++---
 ui-stats.h|   2 +-
 19 files changed, 397 insertions(+), 403 deletions(-)

-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 3/4] cgit.c: Remove context parameter from initializations

2014-01-15 Thread Lukas Fleischer
In initialization routines, use the global context variable instead of
passing a pointer around locally.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 cgit.c | 207 -
 1 file changed, 103 insertions(+), 104 deletions(-)

diff --git a/cgit.c b/cgit.c
index 54efd59..19bcd0d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -320,78 +320,78 @@ static void querystring_cb(const char *name, const char 
*value)
}
 }
 
-static void prepare_context(struct cgit_context *ctx)
+static void prepare_context(void)
 {
-   memset(ctx, 0, sizeof(*ctx));
-   ctx-cfg.agefile = info/web/last-modified;
-   ctx-cfg.nocache = 0;
-   ctx-cfg.cache_size = 0;
-   ctx-cfg.cache_max_create_time = 5;
-   ctx-cfg.cache_root = CGIT_CACHE_ROOT;
-   ctx-cfg.cache_about_ttl = 15;
-   ctx-cfg.cache_repo_ttl = 5;
-   ctx-cfg.cache_root_ttl = 5;
-   ctx-cfg.cache_scanrc_ttl = 15;
-   ctx-cfg.cache_dynamic_ttl = 5;
-   ctx-cfg.cache_static_ttl = -1;
-   ctx-cfg.case_sensitive_sort = 1;
-   ctx-cfg.branch_sort = 0;
-   ctx-cfg.commit_sort = 0;
-   ctx-cfg.css = /cgit.css;
-   ctx-cfg.logo = /cgit.png;
-   ctx-cfg.favicon = /favicon.ico;
-   ctx-cfg.local_time = 0;
-   ctx-cfg.enable_http_clone = 1;
-   ctx-cfg.enable_index_owner = 1;
-   ctx-cfg.enable_tree_linenumbers = 1;
-   ctx-cfg.enable_git_config = 0;
-   ctx-cfg.max_repo_count = 50;
-   ctx-cfg.max_commit_count = 50;
-   ctx-cfg.max_lock_attempts = 5;
-   ctx-cfg.max_msg_len = 80;
-   ctx-cfg.max_repodesc_len = 80;
-   ctx-cfg.max_blob_size = 0;
-   ctx-cfg.max_stats = 0;
-   ctx-cfg.project_list = NULL;
-   ctx-cfg.renamelimit = -1;
-   ctx-cfg.remove_suffix = 0;
-   ctx-cfg.robots = index, nofollow;
-   ctx-cfg.root_title = Git repository browser;
-   ctx-cfg.root_desc = a fast webinterface for the git dscm;
-   ctx-cfg.scan_hidden_path = 0;
-   ctx-cfg.script_name = CGIT_SCRIPT_NAME;
-   ctx-cfg.section = ;
-   ctx-cfg.repository_sort = name;
-   ctx-cfg.section_sort = 1;
-   ctx-cfg.summary_branches = 10;
-   ctx-cfg.summary_log = 10;
-   ctx-cfg.summary_tags = 10;
-   ctx-cfg.max_atom_items = 10;
-   ctx-cfg.ssdiff = 0;
-   ctx-env.cgit_config = getenv(CGIT_CONFIG);
-   ctx-env.http_host = getenv(HTTP_HOST);
-   ctx-env.https = getenv(HTTPS);
-   ctx-env.no_http = getenv(NO_HTTP);
-   ctx-env.path_info = getenv(PATH_INFO);
-   ctx-env.query_string = getenv(QUERY_STRING);
-   ctx-env.request_method = getenv(REQUEST_METHOD);
-   ctx-env.script_name = getenv(SCRIPT_NAME);
-   ctx-env.server_name = getenv(SERVER_NAME);
-   ctx-env.server_port = getenv(SERVER_PORT);
-   ctx-page.mimetype = text/html;
-   ctx-page.charset = PAGE_ENCODING;
-   ctx-page.filename = NULL;
-   ctx-page.size = 0;
-   ctx-page.modified = time(NULL);
-   ctx-page.expires = ctx-page.modified;
-   ctx-page.etag = NULL;
-   memset(ctx-cfg.mimetypes, 0, sizeof(struct string_list));
-   if (ctx-env.script_name)
-   ctx-cfg.script_name = xstrdup(ctx-env.script_name);
-   if (ctx-env.query_string)
-   ctx-qry.raw = xstrdup(ctx-env.query_string);
-   if (!ctx-env.cgit_config)
-   ctx-env.cgit_config = CGIT_CONFIG;
+   memset(ctx, 0, sizeof(ctx));
+   ctx.cfg.agefile = info/web/last-modified;
+   ctx.cfg.nocache = 0;
+   ctx.cfg.cache_size = 0;
+   ctx.cfg.cache_max_create_time = 5;
+   ctx.cfg.cache_root = CGIT_CACHE_ROOT;
+   ctx.cfg.cache_about_ttl = 15;
+   ctx.cfg.cache_repo_ttl = 5;
+   ctx.cfg.cache_root_ttl = 5;
+   ctx.cfg.cache_scanrc_ttl = 15;
+   ctx.cfg.cache_dynamic_ttl = 5;
+   ctx.cfg.cache_static_ttl = -1;
+   ctx.cfg.case_sensitive_sort = 1;
+   ctx.cfg.branch_sort = 0;
+   ctx.cfg.commit_sort = 0;
+   ctx.cfg.css = /cgit.css;
+   ctx.cfg.logo = /cgit.png;
+   ctx.cfg.favicon = /favicon.ico;
+   ctx.cfg.local_time = 0;
+   ctx.cfg.enable_http_clone = 1;
+   ctx.cfg.enable_index_owner = 1;
+   ctx.cfg.enable_tree_linenumbers = 1;
+   ctx.cfg.enable_git_config = 0;
+   ctx.cfg.max_repo_count = 50;
+   ctx.cfg.max_commit_count = 50;
+   ctx.cfg.max_lock_attempts = 5;
+   ctx.cfg.max_msg_len = 80;
+   ctx.cfg.max_repodesc_len = 80;
+   ctx.cfg.max_blob_size = 0;
+   ctx.cfg.max_stats = 0;
+   ctx.cfg.project_list = NULL;
+   ctx.cfg.renamelimit = -1;
+   ctx.cfg.remove_suffix = 0;
+   ctx.cfg.robots = index, nofollow;
+   ctx.cfg.root_title = Git repository browser;
+   ctx.cfg.root_desc = a fast webinterface for the git dscm;
+   ctx.cfg.scan_hidden_path = 0;
+   ctx.cfg.script_name = CGIT_SCRIPT_NAME;
+   ctx.cfg.section = ;
+   ctx.cfg.repository_sort = name

[PATCH/RFC] tests/: Add t0111-filter.sh

2014-01-14 Thread Lukas Fleischer
This adds basic tests for all types of exec filters.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
This only includes tests for exec filters so far. I will send another
patch for Lua filters once this one is merged.

 tests/filters/capitalize-argv1.sh |  3 +++
 tests/filters/capitalize-stdin.sh |  3 +++
 tests/setup.sh| 13 +
 tests/t0111-filter.sh | 38 ++
 4 files changed, 57 insertions(+)
 create mode 100755 tests/filters/capitalize-argv1.sh
 create mode 100755 tests/filters/capitalize-stdin.sh
 create mode 100755 tests/t0111-filter.sh

diff --git a/tests/filters/capitalize-argv1.sh 
b/tests/filters/capitalize-argv1.sh
new file mode 100755
index 000..2ea0098
--- /dev/null
+++ b/tests/filters/capitalize-argv1.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo $1 | tr '[:lower:]' '[:upper:]'
diff --git a/tests/filters/capitalize-stdin.sh 
b/tests/filters/capitalize-stdin.sh
new file mode 100755
index 000..c9f4719
--- /dev/null
+++ b/tests/filters/capitalize-stdin.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+tr '[:lower:]' '[:upper:]'
diff --git a/tests/setup.sh b/tests/setup.sh
index 5476ced..861f48a 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -58,6 +58,8 @@ else
PATH=$(pwd)/../..:$PATH
 fi
 
+FILTER_DIRECTORY=$(cd ../filters  pwd)
+
 mkrepo() {
name=$1
count=$2
@@ -90,6 +92,7 @@ setup_repos()
mkrepo repos/bar 50 /dev/null
mkrepo repos/foo+bar 10 testplus /dev/null
mkrepo repos/with space 2 /dev/null
+   mkrepo repos/filter 5 testplus /dev/null
cat cgitrc EOF
 virtual-root=/
 cache-root=$PWD/cache
@@ -102,6 +105,7 @@ summary-log=5
 summary-branches=5
 summary-tags=5
 clone-url=git://example.org/\$CGIT_REPO_URL.git
+enable-filter-overrides=1
 
 repo.url=foo
 repo.path=$PWD/repos/foo/.git
@@ -120,6 +124,15 @@ repo.desc=the foo+bar repo
 repo.url=with space
 repo.path=$PWD/repos/with space/.git
 repo.desc=spaced repo
+
+repo.url=filter
+repo.path=$PWD/repos/filter/.git
+repo.desc=filtered repo
+repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
+repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
+repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-argv1.sh
+repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
+repo.readme=master:a+b
 EOF
 }
 
diff --git a/tests/t0111-filter.sh b/tests/t0111-filter.sh
new file mode 100755
index 000..2f99880
--- /dev/null
+++ b/tests/t0111-filter.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+test_description='Check filtered content'
+. ./setup.sh
+
+test_expect_success 'generate filter/tree/a%2bb' '
+   cgit_url filter/tree/a%2bb tmp
+'
+
+test_expect_success 'check whether the source filter works' '
+   grep codeHELLO$ tmp
+'
+
+test_expect_success 'generate filter/about/' '
+   cgit_url filter/about/ tmp
+'
+
+test_expect_success 'check whether the about filter works' '
+   grep div id='''summary'''HELLO$ tmp
+'
+
+test_expect_success 'generate filter/commit/' '
+   cgit_url filter/commit/ tmp
+'
+
+test_expect_success 'check whether the commit filter works' '
+   grep div class='''commit-subject'''ADD A+B tmp
+'
+
+test_expect_success 'check whether the email filter works for authors' '
+   grep aut...@example.com tmp
+'
+
+test_expect_success 'check whether the email filter works for committers' '
+   grep commit...@example.com tmp
+'
+
+test_done
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 1/2] t0111: Prepare for other filter prefixes

2014-01-14 Thread Lukas Fleischer
Rename the filter repository to filter-exec. The Git repository itself
is not renamed since it can be shared amongst all filter types.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 tests/setup.sh|  2 +-
 tests/t0111-filter.sh | 22 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/tests/setup.sh b/tests/setup.sh
index 861f48a..6499836 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -125,7 +125,7 @@ repo.url=with space
 repo.path=$PWD/repos/with space/.git
 repo.desc=spaced repo
 
-repo.url=filter
+repo.url=filter-exec
 repo.path=$PWD/repos/filter/.git
 repo.desc=filtered repo
 repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
diff --git a/tests/t0111-filter.sh b/tests/t0111-filter.sh
index 2f99880..c7e9d05 100755
--- a/tests/t0111-filter.sh
+++ b/tests/t0111-filter.sh
@@ -3,35 +3,35 @@
 test_description='Check filtered content'
 . ./setup.sh
 
-test_expect_success 'generate filter/tree/a%2bb' '
-   cgit_url filter/tree/a%2bb tmp
+test_expect_success 'generate filter-exec/tree/a%2bb' '
+   cgit_url filter-exec/tree/a%2bb tmp
 '
 
-test_expect_success 'check whether the source filter works' '
+test_expect_success 'check whether the exec source filter works' '
grep codeHELLO$ tmp
 '
 
-test_expect_success 'generate filter/about/' '
-   cgit_url filter/about/ tmp
+test_expect_success 'generate filter-exec/about/' '
+   cgit_url filter-exec/about/ tmp
 '
 
-test_expect_success 'check whether the about filter works' '
+test_expect_success 'check whether the exec about filter works' '
grep div id='''summary'''HELLO$ tmp
 '
 
-test_expect_success 'generate filter/commit/' '
-   cgit_url filter/commit/ tmp
+test_expect_success 'generate filter-exec/commit/' '
+   cgit_url filter-exec/commit/ tmp
 '
 
-test_expect_success 'check whether the commit filter works' '
+test_expect_success 'check whether the exec commit filter works' '
grep div class='''commit-subject'''ADD A+B tmp
 '
 
-test_expect_success 'check whether the email filter works for authors' '
+test_expect_success 'check whether the exec email filter works for authors' '
grep aut...@example.com tmp
 '
 
-test_expect_success 'check whether the email filter works for committers' '
+test_expect_success 'check whether the exec email filter works for committers' 
'
grep commit...@example.com tmp
 '
 
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 2/2] t0111: Add basic tests for Lua filters

2014-01-14 Thread Lukas Fleischer
Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 tests/filters/capitalize-buffer.lua | 14 ++
 tests/setup.sh  |  9 +
 tests/t0111-filter.sh   | 32 
 3 files changed, 55 insertions(+)
 create mode 100644 tests/filters/capitalize-buffer.lua

diff --git a/tests/filters/capitalize-buffer.lua 
b/tests/filters/capitalize-buffer.lua
new file mode 100644
index 000..7ca4ec6
--- /dev/null
+++ b/tests/filters/capitalize-buffer.lua
@@ -0,0 +1,14 @@
+function filter_open(...)
+   buffer = 
+end
+
+function filter_close()
+   html(buffer)
+   return 0
+end
+
+function filter_write(str)
+   buffer = buffer .. string.upper(str)
+end
+
+
diff --git a/tests/setup.sh b/tests/setup.sh
index 6499836..529f410 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -133,6 +133,15 @@ 
repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
 repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-argv1.sh
 repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
 repo.readme=master:a+b
+
+repo.url=filter-lua
+repo.path=$PWD/repos/filter/.git
+repo.desc=filtered repo
+repo.about-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
+repo.commit-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
+repo.email-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
+repo.source-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
+repo.readme=master:a+b
 EOF
 }
 
diff --git a/tests/t0111-filter.sh b/tests/t0111-filter.sh
index c7e9d05..3833de4 100755
--- a/tests/t0111-filter.sh
+++ b/tests/t0111-filter.sh
@@ -35,4 +35,36 @@ test_expect_success 'check whether the exec email filter 
works for committers' '
grep commit...@example.com tmp
 '
 
+test_expect_success 'generate filter-lua/tree/a%2bb' '
+   cgit_url filter-lua/tree/a%2bb tmp
+'
+
+test_expect_success 'check whether the Lua source filter works' '
+   grep codeHELLO$ tmp
+'
+
+test_expect_success 'generate filter-lua/about/' '
+   cgit_url filter-lua/about/ tmp
+'
+
+test_expect_success 'check whether the Lua about filter works' '
+   grep div id='''summary'''HELLO$ tmp
+'
+
+test_expect_success 'generate filter-lua/commit/' '
+   cgit_url filter-lua/commit/ tmp
+'
+
+test_expect_success 'check whether the Lua commit filter works' '
+   grep div class='''commit-subject'''ADD A+B tmp
+'
+
+test_expect_success 'check whether the Lua email filter works for authors' '
+   grep A U THOR LT;aut...@example.comGT; tmp
+'
+
+test_expect_success 'check whether the Lua email filter works for committers' '
+   grep C O MITTER LT;commit...@example.comGT; tmp
+'
+
 test_done
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH v2 1/3] t0111: Prepare for other filter prefixes

2014-01-14 Thread Lukas Fleischer
* Validate the email filter by manipulating stdin. Additional checks for
  all the arguments can be added in a later patch.

* Add the exec prefix to all informational messages.

* Rename the filter repository to filter-exec. The Git repository itself
  is not renamed since it can be shared amongst all filter types.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 tests/filters/capitalize-argv1.sh |  3 ---
 tests/setup.sh|  4 ++--
 tests/t0111-filter.sh | 26 +-
 3 files changed, 15 insertions(+), 18 deletions(-)
 delete mode 100755 tests/filters/capitalize-argv1.sh

diff --git a/tests/filters/capitalize-argv1.sh 
b/tests/filters/capitalize-argv1.sh
deleted file mode 100755
index 2ea0098..000
--- a/tests/filters/capitalize-argv1.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-echo $1 | tr '[:lower:]' '[:upper:]'
diff --git a/tests/setup.sh b/tests/setup.sh
index 861f48a..a0a9be2 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -125,12 +125,12 @@ repo.url=with space
 repo.path=$PWD/repos/with space/.git
 repo.desc=spaced repo
 
-repo.url=filter
+repo.url=filter-exec
 repo.path=$PWD/repos/filter/.git
 repo.desc=filtered repo
 repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
 repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
-repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-argv1.sh
+repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
 repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
 repo.readme=master:a+b
 EOF
diff --git a/tests/t0111-filter.sh b/tests/t0111-filter.sh
index 2f99880..c235652 100755
--- a/tests/t0111-filter.sh
+++ b/tests/t0111-filter.sh
@@ -3,36 +3,36 @@
 test_description='Check filtered content'
 . ./setup.sh
 
-test_expect_success 'generate filter/tree/a%2bb' '
-   cgit_url filter/tree/a%2bb tmp
+test_expect_success 'generate filter-exec/tree/a%2bb' '
+   cgit_url filter-exec/tree/a%2bb tmp
 '
 
-test_expect_success 'check whether the source filter works' '
+test_expect_success 'check whether the exec source filter works' '
grep codeHELLO$ tmp
 '
 
-test_expect_success 'generate filter/about/' '
-   cgit_url filter/about/ tmp
+test_expect_success 'generate filter-exec/about/' '
+   cgit_url filter-exec/about/ tmp
 '
 
-test_expect_success 'check whether the about filter works' '
+test_expect_success 'check whether the exec about filter works' '
grep div id='''summary'''HELLO$ tmp
 '
 
-test_expect_success 'generate filter/commit/' '
-   cgit_url filter/commit/ tmp
+test_expect_success 'generate filter-exec/commit/' '
+   cgit_url filter-exec/commit/ tmp
 '
 
-test_expect_success 'check whether the commit filter works' '
+test_expect_success 'check whether the exec commit filter works' '
grep div class='''commit-subject'''ADD A+B tmp
 '
 
-test_expect_success 'check whether the email filter works for authors' '
-   grep aut...@example.com tmp
+test_expect_success 'check whether the exec email filter works for authors' '
+   grep A U THOR LT;aut...@example.comGT; tmp
 '
 
-test_expect_success 'check whether the email filter works for committers' '
-   grep commit...@example.com tmp
+test_expect_success 'check whether the exec email filter works for committers' 
'
+   grep C O MITTER LT;commit...@example.comGT; tmp
 '
 
 test_done
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 3/4] Refactor cgit_parse_snapshots_mask()

2014-01-10 Thread Lukas Fleischer
Use Git string lists instead of str{spn,cspn,ncmp}() magic. This
significantly improves readability.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 shared.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/shared.c b/shared.c
index 1f6310a..01197f1 100644
--- a/shared.c
+++ b/shared.c
@@ -404,28 +404,29 @@ void cgit_diff_commit(struct commit *commit, filepair_fn 
fn, const char *prefix)
 
 int cgit_parse_snapshots_mask(const char *str)
 {
+   struct string_list tokens = STRING_LIST_INIT_DUP;
+   struct string_list_item *item;
const struct cgit_snapshot_format *f;
-   static const char *delim =  ;
-   int tl, sl, rv = 0;
+   int rv = 0;
 
/* favor legacy setting */
if (atoi(str))
return 1;
-   for (;;) {
-   str += strspn(str, delim);
-   tl = strcspn(str, delim);
-   if (!tl)
-   break;
+
+   string_list_split(tokens, str, ' ', -1);
+   string_list_remove_empty_items(tokens, 0);
+
+   for_each_string_list_item(item, tokens) {
for (f = cgit_snapshot_formats; f-suffix; f++) {
-   sl = strlen(f-suffix);
-   if ((tl == sl  !strncmp(f-suffix, str, tl)) ||
-  (tl == sl - 1  !strncmp(f-suffix + 1, str, tl - 
1))) {
+   if (!strcmp(item-string, f-suffix) ||
+   !strcmp(item-string, f-suffix + 1)) {
rv |= f-bit;
break;
}
}
-   str += tl;
}
+
+   string_list_clear(tokens, 0);
return rv;
 }
 
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 2/2] cgit.c: Fix comment on bit mask hack

2014-01-10 Thread Lukas Fleischer
* Formatting and spelling fixes.

* A bit mask with the size of one byte only allows for storing 8 (not
  255!) different flags.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 cgit.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/cgit.c b/cgit.c
index f4262d8..d74b0f3 100644
--- a/cgit.c
+++ b/cgit.c
@@ -885,14 +885,16 @@ static void cgit_parse_args(int argc, const char **argv)
ctx.qry.ofs = atoi(argv[i] + 6);
} else if (!prefixcmp(argv[i], --scan-tree=) ||
   !prefixcmp(argv[i], --scan-path=)) {
-   /* HACK: the global snapshot bitmask defines the
-* set of allowed snapshot formats, but the config
-* file hasn't been parsed yet so the mask is
-* currently 0. By setting all bits high before
-* scanning we make sure that any in-repo cgitrc
-* snapshot setting is respected by scan_tree().
-* BTW: we assume that there'll never be more than
-* 255 different snapshot formats supported by cgit...
+   /*
+* HACK: The global snapshot bit mask defines the set
+* of allowed snapshot formats, but the config file
+* hasn't been parsed yet so the mask is currently 0.
+* By setting all bits high before scanning we make
+* sure that any in-repo cgitrc snapshot setting is
+* respected by scan_tree().
+*
+* NOTE: We assume that there aren't more than 8
+* different snapshot formats supported by cgit...
 */
ctx.cfg.snapshots = 0xFF;
scan++;
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 1/2] cgit.c: Use else for mutually exclusive branches

2014-01-10 Thread Lukas Fleischer
When parsing command line arguments, no pair of command line options can
ever match simultaneously. Use else if blocks to reflect this. This
change improves both readability and speed.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
Based on the patches I sent earlier today.

 cgit.c | 29 ++---
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/cgit.c b/cgit.c
index e31962d..f4262d8 100644
--- a/cgit.c
+++ b/cgit.c
@@ -865,35 +865,26 @@ static void cgit_parse_args(int argc, const char **argv)
for (i = 1; i  argc; i++) {
if (!prefixcmp(argv[i], --cache=)) {
ctx.cfg.cache_root = xstrdup(argv[i] + 8);
-   }
-   if (!strcmp(argv[i], --nocache)) {
+   } else if (!strcmp(argv[i], --nocache)) {
ctx.cfg.nocache = 1;
-   }
-   if (!strcmp(argv[i], --nohttp)) {
+   } else if (!strcmp(argv[i], --nohttp)) {
ctx.env.no_http = 1;
-   }
-   if (!prefixcmp(argv[i], --query=)) {
+   } else if (!prefixcmp(argv[i], --query=)) {
ctx.qry.raw = xstrdup(argv[i] + 8);
-   }
-   if (!prefixcmp(argv[i], --repo=)) {
+   } else if (!prefixcmp(argv[i], --repo=)) {
ctx.qry.repo = xstrdup(argv[i] + 7);
-   }
-   if (!prefixcmp(argv[i], --page=)) {
+   } else if (!prefixcmp(argv[i], --page=)) {
ctx.qry.page = xstrdup(argv[i] + 7);
-   }
-   if (!prefixcmp(argv[i], --head=)) {
+   } else if (!prefixcmp(argv[i], --head=)) {
ctx.qry.head = xstrdup(argv[i] + 7);
ctx.qry.has_symref = 1;
-   }
-   if (!prefixcmp(argv[i], --sha1=)) {
+   } else if (!prefixcmp(argv[i], --sha1=)) {
ctx.qry.sha1 = xstrdup(argv[i] + 7);
ctx.qry.has_sha1 = 1;
-   }
-   if (!prefixcmp(argv[i], --ofs=)) {
+   } else if (!prefixcmp(argv[i], --ofs=)) {
ctx.qry.ofs = atoi(argv[i] + 6);
-   }
-   if (!prefixcmp(argv[i], --scan-tree=) ||
-   !prefixcmp(argv[i], --scan-path=)) {
+   } else if (!prefixcmp(argv[i], --scan-tree=) ||
+  !prefixcmp(argv[i], --scan-path=)) {
/* HACK: the global snapshot bitmask defines the
 * set of allowed snapshot formats, but the config
 * file hasn't been parsed yet so the mask is
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Disallow downloading disabled snapshot formats

2014-01-10 Thread Lukas Fleischer
We did only display enabled snapshot formats but we did not prevent from
downloading disabled formats when requested. Fix this by adding an
appropriate check.

Also, add a test case that checks whether downloading disabled snapshot
formats is denied, as expected.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 tests/t0107-snapshot.sh | 5 +
 ui-snapshot.c   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh
index 6cf7aaa..01e8d22 100755
--- a/tests/t0107-snapshot.sh
+++ b/tests/t0107-snapshot.sh
@@ -79,4 +79,9 @@ test_expect_success UNZIP 'verify unzipped file-5' '
test_line_count = 1 master/file-5
 '
 
+test_expect_success 'try to download a disabled snapshot format' '
+   cgit_url foo/snapshot/master.tar.xz |
+   grep Unsupported snapshot format
+'
+
 test_done
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 8f82119..ab20a4a 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -205,7 +205,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
}
 
f = get_format(filename);
-   if (!f) {
+   if (!f || (snapshots  f-bit) == 0) {
show_error(Unsupported snapshot format: %s, filename);
return;
}
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 1/2] README: Spelling and formatting fixes

2014-01-08 Thread Lukas Fleischer
* Several small spelling and capitalization fixes.

* Use consistent and better-looking formatting that is compatible with
  AsciiDoc (and partly compatible with RST).

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 README | 82 +-
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/README b/README
index 8e4ed53..0c35f96 100644
--- a/README
+++ b/README
@@ -1,86 +1,86 @@
+cgit - CGI for Git
+==
 
-   cgit - cgi for git
-
-
-This is an attempt to create a fast web interface for the git scm, using a
-builtin cache to decrease server io-pressure.
-
+This is an attempt to create a fast web interface for the Git SCM, using a
+built-in cache to decrease server I/O pressure.
 
 Installation
+
 
-Building cgit involves building a proper version of git. How to do this
+Building cgit involves building a proper version of Git. How to do this
 depends on how you obtained the cgit sources:
 
 a) If you're working in a cloned cgit repository, you first need to
-initialize and update the git submodule:
+initialize and update the Git submodule:
 
-  $ git submodule init # register the git submodule in .git/config
-  $ $EDITOR .git/config# if you want to specify a different url for git
-  $ git submodule update   # clone/fetch and checkout correct git version
+$ git submodule init # register the Git submodule in .git/config
+$ $EDITOR .git/config# if you want to specify a different url for git
+$ git submodule update   # clone/fetch and checkout correct git version
 
 b) If you're building from a cgit tarball, you can download a proper git
 version like this:
 
-  $ make get-git
-
+$ make get-git
 
 When either a) or b) has been performed, you can build and install cgit like
 this:
 
-  $ make
-  $ sudo make install
+$ make
+$ sudo make install
 
-This will install cgit.cgi and cgit.css into /var/www/htdocs/cgit. You can
-configure this location (and a few other things) by providing a cgit.conf
+This will install `cgit.cgi` and `cgit.css` into `/var/www/htdocs/cgit`. You
+can configure this location (and a few other things) by providing a `cgit.conf`
 file (see the Makefile for details).
 
+Dependencies
+
 
-Dependencies:
-  -git 1.7.4
-  -zip lib
-  -crypto lib
-  -openssl lib
-
+* git 1.7.4
+* zip lib
+* crypto lib
+* openssl lib
 
 Apache configuration
+
 
-A new Directory-section must probably be added for cgit, possibly something
+A new `Directory` section must probably be added for cgit, possibly something
 like this:
 
-  Directory /var/www/htdocs/cgit/
-  AllowOverride None
-  Options +ExecCGI
-  Order allow,deny
-  Allow from all
-  /Directory
+Directory /var/www/htdocs/cgit/
+AllowOverride None
+Options +ExecCGI
+Order allow,deny
+Allow from all
+/Directory
 
 
 Runtime configuration
+-
 
-The file /etc/cgitrc is read by cgit before handling a request. In addition
+The file `/etc/cgitrc` is read by cgit before handling a request. In addition
 to runtime parameters, this file may also contain a list of repositories
-displayed by cgit (see cgitrc.5.txt for further details).
-
+displayed by cgit (see `cgitrc.5.txt` for further details).
 
 The cache
+-
 
-When cgit is invoked it looks for a cachefile matching the request and
-returns it to the client. If no such cachefile exist (or if it has expired),
-the content for the request is written into the proper cachefile before the
+When cgit is invoked it looks for a cache file matching the request and
+returns it to the client. If no such cache file exists (or if it has expired),
+the content for the request is written into the proper cache file before the
 file is returned.
 
-If the cachefile has expired but cgit is unable to obtain a lock for it, the
-stale cachefile is returned to the client. This is done to favour page
+If the cache file has expired but cgit is unable to obtain a lock for it, the
+stale cache file is returned to the client. This is done to favour page
 throughput over page freshness.
 
 The generated content contains the complete response to the client, including
-the http-headers Modified and Expires.
-
+the HTTP headers `Modified` and `Expires`.
 
 Online presence
+---
 
 * The cgit homepage is hosted by cgit at http://git.zx2c4.com/cgit/about/
 
-* Patches, bugreports, discussions and support should go to the cgit
+* Patches, bug reports, discussions and support should go to the cgit
   mailing list: cgit@lists.zx2c4.com. To sign up, visit 
   http://lists.zx2c4.com/mailman/listinfo/cgit
-- 
1.8.5.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 2/2] ui-log.c: Several simplifications

2013-11-22 Thread Lukas Fleischer
* Use argv_array_pushf() for inserting formatted strings.
* Remove unneeded static strings.
* Replace if by else if for readability and speed.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 ui-log.c | 28 +---
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/ui-log.c b/ui-log.c
index 3c5130a..c154f69 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -291,7 +291,6 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char 
*grep, char *pattern
struct argv_array rev_argv = ARGV_ARRAY_INIT;
int i, columns = commit_graph ? 4 : 3;
int must_free_tip = 0;
-   struct strbuf argbuf = STRBUF_INIT;
 
/* rev_argv.argv[0] will be ignored by setup_revisions */
argv_array_push(rev_argv, log_rev_setup);
@@ -305,10 +304,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, 
char *grep, char *pattern
pattern = xstrdup(pattern);
if (!strcmp(grep, grep) || !strcmp(grep, author) ||
!strcmp(grep, committer)) {
-   strbuf_addf(argbuf, --%s=%s, grep, pattern);
-   argv_array_push(rev_argv, argbuf.buf);
-   }
-   if (!strcmp(grep, range)) {
+   argv_array_pushf(rev_argv, --%s=%s, grep, pattern);
+   } else if (!strcmp(grep, range)) {
char *arg;
/* Split the pattern at whitespace and add each token
 * as a revision expression. Do not accept other
@@ -327,25 +324,19 @@ void cgit_print_log(const char *tip, int ofs, int cnt, 
char *grep, char *pattern
}
}
if (commit_graph) {
-   static const char *graph_arg = --graph;
-   static const char *color_arg = --color;
-   argv_array_push(rev_argv, graph_arg);
-   argv_array_push(rev_argv, color_arg);
+   argv_array_push(rev_argv, --graph);
+   argv_array_push(rev_argv, --color);
graph_set_column_colors(column_colors_html,
COLUMN_COLORS_HTML_MAX);
}
 
-   if (commit_sort == 1) {
-   static const char *date_order_arg = --date-order;
-   argv_array_push(rev_argv, date_order_arg);
-   } else if (commit_sort == 2) {
-   static const char *topo_order_arg = --topo-order;
-   argv_array_push(rev_argv, topo_order_arg);
-   }
+   if (commit_sort == 1)
+   argv_array_push(rev_argv, --date-order);
+   else if (commit_sort == 2)
+   argv_array_push(rev_argv, --topo-order);
 
if (path) {
-   static const char *double_dash_arg = --;
-   argv_array_push(rev_argv, double_dash_arg);
+   argv_array_push(rev_argv, --);
argv_array_push(rev_argv, path);
}
 
@@ -437,5 +428,4 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char 
*grep, char *pattern
/* If we allocated tip then it is safe to cast away const. */
if (must_free_tip)
free((char*) tip);
-   strbuf_release(argbuf);
 }
-- 
1.8.4.2

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH v2 1/2] ui-diff: Use diff_tree_sha1() for raw diff formatting

2013-09-14 Thread Lukas Fleischer
On Tue, Aug 27, 2013 at 10:40:50AM +0200, Lukas Fleischer wrote:
 Use Git's internal diff_tree_sha1() function for the /rawdiff/ command
 instead of trying to recreate this functionality.
 
 Signed-off-by: Lukas Fleischer c...@cryptocrack.de
 ---
  ui-diff.c | 23 +--
  1 file changed, 21 insertions(+), 2 deletions(-)
 

Any comments on this series?

 [...]
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH v2 2/2] ui-shared: Drop filepair_cb_raw() and helper

2013-08-27 Thread Lukas Fleischer
Remove filepair_cb_raw() and all related functions. These are no longer
needed. We now use Git's internal functions for raw diff formatting
everywhere.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 ui-shared.c | 72 -
 ui-shared.h |  1 -
 2 files changed, 73 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index 1e19421..7ab2ab1 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -950,75 +950,3 @@ void cgit_print_snapshot_links(const char *repo, const 
char *head,
}
strbuf_release(filename);
 }
-
-static void print_line_raw(char *line, int len)
-{
-   char c = line[len-1];
-
-   line[len-1] = '\0';
-   htmlf(%s\n, line);
-   line[len-1] = c;
-}
-
-static void header_raw(unsigned char *sha1, char *path1, int mode1,
-  unsigned char *sha2, char *path2, int mode2)
-{
-   char *abbrev1, *abbrev2;
-   int subproject;
-
-   subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2));
-   htmlf(diff --git a/%s b/%s\n, path1, path2);
-
-   if (mode1 == 0)
-   htmlf(new file mode %.6o\n, mode2);
-
-   if (mode2 == 0)
-   htmlf(deleted file mode %.6o\n, mode1);
-
-   if (!subproject) {
-   abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
-   abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
-   htmlf(index %s..%s, abbrev1, abbrev2);
-   free(abbrev1);
-   free(abbrev2);
-   if (mode1 != 0  mode2 != 0) {
-   htmlf( %.6o, mode1);
-   if (mode2 != mode1)
-   htmlf(..%.6o, mode2);
-   }
-
-   if (is_null_sha1(sha1)) {
-   path1 = dev/null;
-   htmlf(\n--- /%s\n, path1);
-   } else
-   htmlf(\n--- a/%s\n, path1);
-
-   if (is_null_sha1(sha2)) {
-   path2 = dev/null;
-   htmlf(+++ /%s\n, path2);
-   } else
-   htmlf(+++ b/%s\n, path2);
-   }
-}
-
-void filepair_cb_raw(struct diff_filepair *pair)
-{
-   unsigned long old_size = 0;
-   unsigned long new_size = 0;
-   int binary = 0;
-
-   header_raw(pair-one-sha1, pair-one-path, pair-one-mode,
-  pair-two-sha1, pair-two-path, pair-two-mode);
-   if (S_ISGITLINK(pair-one-mode) || S_ISGITLINK(pair-two-mode)) {
-   if (S_ISGITLINK(pair-one-mode))
-   print_line_raw(fmt(-Subproject %s, 
sha1_to_hex(pair-one-sha1)), 52);
-   if (S_ISGITLINK(pair-two-mode))
-   print_line_raw(fmt(+Subproject %s, 
sha1_to_hex(pair-two-sha1)), 52);
-   return;
-   }
-   if (cgit_diff_files(pair-one-sha1, pair-two-sha1, old_size,
-   new_size, binary, 0, 0, print_line_raw))
-   html(Error running diff);
-   if (binary)
-   html(Binary files differ\n);
-}
diff --git a/ui-shared.h b/ui-shared.h
index a337dce..5987e77 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -67,5 +67,4 @@ extern void cgit_print_snapshot_links(const char *repo, const 
char *head,
  const char *hex, int snapshots);
 extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
   const char *page);
-extern void filepair_cb_raw(struct diff_filepair *pair);
 #endif /* UI_SHARED_H */
-- 
1.8.4.rc3.500.gc3113b0

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 5/5] t0108: Add tests for revision ranges

2013-08-26 Thread Lukas Fleischer
Add tests to check whether generating multiple patches at once works.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 tests/t0108-patch.sh | 17 +
 1 file changed, 17 insertions(+)

diff --git a/tests/t0108-patch.sh b/tests/t0108-patch.sh
index 0a2ec2e..fcc749d 100755
--- a/tests/t0108-patch.sh
+++ b/tests/t0108-patch.sh
@@ -42,4 +42,21 @@ test_expect_success 'find `cgit` signature' '
tail -2 tmp | head -1 | grep ^cgit
 '
 
+test_expect_success 'generate patches for multiple commits' '
+   id=$(git --git-dir=$PWD/repos/foo/.git rev-parse HEAD)
+   id2=$(git --git-dir=$PWD/repos/foo/.git rev-parse HEAD~3)
+   cgit_query url=foo/patchid=$idid2=$id2 tmp
+'
+
+test_expect_success 'find `cgit` signature' '
+   tail -2 tmp | head -1 | grep ^cgit
+'
+
+test_expect_success 'compare with output of git-format-patch(1)' '
+   CGIT_VERSION=$(sed -n s/CGIT_VERSION = //p ../../VERSION)
+   git --git-dir=$PWD/repos/foo/.git format-patch -p -N 
--subject-prefix= --signature=cgit $CGIT_VERSION --stdout HEAD~3..HEAD tmp2
+   sed 1,5d tmp tmp_
+   cmp tmp_ tmp2
+'
+
 test_done
-- 
1.8.4.rc3.500.gc3113b0

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH/RFC 1/2] ui-diff: Use diff_tree_sha1() for raw diff formatting

2013-08-26 Thread Lukas Fleischer
Use Git's internal diff_tree_sha1() function for the /rawdiff/ command
instead of trying to recreate this functionality.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
The test suite still passes. If anybody has any idea how to do this
better: Comments welcome.

 ui-diff.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/ui-diff.c b/ui-diff.c
index 1209c47..c602494 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -360,7 +360,7 @@ void cgit_print_diff_ctrls()
 void cgit_print_diff(const char *new_rev, const char *old_rev,
 const char *prefix, int show_ctrls, int raw)
 {
-   struct commit *commit, *commit2;
+   struct commit *commit, *commit2 = NULL;
 
if (!new_rev)
new_rev = ctx.qry.head;
@@ -394,10 +394,32 @@ void cgit_print_diff(const char *new_rev, const char 
*old_rev,
}
 
if (raw) {
+   unsigned char old_tree_sha1[20], new_tree_sha1[20];
+   struct diff_options diffopt;
+
+   memcpy(new_tree_sha1, commit-tree-object.sha1, 20);
+   if (commit2) {
+   memcpy(old_tree_sha1, commit2-tree-object.sha1, 20);
+   } else {
+   /*
+* SHA-1 of an empty tree. We might be better off not
+* hardcoding this.
+*/
+   get_sha1(4b825dc642cb6eb9a060e54bf8d69288fbee4904,
+old_tree_sha1);
+   }
+
+   diff_setup(diffopt);
+   diffopt.output_format = DIFF_FORMAT_PATCH;
+   DIFF_OPT_SET(diffopt, RECURSIVE);
+   diff_setup_done(diffopt);
+
ctx.page.mimetype = text/plain;
cgit_print_http_headers(ctx);
-   cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb_raw,
-  prefix, 0);
+   diff_tree_sha1(old_tree_sha1, new_tree_sha1, , diffopt);
+   diffcore_std(diffopt);
+   diff_flush(diffopt);
+
return;
}
 
-- 
1.8.4.rc3.500.gc3113b0

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH/RFC 1/2] ui-diff: Use diff_tree_sha1() for raw diff formatting

2013-08-26 Thread Lukas Fleischer
On Tue, Aug 27, 2013 at 03:31:14AM +0200, Jason A. Donenfeld wrote:
 
 
 
 On Tue, Aug 27, 2013 at 3:27 AM, Lukas Fleischer c...@cryptocrack.de wrote:
 
 +   } else {
 +   /*
 +* SHA-1 of an empty tree. We might be better off
 not
 +* hardcoding this.
 +*/
 +   get_sha1
 (4b825dc642cb6eb9a060e54bf8d69288fbee4904,
 +old_tree_sha1);
 +   }
 +
 
 
 What's the story here? 

This is needed if we want to build a diff for the root commit. It
doesn't have any parent, so we need to build against the empty tree. I
am pretty sure there are better ways to do this -- just too tired to
check now (hence the RFC in the subject).
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH v4 1/4] ui-diff: Check the return value of get_sha1()

2013-08-20 Thread Lukas Fleischer
Sync with what we do everywhere else and check the return value of
get_sha1() instead of calling sha1_object_info() to validate the object.
Note that we later call lookup_commit_reference(), which checks that
both SHA1 values refer to commits, anyway.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 ui-diff.c | 23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/ui-diff.c b/ui-diff.c
index 838db8c..1209c47 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -360,15 +360,11 @@ void cgit_print_diff_ctrls()
 void cgit_print_diff(const char *new_rev, const char *old_rev,
 const char *prefix, int show_ctrls, int raw)
 {
-   enum object_type type;
-   unsigned long size;
struct commit *commit, *commit2;
 
if (!new_rev)
new_rev = ctx.qry.head;
-   get_sha1(new_rev, new_rev_sha1);
-   type = sha1_object_info(new_rev_sha1, size);
-   if (type == OBJ_BAD) {
+   if (get_sha1(new_rev, new_rev_sha1)) {
cgit_print_error(Bad object name: %s, new_rev);
return;
}
@@ -378,19 +374,18 @@ void cgit_print_diff(const char *new_rev, const char 
*old_rev,
return;
}
 
-   if (old_rev)
-   get_sha1(old_rev, old_rev_sha1);
-   else if (commit-parents  commit-parents-item)
+   if (old_rev) {
+   if (get_sha1(old_rev, old_rev_sha1)) {
+   cgit_print_error(Bad object name: %s, old_rev);
+   return;
+   }
+   } else if (commit-parents  commit-parents-item) {
hashcpy(old_rev_sha1, commit-parents-item-object.sha1);
-   else
+   } else {
hashclr(old_rev_sha1);
+   }
 
if (!is_null_sha1(old_rev_sha1)) {
-   type = sha1_object_info(old_rev_sha1, size);
-   if (type == OBJ_BAD) {
-   cgit_print_error(Bad object name: %s, 
sha1_to_hex(old_rev_sha1));
-   return;
-   }
commit2 = lookup_commit_reference(old_rev_sha1);
if (!commit2 || parse_commit(commit2)) {
cgit_print_error(Bad commit: %s, 
sha1_to_hex(old_rev_sha1));
-- 
1.8.4.rc3.500.gc3113b0

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH] Use strbuf for reading configuration files

2013-06-04 Thread Lukas Fleischer
Use struct strbuf from Git instead of fixed-size buffers to remove the
limit on the length of configuration file lines and refactor
read_config_line() to improve readability.

Note that this also fixes a buffer overflow that existed with the
original fixed-size buffer implementation.

Signed-off-by: Lukas Fleischer c...@cryptocrack.de
---
 configfile.c | 65 ++--
 configfile.h |  2 ++
 2 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/configfile.c b/configfile.c
index d98989c..e6ad1d6 100644
--- a/configfile.c
+++ b/configfile.c
@@ -31,45 +31,44 @@ static void skip_line(FILE *f)
;
 }
 
-static int read_config_line(FILE *f, char *line, const char **value, int 
bufsize)
+static int read_config_line(FILE *f, struct strbuf *name, struct strbuf *value)
 {
-   int i = 0, isname = 0;
+   int c = next_char(f);
 
-   *value = NULL;
-   while (i  bufsize - 1) {
-   int c = next_char(f);
-   if (!isname  (c == '#' || c == ';')) {
-   skip_line(f);
-   continue;
-   }
-   if (!isname  isspace(c))
-   continue;
+   strbuf_reset(name);
+   strbuf_reset(value);
 
-   if (c == '='  !*value) {
-   line[i] = 0;
-   *value = line[i + 1];
-   } else if (c == '\n'  !isname) {
-   i = 0;
-   continue;
-   } else if (c == '\n' || c == EOF) {
-   line[i] = 0;
-   break;
-   } else {
-   line[i] = c;
-   }
-   isname = 1;
-   i++;
+   /* Skip comments and preceding spaces. */
+   while (c == '#' || c == ';') {
+   skip_line(f);
+   c = next_char(f);
+   }
+   while (isspace(c))
+   c = next_char(f);
+
+   /* Read variable name. */
+   while (c != '=') {
+   if (c == '\n' || c == EOF)
+   return 0;
+   strbuf_addch(name, c);
+   c = next_char(f);
}
-   line[i + 1] = 0;
-   return i;
+
+   /* Read variable value. */
+   c = next_char(f);
+   while (c != '\n'  c != EOF) {
+   strbuf_addch(value, c);
+   c = next_char(f);
+   }
+
+   return 1;
 }
 
 int parse_configfile(const char *filename, configfile_value_fn fn)
 {
static int nesting;
-   int len;
-   char line[256];
-   const char *value;
+   struct strbuf name = STRBUF_INIT;
+   struct strbuf value = STRBUF_INIT;
FILE *f;
 
/* cancel deeply nested include-commands */
@@ -78,10 +77,12 @@ int parse_configfile(const char *filename, 
configfile_value_fn fn)
if (!(f = fopen(filename, r)))
return -1;
nesting++;
-   while ((len = read_config_line(f, line, value, sizeof(line)))  0)
-   fn(line, value);
+   while (read_config_line(f, name, value))
+   fn(name.buf, value.buf);
nesting--;
fclose(f);
+   strbuf_release(name);
+   strbuf_release(value);
return 0;
 }
 
diff --git a/configfile.h b/configfile.h
index 04235e5..af7ca19 100644
--- a/configfile.h
+++ b/configfile.h
@@ -1,6 +1,8 @@
 #ifndef CONFIGFILE_H
 #define CONFIGFILE_H
 
+#include cgit.h
+
 typedef void (*configfile_value_fn)(const char *name, const char *value);
 
 extern int parse_configfile(const char *filename, configfile_value_fn fn);
-- 
1.8.3.450.gf3f2a46

___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH] Use strbuf for reading configuration files

2013-06-04 Thread Lukas Fleischer
On Tue, Jun 04, 2013 at 04:47:53PM +0200, Lukas Fleischer wrote:
 Use struct strbuf from Git instead of fixed-size buffers to remove the
 limit on the length of configuration file lines and refactor
 read_config_line() to improve readability.
 
 Note that this also fixes a buffer overflow that existed with the
 original fixed-size buffer implementation.
 
 Signed-off-by: Lukas Fleischer c...@cryptocrack.de
 ---
  configfile.c | 65 
 ++--
  configfile.h |  2 ++
  2 files changed, 35 insertions(+), 32 deletions(-)
 
 diff --git a/configfile.c b/configfile.c
 index d98989c..e6ad1d6 100644
 --- a/configfile.c
 +++ b/configfile.c
 @@ -31,45 +31,44 @@ static void skip_line(FILE *f)
 [...]
 + /* Skip comments and preceding spaces. */
 + while (c == '#' || c == ';') {
 + skip_line(f);
 + c = next_char(f);
 + }
 + while (isspace(c))
 + c = next_char(f);

Just noticed that this no longer detects indented comments. Not sure if
it makes sense to accept these (since we already only allow full
fill-line comments) but given that no longer allowing them is probably
considered a regression I will amend the patch and resubmit as far and
as soon as there aren't any other comments.

 +
 + /* Read variable name. */
 [...]
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit