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 () { #{{{
36 #example => "", # TODO example
37 description => "tla post-commit executable to generate",
44 description => "mode for tla_wrapper (can safely be made suid)",
50 #example => "", # TODO example
51 description => "url to show file history ([[file]] substituted)",
57 #example => "", # TODO example
58 description => "url to show a diff ([[file]] and [[rev]] substituted)",
64 sub quiet_system (@) { #{{{
65 # See Debian bug #385939.
66 open (SAVEOUT, ">&STDOUT");
68 open (STDOUT, ">/dev/null");
71 open (STDOUT, ">&SAVEOUT");
76 sub rcs_update () { #{{{
77 if (-d "$config{srcdir}/{arch}") {
78 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
79 warn("tla replay failed\n");
84 sub rcs_prepedit ($) { #{{{
87 if (-d "$config{srcdir}/{arch}") {
88 # For Arch, return the tree-id of archive when
90 my $rev=`tla tree-id $config{srcdir}`;
91 return defined $rev ? $rev : "";
95 sub rcs_commit ($$$;$$) { #{{{
103 $message="web commit by $user".(length $message ? ": $message" : "");
105 elsif (defined $ipaddr) {
106 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
109 if (-d "$config{srcdir}/{arch}") {
110 # Check to see if the page has been changed by someone
111 # else since rcs_prepedit was called.
112 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
113 my $rev=`tla tree-id $config{srcdir}`;
114 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
115 # Merge their changes into the file that we've
117 if (quiet_system("tla", "update", "-d",
118 "$config{srcdir}") != 0) {
119 warn("tla update failed\n");
123 if (quiet_system("tla", "commit",
124 "-L".IkiWiki::possibly_foolish_untaint($message),
125 '-d', $config{srcdir}) != 0) {
126 my $conflict=readfile("$config{srcdir}/$file");
127 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
128 warn("tla undo failed\n");
133 return undef # success
136 sub rcs_commit_staged ($$$) {
137 # Commits all staged changes. Changes can be staged using rcs_add,
138 # rcs_remove, and rcs_rename.
139 my ($message, $user, $ipaddr)=@_;
141 error("rcs_commit_staged not implemented for tla"); # TODO
144 sub rcs_add ($) { #{{{
147 if (-d "$config{srcdir}/{arch}") {
148 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
149 warn("tla add failed\n");
154 sub rcs_remove ($) { # {{{
157 error("rcs_remove not implemented for tla"); # TODO
160 sub rcs_rename ($$) { # {{{a
161 my ($src, $dest) = @_;
163 error("rcs_rename not implemented for tla"); # TODO
166 sub rcs_recentchanges ($) {
170 return unless -d "$config{srcdir}/{arch}";
172 eval q{use Date::Parse};
174 eval q{use Mail::Header};
177 my $logs = `tla logs -d $config{srcdir}`;
178 my @changesets = reverse split(/\n/, $logs);
180 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
181 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
183 open(LOG, "tla cat-log -d $config{srcdir} $change|");
184 my $head = Mail::Header->new(\*LOG);
187 my $rev = $head->get("Revision");
188 my $summ = $head->get("Summary");
189 my $newfiles = $head->get("New-files");
190 my $modfiles = $head->get("Modified-files");
191 my $remfiles = $head->get("Removed-files");
192 my $user = $head->get("Creator");
194 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
195 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
197 my $sdate = $head->get("Standard-date");
198 my $when = str2time($sdate, 'UTC');
200 my $committype = "web";
201 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
202 $user = defined $2 ? "$2" : "$3";
210 push @message, { line => $summ };
214 foreach my $file (@paths) {
215 my $diffurl=defined $config{diffurl} ? $config{diffurl} : "";
216 $diffurl=~s/\[\[file\]\]/$file/g;
217 $diffurl=~s/\[\[rev\]\]/$change/g;
219 page => pagename($file),
226 committype => $committype,
228 message => [@message],
238 sub rcs_diff ($) { #{{{
240 my $logs = `tla logs -d $config{srcdir}`;
241 my @changesets = reverse split(/\n/, $logs);
244 for($i=0;$i<$#changesets;$i++) {
245 last if $changesets[$i] eq $rev;
248 my $revminusone = $changesets[$i+1];
249 return `tla diff -d $config{srcdir} $revminusone`;
252 sub rcs_getctime ($) { #{{{
254 eval q{use Date::Parse};
256 eval q{use Mail::Header};
259 my $logs = `tla logs -d $config{srcdir}`;
260 my @changesets = reverse split(/\n/, $logs);
263 for (my $i=0; $i<$#changesets; $i++) {
264 my $change = $changesets[$i];
266 open(LOG, "tla cat-log -d $config{srcdir} $change|");
267 my $head = Mail::Header->new(\*LOG);
270 $sdate = $head->get("Standard-date");
271 my $newfiles = $head->get("New-files");
273 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
274 last if defined($lastcreation);
277 my $date=str2time($sdate, 'UTC');
278 debug("found ctime ".localtime($date)." for $file");