6 use POSIX qw(setlocale LC_CTYPE);
10 my $tla_webcommit=qr/^web commit (by (\w+)|from (\d+\.\d+\.\d+\.\d+)):?(.*)/;
12 sub quiet_system (@) {
13 # See Debian bug #385939.
14 open (SAVEOUT, ">&STDOUT");
16 open (STDOUT, ">/dev/null");
19 open (STDOUT, ">&SAVEOUT");
24 sub rcs_update () { #{{{
25 if (-d "$config{srcdir}/{arch}") {
26 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
27 warn("tla replay failed\n");
32 sub rcs_prepedit ($) { #{{{
35 if (-d "$config{srcdir}/{arch}") {
36 # For Arch, return the tree-id of archive when
38 my $rev=`tla tree-id $config{srcdir}`;
39 return defined $rev ? $rev : "";
43 sub rcs_commit ($$$) { #{{{
48 if (-d "$config{srcdir}/{arch}") {
49 # Check to see if the page has been changed by someone
50 # else since rcs_prepedit was called.
51 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
52 my $rev=`tla tree-id $config{srcdir}`;
53 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
54 # Merge their changes into the file that we've
56 if (quiet_system("tla", "update", "-d",
57 "$config{srcdir}") != 0) {
58 warn("tla update failed\n");
62 if (quiet_system("tla", "commit",
63 "-L".possibly_foolish_untaint($message),
64 '-d', $config{srcdir}) != 0) {
65 my $conflict=readfile("$config{srcdir}/$file");
66 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
67 warn("tla undo failed\n");
72 return undef # success
75 sub rcs_add ($) { #{{{
78 if (-d "$config{srcdir}/{arch}") {
79 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
80 warn("tla add failed\n");
85 sub rcs_recentchanges ($) {
89 return unless -d "$config{srcdir}/{arch}";
91 eval q{use Date::Parse};
93 eval q{use Mail::Header};
96 my $logs = `tla logs -d $config{srcdir}`;
97 my @changesets = reverse split(/\n/, $logs);
99 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
100 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
102 open(LOG, "tla cat-log -d $config{srcdir} $change|");
103 my $head = Mail::Header->new(\*LOG);
106 my $rev = $head->get("Revision");
107 my $summ = $head->get("Summary");
108 my $newfiles = $head->get("New-files");
109 my $modfiles = $head->get("Modified-files");
110 my $remfiles = $head->get("Removed-files");
111 my $user = $head->get("Creator");
113 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
114 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
116 my $sdate = $head->get("Standard-date");
117 my $when = time - str2time($sdate, 'UTC');
119 my $committype = "web";
120 if (defined $summ && $summ =~ /$tla_webcommit/) {
121 $user = defined $2 ? "$2" : "$3";
129 push @message, { line => escapeHTML($summ) };
133 foreach my $file (@paths) {
134 my $diffurl=$config{diffurl};
135 $diffurl=~s/\[\[file\]\]/$file/g;
136 $diffurl=~s/\[\[rev\]\]/$change/g;
138 page => pagename($file),
142 push @ret, { rev => $change,
144 committype => $committype,
146 message => [@message],
156 sub rcs_notify () { #{{{
158 if (! exists $ENV{ARCH_VERSION}) {
159 error("ARCH_VERSION is not set, not running from tla post-commit hook, cannot send notifications");
161 my $rev=int(possibly_foolish_untaint($ENV{REV}));
163 eval q{use Mail::Header};
165 open(LOG, $ENV{"ARCH_LOG"});
166 my $head = Mail::Header->new(\*LOG);
169 my $message = $head->get("Summary");
170 my $user = $head->get("Creator");
172 my $newfiles = $head->get("New-files");
173 my $modfiles = $head->get("Modified-files");
174 my $remfiles = $head->get("Removed-files");
176 my @changed_pages = grep { !/(^.*\/)?\.arch-ids\/.*\.id$/ }
177 split(/ /, "$newfiles $modfiles $remfiles .arch-ids/fake.id");
179 if ($message =~ /$tla_webcommit/) {
180 $user=defined $2 ? "$2" : "$3";
184 require IkiWiki::UserInfo;
185 my @email_recipients=commit_notify_list($user, @changed_pages);
186 if (@email_recipients) {
187 # TODO: if a commit spans multiple pages, this will send
188 # subscribers a diff that might contain pages they did not
189 # sign up for. Should separate the diff per page and
190 # reassemble into one mail with just the pages subscribed to.
191 my $logs = `tla logs -d $config{srcdir}`;
192 my @changesets = reverse split(/\n/, $logs);
195 for($i=0;$i<$#changesets;$i++) {
196 last if $changesets[$i] eq $rev;
199 my $revminusone = $changesets[$i+1];
200 my $diff=`tla diff -d $ENV{ARCH_TREE_ROOT} $revminusone`;
202 my $subject="$config{wikiname} update of ";
203 if (@changed_pages > 2) {
204 $subject.="$changed_pages[0] $changed_pages[1] etc";
207 $subject.=join(" ", @changed_pages);
209 $subject.=" by $user";
211 my $template=template("notifymail.tmpl");
213 wikiname => $config{wikiname},
219 eval q{use Mail::Sendmail};
221 foreach my $email (@email_recipients) {
224 From => "$config{wikiname} <$config{adminemail}>",
226 Message => $template->output,
227 ) or error("Failed to send update notification mail");
232 sub rcs_getctime ($) { #{{{
234 eval q{use Date::Parse};
236 eval q{use Mail::Header};
239 my $logs = `tla logs -d $config{srcdir}`;
240 my @changesets = reverse split(/\n/, $logs);
243 for (my $i=0; $i<$#changesets; $i++) {
244 my $change = $changesets[$i];
246 open(LOG, "tla cat-log -d $config{srcdir} $change|");
247 my $head = Mail::Header->new(\*LOG);
250 $sdate = $head->get("Standard-date");
251 my $newfiles = $head->get("New-files");
253 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
254 last if defined($lastcreation);
257 my $date=str2time($sdate, 'UTC');
258 debug("found ctime ".localtime($date)." for $file");