Not everyone uses the same tab width. gitweb learns a new setting to
control the tabstop width. The configuration can be set globally and
on a per project basis. The default is 8, preserving existing
behaviour. The configuration variable name is borrowed from the vim
setting with the same behaviour.
Signed-off-by: Charles Bailey <redacted>
---
The untabify function seems the sensible place to make the change. As
untabify is called once per line from various different locations it
also makes sense to cache the result of the config lookup in a package
variable, though this makes the change slightly less neat.
This change should have a minimal impact on performance but it would
appreciate some more eyes and ideally some performance testing on
heavier systems than my own.
gitweb/gitweb.perl | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 922dee9..cdabe37 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -108,6 +108,12 @@ our $mimetypes_file = undef;
# could be even 'utf-8' for the old behavior)
our $fallback_encoding = 'latin1';
+# variable to keep track of the the current tabstop width
+# this is a package variable as the natural place to check the feature is in
+# the untabify function, but as the function is called once per line we don't
+# want to have to recheck the config for each line
+our $tabstop_width;
+
# rename detection options for git-diff and git-diff-tree
# - default is '-M', with the cost proportional to
# (number of removed files) * (number of new files).
@@ -275,6 +281,18 @@ our %feature = (
'forks' => {
'override' => 0,
'default' => [0]},
+
+ # Tabstop width. Controls the number of spaces to which tabs are
+ # expanded. Default is 8.
+ # To change system wide add the following to $GITWEB_CONFIG
+ # $feature{'tabstop'}{'default'} = [8];
+ # To have project specific config enable override in $GITWEB_CONFIG
+ # $feature{'tabstop'}{'override'} = 1;
+ # and in project config gitweb.tabstop = <width>
+ 'tabstop' => {
+ 'sub' => \&feature_tabstop,
+ 'override' => 0,
+ 'default' => [8]},
);
sub gitweb_check_feature {@@ -340,6 +358,11 @@ sub feature_pickaxe {
return ($_[0]);
}
+sub feature_tabstop {
+ my ($val) = git_get_project_config('tabstop', '--int');
+ return defined($val) ? ($val) : ($_[0])
+}
+
# checking HEAD file with -e is fragile if the repository was
# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
# and then pruned.@@ -832,8 +855,12 @@ sub unquote {
sub untabify {
my $line = shift;
+ if (!defined($tabstop_width)) {
+ ($tabstop_width) = gitweb_check_feature('tabstop');
+ }
+
while ((my $pos = index($line, "\t")) != -1) {
- if (my $count = (8 - ($pos % 8))) {
+ if (my $count = ($tabstop_width - ($pos % $tabstop_width))) {
my $spaces = ' ' x $count;
$line =~ s/\t/$spaces/;
}--
1.5.4.3.432.g5ecfc
--
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
Charles Bailey [off-list ref] writes:
Not everyone uses the same tab width. gitweb learns a new setting to
control the tabstop width. The configuration can be set globally and
on a per project basis. The default is 8, preserving existing
behaviour. The configuration variable name is borrowed from the vim
setting with the same behaviour.
Good idea. Very nice change.
Signed-off-by: Charles Bailey <redacted>
---
The untabify function seems the sensible place to make the change. As
untabify is called once per line from various different locations it
also makes sense to cache the result of the config lookup in a package
variable, though this makes the change slightly less neat.
Since b201927 (gitweb: Read repo config using 'git config -z -l')
repository config is cached in %config hash (per repository), so
I don't think global / package variable $tabstop_width is really
needed...
This change should have a minimal impact on performance but it would
appreciate some more eyes and ideally some performance testing on
heavier systems than my own.
...but it would be better if you have checked at least on your system
if it does affect performance or not.
[...]
+our $tabstop_width;
I think I would write "our $tabstop_width = 8;" here.
--
Jakub Narebski
Poland
ShadeHawk on #git
On Mon, Mar 03, 2008 at 11:33:28PM +0100, Jakub Narebski wrote:
Charles Bailey [off-list ref] writes:
quoted
The untabify function seems the sensible place to make the change. As
untabify is called once per line from various different locations it
also makes sense to cache the result of the config lookup in a package
variable, though this makes the change slightly less neat.
Since b201927 (gitweb: Read repo config using 'git config -z -l')
repository config is cached in %config hash (per repository), so
I don't think global / package variable $tabstop_width is really
needed...
Fair point, although we still save the cost of some 'is the config
variable overrideable and if so is it overriden' logic. Untabify is a
once per line call which is more frequesnt than most gitweb config
checking calls.
quoted
This change should have a minimal impact on performance but it would
appreciate some more eyes and ideally some performance testing on
heavier systems than my own.
...but it would be better if you have checked at least on your system
if it does affect performance or not.
Not noticeably (on an old AMD Duron 900MHz), but my tests have been
unscientific.
[...]
+our $tabstop_width;
I think I would write "our $tabstop_width = 8;" here.
Currently, I use the fact that it is initially 'undef' to know that I
haven't checked the config yet. The config is then checked on the
first time through untabify.
Charles.
Jakub Narebski wrote:
+our $tabstop_width;
I think I would write "our $tabstop_width = 8;" here.
I'm sorry. Please drop this part. Seting it to undef is needed
if it is used as cache (as: not read in), while if we use %config
it is simply not needed.
--
Jakub Narebski
Poland
Charles Bailey wrote:
On Mon, Mar 03, 2008 at 11:33:28PM +0100, Jakub Narebski wrote:
quoted
Charles Bailey [off-list ref] writes:
quoted
The untabify function seems the sensible place to make the change. As
untabify is called once per line from various different locations it
also makes sense to cache the result of the config lookup in a package
variable, though this makes the change slightly less neat.
Since b201927 (gitweb: Read repo config using 'git config -z -l')
repository config is cached in %config hash (per repository), so
I don't think global / package variable $tabstop_width is really
needed...
Fair point, although we still save the cost of some 'is the config
variable overrideable and if so is it overriden' logic. Untabify is a
once per line call which is more frequesnt than most gitweb config
checking calls.
Good enough.
One think I'd worry about is interaction with mod_perl (or FastCGI),
namely if $tabstop_width wouldn't get stale information. Perhaps
writing
our $tabstop_width = undef;
as initializer would be enough.
--
Jakub Narebski
Poland