6 use POSIX qw(setlocale LC_CTYPE);
10 sub quiet_system (@) {
11 # See Debian bug #385939.
12 open (SAVEOUT, ">&STDOUT");
14 open (STDOUT, ">/dev/null");
17 open (STDOUT, ">&SAVEOUT");
22 sub rcs_update () { #{{{
23 if (-d "$config{srcdir}/{arch}") {
24 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
25 warn("tla replay failed\n");
30 sub rcs_prepedit ($) { #{{{
33 if (-d "$config{srcdir}/{arch}") {
34 # For Arch, return the tree-id of archive when
36 my $rev=`tla tree-id $config{srcdir}`;
37 return defined $rev ? $rev : "";
41 sub rcs_commit ($$$) { #{{{
46 if (-d "$config{srcdir}/{arch}") {
47 # Check to see if the page has been changed by someone
48 # else since rcs_prepedit was called.
49 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
50 my $rev=`tla tree-id $config{srcdir}`;
51 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
52 # Merge their changes into the file that we've
54 if (quiet_system("tla", "update", "-d",
55 "$config{srcdir}") != 0) {
56 warn("tla update failed\n");
60 if (quiet_system("tla", "commit",
61 "-L".possibly_foolish_untaint($message),
62 '-d', $config{srcdir}) != 0) {
63 my $conflict=readfile("$config{srcdir}/$file");
64 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
65 warn("tla undo failed\n");
70 return undef # success
73 sub rcs_add ($) { #{{{
76 if (-d "$config{srcdir}/{arch}") {
77 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
78 warn("tla add failed\n");
83 sub rcs_recentchanges ($) {
87 return unless -d "$config{srcdir}/{arch}";
89 eval q{use Date::Parse};
91 eval q{use Mail::Header};
94 my $logs = `tla logs -d $config{srcdir}`;
95 my @changesets = reverse split(/\n/, $logs);
97 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
98 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
100 open(LOG, "tla cat-log -d $config{srcdir} $change|");
101 my $head = Mail::Header->new(\*LOG);
104 my $rev = $head->get("Revision");
105 my $summ = $head->get("Summary");
106 my $newfiles = $head->get("New-files");
107 my $modfiles = $head->get("Modified-files");
108 my $remfiles = $head->get("Removed-files");
109 my $user = $head->get("Creator");
111 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
112 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
114 my $sdate = $head->get("Standard-date");
115 my $when = time - str2time($sdate, 'UTC');
117 my $committype = "web";
118 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
119 $user = defined $2 ? "$2" : "$3";
127 push @message, { line => escapeHTML($summ) };
131 foreach my $file (@paths) {
132 my $diffurl=$config{diffurl};
133 $diffurl=~s/\[\[file\]\]/$file/g;
134 $diffurl=~s/\[\[rev\]\]/$change/g;
136 page => pagename($file),
140 push @ret, { rev => $change,
142 committype => $committype,
144 message => [@message],
154 sub rcs_notify () { #{{{
156 if (! exists $ENV{ARCH_VERSION}) {
157 error("ARCH_VERSION is not set, not running from tla post-commit hook, cannot send notifications");
159 my $rev=int(possibly_foolish_untaint($ENV{REV}));
161 eval q{use Mail::Header};
163 open(LOG, $ENV{"ARCH_LOG"});
164 my $head = Mail::Header->new(\*LOG);
167 my $user = $head->get("Creator");
169 my $newfiles = $head->get("New-files");
170 my $modfiles = $head->get("Modified-files");
171 my $remfiles = $head->get("Removed-files");
173 my @changed_pages = grep { !/(^.*\/)?\.arch-ids\/.*\.id$/ }
174 split(/ /, "$newfiles $modfiles $remfiles .arch-ids/fake.id");
176 require IkiWiki::UserInfo;
179 my $message = $head->get("Summary");
180 if ($message =~ /$config{web_commit_regexp}/) {
181 $user=defined $2 ? "$2" : "$3";
186 my $logs = `tla logs -d $config{srcdir}`;
187 my @changesets = reverse split(/\n/, $logs);
190 for($i=0;$i<$#changesets;$i++) {
191 last if $changesets[$i] eq $rev;
194 my $revminusone = $changesets[$i+1];
195 `tla diff -d $ENV{ARCH_TREE_ROOT} $revminusone`;
196 }, $user, @changed_pages);
199 sub rcs_getctime ($) { #{{{
201 eval q{use Date::Parse};
203 eval q{use Mail::Header};
206 my $logs = `tla logs -d $config{srcdir}`;
207 my @changesets = reverse split(/\n/, $logs);
210 for (my $i=0; $i<$#changesets; $i++) {
211 my $change = $changesets[$i];
213 open(LOG, "tla cat-log -d $config{srcdir} $change|");
214 my $head = Mail::Header->new(\*LOG);
217 $sdate = $head->get("Standard-date");
218 my $newfiles = $head->get("New-files");
220 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
221 last if defined($lastcreation);
224 my $date=str2time($sdate, 'UTC');
225 debug("found ctime ".localtime($date)." for $file");