diff options
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/filecheck.pm | 1 | ||||
-rw-r--r-- | IkiWiki/Plugin/format.pm | 24 | ||||
-rw-r--r-- | IkiWiki/Plugin/git.pm | 49 | ||||
-rw-r--r-- | IkiWiki/Plugin/highlight.pm | 7 | ||||
-rw-r--r-- | IkiWiki/Plugin/img.pm | 5 | ||||
-rw-r--r-- | IkiWiki/Plugin/monotone.pm | 13 | ||||
-rw-r--r-- | IkiWiki/Plugin/txt.pm | 38 | ||||
-rw-r--r-- | IkiWiki/Plugin/websetup.pm | 4 |
8 files changed, 98 insertions, 43 deletions
diff --git a/IkiWiki/Plugin/filecheck.pm b/IkiWiki/Plugin/filecheck.pm index a78058ffe..3b0a7b314 100644 --- a/IkiWiki/Plugin/filecheck.pm +++ b/IkiWiki/Plugin/filecheck.pm @@ -148,6 +148,7 @@ sub match_mimetype ($$;@) { if (! defined $mimetype) { open(my $file_h, "-|", "file", "-bi", $file); $mimetype=<$file_h>; + chomp $mimetype; close $file_h; } if (! defined $mimetype || $mimetype !~s /;.*//) { diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm index d54e71131..b596bc0a1 100644 --- a/IkiWiki/Plugin/format.pm +++ b/IkiWiki/Plugin/format.pm @@ -29,22 +29,24 @@ sub preprocess (@) { if (! defined $format || ! defined $text) { error(gettext("must specify format and text")); } + + # Other plugins can register htmlizeformat hooks to add support + # for page types not suitable for htmlize, or that need special + # processing when included via format. Try them until one succeeds. + my $ret; + IkiWiki::run_hooks(htmlizeformat => sub { + $ret=shift->($format, $text) + unless defined $ret; + }); + + if (defined $ret) { + return $ret; + } elsif (exists $IkiWiki::hooks{htmlize}{$format}) { return IkiWiki::htmlize($params{page}, $params{destpage}, $format, $text); } else { - # Other plugins can register htmlizefallback - # hooks to add support for page types - # not suitable for htmlize. Try them until - # one succeeds. - my $ret; - IkiWiki::run_hooks(htmlizefallback => sub { - $ret=shift->($format, $text) - unless defined $ret; - }); - return $ret if defined $ret; - error(sprintf(gettext("unsupported page format %s"), $format)); } } diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index e89813253..f5101d904 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm @@ -9,7 +9,7 @@ use open qw{:utf8 :std}; my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate Git sha1sums my $dummy_commit_msg = 'dummy commit'; # message to skip in recent changes -my $no_chdir=0; +my $git_dir=undef; sub import { hook(type => "checkconfig", id => "git", call => \&checkconfig); @@ -164,9 +164,13 @@ sub safe_git (&@) { if (!$pid) { # In child. # Git commands want to be in wc. - if (! $no_chdir) { + if (! defined $git_dir) { chdir $config{srcdir} - or error("Cannot chdir to $config{srcdir}: $!"); + or error("cannot chdir to $config{srcdir}: $!"); + } + else { + chdir $git_dir + or error("cannot chdir to $git_dir: $!"); } exec @cmdline or error("Cannot exec '@cmdline': $!"); } @@ -721,14 +725,13 @@ sub rcs_getmtime ($) { } { -my $git_root; - +my $ret; sub git_find_root { # The wiki may not be the only thing in the git repo. # Determine if it is in a subdirectory by examining the srcdir, # and its parents, looking for the .git directory. - return $git_root if defined $git_root; + return @$ret if defined $ret; my $subdir=""; my $dir=$config{srcdir}; @@ -740,7 +743,8 @@ sub git_find_root { } } - return $git_root=$subdir; + $ret=[$subdir, $dir]; + return @$ret; } } @@ -748,7 +752,7 @@ sub git_find_root { sub git_parse_changes { my @changes = @_; - my $subdir = git_find_root(); + my ($subdir, $rootdir) = git_find_root(); my @rets; foreach my $ci (@changes) { foreach my $detail (@{ $ci->{'details'} }) { @@ -794,8 +798,8 @@ sub git_parse_changes { die $@ if $@; my $fh; ($fh, $path)=File::Temp::tempfile("XXXXXXXXXX", UNLINK => 1); - my $cmd = ($no_chdir ? '' : "cd $config{srcdir} && ") - . "git show $detail->{sha1_to} > '$path'"; + my $cmd = "cd $git_dir && ". + "git show $detail->{sha1_to} > '$path'"; if (system($cmd) != 0) { error("failed writing temp file '$path'."); } @@ -825,10 +829,12 @@ sub rcs_receive () { # Avoid chdir when running git here, because the changes # are in the master git repo, not the srcdir repo. + # (Also, if a subdir is involved, we don't want to chdir to + # it and only see changes in it.) # The pre-receive hook already puts us in the right place. - $no_chdir=1; + $git_dir="."; push @rets, git_parse_changes(git_commit_info($oldrev."..".$newrev)); - $no_chdir=0; + $git_dir=undef; } return reverse @rets; @@ -838,7 +844,24 @@ sub rcs_preprevert ($) { my $rev=shift; my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint - return git_parse_changes(git_commit_info($sha1, 1)); + # Examine changes from root of git repo, not from any subdir, + # in order to see all changes. + my ($subdir, $rootdir) = git_find_root(); + $git_dir=$rootdir; + my @commits=git_commit_info($sha1, 1); + $git_dir=undef; + + if (! @commits) { + error "unknown commit"; # just in case + } + + # git revert will fail on merge commits. Add a nice message. + if (exists $commits[0]->{parents} && + @{$commits[0]->{parents}} > 1) { + error gettext("you are not allowed to revert a merge"); + } + + return git_parse_changes(@commits); } sub rcs_revert ($) { diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm index d4ade0a7b..872537c72 100644 --- a/IkiWiki/Plugin/highlight.pm +++ b/IkiWiki/Plugin/highlight.pm @@ -10,8 +10,8 @@ sub import { hook(type => "getsetup", id => "highlight", call => \&getsetup); hook(type => "checkconfig", id => "highlight", call => \&checkconfig); # this hook is used by the format plugin - hook(type => "htmlizefallback", id => "highlight", call => - \&htmlizefallback); + hook(type => "htmlizeformat", id => "highlight", + call => \&htmlizeformat, last => 1); } sub getsetup () { @@ -74,12 +74,13 @@ sub checkconfig () { }, longname => sprintf(gettext("Source code: %s"), $file), @opts, + last => 1, ); } } } -sub htmlizefallback { +sub htmlizeformat { my $format=lc shift; my $langfile=ext2langfile($format); diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm index 2375ead89..bd527c8c8 100644 --- a/IkiWiki/Plugin/img.pm +++ b/IkiWiki/Plugin/img.pm @@ -156,10 +156,7 @@ sub preprocess (@) { $imgurl="$config{url}/$imglink"; } - if (exists $params{class}) { - $params{class}.=" img"; - } - else { + if (! exists $params{class}) { $params{class}="img"; } diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm index 95fbcee76..75bf2f458 100644 --- a/IkiWiki/Plugin/monotone.pm +++ b/IkiWiki/Plugin/monotone.pm @@ -252,9 +252,20 @@ sub get_changed_files ($$) { my @ret; my %seen = (); - + + # we need to strip off the relative path to the source dir + # because monotone outputs all file paths absolute according + # to the workspace root + my $rel_src_dir = $config{'srcdir'}; + $rel_src_dir =~ s/^\Q$config{'mtnrootdir'}\E\/?//; + $rel_src_dir .= "/" if length $rel_src_dir; + while ($changes =~ m/\s*(add_file|patch|delete|rename)\s"(.*?)(?<!\\)"\n/sg) { my $file = $2; + # ignore all file changes outside the source dir + next unless $file =~ m/^\Q$rel_src_dir\E/; + $file =~ s/^\Q$rel_src_dir\E//; + # don't add the same file multiple times if (! $seen{$file}) { push @ret, $file; diff --git a/IkiWiki/Plugin/txt.pm b/IkiWiki/Plugin/txt.pm index 0d9a0b35b..fcfb68be9 100644 --- a/IkiWiki/Plugin/txt.pm +++ b/IkiWiki/Plugin/txt.pm @@ -17,6 +17,7 @@ sub import { hook(type => "getsetup", id => "txt", call => \&getsetup); hook(type => "filter", id => "txt", call => \&filter); hook(type => "htmlize", id => "txt", call => \&htmlize); + hook(type => "htmlizeformat", id => "txt", call => \&htmlizeformat); eval q{use URI::Find}; if (! $@) { @@ -46,25 +47,42 @@ sub filter (@) { will_render($params{page}, 'robots.txt'); writefile('robots.txt', $config{destdir}, $content); } - - encode_entities($content, "<>&"); - if ($findurl) { - my $finder = URI::Find->new(sub { - my ($uri, $orig_uri) = @_; - return qq|<a href="$uri">$orig_uri</a>|; - }); - $finder->find(\$content); - } - $content = "<pre>" . $content . "</pre>"; + return txt2html($content); } return $content; } +sub txt2html ($) { + my $content=shift; + + encode_entities($content, "<>&"); + if ($findurl) { + my $finder = URI::Find->new(sub { + my ($uri, $orig_uri) = @_; + return qq|<a href="$uri">$orig_uri</a>|; + }); + $finder->find(\$content); + } + return "<pre>" . $content . "</pre>"; +} + # We need this to register the .txt file extension sub htmlize (@) { my %params=@_; return $params{content}; } +sub htmlizeformat ($$) { + my $format=shift; + my $content=shift; + + if ($format eq 'txt') { + return txt2html($content); + } + else { + return; + } +} + 1 diff --git a/IkiWiki/Plugin/websetup.pm b/IkiWiki/Plugin/websetup.pm index 11b4428e3..0ab18997c 100644 --- a/IkiWiki/Plugin/websetup.pm +++ b/IkiWiki/Plugin/websetup.pm @@ -219,7 +219,8 @@ sub showfields ($$$@) { options => [ [ 1 => $description ] ], fieldset => $section, ); - if (! $form->submitted) { + if (! $form->submitted || + ($info{advanced} && $form->submitted eq 'Advanced Mode')) { $form->field(name => $name, value => $value); } } @@ -295,6 +296,7 @@ sub showform ($$) { $form->field(name => "do", type => "hidden", value => "setup", force => 1); $form->field(name => "rebuild_asked", type => "hidden"); + $form->field(name => "showadvanced", type => "hidden"); if ($form->submitted eq 'Basic Mode') { $form->field(name => "showadvanced", type => "hidden", |