6 use POSIX qw(setlocale LC_CTYPE);
10 sub quiet_system (@) {
11 # See Debian bug #385939.
12 open (SAVEOUT, ">&STDOUT");
14 open (STDOUT, ">/dev/null");
17 open (STDOUT, ">&SAVEOUT");
22 sub rcs_update () { #{{{
23 if (-d "$config{srcdir}/{arch}") {
24 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
25 warn("tla replay failed\n");
30 sub rcs_prepedit ($) { #{{{
33 if (-d "$config{srcdir}/{arch}") {
34 # For Arch, return the tree-id of archive when
36 my $rev=`tla tree-id $config{srcdir}`;
37 return defined $rev ? $rev : "";
41 sub rcs_commit ($$$;$$) { #{{{
49 $message="web commit by $user".(length $message ? ": $message" : "");
51 elsif (defined $ipaddr) {
52 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
55 if (-d "$config{srcdir}/{arch}") {
56 # Check to see if the page has been changed by someone
57 # else since rcs_prepedit was called.
58 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
59 my $rev=`tla tree-id $config{srcdir}`;
60 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
61 # Merge their changes into the file that we've
63 if (quiet_system("tla", "update", "-d",
64 "$config{srcdir}") != 0) {
65 warn("tla update failed\n");
69 if (quiet_system("tla", "commit",
70 "-L".possibly_foolish_untaint($message),
71 '-d', $config{srcdir}) != 0) {
72 my $conflict=readfile("$config{srcdir}/$file");
73 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
74 warn("tla undo failed\n");
79 return undef # success
82 sub rcs_add ($) { #{{{
85 if (-d "$config{srcdir}/{arch}") {
86 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
87 warn("tla add failed\n");
92 sub rcs_recentchanges ($) {
96 return unless -d "$config{srcdir}/{arch}";
98 eval q{use Date::Parse};
100 eval q{use Mail::Header};
103 my $logs = `tla logs -d $config{srcdir}`;
104 my @changesets = reverse split(/\n/, $logs);
106 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
107 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
109 open(LOG, "tla cat-log -d $config{srcdir} $change|");
110 my $head = Mail::Header->new(\*LOG);
113 my $rev = $head->get("Revision");
114 my $summ = $head->get("Summary");
115 my $newfiles = $head->get("New-files");
116 my $modfiles = $head->get("Modified-files");
117 my $remfiles = $head->get("Removed-files");
118 my $user = $head->get("Creator");
120 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
121 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
123 my $sdate = $head->get("Standard-date");
124 my $when = time - str2time($sdate, 'UTC');
126 my $committype = "web";
127 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
128 $user = defined $2 ? "$2" : "$3";
136 push @message, { line => escapeHTML($summ) };
140 foreach my $file (@paths) {
141 my $diffurl=$config{diffurl};
142 $diffurl=~s/\[\[file\]\]/$file/g;
143 $diffurl=~s/\[\[rev\]\]/$change/g;
145 page => pagename($file),
149 push @ret, { rev => $change,
151 committype => $committype,
153 message => [@message],
163 sub rcs_notify () { #{{{
165 if (! exists $ENV{ARCH_VERSION}) {
166 error("ARCH_VERSION is not set, not running from tla post-commit hook, cannot send notifications");
168 my $rev=int(possibly_foolish_untaint($ENV{REV}));
170 eval q{use Mail::Header};
172 open(LOG, $ENV{"ARCH_LOG"});
173 my $head = Mail::Header->new(\*LOG);
176 my $user = $head->get("Creator");
178 my $newfiles = $head->get("New-files");
179 my $modfiles = $head->get("Modified-files");
180 my $remfiles = $head->get("Removed-files");
182 my @changed_pages = grep { !/(^.*\/)?\.arch-ids\/.*\.id$/ }
183 split(/ /, "$newfiles $modfiles $remfiles .arch-ids/fake.id");
185 require IkiWiki::UserInfo;
188 my $message = $head->get("Summary");
189 if ($message =~ /$config{web_commit_regexp}/) {
190 $user=defined $2 ? "$2" : "$3";
195 my $logs = `tla logs -d $config{srcdir}`;
196 my @changesets = reverse split(/\n/, $logs);
199 for($i=0;$i<$#changesets;$i++) {
200 last if $changesets[$i] eq $rev;
203 my $revminusone = $changesets[$i+1];
204 `tla diff -d $ENV{ARCH_TREE_ROOT} $revminusone`;
205 }, $user, @changed_pages);
208 sub rcs_getctime ($) { #{{{
210 eval q{use Date::Parse};
212 eval q{use Mail::Header};
215 my $logs = `tla logs -d $config{srcdir}`;
216 my @changesets = reverse split(/\n/, $logs);
219 for (my $i=0; $i<$#changesets; $i++) {
220 my $change = $changesets[$i];
222 open(LOG, "tla cat-log -d $config{srcdir} $change|");
223 my $head = Mail::Header->new(\*LOG);
226 $sdate = $head->get("Standard-date");
227 my $newfiles = $head->get("New-files");
229 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
230 last if defined($lastcreation);
233 my $date=str2time($sdate, 'UTC');
234 debug("found ctime ".localtime($date)." for $file");