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 ($$$;$$$) {
110 $message="web commit by $user".(length $message ? ": $message" : "");
112 elsif (defined $ipaddr) {
113 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
116 if (-d "$config{srcdir}/{arch}") {
117 # Check to see if the page has been changed by someone
118 # else since rcs_prepedit was called.
119 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
120 my $rev=`tla tree-id $config{srcdir}`;
121 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
122 # Merge their changes into the file that we've
124 if (quiet_system("tla", "update", "-d",
125 "$config{srcdir}") != 0) {
126 warn("tla update failed\n");
130 if (quiet_system("tla", "commit",
131 "-L".IkiWiki::possibly_foolish_untaint($message),
132 '-d', $config{srcdir}) != 0) {
133 my $conflict=readfile("$config{srcdir}/$file");
134 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
135 warn("tla undo failed\n");
140 return undef # success
143 sub rcs_commit_staged ($$$;$) {
144 # Commits all staged changes. Changes can be staged using rcs_add,
145 # rcs_remove, and rcs_rename.
146 my ($message, $user, $ipaddr, $emailuser)=@_;
148 error("rcs_commit_staged not implemented for tla"); # TODO
154 if (-d "$config{srcdir}/{arch}") {
155 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
156 warn("tla add failed\n");
164 error("rcs_remove not implemented for tla"); # TODO
167 sub rcs_rename ($$) {
168 my ($src, $dest) = @_;
170 error("rcs_rename not implemented for tla"); # TODO
173 sub rcs_recentchanges ($) {
177 return unless -d "$config{srcdir}/{arch}";
179 eval q{use Date::Parse};
181 eval q{use Mail::Header};
184 my $logs = `tla logs -d $config{srcdir}`;
185 my @changesets = reverse split(/\n/, $logs);
187 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
188 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
190 open(LOG, "tla cat-log -d $config{srcdir} $change|");
191 my $head = Mail::Header->new(\*LOG);
194 my $rev = $head->get("Revision");
195 my $summ = $head->get("Summary");
196 my $newfiles = $head->get("New-files");
197 my $modfiles = $head->get("Modified-files");
198 my $remfiles = $head->get("Removed-files");
199 my $user = $head->get("Creator");
201 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
202 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
204 my $sdate = $head->get("Standard-date");
205 my $when = str2time($sdate, 'UTC');
207 my $committype = "web";
208 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
209 $user = defined $2 ? "$2" : "$3";
217 push @message, { line => $summ };
221 foreach my $file (@paths) {
222 my $diffurl=defined $config{diffurl} ? $config{diffurl} : "";
223 $diffurl=~s/\[\[file\]\]/$file/g;
224 $diffurl=~s/\[\[rev\]\]/$change/g;
226 page => pagename($file),
233 committype => $committype,
235 message => [@message],
247 my $logs = `tla logs -d $config{srcdir}`;
248 my @changesets = reverse split(/\n/, $logs);
251 for($i=0;$i<$#changesets;$i++) {
252 last if $changesets[$i] eq $rev;
255 my $revminusone = $changesets[$i+1];
256 return `tla diff -d $config{srcdir} $revminusone`;
259 sub rcs_getctime ($) {
261 eval q{use Date::Parse};
263 eval q{use Mail::Header};
266 my $logs = `tla logs -d $config{srcdir}`;
267 my @changesets = reverse split(/\n/, $logs);
270 for (my $i=0; $i<$#changesets; $i++) {
271 my $change = $changesets[$i];
273 open(LOG, "tla cat-log -d $config{srcdir} $change|");
274 my $head = Mail::Header->new(\*LOG);
277 $sdate = $head->get("Standard-date");
278 my $newfiles = $head->get("New-files");
280 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
281 last if defined($lastcreation);
284 my $date=str2time($sdate, 'UTC');
285 debug("found ctime ".localtime($date)." for $file");
289 sub rcs_getmtime ($) {
290 error "rcs_getmtime is not implemented for tla\n"; # TODO