]> Lady’s Gitweb - Gitweb/log
Gitweb
25 hours agogitweb/Makefile: define all .PHONY prerequisites inline
Ævar Arnfjörð Bjarmason [Tue, 28 Jun 2022 10:15:55 +0000 (12:15 +0200)]
gitweb/Makefile: define all .PHONY prerequisites inline

Move the '.PHONY' definition so that it's split up and accompanies the
relevant as they're defined. This will make a subsequent diff smaller
as we'll remove some of these, and won't need to re-edit the
now-removed '.PHONY' line.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: switch to an XHTML5 DOCTYPE
Jason Yundt [Thu, 2 Jun 2022 11:43:05 +0000 (07:43 -0400)]
gitweb: switch to an XHTML5 DOCTYPE

According to the HTML Standard FAQ:

“What is the DOCTYPE for modern HTML documents?

In text/html documents:

<!DOCTYPE html>

In documents delivered with an XML media type: no DOCTYPE is required
and its use is generally unnecessary. However, you may use one if you
want (see the following question). Note that the above is well-formed
XML.”

Source: [1]

Gitweb uses an XHTML 1.0 DOCTYPE:

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

While that DOCTYPE is still valid [2], it has several disadvantages:

1. It’s misleading. If an XML parser uses the DTD at the given link,
   then the entities &nbsp; and &sdot; won’t get declared. Instead, the
   parser has to use a DTD from the HTML Standard that has nothing to do
   with XHTML 1.0 [2].
2. It’s obsolete. XHTML 1.0 was last revised in 2002 and was superseded in
   2018 [3].
3. It’s unreliable. Gitweb uses &nbsp; and &sdot; but lets an external file
   define them. “[…U]using entity references for characters in XML documents
   is unsafe if they are defined in an external file (except for &lt;, &gt;,
   &amp;, &quot;, and &apos;).” [4]

[1]: <https://github.com/whatwg/html/blob/main/FAQ.md#what-is-the-doctype-for-modern-html-documents>
[2]: <https://html.spec.whatwg.org/multipage/xhtml.html#parsing-xhtml-documents>
[3]: <https://www.w3.org/TR/xhtml1/#xhtml>
[4]: <https://html.spec.whatwg.org/multipage/xhtml.html#writing-xhtml-documents>

Signed-off-by: Jason Yundt <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: remove invalid http-equiv="content-type"
Jason Yundt [Tue, 8 Mar 2022 15:56:12 +0000 (10:56 -0500)]
gitweb: remove invalid http-equiv="content-type"

Before this change, gitweb would generate pages which included:

<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/>

When a meta's http-equiv equals "content-type", the http-equiv is said
to be in the "Encoding declaration state". According to the HTML
Standard,

The Encoding declaration state may be used in HTML documents,
but elements with an http-equiv attribute in that state must not
be used in XML documents.

Source: <https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-content-type>

This change removes that meta element since gitweb always generates XML
documents.

Signed-off-by: Jason Yundt <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: use HEAD as secondary sort key in git_get_heads_list()
Greg Hurrell [Wed, 9 Jun 2021 19:28:06 +0000 (21:28 +0200)]
gitweb: use HEAD as secondary sort key in git_get_heads_list()

The "heads" section on the gitweb summary page shows heads in
`-committerdate` order (ie. the most recently-modified ones at the
top), tie-breaking equal-dated refs using the implicit `refname` sort
fallback. This recency-based ordering appears in multiple places in the
UI, such as the project listing, the tags list, and even the
shortlog and log views.

Given two equal-dated refs, however, sorting the `HEAD` ref before
the non-`HEAD` ref provides more useful signal than merely sorting by
refname. For example, say we had "master" and "trunk" both pointing at
the same commit but "trunk" was `HEAD`, sorting "trunk" first helps
communicate its special status as the default branch that you'll check
out if you clone the repo.

Add `-HEAD` as a secondary sort key to the `git for-each-ref` call
in `git_get_heads_list()` to provide the desired behavior. The most
recently committed refs will appear first, but `HEAD`-ness will be used
as a tie-breaker. Note that `refname` is the implicit fallback sort key,
which means that two same-dated non-`HEAD` refs will continue to be
sorted in lexicographical order, as they are today.

Signed-off-by: Greg Hurrell <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: add "e-mail privacy" feature to redact e-mail addresses
Georgios Kontaxis [Sun, 28 Mar 2021 23:26:03 +0000 (23:26 +0000)]
gitweb: add "e-mail privacy" feature to redact e-mail addresses

Gitweb extracts content from the Git log and makes it accessible
over HTTP. As a result, e-mail addresses found in commits are
exposed to web crawlers and they may not respect robots.txt.
This can result in unsolicited messages.

Introduce an 'email-privacy' feature which redacts e-mail addresses
from the generated HTML content. Specifically, obscure addresses
retrieved from the the author/committer and comment sections of the
Git log. The feature is off by default.

This feature does not prevent someone from downloading the
unredacted commit log, e.g., by cloning the repository, and
extracting information from it. It aims to hinder the low-
effort, bulk collection of e-mail addresses by web crawlers.

Signed-off-by: Georgios Kontaxis <redacted>
Acked-by: Eric Wong <redacted>
Acked-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb/Makefile: conditionally include ../GIT-VERSION-FILE
Ramsay Jones [Tue, 8 Dec 2020 22:34:28 +0000 (22:34 +0000)]
gitweb/Makefile: conditionally include ../GIT-VERSION-FILE

The 'clean' target is still noticeably slow on cygwin, despite the
improvements made by previous patches. For example, the second
invocation of 'make clean' below:

  $ make clean >/dev/null 2>&1
  $ make clean
  ...
  make[1]: Entering directory '/home/ramsay/git/gitweb'
  make[2]: Entering directory '/home/ramsay/git'
  make[2]: 'GIT-VERSION-FILE' is up to date.
  make[2]: Leaving directory '/home/ramsay/git'
  ...
  $

has been timed at 10.361s on my laptop (an old core i5-4200M @ 2.50GHz,
8GB RAM, 1TB HDD).

Notice that the 'clean' target is making a nested call to the parent
Makefile to ensure that the GIT-VERSION-FILE is up-to-date. This is to
ensure that the $(GIT_VERSION) make variable is set, once that file had
been included. However, the 'clean' target does not use the $(GIT_VERSION)
variable, directly or indirectly, so it does not have any affect on what
the target removes. Therefore, the time spent on ensuring an up to date
GIT-VERSION-FILE is wasted effort.

In order to eliminate such wasted effort, use the value of the internal
$(MAKECMDGOALS) variable to only '-include ../GIT-VERSION-FILE' when the
target is not 'clean'. (This drops the time down to 8.430s, on my laptop,
giving an improvement of 18.64%).

Signed-off-by: Ramsay Jones <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Recognize *-to and Closes/Fixes trailers
Emma Brooks [Sat, 25 Apr 2020 02:17:23 +0000 (02:17 +0000)]
gitweb: Recognize *-to and Closes/Fixes trailers

Commit trailers like "Thanks-to:", "Fixes:", and "Closes:" are fairly
common, but gitweb didn't highlight them like other trailers.

Signed-off-by: Emma Brooks <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: fix UTF-8 encoding when using CGI::Fast
Julien Moutinho [Sun, 29 Mar 2020 00:20:28 +0000 (01:20 +0100)]
gitweb: fix UTF-8 encoding when using CGI::Fast

FCGI streams are implemented using the older stream API: TIEHANDLE,
therefore applying PerlIO layers using binmode() has no effect to them.
The solution in this patch is to redefine the FCGI::Stream::PRINT function
to use UTF-8 as output encoding, except within git_blob_plain() and git_snapshot()
which must still output in raw binary mode.

This problem and solution were previously reported back in 2012:
- http://git.661346.n2.nabble.com/Gitweb-running-as-FCGI-does-not-print-its-output-in-UTF-8-td7573415.html
- http://stackoverflow.com/questions/5005104

Signed-off-by: Julien Moutinho <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: fix a couple spelling errors in comments
Denis Ovsienko [Sat, 4 Jan 2020 17:39:26 +0000 (18:39 +0100)]
gitweb: fix a couple spelling errors in comments

Signed-off-by: Denis Ovsienko <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: escape URLs generated by href()
Jeff King [Fri, 15 Nov 2019 09:06:07 +0000 (04:06 -0500)]
gitweb: escape URLs generated by href()

There's a cross-site scripting problem in gitweb, where it will print
URLs generated by its href() helper without further quoting. This allows
an attacker to point a victim to a specially crafted gitweb URL and
inject arbitrary HTML into the resulting page (which the victim sees as
coming from gitweb).

The base of the URL comes from evaluate_uri(), which pulls the value of
$REQUEST_URI via the CGI module. It tries to strip off $PATH_INFO, but
fails to do so in some cases (including ones that contain special
characters, like "+"). Most of the uses of the URL end up being passed
to "$cgi->a(-href = href())", which will get quoted properly by the CGI
module. But in a few places, we output them ourselves as part of
manually-generated HTML, and whatever was in the original URL will
appear unquoted in the output.

Given that all of the nearby variables placed into this manual HTML
_are_ quoted, it seems like the authors assumed that these URLs would
not need quoting. So it's possible that the bug is actually in
evaluate_uri(), which should be doing a more careful job of stripping
$PATH_INFO. There's some discussion in a comment in that function, as
well as the commit message in 81d3fe9f48 (gitweb: fix wrong base URL
when non-root DirectoryIndex, 2009-02-15). But I'm not sure I understand
it.

Regardless, it's a good idea to quote these values at the point of
insertion into the HTML output:

  1. Even if there is a bug in evaluate_uri(), this would give us
     belt-and-suspenders protection.

  2. evaluate_uri() is only handling the base. Some generated URLs will
     also mention arbitrary refs or filenames in the repositories, and
     these should be quoted anyway.

  3. It should never _hurt_ to quote (and that's what all of the
     $cgi->a() calls are doing already).

So there may be further work here, but this patch at least prevents the
XSS vulnerability, and shouldn't make anything worse.

The test here covers the calls in print_feed_meta(), but I manually
audited every call to href() to see how its output was used, and quoted
appropriately. Most of them are esc_attr(), as they're used in tag
attributes, but I used esc_html() when the URLs were printed bare. The
distinction is largely academic, as one is implemented as a wrapper for
the other.

Reported-by: NAKAYAMA DAISUKE <redacted>
Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agoFix spelling errors in code comments
Elijah Newren [Tue, 5 Nov 2019 17:07:23 +0000 (17:07 +0000)]
Fix spelling errors in code comments

Reported-by: Jens Schleusener <redacted>
Signed-off-by: Elijah Newren <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: correctly store previous rev in javascript-actions mode
Robert Luberda [Sun, 27 Oct 2019 09:14:26 +0000 (10:14 +0100)]
gitweb: correctly store previous rev in javascript-actions mode

Without this change, the setting

 $feature{'javascript-actions'}{'default'} = [1];

in gitweb.conf breaks gitweb's blame page: clicking on line numbers
displayed in the second column on the page has no effect.

For comparison, with javascript-actions disabled, clicking on line
numbers loads the previous version of the line.

Addresses https://bugs.debian.org/741883.

Signed-off-by: Jonathan Nieder <redacted>
Signed-off-by: Robert Luberda <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: make hash size independent
brian m. carlson [Tue, 19 Feb 2019 00:05:26 +0000 (00:05 +0000)]
gitweb: make hash size independent

Gitweb has several hard-coded 40 values throughout it to check for
values that are passed in or acquired from Git.  To simplify the code,
introduce a regex variable that matches either exactly 40 or exactly 64
hex characters, and use this variable anywhere we would have previously
hard-coded a 40 in a regex.

Add some helper functions which allow us to write tighter regexes that
match exactly the number of hex characters we're expecting.

Similarly, switch the code that looks for deleted diffinfo information
to look for either 40 or 64 zeros, and update one piece of code to use
this function.  Finally, when formatting a log line, allow an
abbreviated describe output to contain up to 64 characters.

Helped-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: brian m. carlson <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: hard-depend on the Digest::MD5 5.8 module
Ævar Arnfjörð Bjarmason [Sat, 3 Mar 2018 15:38:08 +0000 (15:38 +0000)]
gitweb: hard-depend on the Digest::MD5 5.8 module

Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
conditionally require Digest::MD5 anymore. It was released with perl
v5.7.3[1]

The initial introduction of the dependency in
e9fdd74e53 ("gitweb: (gr)avatar support", 2009-06-30) says as much,
this also undoes part of the later 2e9c8789b7 ("gitweb: Mention
optional Perl modules in INSTALL", 2011-02-04) since gitweb will
always be run on at least 5.8, so there's no need to mention
Digest::MD5 as a required module in the documentation, let's instead
say that we require perl 5.8.

1. $ corelist Digest::MD5
   Data for 2015-02-14
   Digest::MD5 was first released with perl v5.7.3

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: use filetest to allow ACLs
Guillaume Castagnino [Thu, 19 Oct 2017 07:32:46 +0000 (09:32 +0200)]
gitweb: use filetest to allow ACLs

In commit 46a1385 (gitweb: skip unreadable subdirectories, 2017-07-18)
we forgot to handle non-unix ACLs as well. Fix this.

Signed-off-by: Guillaume Castagnino <redacted>
Reviewed-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: add 'raw' blob_plain link in history overview
Job Snijders [Tue, 22 Aug 2017 20:07:29 +0000 (22:07 +0200)]
gitweb: add 'raw' blob_plain link in history overview

For people that work with very large plain text files it may be easier
if one can bypass viewing the htmlized blob and instead click directly
to the raw file (rather then click through 'blob' and then to 'raw').

Signed-off-by: Job Snijders <redacted>
Reviewed-by: Giuseppe Bilotta <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: skip unreadable subdirectories
Hielke Christian Braun [Tue, 18 Jul 2017 08:41:54 +0000 (10:41 +0200)]
gitweb: skip unreadable subdirectories

gitweb terminates and shows no project list, if it can not access a
sub-directory in the project root directory while looking for projects
to show.

Work it around by skipping unreadable directories.

Signed-off-by: Hielke Christian Braun <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agoSpelling fixes
Ville Skyttä [Sun, 25 Jun 2017 10:20:41 +0000 (13:20 +0300)]
Spelling fixes

Signed-off-by: Ville Skyttä <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agodoc: use https links to Wikipedia to avoid http redirects
Sven Strickroth [Sat, 13 May 2017 09:54:51 +0000 (11:54 +0200)]
doc: use https links to Wikipedia to avoid http redirects

Signed-off-by: Sven Strickroth <redacted>
Reviewed-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: link to "git describe"'d commits in log messages
Ævar Arnfjörð Bjarmason [Thu, 6 Oct 2016 09:11:35 +0000 (09:11 +0000)]
gitweb: link to "git describe"'d commits in log messages

Change the log formatting function to know about "git describe" output
such as "v2.8.0-4-g867ad08", in addition to just plain "867ad08".

There are still many valid refnames that we don't link to
e.g. v2.10.0-rc1~2^2~1 is also a valid way to refer to
v2.8.0-4-g867ad08, but I'm not supporting that with this commit,
similarly it's trivially possible to create some refnames like
"æ/var-gf6727b0" or which won't be picked up by this regex.

There's surely room for improvement here, but I just wanted to address
the very common case of sticking "git describe" output into commit
messages without trying to link to all possible refnames, that's going
to be a rather futile exercise given that this is free text, and it
would be prohibitively expensive to look up whether the references in
question exist in our repository.

There was on-list discussion about how we could do better than this
patch. Junio suggested to update parse_commits() to call a new
"gitweb--helper" command which would pass each of the revision
candidates through "rev-parse --verify --quiet". That would cut down
on our false positives (e.g. we'll link to "deadbeef"), and also allow
us to be more aggressive in selecting candidate revisions.

That may be too expensive to work in practice, or it may
not. Investigating that would be a good follow-up to this patch.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: link to 7-char+ SHA-1s, not only 8-char+
Ævar Arnfjörð Bjarmason [Thu, 6 Oct 2016 09:11:34 +0000 (09:11 +0000)]
gitweb: link to 7-char+ SHA-1s, not only 8-char+

Change the minimum length of an abbreviated object identifier in the
commit message gitweb tries to turn into link from 8 hexchars to 7.

This arbitrary minimum length of 8 was introduced in bfe2191 ("gitweb:
SHA-1 in commit log message links to "object" view", 2006-12-10), but
the default abbreviation length is 7, and has been for a long time.

It's still possible to reference SHA-1s down to 4 characters in length,
see v1.7.4-1-gdce9648's MINIMUM_ABBREV, but I can't see how to make
git actually produce that, so I doubt anyone is putting that into log
messages in practice, but people definitely do put 7 character SHA-1s
into log messages.

I think it's fairly dubious to link to things matching [0-9a-fA-F]
here as opposed to just [0-9a-f], that dates back to the initial
version of gitweb from 161332a ("first working version",
2005-08-07). Git will accept all-caps SHA-1s, but didn't ever produce
them as far as I can tell.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: fix a typo in a comment
Ævar Arnfjörð Bjarmason [Thu, 6 Oct 2016 09:11:33 +0000 (09:11 +0000)]
gitweb: fix a typo in a comment

Change a typo'd MIME type in a comment. The Content-Type is
application/xhtml+xml, not application/xhtm+xml.

Fixes up code originally added in 53c4031 ("gitweb: Strip
non-printable characters from syntax highlighter output", 2011-09-16).

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: use highlight's shebang detection
Ian Kelling [Sat, 24 Sep 2016 22:32:58 +0000 (15:32 -0700)]
gitweb: use highlight's shebang detection

The "highlight" binary can, in some cases, determine the language type
by the means of file contents, for example the shebang in the first line
for some scripting languages.  Make use of this autodetection for files
which syntax is not known by gitweb.  In that case, pass the blob
contents to "highlight --force"; the parameter is needed to make it
always generate HTML output (which includes HTML-escaping).

Although we now run highlight on files which do not end up highlighted,
performance is virtually unaffected because when we call highlight, it
is used for escaping HTML.  In the case that highlight is used, gitweb
calls sanitize() instead of esc_html(), and the latter is significantly
slower (it does more, being roughly a superset of sanitize()).  Simple
benchmark comparing performance of 'blob' view of files without syntax
highlighting in gitweb before and after this change indicates ±1%
difference in request time for all file types.  Benchmark was performed
on local instance on Debian, using Apache/2.4.23 web server and CGI.

Document the feature and improve syntax highlight documentation, add
test to ensure gitweb doesn't crash when language detection is used.

Signed-off-by: Ian Kelling <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: remove unused guess_file_syntax() parameter
Ian Kelling [Sat, 24 Sep 2016 22:32:57 +0000 (15:32 -0700)]
gitweb: remove unused guess_file_syntax() parameter

Signed-off-by: Ian Kelling <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: escape link body in format_ref_marker
Andreas Brauchli [Fri, 29 Jul 2016 14:49:37 +0000 (16:49 +0200)]
gitweb: escape link body in format_ref_marker

Fix a case where an html link can be generated from unescaped input
resulting in invalid strict xhtml or potentially injected code.

An overview of a repo with a tag "1.0.0&0.0.1" would previously result
in an unescaped ampersand in the link body.

Signed-off-by: Andreas Brauchli <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: apply fallback encoding before highlight
Shin Kojima [Tue, 3 May 2016 13:00:51 +0000 (22:00 +0900)]
gitweb: apply fallback encoding before highlight

Some multi-byte character encodings (such as Shift_JIS and GBK) have
characters whose final bytes is an ASCII '\' (0x5c), and they
will be displayed as funny-characters even if $fallback_encoding is
correct.  This is because `highlight` command always expects UTF-8
encoded strings from STDIN.

    $ echo 'my $v = "申";' | highlight --syntax perl | w3m -T text/html -dump
    my $v = "申";

    $ echo 'my $v = "申";' | iconv -f UTF-8 -t Shift_JIS | highlight \
        --syntax perl | iconv -f Shift_JIS -t UTF-8 | w3m -T text/html -dump

    iconv: (stdin):9:135: cannot convert
    my $v = "

This patch prepare git blob objects to be encoded into UTF-8 before
highlighting in the manner of `to_utf8` subroutine.

Signed-off-by: Shin Kojima <redacted>
Reviewed-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: squelch "uninitialized value" warning
Øyvind A. Holm [Tue, 12 Jan 2016 03:31:56 +0000 (04:31 +0100)]
gitweb: squelch "uninitialized value" warning

git_object() chomps $type that is read from "cat-file -t", but
it does so before checking if $type is defined, resulting in
a Perl warning in the server error log:

  gitweb.cgi: Use of uninitialized value $type in scalar chomp at
  [...]/gitweb.cgi line 7579., referer: [...]

when trying to access a non-existing commit, for example:

  http://HOST/?p=PROJECT.git;a=commit;h=NON_EXISTING_COMMIT

Check the value in $type before chomping.  This will cause us to
call href with its action parameter set to undef when formulating
the URL to redirect to, but that is harmless, as the function treats
a parameter that set to undef as if it does not exist.

Signed-off-by: Øyvind A. Holm <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: hack around CGI's list-context param() handling
Jeff King [Tue, 18 Nov 2014 17:10:22 +0000 (12:10 -0500)]
gitweb: hack around CGI's list-context param() handling

As of CGI.pm's 4.08 release, the behavior to call
CGI::param() in a list context is deprecated (because it can
be potentially unsafe if called inside a hash constructor).
This causes gitweb to issue a warning for some of our code,
which in turn causes the tests to fail.

Our use is in fact _not_ one of the dangerous cases, as we
are intentionally using a list context. The recommended
route by 4.08 is to use the new CGI::multi_param() call to
make it explicit that we know what we are doing.
However, that function is only available in 4.08, which is
about a month old; we cannot rely on having it.

One option would be to set $CGI::LIST_CONTEXT_WARN globally,
which turns off the warning. However, that would eliminate
the protection these newer releases are trying to provide.
We want to annotate each site as OK using the new function.

So instead, let's check whether CGI provides the
multi_param() function, and if not, provide an
implementation that just wraps param(). That will work on
both old and new versions of CGI. Sadly, we cannot just
check defined(\&CGI::multi_param), because CGI uses the
autoload feature, which claims that all functions are
defined. Instead, we just do a version check.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: use start_form, not startform that was removed in CGI.pm 4.04
Roland Mas [Thu, 16 Oct 2014 06:54:47 +0000 (08:54 +0200)]
gitweb: use start_form, not startform that was removed in CGI.pm 4.04

CGI.pm 4.04 removed the startform method, which had previously been
deprecated in favour of start_form.  Changes file for CGI.pm says:

    4.04 2014-09-04
     [ REMOVED / DEPRECATIONS ]
- startform and endform methods removed (previously deprecated,
  you should be using the start_form and end_form methods)

Signed-off-by: Roland Mas <redacted>
Reviewed-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agocomments: fix misuses of "nor"
Justin Lebar [Mon, 31 Mar 2014 22:11:46 +0000 (15:11 -0700)]
comments: fix misuses of "nor"

Signed-off-by: Justin Lebar <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Avoid overflowing page body frame with large images
Andrew Keller [Mon, 17 Feb 2014 14:25:13 +0000 (09:25 -0500)]
gitweb: Avoid overflowing page body frame with large images

When displaying a blob in gitweb, if it's an image, specify constraints for
maximum display width and height to prevent the image from overflowing the
frame of the enclosing page_body div.

This change assumes that it is more desirable to see the whole image without
scrolling (new behavior) than it is to see every pixel without zooming
(previous behavior).

Signed-off-by: Andrew Keller <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Denote non-heads, non-remotes branches
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:44 +0000 (12:54 +0100)]
gitweb: Denote non-heads, non-remotes branches

Given two branches residing in refs/heads/master and refs/wip/feature
the list-of-branches view will present them in following way:
master
feature (wip)

When getting a snapshot of a 'feature' branch, the tarball is going to
have name like 'project-wip-feature-<short hash>.tgz'.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Add a feature for adding more branch refs
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:43 +0000 (12:54 +0100)]
gitweb: Add a feature for adding more branch refs

Allow extra-branch-refs feature to tell gitweb to show refs from
additional hierarchies in addition to branches in the list-of-branches
view.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Return 1 on validation success instead of passed input
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:42 +0000 (12:54 +0100)]
gitweb: Return 1 on validation success instead of passed input

Users of validate_* passing "0" might get failures on correct name
because of coercion of "0" to false in code like:
die_error(500, "invalid ref") unless (check_ref_format ("0"));

Also, the validate_foo subs are renamed to is_valid_foo.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Move check-ref-format code into separate function
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:41 +0000 (12:54 +0100)]
gitweb: Move check-ref-format code into separate function

This check will be used in more than one place later.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix the author initials in blame for non-ASCII names
Ævar Arnfjörð Bjarmason [Fri, 30 Aug 2013 08:37:01 +0000 (08:37 +0000)]
gitweb: Fix the author initials in blame for non-ASCII names

Change the @author_initials feature Jakub added in
v1.6.4-rc2-14-ga36817b to match non-ASCII author initials as intended.

The regexp Jakub added was intended to match
non-ASCII (/\b([[:upper:]])\B/g). But in Perl this doesn't actually
match non-ASCII upper-case characters unless the string being matched
against has the UTF8 flag.

So when we open a pipe to "git blame" we need to mark the file
descriptor we're opening as utf8 explicitly.

So as a result it abbreviates me to "AB" not "ÆAB", entirely because "Æ"
isn't /[[:upper:]]/ unless the string being matched against has the UTF8
flag.

Here's something that demonstrates the issue:

    #!/usr/bin/env perl
    use strict;
    use warnings;

    binmode STDOUT, ':utf8' if $ENV{UTF8};
    open my $fd, "-|", "git", "blame", "--incremental", "--", "Makefile" or die "Can't open: $!";
    binmode $fd, ":utf8" if $ENV{UTF8};
    while (my $line = <$fd>) {
     next unless my ($author) = $line =~ /^author (.*)/;
     my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
     printf "%s (%s)\n",  join("", @author_initials), $author;
    }

When that's run with and without UTF8 being true in the environment it
gives, on git.git:

    $ UTF8=0 perl author-initials.pl | sort | uniq -c |
    sort -nr | head -n 5
         99 JH (Junio C Hamano)
         35 JN (Jonathan Nieder)
         35 JK (Jeff King)
         20 JS (Johannes Schindelin)
         16 AB (Ævar Arnfjörð Bjarmason)
    $ UTF8=1 perl author-initials.pl | sort | uniq -c |
    sort -nr | head -n 5
         99 JH (Junio C Hamano)
         35 JN (Jonathan Nieder)
         35 JK (Jeff King)
         20 JS (Johannes Schindelin)
         16 ÆAB (Ævar Arnfjörð Bjarmason)

Acked-by: Jakub Narębski <redacted>
Tested-by: Ævar Arnfjörð Bjarmason <redacted>
Tested-by: Simon Ruderich <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: make search help link less ugly
Tony Finch [Tue, 20 Aug 2013 16:59:54 +0000 (17:59 +0100)]
gitweb: make search help link less ugly

The search help link was a superscript question mark right next to
a drop-down menu, which looks misaligned and is a cramped and
awkward click target. Remove the superscript tags and add some
spacing to fix these nits. Add a title attribute to provide an
explanatory mouseover.

Signed-off-by: Tony Finch <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: omit the repository owner when it is unset
Tony Finch [Tue, 20 Aug 2013 16:59:44 +0000 (17:59 +0100)]
gitweb: omit the repository owner when it is unset

On the repository summary page, leave the owner line out if the
repo does not have an owner, rather than displaying a labelled empty
field. This does not affect the owner column in the projects list
page, which is present unless $omit_owner is true.

Signed-off-by: Tony Finch <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: vertically centre contents of page footer
Tony Finch [Tue, 20 Aug 2013 16:59:03 +0000 (17:59 +0100)]
gitweb: vertically centre contents of page footer

Signed-off-by: Tony Finch <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: ensure OPML text fits inside its box
Tony Finch [Tue, 20 Aug 2013 16:59:02 +0000 (17:59 +0100)]
gitweb: ensure OPML text fits inside its box

The rss_logo CSS style has a fixed width which is too narrow for
the string "OPML". Replace the fixed width with horizontal padding
so the text fits with nice margins.

Signed-off-by: Tony Finch <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: allow extra breadcrumbs to prefix the trail
Tony Finch [Thu, 4 Jul 2013 17:02:12 +0000 (18:02 +0100)]
gitweb: allow extra breadcrumbs to prefix the trail

There are often parent pages logically above the gitweb projects
list, e.g. home pages of the organization and department that host
the gitweb server. This change allows you to include links to those
pages in gitweb's breadcrumb trail.

Signed-off-by: Tony Finch <redacted>
Reviewed-by: Jonathan Nieder <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: fix problem causing erroneous project list
Charles McGarvey [Wed, 5 Jun 2013 04:44:28 +0000 (22:44 -0600)]
gitweb: fix problem causing erroneous project list

The bug is manifest when running gitweb in a persistent process (e.g.
FastCGI, PSGI), and it's easy to reproduce.  If a gitweb request
includes the searchtext parameter (i.e. s), subsequent requests using
the project_list action--which is the default action--and without
a searchtext parameter will be filtered by the searchtext value of the
first request.  This is because the value of the $search_regexp global
(the value of which is based on the searchtext parameter) is currently
being persisted between requests.

Instead, clear $search_regexp before dispatching each request.

Signed-off-by: Charles McGarvey <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb/INSTALL: Simplify description of GITWEB_CONFIG_SYSTEM
Jakub Narębski [Fri, 12 Apr 2013 22:20:48 +0000 (00:20 +0200)]
gitweb/INSTALL: Simplify description of GITWEB_CONFIG_SYSTEM

The flow of the text describing GITWEB_CONFIG_SYSTEM and
GITWEB_CONFIG_COMMON in gitweb/INSTALL is awkward.  "This is bad. Oh
the other hand, better is broken. Therefore we do this." forces
readers to make multiple guesses while reading: "ok, bad, so you
plan to change it and warn us about upcoming change?  oh, not that,
changing it is bad, so we have to live with it?  oh, not that, there
is another one that is common and that is what we can use".

Better rewrite said paragraph to avoid such a mental roller-coaster in
the first place.

Signed-off-by: Junio Hamano <redacted>
Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agoCorrect common spelling mistakes in comments and tests
Stefano Lattarini [Thu, 11 Apr 2013 22:36:10 +0000 (00:36 +0200)]
Correct common spelling mistakes in comments and tests

Most of these were found using Lucas De Marchi's codespell tool.

Signed-off-by: Stefano Lattarini <redacted>
Signed-off-by: Jonathan Nieder <redacted>
Acked-by: Matthieu Moy <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agodoc: various spelling fixes
Stefano Lattarini [Thu, 11 Apr 2013 22:36:10 +0000 (00:36 +0200)]
doc: various spelling fixes

Most of these were found using Lucas De Marchi's codespell tool.

Signed-off-by: Stefano Lattarini <redacted>
Signed-off-by: Jonathan Nieder <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb/README: remove reference to git.kernel.org
Fredrik Gustafsson [Thu, 7 Mar 2013 01:23:43 +0000 (02:23 +0100)]
gitweb/README: remove reference to git.kernel.org

git.kernel.org no longer uses gitweb but has switched to cgit.

Info about this can be found on: https://www.kernel.org/pelican.html
or simply by looking at http://git.kernel.org . This is change since
2013-03-01.

Signed-off-by: Fredrik Gustafsson <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: refer to picon/gravatar images over the same scheme
Andrej E Baranov [Mon, 28 Jan 2013 23:41:32 +0000 (00:41 +0100)]
gitweb: refer to picon/gravatar images over the same scheme

With the current code, the images from picon and gravatar are
requested over http://, and browsers give mixed contents warning
when gitweb is served over https://.

Just drop the scheme: part from the URL, so that these external
sites are accessed over https:// in such a case.

Signed-off-by: Andrej E Baranov <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: fix error in sanitize when highlight is enabled
Orgad Shaneh [Sun, 30 Dec 2012 11:52:53 +0000 (13:52 +0200)]
gitweb: fix error in sanitize when highlight is enabled

$1 becomes undef by internal regex, since it has no capture groups.

Match against accpetable control characters using index() instead of a regex.

Signed-off-by: Orgad Shaneh <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Sort projects with undefined ages last
Matthew Daley [Tue, 11 Dec 2012 10:56:07 +0000 (23:56 +1300)]
gitweb: Sort projects with undefined ages last

Sorting gitweb's project list by age ('Last Change') currently shows
projects with undefined ages at the head of the list. This gives a less
useful result when there are a number of projects that are missing or
otherwise faulty and one is trying to see what projects have been
updated recently.

Fix by sorting these projects with undefined ages at the bottom of the
list when sorting by age.

Signed-off-by: Matthew Daley <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: make remote_heads config setting work
Phil Pennock [Mon, 5 Nov 2012 23:50:47 +0000 (18:50 -0500)]
gitweb: make remote_heads config setting work

Git configuration items can not contain underscores in their section
and bottom-level variable name; the 'remote_heads' feature can not
be enabled on a per-repository basis with that name.

This changes the git-config option to be `gitweb.remoteheads` but does
not change the gitweb.conf option, to avoid backwards compatibility
issues.  We strip underscores from keys before looking through
git-config output for them.

An existing check on keynames was overly eager to reject non-word
letters, but if we ever start using three-level names, the middle
level string can contain almost anything, so fix that as well while
we are in the vicinity.

Signed-off-by: Phil Pennock <redacted>
Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: escape html in rss title
Jeff King [Mon, 12 Nov 2012 21:34:28 +0000 (16:34 -0500)]
gitweb: escape html in rss title

The title of an RSS feed is generated from many components,
including the filename provided as a query parameter, but we
failed to quote it.  Besides showing the wrong output, this
is a vector for XSS attacks.

Signed-off-by: Jeff King <redacted>
25 hours agogitweb.perl: fix %highlight_ext mappings
Richard Hubbell [Sun, 4 Nov 2012 17:45:55 +0000 (09:45 -0800)]
gitweb.perl: fix %highlight_ext mappings

When commit 592ea41 refactored the list of extensions for
syntax highlighting, it failed to take into account perl's
operator precedence within lists. As a result, we end up
creating a dictionary of one-to-one elements when the intent
was to map mutliple related types to one main type (e.g.,
bash, ksh, zsh, and sh should all map to sh since they share
similar syntax, but we ended up just mapping "bash" to
"bash" and so forth).

This patch adds parentheses to make the mapping as the
original change intended. It also reorganizes the list to
keep mapped extensions together.

Signed-off-by: Richard Hubbell <redacted>
Signed-off-by: Jeff King <redacted>
25 hours agogitweb.cgi: fix "comitter_tz" typo in feed
Dylan Alex Simon [Thu, 11 Oct 2012 20:40:35 +0000 (16:40 -0400)]
gitweb.cgi: fix "comitter_tz" typo in feed

gitweb's feeds sometimes contained committer timestamps in the wrong timezone
due to a misspelling.

Signed-off-by: Dylan Simon <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: URL-decode $my_url/$my_uri when stripping PATH_INFO
Jay Soffian [Thu, 9 Aug 2012 02:29:26 +0000 (22:29 -0400)]
gitweb: URL-decode $my_url/$my_uri when stripping PATH_INFO

When gitweb is used as a DirectoryIndex, it attempts to strip
PATH_INFO on its own, as $cgi->url() fails to do so.

However, it fails to account for the fact that PATH_INFO has
already been URL-decoded by the web server, but the value
returned by $cgi->url() has not been. This causes the stripping
to fail whenever the URL contains encoded characters.

To see this in action, setup gitweb as a DirectoryIndex and
then use it on a repository with a directory containing a
space in the name. Navigate to tree view, examine the gitweb
generated html and you'll see a link such as:

  <a href="/test.git/tree/HEAD:/directory with spaces">directory with spaces</a>

When clicked on, the browser will URL-encode this link, giving
a $cgi->url() of the form:

   /test.git/tree/HEAD:/directory%20with%20spaces

While PATH_INFO is:

   /test.git/tree/HEAD:/directory with spaces

Fix this by calling unescape() on both $my_url and $my_uri before
stripping PATH_INFO from them.

Signed-off-by: Jay Soffian <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Add support to Link: tag
Namhyung Kim [Wed, 4 Jul 2012 02:47:26 +0000 (11:47 +0900)]
gitweb: Add support to Link: tag

The tip tree is the one of major subsystem tree in the
Linux kernel project. On the tip tree, the Link: (or
similar Buglink:) tag is used for tracking the original
discussion or context. Since it's ususally in the S-o-b
area, it'd be better using same style with others.

Also as it tends to contain a message-id sent from git
send-email, a part of the line would set a wrong hyperlink
like [1]. Fix it by not using format_log_line_html().

[1] git.kernel.org/?p=linux/kernel/git/tip/tip.git;a=commit;h=08942f6d5d992e9486b07653fd87ea8182a22fa0

Signed-off-by: Namhyung Kim <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Handle other types of tag in git_print_log
Namhyung Kim [Wed, 4 Jul 2012 02:47:25 +0000 (11:47 +0900)]
gitweb: Handle other types of tag in git_print_log

There are many types of tags used in S-o-b area [1].
Update the regex to handle them properly. It requires
the tag should be started by a capital letter and ended
by '-by: ' or '-By: '. The only exception is 'Cc: '.

[1] http://lwn.net/Articles/503829/

Signed-off-by: Namhyung Kim <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Cleanup git_print_log()
Namhyung Kim [Wed, 4 Jul 2012 02:47:24 +0000 (11:47 +0900)]
gitweb: Cleanup git_print_log()

When we see a signed-off-by line (and its friends), we set $signoff
to true, but then we process the next line after we are done without
giving control to the rest of the loop.  And when the line we saw is
not a signed-off-by line, we reset $signoff to false before running
the remainder of the loop.

Hence, the check for $signoff that attempts to remove an extra empty
line between two signed-off-by line was not doing anything useful.

Rename $empty to a more explicit name $skip_blank_line to tell us to
skip a blank line when we see one, set it after we see and emit a
blank line (to avoid showing more than one empty lines in a raw) or
after we handle a signed-off-by line (to avoid empty lines after
such a line), to fix this bug, and get rid of the $signoff variable
that is not useful.

Signed-off-by: Namhyung Kim <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Option to not display information about owner
Kacper Kornet [Thu, 26 Apr 2012 16:45:44 +0000 (18:45 +0200)]
gitweb: Option to not display information about owner

In some setups the repository owner is not a well defined concept
and administrator can prefer it to be not shown. This commit add
and an option that enable to reach this effect.

Signed-off-by: Kacper Kornet <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Option to omit column with time of the last change
Kacper Kornet [Tue, 24 Apr 2012 17:39:15 +0000 (19:39 +0200)]
gitweb: Option to omit column with time of the last change

Generating information about last change for a large number of git
repositories can be very time consuming. This commit add an option to
omit 'Last Change' column when presenting the list of repositories.

Signed-off-by: Kacper Kornet <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Don't set owner if got empty value from projects.list
Kacper Kornet [Tue, 24 Apr 2012 17:50:05 +0000 (19:50 +0200)]
gitweb: Don't set owner if got empty value from projects.list

Prevent setting owner to an empty value if it is not specified in
projects.list file. Otherwise it stops retrieving information about the
owner from other files.

Signed-off-by: Kacper Kornet <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Refinement highlightning in combined diffs
Michał Kiedrowicz [Wed, 11 Apr 2012 21:18:44 +0000 (23:18 +0200)]
gitweb: Refinement highlightning in combined diffs

The highlightning of combined diffs is currently disabled.  This is
because output from a combined diff is much harder to highlight because
it is not obvious which removed and added lines should be compared.

Current code requires that the number of added lines is equal to the
number of removed lines and only skips first +/- character, treating
second +/- as a line content, Thus, it is not possible to simply use
existing algorithm unchanged for combined diffs.

Let's start with a simple case: only highlight changes that come from
one parent, i.e. when every removed line has a corresponding added line
for the same parent.  This way the highlightning cannot get wrong. For
example, following diffs would be highlighted:

- removed line for first parent
+ added line for first parent
  context line
 -removed line for second parent
 +added line for second parent

or

- removed line for first parent
 -removed line for second parent
+ added line for first parent
 +added line for second parent

but following output will not:

- removed line for first parent
 -removed line for second parent
 +added line for second parent
++added line for both parents

In other words, we require that pattern of '-'-es in pre-image matches
pattern of '+'-es in post-image.

Further changes may introduce more intelligent approach that better
handles combined diffs.

Signed-off-by: Michał Kiedrowicz <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Highlight interesting parts of diff
Michał Kiedrowicz [Wed, 11 Apr 2012 21:18:43 +0000 (23:18 +0200)]
gitweb: Highlight interesting parts of diff

Reading diff output is sometimes very hard, even if it's colored,
especially if lines differ only in few characters.  This is often true
when a commit fixes a typo or renames some variables or functions.

This commit teaches gitweb to highlight characters that are different
between old and new line with a light green/red background.  This should
work in the similar manner as in Trac or GitHub.

The algorithm that compares lines is based on contrib/diff-highlight.
Basically, it works by determining common prefix/suffix of corresponding
lines and highlightning only the middle part of lines.  For more
information, see contrib/diff-highlight/README.

Combined diffs are not supported but a following commit will change it.

Since we need to pass esc_html()'ed or esc_html_hl_regions()'ed lines to
format_diff_lines(), so it was taught to accept preformatted lines
passed as a reference.

Signed-off-by: Michał Kiedrowicz <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Push formatting diff lines to print_diff_chunk()
Michał Kiedrowicz [Wed, 11 Apr 2012 21:18:42 +0000 (23:18 +0200)]
gitweb: Push formatting diff lines to print_diff_chunk()

Now lines are formatted closer to place where we actually use HTML
formatted output.

This means that we put raw lines in the @chunk accumulator, rather than
formatted lines.  Because we still need to know class (type) of line
when accumulating data to post-process and print, process_diff_line()
subroutine was retired and replaced by diff_line_class() used in
git_patchset_body() and new restructured format_diff_line() used in
print_diff_chunk().

As a side effect, we have to pass \%from and \%to down to callstack.

This is a preparation patch for diff refinement highlightning. It's not
meant to change gitweb output.

[jn: wrote commit message]

Signed-off-by: Michał Kiedrowicz <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Use print_diff_chunk() for both side-by-side and inline diffs
Michał Kiedrowicz [Wed, 11 Apr 2012 21:18:41 +0000 (23:18 +0200)]
gitweb: Use print_diff_chunk() for both side-by-side and inline diffs

This renames print_sidebyside_diff_chunk() to print_diff_chunk() and
makes use of it for both side-by-side and inline diffs.  Now diff lines
are always accumulated before they are printed.  This opens the
possibility to preprocess diff output before it's printed, which is
needed for diff refinement highlightning (implemented in incoming
patches).

If print_diff_chunk() was left as is, the new function
print_inline_diff_lines() could reorder diff lines.  It first prints all
context lines, then all removed lines and finally all added lines.  If
the diff output consisted of mixed added and removed lines, gitweb would
reorder these lines.  This is true for combined diff output, for
example:

 - removed line for first parent
 + added line for first parent
  -removed line for second parent
 ++added line for both parents

would be rendered as:

- removed line for first parent
 -removed line for second parent
+ added line for first parent
++added line for both parents

To prevent gitweb from reordering lines, print_diff_chunk() calls
print_diff_lines() as soon as it detects that both added and removed
lines are present and there was a class change, and at the end of chunk.

Signed-off-by: Michał Kiedrowicz <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Extract print_sidebyside_diff_lines()
Michał Kiedrowicz [Wed, 11 Apr 2012 21:18:40 +0000 (23:18 +0200)]
gitweb: Extract print_sidebyside_diff_lines()

Currently, print_sidebyside_diff_chunk() does two things: it
accumulates diff lines and prints them.  Accumulation may be used to
perform additional operations on diff lines, so it makes sense to split
these two things.  Thus, whole code that formats and prints diff lines
in the 'side-by-side' manner is moved out of print_sidebyside_diff_chunk()
to a separate subroutine and two conditions that control printing
diff liens are merged.

Thanks to that, we can easily (in later patches) replace call to that
subroutine with a call to more generic print_diff_lines() that will
control whether 'inline' or 'side-by-side' diff should be printed.

As a side effect, context lines are printed just before printing added
and removed lines, and at the end of chunk (previously, they were
printed immediately on the class change).  However, this doesn't change
gitweb output.

The outcome of this patch is that print_sidebyside_diff_chunk() is now
much shorter and easier to read.

While at it, drop the '# assume that it is change' comment.  According
to Jakub Narębski:

What I meant here when I was writing it that they are lines that
changed between two versions, like '!' in original (not unified)
context format.

We can omit this comment.

Signed-off-by: Michał Kiedrowicz <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Pass esc_html_hl_regions() options to esc_html()
Jakub Narębski [Wed, 11 Apr 2012 21:18:39 +0000 (23:18 +0200)]
gitweb: Pass esc_html_hl_regions() options to esc_html()

With this change, esc_html_hl_regions() accepts options and passes them
down to esc_html().  This may be needed if a caller wants to pass
-nbsp=>1 to esc_html().

The idea and implementation example of this change was described in
337da8d2 (gitweb: Introduce esc_html_match_hl and esc_html_hl_regions,
2012-02-27).  While other suggestions may be more useful in some cases,
there is no need to implement them at the moment.  The
esc_html_hl_regions() interface may be changed later if it's needed.

[mk: extracted from larger patch and wrote commit message]

Signed-off-by: Jakub Narębski <redacted>
Signed-off-by: Michał Kiedrowicz <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: esc_html_hl_regions(): Don't create empty <span> elements
Michał Kiedrowicz [Wed, 11 Apr 2012 21:18:38 +0000 (23:18 +0200)]
gitweb: esc_html_hl_regions(): Don't create empty <span> elements

If $end is equal to or less than $begin, esc_html_hl_regions()
generates an empty <span> element.  It normally shouldn't be visible in
the web browser, but it doesn't look good when looking at page source.
It also minimally increases generated page size for no special reason.

Signed-off-by: Michał Kiedrowicz <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Use descriptive names in esc_html_hl_regions()
Michał Kiedrowicz [Wed, 11 Apr 2012 21:18:37 +0000 (23:18 +0200)]
gitweb: Use descriptive names in esc_html_hl_regions()

The $s->[0] and $s->[1] variables look a bit cryptic.  Let's rename them
to $begin and $end so that it's clear what they do.

Suggested-by: Jakub Narębski <redacted>
Signed-off-by: Michał Kiedrowicz <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix unintended "--no-merges" for regular Atom feed
Sebastian Pipping [Wed, 4 Apr 2012 12:25:44 +0000 (14:25 +0200)]
gitweb: Fix unintended "--no-merges" for regular Atom feed

The print_feed_meta() subroutine generates links for feeds with and
without merges, in RSS and Atom formats.  However because %href_params
was not properly reset, it generated links with "--no-merges" for all
except the very first link.

Before:
<link rel="alternate" title="[..] - Atom feed" href="/?p=.git;a=atom;opt=--no-merges" type="application/atom+xml" />
<link rel="alternate" title="[..] - Atom feed (no merges)" href="/?p=.git;a=atom;opt=--no-merges" type="application/atom+xml" />

After:
<link rel="alternate" title="[..] - Atom feed" href="/?p=.git;a=atom" type="application/atom+xml" />
<link rel="alternate" title="[..] - Atom feed (no merges)" href="/?p=.git;a=atom;opt=--no-merges" type="application/atom+xml" />

Signed-off-by: Sebastian Pipping <redacted>
Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: add If-Modified-Since handling to git_snapshot().
W. Trevor King [Thu, 29 Mar 2012 12:45:49 +0000 (08:45 -0400)]
gitweb: add If-Modified-Since handling to git_snapshot().

Because snapshots can be large, you can save some bandwidth by
supporting caching via If-Modified-Since.  This patch adds support for
the i-m-s request to git_snapshot() if the request is a commit.
Requests for snapshots of trees, which lack well defined timestamps,
are still handled as they were before.

Signed-off-by: W Trevor King <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: refactor If-Modified-Since handling
W. Trevor King [Thu, 29 Mar 2012 12:45:48 +0000 (08:45 -0400)]
gitweb: refactor If-Modified-Since handling

The current gitweb only generates Last-Modified and handles
If-Modified-Since headers for the git_feed action.  This patch breaks
the Last-Modified and If-Modified-Since handling code out from
git_feed into a new function exit_if_unmodified_since.  This makes the
code easy to reuse for other actions.

Only gitweb actions which can easily calculate a modification time
should use exit_if_unmodified_since, as the goal is to balance local
processing time vs. upload bandwidth.

Signed-off-by: W Trevor King <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: add `status` headers to git_feed() responses.
W. Trevor King [Thu, 29 Mar 2012 12:45:47 +0000 (08:45 -0400)]
gitweb: add `status` headers to git_feed() responses.

The git_feed() method was not setting a `Status` header unless it was
responding to an If-Modified-Since request with `304 Not Modified`.
Now, when it is serving successful responses, it sets status to `200
OK`.

Signed-off-by: W Trevor King <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agocorrect a few doubled-word nits in comments and documentation
Jim Meyering [Wed, 28 Mar 2012 08:45:36 +0000 (10:45 +0200)]
correct a few doubled-word nits in comments and documentation

Found by running this command:
$ git ls-files -z|xargs -0 perl -0777 -n \
 -e 'while (/\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims)' \
 -e '  {' \
 -e '    $n = ($` =~ tr/\n/\n/ + 1);' \
 -e '    ($v = $&) =~ s/\n/\\n/g;' \
 -e '    print "$ARGV:$n:$v\n";' \
 -e '  }'

Why not just git grep -E ...?
That wouldn't work then the doubled words are separated by a newline.
This is derived from a Makefile syntax-check rule in gnulib's maint.mk:
  http://git.sv.gnu.org/cgit/gnulib.git/tree/top/maint.mk

Signed-off-by: Jim Meyering <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix fixed string (non-regexp) project search
Jakub Narebski [Fri, 2 Mar 2012 22:34:24 +0000 (23:34 +0100)]
gitweb: Fix fixed string (non-regexp) project search

Use $search_regexp, where regex metacharacters are quoted, for
searching projects list, rather than $searchtext, which contains
original search term.

Reported-by: Ramsay Jones <redacted>
Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix passing parameters to git_project_search_form
Jakub Narebski [Fri, 2 Mar 2012 22:50:01 +0000 (23:50 +0100)]
gitweb: Fix passing parameters to git_project_search_form

The git_project_search_form() subroutine, introduced in a1e1b2d
(gitweb: improve usability of projects search form, 2012-01-31) didn't
get its arguments from caller correctly.  Gitweb worked correctly
thanks to sticky-ness of form fields in CGI.pm... but it make UTF-8
fix for project search not working.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Handle invalid regexp in regexp search
Jakub Narebski [Tue, 28 Feb 2012 18:41:47 +0000 (19:41 +0100)]
gitweb: Handle invalid regexp in regexp search

When using regexp search ('sr' parameter / $search_use_regexp variable
is true), check first that regexp is valid.

Without this patch we would get an error from Perl during search (if
searching is performed by gitweb), or highlighting matches substring
(if applicable), if user provided invalid regexp... which means broken
HTML, with error page (including HTTP headers) generated after gitweb
already produced some output.

Add test that illustrates such error: for example for regexp "*\.git"
we would get the following error:

  Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE \.git/
  at /var/www/cgi-bin/gitweb.cgi line 3084.

Reported-by: Ramsay Jones <redacted>
Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Highlight matched part of shortened project description
Jakub Narebski [Mon, 27 Feb 2012 01:55:22 +0000 (02:55 +0100)]
gitweb: Highlight matched part of shortened project description

Previous commit make gitweb use esc_html_match_hl() to mark match in
the _whole_ description of a project when searching projects.

This commit makes gitweb highlight match in _shortened_ description,
based on match in whole description, using esc_html_match_hl_chopped()
subroutine.

If match is in removed (chopped) part, even partially, then trailing
"... " is highlighted.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Highlight matched part of project description when searching projects
Jakub Narebski [Mon, 27 Feb 2012 01:55:21 +0000 (02:55 +0100)]
gitweb: Highlight matched part of project description when searching projects

Use esc_html_match_hl() from earlier commit to mark match in the
_whole_ description when searching projects.

Currently, with this commit, when searching projects there is always
shown full description of a project, and not a shortened one (like for
ordinary projects list view), even if the match is on project name and
not project description.  Because we always show full description of a
project, and not possibly shortened name, there is no need for having
full description on mouseover via title attribute.

Showing full description when there is match on it is useful to avoid
situation where match is in shortened, invisible part.  On the other
hand that makes project search different than projects list view; also
there can be problems with overly-long project descriptions.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Highlight matched part of project name when searching projects
Jakub Narebski [Mon, 27 Feb 2012 01:55:20 +0000 (02:55 +0100)]
gitweb: Highlight matched part of project name when searching projects

Use esc_html_match_hl() introduced in previous commit to escape HTML
and mark match, using span element with 'match' class.  Currently only
the 'path' part (i.e. the project name) is highlighted; match might be
on the project description.  Highlighting match in description is left
for next commit.

The code makes use of the fact that defined $search_regexp means that
there was search going on.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Introduce esc_html_match_hl and esc_html_hl_regions
Jakub Narebski [Mon, 27 Feb 2012 01:55:19 +0000 (02:55 +0100)]
gitweb: Introduce esc_html_match_hl and esc_html_hl_regions

The esc_html_match_hl() subroutine added in this commit will be used
to highlight *all* matches of given regexp, using 'match' class.
Ultimately it is to be used in all match highlighting, starting
with project search, which does not have it yet.

It uses the esc_html_hl_regions() subroutine, which is meant to
highlight in a given string a list of regions (given as a list of
[ beg, end ] pairs of positions in string), using HTML <span> element
with given class.  It could probably be used in other places that
do highlighting of part of ready line, like highlighting of changes
in a diff (diff refinement highlighting).

Implementation and enhancement notes:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Currently esc_html_hl_regions() subroutine doesn't accept any
  parameters, like esc_html() does.  We might want for example to
  pass  nbsp=>1  to it.

  It can easily be done with the following code:

    my %opts = grep { ref($_) ne "ARRAY" } @sel;
    @sel     = grep { ref($_) eq "ARRAY" } @sel;

  This allow adding parameters after or before regions, e.g.:

    esc_html_hl_regions("foo bar", "mark", [ 0, 3 ], -nbsp => 1);

* esc_html_hl_regions() escapes like esc_html(); if we wanted to
  highlight with esc_path(), we could pass subroutine reference
  to now named esc_gen_hl_regions().

    esc_html_hl_regions("foo bar", "mark", \&esc_path, [ 0, 3 ]);

  Note that this way we can handle -nbsp=>1 case automatically,
  e.g.

    esc_html_hl_regions("foo bar", "mark",
                        sub { esc_html(@_, -nbsp=>1) },
                        [ 0, 3 ]);

* Alternate solution for highlighting region of a string would be to
  use the idea that strings are to be HTML-escaped, and references to
  scalars are HTML (like in the idea for generic committags).

  This would require modifying gitweb code or esc_html to get list of
  fragments, e.g.:

    esc_html(\'<span class="mark">', 'foo', \'</span>', ' bar',
             { -nbsp => 1 });

  or

    esc_html([\'<span class="mark">', 'foo', \'</span>', ' bar'],
             -nbsp=>1);

  esc_html_match_hl() could be then simple wrapper around "match
  formatter", e.g.

    esc_html([ render_match_hl($str, $regexp) ], -nbsp=>1);

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Faster project search
Jakub Narebski [Thu, 23 Feb 2012 15:54:48 +0000 (16:54 +0100)]
gitweb: Faster project search

Before searching by some field the information we search for must be
filled in, but we do not have to fill other fields that are not
involved in the search.

To be able to request filling only specified fields,
fill_project_list_info() was enhanced in previous commit to take
additional parameters which specify part of projects info to fill.
This way we can limit doing expensive calculations (like running
git-for-each-ref to get 'age' / "Last changed" info) to doing those
only for projects which we will show as search results.

This commit actually uses this interface, changing gitweb code from
the following behavior

  fill all project info on all projects
  search projects

to behaving like this pseudocode

  fill search fields on all projects
  search projects
  fill all project info on search results

With this commit the number of git commands used to generate search
results is 2*<matched projects> + 1, and depends on number of matched
projects rather than number of all projects (all repositories).

Note: this is 'git for-each-ref' to find last activity, and 'git config'
for each project, and 'git --version' once.

Example performance improvements, for search that selects 2
repositories out of 12 in total:

* Before (warm cache):
  "This page took 0.867151 seconds  and 27 git commands to generate."

* After (warm cache):
  "This page took 0.673643 seconds  and 5 git commands to generate."

Now imagine that they are 5 repositories out of 5000, and cold or
trashed cache case.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Option for filling only specified info in fill_project_list_info
Jakub Narebski [Thu, 23 Feb 2012 15:54:47 +0000 (16:54 +0100)]
gitweb: Option for filling only specified info in fill_project_list_info

Enhance fill_project_list_info() subroutine to accept optional
parameters that specify which fields in project information needs to
be filled.  If none are specified then fill_project_list_info()
behaves as it used to, and ensure that all project info is filled.

This is in preparation of future lazy filling of project info in
project search and pagination of sorted list of projects.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Refactor checking if part of project info need filling
Jakub Narebski [Thu, 23 Feb 2012 15:54:46 +0000 (16:54 +0100)]
gitweb: Refactor checking if part of project info need filling

Extract the check if given keys (given parts) of project info needs to
be filled into project_info_needs_filling() subroutine.  It is for now
a thin wrapper around "!exists $project_info->{$key}".

Note that !defined was replaced by more correct !exists.

While at it uniquify treating of all project info, adding checks for
'age' field before running git_get_last_activity(), and also checking
for all keys filled in code protected by conditional, and not only
one.

The code now looks like this

  foreach my $project (@$project_list) {
   if (given keys need to be filled) {
   fill given keys
   }
   ...
  }

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix 'grep' search for multiple matches in file
Jakub Narebski [Wed, 15 Feb 2012 16:37:06 +0000 (17:37 +0100)]
gitweb: Fix 'grep' search for multiple matches in file

Commit ff7f218 (gitweb: Fix file links in "grep" search, 2012-01-05),
added $file_href variable, to reduce duplication and have the fix
applied in single place.

Unfortunately it made variable defined inside the loop, not taking into
account the fact that $file_href was set only if file changed.
Therefore for files with multiple matches $file_href was undefined for
second and subsequent matches.

Fix this bug by moving $file_href declaration outside loop.

Adds tests for almost all forms of sarch in gitweb, which were missing
from testuite.  Note that it only tests if there are no warnings, and
it doesn't check that gitweb finds what it should find.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix "heads" view when there is no current branch
Jakub Narebski [Wed, 15 Feb 2012 15:36:41 +0000 (16:36 +0100)]
gitweb: Fix "heads" view when there is no current branch

In a repository whose HEAD points to an unborn branch with no commits,
"heads" view and "summary" view (which shows what is shown in "heads"
view) compared the object names of commits at the tip of branches with the
output from "git rev-parse HEAD", which caused comparison of a string with
undef and resulted in a warning in the server log.

This can happen if non-bare repository (with default 'master' branch)
is updated not via committing but by other means like push to it, or
Gerrit.  It can happen also just after running "git checkout --orphan
<new branch>" but before creating any new commit on this branch.

Rewrite the comparison so that it also works when $head points at nothing;
in such a case, no branch can be "the current branch", add a test for it.
While at it, rename local variable $head to $head_at, as it points to
current commit rather than current branch name (HEAD contents).

The code still incorrectly shows all branches that point at the same
commit as what HEAD points as "the current branch", even when HEAD is
detached. Fixing this bug is outside the scope of this patch.

Reported-by: Rajesh Boyapati
Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Harden and improve $project_filter page title
Jakub Narebski [Sun, 12 Feb 2012 15:21:30 +0000 (16:21 +0100)]
gitweb: Harden and improve $project_filter page title

Commit 19d2d23 (gitweb: add project_filter to limit project list
to a subdirectory, 2012-01-30) added also support for displaying
$project_filter, if present, in page title.

Unfortunately it forgot to treat $project_filter as path, and escape
it using esc_path(), like it is done for $filename.

Also, it was not obvious that "$site_name - $project_filter" is about
project filtering: use "$site_name - projects in '$project_filter'".

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Allow UTF-8 encoded CGI query parameters and path_info
Jakub Narebski [Fri, 3 Feb 2012 12:44:54 +0000 (13:44 +0100)]
gitweb: Allow UTF-8 encoded CGI query parameters and path_info

Gitweb forgot to turn query parameters into UTF-8. This results in a bug
that one cannot search for a string with characters outside US-ASCII.  For
example searching for "Michał Kiedrowicz" (containing letter 'ł' - LATIN
SMALL LETTER L WITH STROKE, with Unicode codepoint U+0142, represented
with 0xc5 0x82 bytes in UTF-8 and percent-encoded as %C5%82) result in the
following incorrect data in search field

MichaÅ\202 Kiedrowicz

This is caused by CGI by default treating '0xc5 0x82' bytes as two
characters in Perl legacy encoding latin-1 (iso-8859-1), because 's'
query parameter is not processed explicitly as UTF-8 encoded string.

The solution used here follows "Using Unicode in a Perl CGI script"
article on http://www.lemoda.net/cgi/perl-unicode/index.html:

use CGI;
use Encode 'decode_utf8;
my $value = params('input');
$value = decode_utf8($value);

Decoding UTF-8 is done when filling %input_params hash and $path_info
variable; the former requires to move from explicit $cgi->param(<label>)
to $input_params{<name>} in a few places, which is a good idea anyway.

Also add -override=>1 parameter to $cgi->textfield() invocation in search
form.  Otherwise CGI would use values from query string if it is present,
filling value from $cgi->param... without decode_utf8().  As we are using
value of appropriate parameter anyway, -override=>1 doesn't change the
situation but makes gitweb fill search field correctly.

We could simply use the '-utf8' pragma (via "use CGI '-utf8';") to solve
this, but according to CGI.pm documentation, it may cause problems with
POST requests containing binary files, and it requires CGI 3.31 (I think),
released with perl v5.8.9.

Reported-by: Michał Kiedrowicz <redacted>
Signed-off-by: Jakub Narębski <redacted>
Tested-by: Michał Kiedrowicz <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Make project search respect project_filter
Jakub Narebski [Tue, 31 Jan 2012 00:20:55 +0000 (01:20 +0100)]
gitweb: Make project search respect project_filter

Make gitweb search within filtered projects (i.e. projects shown), and
change "List all projects" to "List all projects in '$project_filter/'"
if project_filter is used.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: improve usability of projects search form
Jakub Narebski [Tue, 31 Jan 2012 00:20:54 +0000 (01:20 +0100)]
gitweb: improve usability of projects search form

Refactor generating project search form into git_project_search_form().

Make text field wider and add on mouse over explanation (via "title"
attribute), add an option to use regular expressions, and replace
'Search:' label with [Search] button.

Also add "List all projects" link to make it easier to go back from search
result to list of all projects (note that an empty search term is
disallowed).

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: place links to parent directories in page header
Bernhard R. Link [Mon, 30 Jan 2012 20:10:23 +0000 (21:10 +0100)]
gitweb: place links to parent directories in page header

Change html page headers to not only link the project root and the
currently selected project but also the directories in between using
project_filter. (Allowing to jump to a list of all projects within
that intermediate directory directly and making the project_filter
feature visible to users).

Signed-off-by: Bernhard R. Link <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: show active project_filter in project_list page header
Bernhard R. Link [Mon, 30 Jan 2012 20:09:43 +0000 (21:09 +0100)]
gitweb: show active project_filter in project_list page header

In the page header of a project_list view with a project_filter
given show breadcrumbs in the page headers showing which directory
it is currently limited to and also containing links to the parent
directories.

Signed-off-by: Bernhard R. Link <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: limit links to alternate forms of project_list to active project_filter
Bernhard R. Link [Mon, 30 Jan 2012 20:09:00 +0000 (21:09 +0100)]
gitweb: limit links to alternate forms of project_list to active project_filter

If project_list action is given a project_filter argument, pass that to
TXT and OPML formats.

This way [OPML] and [TXT] links provide the same list of projects as
the projects_list page they are linked from.

Signed-off-by: Bernhard R. Link <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: add project_filter to limit project list to a subdirectory
Bernhard R. Link [Mon, 30 Jan 2012 20:07:37 +0000 (21:07 +0100)]
gitweb: add project_filter to limit project list to a subdirectory

This commit changes the project listing views (project_list,
project_index and opml) to limit the output to only projects in a
subdirectory if the new optional parameter ?pf=directory name is
used.

The implementation of the filter reuses the implementation used for
the 'forks' action (i.e. listing all projects within that directory
from the projects list file (GITWEB_LIST) or only projects in the
given subdirectory of the project root directory without a projects
list file).

Reusing $project instead of adding a new parameter would have been
nicer from a UI point-of-view (including PATH_INFO support) but
would complicate the $project validating code that is currently
being used to ensure nothing is exported that should not be viewable.

Signed-off-by: Bernhard R. Link <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: prepare git_get_projects_list for use outside 'forks'.
Bernhard R. Link [Mon, 30 Jan 2012 20:06:38 +0000 (21:06 +0100)]
gitweb: prepare git_get_projects_list for use outside 'forks'.

Use of the filter option of git_get_projects_list is currently limited
to forks. It currently assumes the project belonging to the filter
directory was already validated to be visible in the project list.

To make it more generic add an optional argument to denote visibility
verification is still needed.

If there is a projects list file (GITWEB_LIST) only projects from
this list are returned anyway, so no more checks needed.

If there is no projects list file and the caller requests strict
checking (GITWEB_STRICT_EXPORT), do not jump directly to the
given directory but instead do a normal search and filter the
results instead.

The only effect of GITWEB_STRICT_EXPORT without GITWEB_LIST is to make
sure no project can be viewed without also be found starting from
project root. git_get_projects_list without this patch does not enforce
this but all callers only call it with a filter already checked this
way. With this parameter a caller can request this check if the filter
cannot be checked this way.

Signed-off-by: Bernhard R. Link <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: move hard coded .git suffix out of git_get_projects_list
Bernhard R. Link [Mon, 30 Jan 2012 20:05:47 +0000 (21:05 +0100)]
gitweb: move hard coded .git suffix out of git_get_projects_list

Use of the filter option of git_get_projects_list is currently
limited to forks. It hard codes removal of ".git" suffixes from
the filter.

To make it more generic move the .git suffix removal to the callers.

Signed-off-by: Bernhard R. Link <redacted>
Acked-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix actionless dispatch for non-existent objects
Jakub Narebski [Sat, 7 Jan 2012 10:47:38 +0000 (11:47 +0100)]
gitweb: Fix actionless dispatch for non-existent objects

When gitweb URL does not provide action explicitly, e.g.

  http://git.example.org/repo.git/branch

dispatch() tries to guess action (view to be used) based on remaining
parameters.  Among others it is based on the type of requested object,
which gave problems when asking for non-existent branch or file (for
example misspelt name).

Now undefined $action from dispatch() should not result in problems.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Harden "grep" search against filenames with ':'
Jakub Narebski [Thu, 5 Jan 2012 20:32:56 +0000 (21:32 +0100)]
gitweb: Harden "grep" search against filenames with ':'

Run "git grep" in "grep" search with '-z' option, to be able to parse
response also for files with filename containing ':' character.  The
':' character is otherwise (without '-z') used to separate filename
from line number and from matched line.

Note that this does not protect files with filename containing
embedded newline.  This would be hard but doable for text files, and
harder or even currently impossible with binary files: git does not
quote filename in

  "Binary file <foo> matches"

message, but new `--break` and/or `--header` options to git-grep could
help here.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix file links in "grep" search
Jakub Narebski [Thu, 5 Jan 2012 20:26:48 +0000 (21:26 +0100)]
gitweb: Fix file links in "grep" search

There were two bugs in generating file links (links to "blob" view),
one hidden by the other.  The correct way of generating file link is

href(action=>"blob", hash_base=>$co{'id'},
     file_name=>$file);

It was $co{'hash'} (this key does not exist, and therefore this is
undef), and 'hash' instead of 'hash_base'.

To have this fix applied in single place, this commit also reduces
code duplication by saving file link (which is used for line links) in
$file_href.

Reported-by: Thomas Perl <redacted>
Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: accept trailing "/" in $project_list
Matthieu Moy [Wed, 4 Jan 2012 10:07:45 +0000 (11:07 +0100)]
gitweb: accept trailing "/" in $project_list

The current code is removing the trailing "/", but computing the string
length on the previous value, i.e. with the trailing "/". Later in the
code, we do

  my $path = substr($File::Find::name, $pfxlen + 1);

And the "$pfxlen + 1" is supposed to mean "the length of the prefix, plus
1 for the / separating the prefix and the path", but with an incorrect
$pfxlen, this basically eats the first character of the path, and yields
"404 - No projects found".

While we're there, also fix $pfxdepth to use $dir, although a change of 1
in the depth shouldn't really matter.

Signed-off-by: Matthieu Moy <redacted>
Signed-off-by: Junio C Hamano <redacted>
25 hours agogitweb: Fix fallback mode of to_utf8 subroutine
Jakub Narebski [Sun, 18 Dec 2011 22:00:58 +0000 (23:00 +0100)]
gitweb: Fix fallback mode of to_utf8 subroutine

e5d3de5 (gitweb: use Perl built-in utf8 function for UTF-8 decoding.,
2007-12-04) was meant to make gitweb faster by using Perl's internals
(see subsection "Messing with Perl's Internals" in Encode(3pm) manpage)

Simple benchmark confirms that (old = 00f429a, new = this version):

        old  new
  old    -- -65%
  new  189%   --

Unfortunately it made fallback mode of to_utf8 do not work...  except
for default value 'latin1' of $fallback_encoding ('latin1' is Perl
native encoding), which is why it was not noticed for such long time.

utf8::valid(STRING) is an internal function that tests whether STRING
is in a _consistent state_ regarding UTF-8.  It returns true is
well-formed UTF-8 and has the UTF-8 flag on _*or*_ if string is held
as bytes (both these states are 'consistent').  For gitweb the second
option was true, as output from git commands is opened without ':utf8'
layer.

What made it work at all for STRING in 'latin1' encoding is the fact
that utf8:decode(STRING) turns on UTF-8 flag only if source string is
valid UTF-8 and contains multi-byte UTF-8 characters... and that if
string doesn't have UTF-8 flag set it is treated as in native Perl
encoding, i.e.  'latin1' / 'iso-8859-1' (unless native encoding it is
EBCDIC ;-)).  It was ':utf8' layer that actually converted 'latin1'
(no UTF-8 flag == native == 'latin1) to 'utf8'.

Let's make use of the fact that utf8:decode(STRING) returns false if
STRING is invalid as UTF-8 to check whether to enable fallback mode.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
This page took 0.870434 seconds and 4 git commands to generate.