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 : "";
104 my ($file, $message, $rcstoken)=
105 ($params{file
}, $params{message
}, $params{token
});
107 if (defined $params{session
}) {
108 if (defined $params{session
}->param("name")) {
109 $message="web commit by ".
110 $params{session
}->param("name").
111 (length $message ?
": $message" : "");
113 elsif (defined $params{session
}->remote_addr()) {
114 $message="web commit from ".
115 $params{session
}->remote_addr().
116 (length $message ?
": $message" : "");
120 if (-d
"$config{srcdir}/{arch}") {
121 # Check to see if the page has been changed by someone
122 # else since rcs_prepedit was called.
123 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._
-]+)$/; # untaint
124 my $rev=`tla tree-id $config{srcdir}`;
125 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
126 # Merge their changes into the file that we've
128 if (quiet_system
("tla", "update", "-d",
129 "$config{srcdir}") != 0) {
130 warn("tla update failed\n");
134 if (quiet_system
("tla", "commit",
135 "-L".IkiWiki
::possibly_foolish_untaint
($message),
136 '-d', $config{srcdir
}) != 0) {
137 my $conflict=readfile
("$config{srcdir}/$file");
138 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
139 warn("tla undo failed\n");
144 return undef # success
147 sub rcs_commit_staged
(@
) {
148 # Commits all staged changes. Changes can be staged using rcs_add,
149 # rcs_remove, and rcs_rename.
152 error
("rcs_commit_staged not implemented for tla"); # TODO
158 if (-d
"$config{srcdir}/{arch}") {
159 if (quiet_system
("tla", "add", "$config{srcdir}/$file") != 0) {
160 warn("tla add failed\n");
168 error
("rcs_remove not implemented for tla"); # TODO
171 sub rcs_rename
($$) {
172 my ($src, $dest) = @_;
174 error
("rcs_rename not implemented for tla"); # TODO
177 sub rcs_recentchanges
($) {
181 return unless -d
"$config{srcdir}/{arch}";
183 eval q{use Date::Parse};
185 eval q{use Mail::Header};
188 my $logs = `tla logs -d $config{srcdir}`;
189 my @changesets = reverse split(/\n/, $logs);
191 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
192 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._
-]+)$/; # untaint
194 open(LOG
, "tla cat-log -d $config{srcdir} $change|");
195 my $head = Mail
::Header
->new(\
*LOG
);
198 my $rev = $head->get("Revision");
199 my $summ = $head->get("Summary");
200 my $newfiles = $head->get("New-files");
201 my $modfiles = $head->get("Modified-files");
202 my $remfiles = $head->get("Removed-files");
203 my $user = $head->get("Creator");
205 my @paths = grep { !/^(.*\/)?\
.arch
-ids\
/.*\.id$/ }
206 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
208 my $sdate = $head->get("Standard-date");
209 my $when = str2time
($sdate, 'UTC');
211 my $committype = "web";
212 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
213 $user = defined $2 ?
"$2" : "$3";
221 push @message, { line
=> $summ };
225 foreach my $file (@paths) {
226 my $diffurl=defined $config{diffurl
} ?
$config{diffurl
} : "";
227 $diffurl=~s/\[\[file\]\]/$file/g;
228 $diffurl=~s/\[\[rev\]\]/$change/g;
230 page
=> pagename
($file),
237 committype
=> $committype,
239 message
=> [@message],
251 my $logs = `tla logs -d $config{srcdir}`;
252 my @changesets = reverse split(/\n/, $logs);
255 for($i=0;$i<$#changesets;$i++) {
256 last if $changesets[$i] eq $rev;
259 my $revminusone = $changesets[$i+1];
260 return `tla diff -d $config{srcdir} $revminusone`;
263 sub rcs_getctime
($) {
265 eval q{use Date::Parse};
267 eval q{use Mail::Header};
270 my $logs = `tla logs -d $config{srcdir}`;
271 my @changesets = reverse split(/\n/, $logs);
274 for (my $i=0; $i<$#changesets; $i++) {
275 my $change = $changesets[$i];
277 open(LOG
, "tla cat-log -d $config{srcdir} $change|");
278 my $head = Mail
::Header
->new(\
*LOG
);
281 $sdate = $head->get("Standard-date");
282 my $newfiles = $head->get("New-files");
284 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
285 last if defined($lastcreation);
288 my $date=str2time
($sdate, 'UTC');
289 debug
("found ctime ".localtime($date)." for $file");
293 sub rcs_getmtime
($) {
294 error
"rcs_getmtime is not implemented for tla\n"; # TODO