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);
23 sub checkconfig () { #{{{
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"),
32 sub getsetup () { #{{{
35 safe => 0, # rcs plugin
40 #example => "", # TODO example
41 description => "tla post-commit hook to generate",
48 description => "mode for tla_wrapper (can safely be made suid)",
54 #example => "", # TODO example
55 description => "url to show file history ([[file]] substituted)",
61 #example => "", # TODO example
62 description => "url to show a diff ([[file]] and [[rev]] substituted)",
68 sub quiet_system (@) { #{{{
69 # See Debian bug #385939.
70 open (SAVEOUT, ">&STDOUT");
72 open (STDOUT, ">/dev/null");
75 open (STDOUT, ">&SAVEOUT");
80 sub rcs_update () { #{{{
81 if (-d "$config{srcdir}/{arch}") {
82 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
83 warn("tla replay failed\n");
88 sub rcs_prepedit ($) { #{{{
91 if (-d "$config{srcdir}/{arch}") {
92 # For Arch, return the tree-id of archive when
94 my $rev=`tla tree-id $config{srcdir}`;
95 return defined $rev ? $rev : "";
99 sub rcs_commit ($$$;$$) { #{{{
107 $message="web commit by $user".(length $message ? ": $message" : "");
109 elsif (defined $ipaddr) {
110 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
113 if (-d "$config{srcdir}/{arch}") {
114 # Check to see if the page has been changed by someone
115 # else since rcs_prepedit was called.
116 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
117 my $rev=`tla tree-id $config{srcdir}`;
118 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
119 # Merge their changes into the file that we've
121 if (quiet_system("tla", "update", "-d",
122 "$config{srcdir}") != 0) {
123 warn("tla update failed\n");
127 if (quiet_system("tla", "commit",
128 "-L".IkiWiki::possibly_foolish_untaint($message),
129 '-d', $config{srcdir}) != 0) {
130 my $conflict=readfile("$config{srcdir}/$file");
131 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
132 warn("tla undo failed\n");
137 return undef # success
140 sub rcs_commit_staged ($$$) {
141 # Commits all staged changes. Changes can be staged using rcs_add,
142 # rcs_remove, and rcs_rename.
143 my ($message, $user, $ipaddr)=@_;
145 error("rcs_commit_staged not implemented for tla"); # TODO
148 sub rcs_add ($) { #{{{
151 if (-d "$config{srcdir}/{arch}") {
152 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
153 warn("tla add failed\n");
158 sub rcs_remove ($) { # {{{
161 error("rcs_remove not implemented for tla"); # TODO
164 sub rcs_rename ($$) { # {{{a
165 my ($src, $dest) = @_;
167 error("rcs_rename not implemented for tla"); # TODO
170 sub rcs_recentchanges ($) {
174 return unless -d "$config{srcdir}/{arch}";
176 eval q{use Date::Parse};
178 eval q{use Mail::Header};
181 my $logs = `tla logs -d $config{srcdir}`;
182 my @changesets = reverse split(/\n/, $logs);
184 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
185 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
187 open(LOG, "tla cat-log -d $config{srcdir} $change|");
188 my $head = Mail::Header->new(\*LOG);
191 my $rev = $head->get("Revision");
192 my $summ = $head->get("Summary");
193 my $newfiles = $head->get("New-files");
194 my $modfiles = $head->get("Modified-files");
195 my $remfiles = $head->get("Removed-files");
196 my $user = $head->get("Creator");
198 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
199 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
201 my $sdate = $head->get("Standard-date");
202 my $when = str2time($sdate, 'UTC');
204 my $committype = "web";
205 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
206 $user = defined $2 ? "$2" : "$3";
214 push @message, { line => $summ };
218 foreach my $file (@paths) {
219 my $diffurl=defined $config{diffurl} ? $config{diffurl} : "";
220 $diffurl=~s/\[\[file\]\]/$file/g;
221 $diffurl=~s/\[\[rev\]\]/$change/g;
223 page => pagename($file),
230 committype => $committype,
232 message => [@message],
242 sub rcs_diff ($) { #{{{
244 my $logs = `tla logs -d $config{srcdir}`;
245 my @changesets = reverse split(/\n/, $logs);
248 for($i=0;$i<$#changesets;$i++) {
249 last if $changesets[$i] eq $rev;
252 my $revminusone = $changesets[$i+1];
253 return `tla diff -d $config{srcdir} $revminusone`;
256 sub rcs_getctime ($) { #{{{
258 eval q{use Date::Parse};
260 eval q{use Mail::Header};
263 my $logs = `tla logs -d $config{srcdir}`;
264 my @changesets = reverse split(/\n/, $logs);
267 for (my $i=0; $i<$#changesets; $i++) {
268 my $change = $changesets[$i];
270 open(LOG, "tla cat-log -d $config{srcdir} $change|");
271 my $head = Mail::Header->new(\*LOG);
274 $sdate = $head->get("Standard-date");
275 my $newfiles = $head->get("New-files");
277 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
278 last if defined($lastcreation);
281 my $date=str2time($sdate, 'UTC');
282 debug("found ctime ".localtime($date)." for $file");