]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Rcs/tla.pm
* Removed support for sending commit notification mails. Along with it went
[ikiwiki.git] / IkiWiki / Rcs / tla.pm
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use IkiWiki;
6
7 package IkiWiki;
8
9 sub quiet_system (@) {
10         # See Debian bug #385939.
11         open (SAVEOUT, ">&STDOUT");
12         close STDOUT;
13         open (STDOUT, ">/dev/null");
14         my $ret=system(@_);
15         close STDOUT;
16         open (STDOUT, ">&SAVEOUT");
17         close SAVEOUT;
18         return $ret;
19 }
20
21 sub rcs_update () { #{{{
22         if (-d "$config{srcdir}/{arch}") {
23                 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
24                         warn("tla replay failed\n");
25                 }
26         }
27 } #}}}
28
29 sub rcs_prepedit ($) { #{{{
30         my $file=shift;
31
32         if (-d "$config{srcdir}/{arch}") {
33                 # For Arch, return the tree-id of archive when
34                 # editing begins.
35                 my $rev=`tla tree-id $config{srcdir}`;
36                 return defined $rev ? $rev : "";
37         }
38 } #}}}
39
40 sub rcs_commit ($$$;$$) { #{{{
41         my $file=shift;
42         my $message=shift;
43         my $rcstoken=shift;
44         my $user=shift;
45         my $ipaddr=shift;
46
47         if (defined $user) {
48                 $message="web commit by $user".(length $message ? ": $message" : "");
49         }
50         elsif (defined $ipaddr) {
51                 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
52         }
53
54         if (-d "$config{srcdir}/{arch}") {
55                 # Check to see if the page has been changed by someone
56                 # else since rcs_prepedit was called.
57                 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
58                 my $rev=`tla tree-id $config{srcdir}`;
59                 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
60                         # Merge their changes into the file that we've
61                         # changed.
62                         if (quiet_system("tla", "update", "-d",
63                                    "$config{srcdir}") != 0) {
64                                 warn("tla update failed\n");
65                         }
66                 }
67
68                 if (quiet_system("tla", "commit",
69                            "-L".possibly_foolish_untaint($message),
70                            '-d', $config{srcdir}) != 0) {
71                         my $conflict=readfile("$config{srcdir}/$file");
72                         if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
73                                 warn("tla undo failed\n");
74                         }
75                         return $conflict;
76                 }
77         }
78         return undef # success
79 } #}}}
80
81 sub rcs_add ($) { #{{{
82         my $file=shift;
83
84         if (-d "$config{srcdir}/{arch}") {
85                 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
86                         warn("tla add failed\n");
87                 }
88         }
89 } #}}}
90
91 sub rcs_recentchanges ($) {
92         my $num=shift;
93         my @ret;
94
95         return unless -d "$config{srcdir}/{arch}";
96
97         eval q{use Date::Parse};
98         error($@) if $@;
99         eval q{use Mail::Header};
100         error($@) if $@;
101
102         my $logs = `tla logs -d $config{srcdir}`;
103         my @changesets = reverse split(/\n/, $logs);
104
105         for (my $i=0; $i<$num && $i<$#changesets; $i++) {
106                 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
107
108                 open(LOG, "tla cat-log -d $config{srcdir} $change|");
109                 my $head = Mail::Header->new(\*LOG);
110                 close(LOG);
111
112                 my $rev = $head->get("Revision");
113                 my $summ = $head->get("Summary");
114                 my $newfiles = $head->get("New-files");
115                 my $modfiles = $head->get("Modified-files");
116                 my $remfiles = $head->get("Removed-files");
117                 my $user = $head->get("Creator");
118
119                 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
120                         split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
121
122                 my $sdate = $head->get("Standard-date");
123                 my $when = str2time($sdate, 'UTC');
124
125                 my $committype = "web";
126                 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
127                         $user = defined $2 ? "$2" : "$3";
128                         $summ = $4;
129                 }
130                 else {
131                         $committype="tla";
132                 }
133
134                 my @message;
135                 push @message, { line => escapeHTML($summ) };
136
137                 my @pages;
138
139                 foreach my $file (@paths) {
140                         my $diffurl=$config{diffurl};
141                         $diffurl=~s/\[\[file\]\]/$file/g;
142                         $diffurl=~s/\[\[rev\]\]/$change/g;
143                         push @pages, {
144                                 page => pagename($file),
145                                 diffurl => $diffurl,
146                         } if length $file;
147                 }
148                 push @ret, {
149                         rev => $change,
150                         user => $user,
151                         committype => $committype,
152                         when => $when,
153                         message => [@message],
154                         pages => [@pages],
155                 } if @pages;
156
157                 last if $i == $num;
158         }
159
160         return @ret;
161 }
162
163 sub rcs_getctime ($) { #{{{
164         my $file=shift;
165         eval q{use Date::Parse};
166         error($@) if $@;
167         eval q{use Mail::Header};
168         error($@) if $@;
169
170         my $logs = `tla logs -d $config{srcdir}`;
171         my @changesets = reverse split(/\n/, $logs);
172         my $sdate;
173
174         for (my $i=0; $i<$#changesets; $i++) {
175                 my $change = $changesets[$i];
176
177                 open(LOG, "tla cat-log -d $config{srcdir} $change|");
178                 my $head = Mail::Header->new(\*LOG);
179                 close(LOG);
180
181                 $sdate = $head->get("Standard-date");
182                 my $newfiles = $head->get("New-files");
183
184                 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
185                 last if defined($lastcreation);
186         }
187
188         my $date=str2time($sdate, 'UTC');
189         debug("found ctime ".localtime($date)." for $file");
190         return $date;
191 } #}}}
192
193 1