10 # See Debian bug #385939.
11 open (SAVEOUT, ">&STDOUT");
13 open (STDOUT, ">/dev/null");
16 open (STDOUT, ">&SAVEOUT");
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");
29 sub rcs_prepedit ($) { #{{{
32 if (-d "$config{srcdir}/{arch}") {
33 # For Arch, return the tree-id of archive when
35 my $rev=`tla tree-id $config{srcdir}`;
36 return defined $rev ? $rev : "";
40 sub rcs_commit ($$$;$$) { #{{{
48 $message="web commit by $user".(length $message ? ": $message" : "");
50 elsif (defined $ipaddr) {
51 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
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
62 if (quiet_system("tla", "update", "-d",
63 "$config{srcdir}") != 0) {
64 warn("tla update failed\n");
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");
78 return undef # success
81 sub rcs_add ($) { #{{{
84 if (-d "$config{srcdir}/{arch}") {
85 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
86 warn("tla add failed\n");
91 sub rcs_recentchanges ($) {
95 return unless -d "$config{srcdir}/{arch}";
97 eval q{use Date::Parse};
99 eval q{use Mail::Header};
102 my $logs = `tla logs -d $config{srcdir}`;
103 my @changesets = reverse split(/\n/, $logs);
105 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
106 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
108 open(LOG, "tla cat-log -d $config{srcdir} $change|");
109 my $head = Mail::Header->new(\*LOG);
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");
119 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
120 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
122 my $sdate = $head->get("Standard-date");
123 my $when = str2time($sdate, 'UTC');
125 my $committype = "web";
126 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
127 $user = defined $2 ? "$2" : "$3";
135 push @message, { line => escapeHTML($summ) };
139 foreach my $file (@paths) {
140 my $diffurl=$config{diffurl};
141 $diffurl=~s/\[\[file\]\]/$file/g;
142 $diffurl=~s/\[\[rev\]\]/$change/g;
144 page => pagename($file),
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");