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);
21 hook(type => "rcs", id => "rcs_getmtime", call => \&rcs_getmtime);
25 if (defined $config{tla_wrapper} && length $config{tla_wrapper}) {
26 push @{$config{wrappers}}, {
27 wrapper => $config{tla_wrapper},
28 wrappermode => (defined $config{tla_wrappermode} ? $config{tla_wrappermode} : "06755"),
36 safe => 0, # rcs plugin
42 #example => "", # TODO example
43 description => "tla post-commit hook to generate",
50 description => "mode for tla_wrapper (can safely be made suid)",
56 #example => "", # TODO example
57 description => "url to show file history ([[file]] substituted)",
63 #example => "", # TODO example
64 description => "url to show a diff ([[file]] and [[rev]] substituted)",
70 sub quiet_system (@) {
71 # See Debian bug #385939.
72 open (SAVEOUT, ">&STDOUT");
74 open (STDOUT, ">/dev/null");
77 open (STDOUT, ">&SAVEOUT");
83 if (-d "$config{srcdir}/{arch}") {
84 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
85 warn("tla replay failed\n");
90 sub rcs_prepedit ($) {
93 if (-d "$config{srcdir}/{arch}") {
94 # For Arch, return the tree-id of archive when
96 my $rev=`tla tree-id $config{srcdir}`;
97 return defined $rev ? $rev : "";
101 sub rcs_commit ($$$;$$) {
109 $message="web commit by $user".(length $message ? ": $message" : "");
111 elsif (defined $ipaddr) {
112 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
115 if (-d "$config{srcdir}/{arch}") {
116 # Check to see if the page has been changed by someone
117 # else since rcs_prepedit was called.
118 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
119 my $rev=`tla tree-id $config{srcdir}`;
120 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
121 # Merge their changes into the file that we've
123 if (quiet_system("tla", "update", "-d",
124 "$config{srcdir}") != 0) {
125 warn("tla update failed\n");
129 if (quiet_system("tla", "commit",
130 "-L".IkiWiki::possibly_foolish_untaint($message),
131 '-d', $config{srcdir}) != 0) {
132 my $conflict=readfile("$config{srcdir}/$file");
133 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
134 warn("tla undo failed\n");
139 return undef # success
142 sub rcs_commit_staged ($$$) {
143 # Commits all staged changes. Changes can be staged using rcs_add,
144 # rcs_remove, and rcs_rename.
145 my ($message, $user, $ipaddr)=@_;
147 error("rcs_commit_staged not implemented for tla"); # TODO
153 if (-d "$config{srcdir}/{arch}") {
154 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
155 warn("tla add failed\n");
163 error("rcs_remove not implemented for tla"); # TODO
166 sub rcs_rename ($$) {
167 my ($src, $dest) = @_;
169 error("rcs_rename not implemented for tla"); # TODO
172 sub rcs_recentchanges ($) {
176 return unless -d "$config{srcdir}/{arch}";
178 eval q{use Date::Parse};
180 eval q{use Mail::Header};
183 my $logs = `tla logs -d $config{srcdir}`;
184 my @changesets = reverse split(/\n/, $logs);
186 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
187 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
189 open(LOG, "tla cat-log -d $config{srcdir} $change|");
190 my $head = Mail::Header->new(\*LOG);
193 my $rev = $head->get("Revision");
194 my $summ = $head->get("Summary");
195 my $newfiles = $head->get("New-files");
196 my $modfiles = $head->get("Modified-files");
197 my $remfiles = $head->get("Removed-files");
198 my $user = $head->get("Creator");
200 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
201 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
203 my $sdate = $head->get("Standard-date");
204 my $when = str2time($sdate, 'UTC');
206 my $committype = "web";
207 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
208 $user = defined $2 ? "$2" : "$3";
216 push @message, { line => $summ };
220 foreach my $file (@paths) {
221 my $diffurl=defined $config{diffurl} ? $config{diffurl} : "";
222 $diffurl=~s/\[\[file\]\]/$file/g;
223 $diffurl=~s/\[\[rev\]\]/$change/g;
225 page => pagename($file),
232 committype => $committype,
234 message => [@message],
246 my $logs = `tla logs -d $config{srcdir}`;
247 my @changesets = reverse split(/\n/, $logs);
250 for($i=0;$i<$#changesets;$i++) {
251 last if $changesets[$i] eq $rev;
254 my $revminusone = $changesets[$i+1];
255 return `tla diff -d $config{srcdir} $revminusone`;
258 sub rcs_getctime ($) {
260 eval q{use Date::Parse};
262 eval q{use Mail::Header};
265 my $logs = `tla logs -d $config{srcdir}`;
266 my @changesets = reverse split(/\n/, $logs);
269 for (my $i=0; $i<$#changesets; $i++) {
270 my $change = $changesets[$i];
272 open(LOG, "tla cat-log -d $config{srcdir} $change|");
273 my $head = Mail::Header->new(\*LOG);
276 $sdate = $head->get("Standard-date");
277 my $newfiles = $head->get("New-files");
279 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
280 last if defined($lastcreation);
283 my $date=str2time($sdate, 'UTC');
284 debug("found ctime ".localtime($date)." for $file");
288 sub rcs_getmtime ($) {
289 error "rcs_getmtime is not implemented for tla\n"; # TODO