2 package IkiWiki::Plugin::tla;
9 hook(type => "checkconfig", id => "tla", call => \&checkconfig);
10 hook(type => "getsetup", id => "tla", call => \&getsetup);
11 hook(type => "rcs", id => "rcs_update", call => \&rcs_update);
12 hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit);
13 hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit);
14 hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged);
15 hook(type => "rcs", id => "rcs_add", call => \&rcs_add);
16 hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove);
17 hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename);
18 hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges);
19 hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff);
20 hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime);
24 if (defined $config{tla_wrapper} && length $config{tla_wrapper}) {
25 push @{$config{wrappers}}, {
26 wrapper => $config{tla_wrapper},
27 wrappermode => (defined $config{tla_wrappermode} ? $config{tla_wrappermode} : "06755"),
35 safe => 0, # rcs plugin
41 #example => "", # TODO example
42 description => "tla post-commit hook to generate",
49 description => "mode for tla_wrapper (can safely be made suid)",
55 #example => "", # TODO example
56 description => "url to show file history ([[file]] substituted)",
62 #example => "", # TODO example
63 description => "url to show a diff ([[file]] and [[rev]] substituted)",
69 sub quiet_system (@) {
70 # See Debian bug #385939.
71 open (SAVEOUT, ">&STDOUT");
73 open (STDOUT, ">/dev/null");
76 open (STDOUT, ">&SAVEOUT");
82 if (-d "$config{srcdir}/{arch}") {
83 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
84 warn("tla replay failed\n");
89 sub rcs_prepedit ($) {
92 if (-d "$config{srcdir}/{arch}") {
93 # For Arch, return the tree-id of archive when
95 my $rev=`tla tree-id $config{srcdir}`;
96 return defined $rev ? $rev : "";
100 sub rcs_commit ($$$;$$) {
108 $message="web commit by $user".(length $message ? ": $message" : "");
110 elsif (defined $ipaddr) {
111 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
114 if (-d "$config{srcdir}/{arch}") {
115 # Check to see if the page has been changed by someone
116 # else since rcs_prepedit was called.
117 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
118 my $rev=`tla tree-id $config{srcdir}`;
119 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
120 # Merge their changes into the file that we've
122 if (quiet_system("tla", "update", "-d",
123 "$config{srcdir}") != 0) {
124 warn("tla update failed\n");
128 if (quiet_system("tla", "commit",
129 "-L".IkiWiki::possibly_foolish_untaint($message),
130 '-d', $config{srcdir}) != 0) {
131 my $conflict=readfile("$config{srcdir}/$file");
132 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
133 warn("tla undo failed\n");
138 return undef # success
141 sub rcs_commit_staged ($$$) {
142 # Commits all staged changes. Changes can be staged using rcs_add,
143 # rcs_remove, and rcs_rename.
144 my ($message, $user, $ipaddr)=@_;
146 error("rcs_commit_staged not implemented for tla"); # TODO
152 if (-d "$config{srcdir}/{arch}") {
153 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
154 warn("tla add failed\n");
162 error("rcs_remove not implemented for tla"); # TODO
165 sub rcs_rename ($$) {
166 my ($src, $dest) = @_;
168 error("rcs_rename not implemented for tla"); # TODO
171 sub rcs_recentchanges ($) {
175 return unless -d "$config{srcdir}/{arch}";
177 eval q{use Date::Parse};
179 eval q{use Mail::Header};
182 my $logs = `tla logs -d $config{srcdir}`;
183 my @changesets = reverse split(/\n/, $logs);
185 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
186 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
188 open(LOG, "tla cat-log -d $config{srcdir} $change|");
189 my $head = Mail::Header->new(\*LOG);
192 my $rev = $head->get("Revision");
193 my $summ = $head->get("Summary");
194 my $newfiles = $head->get("New-files");
195 my $modfiles = $head->get("Modified-files");
196 my $remfiles = $head->get("Removed-files");
197 my $user = $head->get("Creator");
199 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
200 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
202 my $sdate = $head->get("Standard-date");
203 my $when = str2time($sdate, 'UTC');
205 my $committype = "web";
206 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
207 $user = defined $2 ? "$2" : "$3";
215 push @message, { line => $summ };
219 foreach my $file (@paths) {
220 my $diffurl=defined $config{diffurl} ? $config{diffurl} : "";
221 $diffurl=~s/\[\[file\]\]/$file/g;
222 $diffurl=~s/\[\[rev\]\]/$change/g;
224 page => pagename($file),
231 committype => $committype,
233 message => [@message],
245 my $logs = `tla logs -d $config{srcdir}`;
246 my @changesets = reverse split(/\n/, $logs);
249 for($i=0;$i<$#changesets;$i++) {
250 last if $changesets[$i] eq $rev;
253 my $revminusone = $changesets[$i+1];
254 return `tla diff -d $config{srcdir} $revminusone`;
257 sub rcs_getctime ($) {
259 eval q{use Date::Parse};
261 eval q{use Mail::Header};
264 my $logs = `tla logs -d $config{srcdir}`;
265 my @changesets = reverse split(/\n/, $logs);
268 for (my $i=0; $i<$#changesets; $i++) {
269 my $change = $changesets[$i];
271 open(LOG, "tla cat-log -d $config{srcdir} $change|");
272 my $head = Mail::Header->new(\*LOG);
275 $sdate = $head->get("Standard-date");
276 my $newfiles = $head->get("New-files");
278 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
279 last if defined($lastcreation);
282 my $date=str2time($sdate, 'UTC');
283 debug("found ctime ".localtime($date)." for $file");