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};
92 eval q{use Mail::Header};
94 my $logs = `tla logs -d $config{srcdir}`;
95 my @changesets = reverse split(/\n/, $logs);
97 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
98 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
100 open(LOG, "tla cat-log -d $config{srcdir} $change|");
101 my $head = Mail::Header->new(\*LOG);
104 my $rev = $head->get("Revision");
105 my $summ = $head->get("Summary");
106 my $newfiles = $head->get("New-files");
107 my $modfiles = $head->get("Modified-files");
108 my $remfiles = $head->get("Removed-files");
109 my $user = $head->get("Creator");
111 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
112 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
114 my $sdate = $head->get("Standard-date");
115 my $when = time - str2time($sdate, 'UTC');
117 my $committype = "web";
118 if (defined $summ && $summ =~ /$tla_webcommit/) {
119 $user = defined $2 ? "$2" : "$3";
127 push @message, { line => escapeHTML($summ) };
131 foreach my $file (@paths) {
132 my $diffurl=$config{diffurl};
133 $diffurl=~s/\[\[file\]\]/$file/g;
134 $diffurl=~s/\[\[rev\]\]/$change/g;
136 page => pagename($file),
140 push @ret, { rev => $change,
142 committype => $committype,
144 message => [@message],
154 sub rcs_notify () { #{{{
156 if (! exists $ENV{ARCH_VERSION}) {
157 error("ARCH_VERSION is not set, not running from tla post-commit hook, cannot send notifications");
159 my $rev=int(possibly_foolish_untaint($ENV{REV}));
161 eval q{use Mail::Header};
162 open(LOG, $ENV{"ARCH_LOG"});
163 my $head = Mail::Header->new(\*LOG);
166 my $message = $head->get("Summary");
167 my $user = $head->get("Creator");
169 my $newfiles = $head->get("New-files");
170 my $modfiles = $head->get("Modified-files");
171 my $remfiles = $head->get("Removed-files");
173 my @changed_pages = grep { !/(^.*\/)?\.arch-ids\/.*\.id$/ }
174 split(/ /, "$newfiles $modfiles $remfiles .arch-ids/fake.id");
176 if ($message =~ /$tla_webcommit/) {
177 $user=defined $2 ? "$2" : "$3";
181 require IkiWiki::UserInfo;
182 my @email_recipients=commit_notify_list($user, @changed_pages);
183 if (@email_recipients) {
184 # TODO: if a commit spans multiple pages, this will send
185 # subscribers a diff that might contain pages they did not
186 # sign up for. Should separate the diff per page and
187 # reassemble into one mail with just the pages subscribed to.
188 my $logs = `tla logs -d $config{srcdir}`;
189 my @changesets = reverse split(/\n/, $logs);
192 for($i=0;$i<$#changesets;$i++) {
193 last if $changesets[$i] eq $rev;
196 my $revminusone = $changesets[$i+1];
197 my $diff=`tla diff -d $ENV{ARCH_TREE_ROOT} $revminusone`;
199 my $subject="$config{wikiname} update of ";
200 if (@changed_pages > 2) {
201 $subject.="$changed_pages[0] $changed_pages[1] etc";
204 $subject.=join(" ", @changed_pages);
206 $subject.=" by $user";
208 my $template=template("notifymail.tmpl");
210 wikiname => $config{wikiname},
216 eval q{use Mail::Sendmail};
217 foreach my $email (@email_recipients) {
220 From => "$config{wikiname} <$config{adminemail}>",
222 Message => $template->output,
223 ) or error("Failed to send update notification mail");
228 sub rcs_getctime ($) { #{{{
230 eval q{use Date::Parse};
231 eval q{use Mail::Header};
233 my $logs = `tla logs -d $config{srcdir}`;
234 my @changesets = reverse split(/\n/, $logs);
237 for (my $i=0; $i<$#changesets; $i++) {
238 my $change = $changesets[$i];
240 open(LOG, "tla cat-log -d $config{srcdir} $change|");
241 my $head = Mail::Header->new(\*LOG);
244 $sdate = $head->get("Standard-date");
245 my $newfiles = $head->get("New-files");
247 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
248 last if defined($lastcreation);
251 my $date=str2time($sdate, 'UTC');
252 debug("found ctime ".localtime($date)." for $file");