10 # See Debian bug #385939.
11 open (SAVEOUT, ">&STDOUT");
13 open (STDOUT, ">/dev/null");
16 open (STDOUT, ">&SAVEOUT");
21 sub rcs_update () { #{{{
22 if (-d "$config{srcdir}/{arch}") {
23 if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
24 warn("tla replay failed\n");
29 sub rcs_prepedit ($) { #{{{
32 if (-d "$config{srcdir}/{arch}") {
33 # For Arch, return the tree-id of archive when
35 my $rev=`tla tree-id $config{srcdir}`;
36 return defined $rev ? $rev : "";
40 sub rcs_commit ($$$;$$) { #{{{
48 $message="web commit by $user".(length $message ? ": $message" : "");
50 elsif (defined $ipaddr) {
51 $message="web commit from $ipaddr".(length $message ? ": $message" : "");
54 if (-d "$config{srcdir}/{arch}") {
55 # Check to see if the page has been changed by someone
56 # else since rcs_prepedit was called.
57 my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
58 my $rev=`tla tree-id $config{srcdir}`;
59 if (defined $rev && defined $oldrev && $rev ne $oldrev) {
60 # Merge their changes into the file that we've
62 if (quiet_system("tla", "update", "-d",
63 "$config{srcdir}") != 0) {
64 warn("tla update failed\n");
68 if (quiet_system("tla", "commit",
69 "-L".possibly_foolish_untaint($message),
70 '-d', $config{srcdir}) != 0) {
71 my $conflict=readfile("$config{srcdir}/$file");
72 if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
73 warn("tla undo failed\n");
78 return undef # success
81 sub rcs_add ($) { #{{{
84 if (-d "$config{srcdir}/{arch}") {
85 if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
86 warn("tla add failed\n");
91 sub rcs_recentchanges ($) {
95 return unless -d "$config{srcdir}/{arch}";
97 eval q{use Date::Parse};
99 eval q{use Mail::Header};
102 my $logs = `tla logs -d $config{srcdir}`;
103 my @changesets = reverse split(/\n/, $logs);
105 for (my $i=0; $i<$num && $i<$#changesets; $i++) {
106 my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
108 open(LOG, "tla cat-log -d $config{srcdir} $change|");
109 my $head = Mail::Header->new(\*LOG);
112 my $rev = $head->get("Revision");
113 my $summ = $head->get("Summary");
114 my $newfiles = $head->get("New-files");
115 my $modfiles = $head->get("Modified-files");
116 my $remfiles = $head->get("Removed-files");
117 my $user = $head->get("Creator");
119 my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
120 split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
122 my $sdate = $head->get("Standard-date");
123 my $when = time - str2time($sdate, 'UTC');
125 my $committype = "web";
126 if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
127 $user = defined $2 ? "$2" : "$3";
135 push @message, { line => escapeHTML($summ) };
139 foreach my $file (@paths) {
140 my $diffurl=$config{diffurl};
141 $diffurl=~s/\[\[file\]\]/$file/g;
142 $diffurl=~s/\[\[rev\]\]/$change/g;
144 page => pagename($file),
148 push @ret, { rev => $change,
150 committype => $committype,
152 message => [@message],
162 sub rcs_notify () { #{{{
164 if (! exists $ENV{ARCH_VERSION}) {
165 error("ARCH_VERSION is not set, not running from tla post-commit hook, cannot send notifications");
167 my $rev=int(possibly_foolish_untaint($ENV{REV}));
169 eval q{use Mail::Header};
171 open(LOG, $ENV{"ARCH_LOG"});
172 my $head = Mail::Header->new(\*LOG);
175 my $user = $head->get("Creator");
177 my $newfiles = $head->get("New-files");
178 my $modfiles = $head->get("Modified-files");
179 my $remfiles = $head->get("Removed-files");
181 my @changed_pages = grep { !/(^.*\/)?\.arch-ids\/.*\.id$/ }
182 split(/ /, "$newfiles $modfiles $remfiles .arch-ids/fake.id");
184 require IkiWiki::UserInfo;
187 my $message = $head->get("Summary");
188 if ($message =~ /$config{web_commit_regexp}/) {
189 $user=defined $2 ? "$2" : "$3";
194 my $logs = `tla logs -d $config{srcdir}`;
195 my @changesets = reverse split(/\n/, $logs);
198 for($i=0;$i<$#changesets;$i++) {
199 last if $changesets[$i] eq $rev;
202 my $revminusone = $changesets[$i+1];
203 `tla diff -d $ENV{ARCH_TREE_ROOT} $revminusone`;
204 }, $user, @changed_pages);
207 sub rcs_getctime ($) { #{{{
209 eval q{use Date::Parse};
211 eval q{use Mail::Header};
214 my $logs = `tla logs -d $config{srcdir}`;
215 my @changesets = reverse split(/\n/, $logs);
218 for (my $i=0; $i<$#changesets; $i++) {
219 my $change = $changesets[$i];
221 open(LOG, "tla cat-log -d $config{srcdir} $change|");
222 my $head = Mail::Header->new(\*LOG);
225 $sdate = $head->get("Standard-date");
226 my $newfiles = $head->get("New-files");
228 my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
229 last if defined($lastcreation);
232 my $date=str2time($sdate, 'UTC');
233 debug("found ctime ".localtime($date)." for $file");