add
[ikiwiki] / doc / patchqueue / webcommit-from.mdwn
1 From [[Faidon]]:
2         
3 Match 'web commit from' in SVN and git, these are web
4 commits too. Show the IP instead of the user 'www-data' (which is kind
5 of security fix too, since the user Apache is running as was visible).
6
7 Note that the git backend patch is untested.
8 Recai, could you test it? (if Joey finds the change acceptable that is).
9         
10         Index: IkiWiki/Rcs/svn.pm
11         ===================================================================
12         --- IkiWiki/Rcs/svn.pm  (revision 904)
13         +++ IkiWiki/Rcs/svn.pm  (working copy)
14         @@ -7,7 +7,7 @@
15          
16          package IkiWiki;
17                         
18         -my $svn_webcommit=qr/^web commit by (\w+):?(.*)/;
19         +my $svn_webcommit=qr/^web commit (by (\w+)|from (\d+\.\d+\.\d+\.\d+)):?(.*)/;
20          
21          sub svn_info ($$) { #{{{
22                 my $field=shift;
23         @@ -136,8 +136,8 @@
24                         my $committype="web";
25                         if (defined $message[0] &&
26                             $message[0]->{line}=~/$svn_webcommit/) {
27         -                       $user="$1";
28         -                       $message[0]->{line}=$2;
29         +                       $user=defined $2 ? "$2" : "$3";
30         +                       $message[0]->{line}=$4;
31                         }
32                         else {
33                                 $committype="svn";
34         @@ -178,8 +178,8 @@
35                 chomp $user;
36                 my $message=`svnlook log $config{svnrepo} -r $rev`;
37                 if ($message=~/$svn_webcommit/) {
38         -               $user="$1";
39         -               $message=$2;
40         +               $user=defined $2 ? "$2" : "$3";
41         +               $message=$4;
42                 }
43          
44                 my @changed_pages;
45         Index: IkiWiki/Rcs/git.pm
46         ===================================================================
47         --- IkiWiki/Rcs/git.pm  (revision 904)
48         +++ IkiWiki/Rcs/git.pm  (working copy)
49         @@ -12,7 +12,7 @@
50          my $master_branch    = 'master';            # working branch
51          my $sha1_pattern     = qr/[0-9a-fA-F]{40}/; # pattern to validate Git sha1sums
52          my $dummy_commit_msg = 'dummy commit';      # message to skip in recent changes
53         -my $web_commit_msg   = qr/^web commit by (\w+):?(.*)/; # pattern for web commits
54         +my $web_commit_msg   = qr/^web commit (by (\w+)|from (\d+\.\d+\.\d+\.\d+)):?(.*)/;
55          
56          sub _safe_git (&@) { #{{{
57                 # Start a child process safely without resorting /bin/sh.
58         @@ -377,8 +377,8 @@
59          
60                         if (defined $message[0] &&
61                             $message[0]->{line} =~ m/$web_commit_msg/) {
62         -                       $user = "$1";
63         -                       $message[0]->{line} = $2;
64         +                       $user=defined $2 ? "$2" : "$3";
65         +                       $message[0]->{line}=$4;
66                         } else {
67                                 $type ="git";
68                                 $user = $ci->{'author_username'};
69         @@ -426,8 +426,8 @@
70          
71                 my ($user, $message);
72                 if (@{ $ci->{'comment'} }[0] =~ m/$web_commit_msg/) {
73         -               $user    = "$1";
74         -               $message = $2;
75         +               $user    = defined $2 ? "$2" : "$3";
76         +               $message = $4;
77                 } else {
78                         $user    = $ci->{'author_username'};
79                         $message = join "\n", @{ $ci->{'comment'} };