summaryrefslogtreecommitdiff
path: root/IkiWiki/Rcs/tla.pm
blob: 29dbd092a0ac67c812f76fdce9f31c1883b5cbdb (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. sub quiet_system (@) {
  7. # See Debian bug #385939.
  8. open (SAVEOUT, ">&STDOUT");
  9. close STDOUT;
  10. open (STDOUT, ">/dev/null");
  11. my $ret=system(@_);
  12. close STDOUT;
  13. open (STDOUT, ">&SAVEOUT");
  14. close SAVEOUT;
  15. return $ret;
  16. }
  17. sub rcs_update () { #{{{
  18. if (-d "$config{srcdir}/{arch}") {
  19. if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) {
  20. warn("tla replay failed\n");
  21. }
  22. }
  23. } #}}}
  24. sub rcs_prepedit ($) { #{{{
  25. my $file=shift;
  26. if (-d "$config{srcdir}/{arch}") {
  27. # For Arch, return the tree-id of archive when
  28. # editing begins.
  29. my $rev=`tla tree-id $config{srcdir}`;
  30. return defined $rev ? $rev : "";
  31. }
  32. } #}}}
  33. sub rcs_commit ($$$;$$) { #{{{
  34. my $file=shift;
  35. my $message=shift;
  36. my $rcstoken=shift;
  37. my $user=shift;
  38. my $ipaddr=shift;
  39. if (defined $user) {
  40. $message="web commit by $user".(length $message ? ": $message" : "");
  41. }
  42. elsif (defined $ipaddr) {
  43. $message="web commit from $ipaddr".(length $message ? ": $message" : "");
  44. }
  45. if (-d "$config{srcdir}/{arch}") {
  46. # Check to see if the page has been changed by someone
  47. # else since rcs_prepedit was called.
  48. my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
  49. my $rev=`tla tree-id $config{srcdir}`;
  50. if (defined $rev && defined $oldrev && $rev ne $oldrev) {
  51. # Merge their changes into the file that we've
  52. # changed.
  53. if (quiet_system("tla", "update", "-d",
  54. "$config{srcdir}") != 0) {
  55. warn("tla update failed\n");
  56. }
  57. }
  58. if (quiet_system("tla", "commit",
  59. "-L".possibly_foolish_untaint($message),
  60. '-d', $config{srcdir}) != 0) {
  61. my $conflict=readfile("$config{srcdir}/$file");
  62. if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) {
  63. warn("tla undo failed\n");
  64. }
  65. return $conflict;
  66. }
  67. }
  68. return undef # success
  69. } #}}}
  70. sub rcs_add ($) { #{{{
  71. my $file=shift;
  72. if (-d "$config{srcdir}/{arch}") {
  73. if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
  74. warn("tla add failed\n");
  75. }
  76. }
  77. } #}}}
  78. sub rcs_remove ($) { # {{{
  79. my $file = shift;
  80. error("rcs_remove not implemented for tla"); # TODO
  81. } #}}}
  82. sub rcs_recentchanges ($) {
  83. my $num=shift;
  84. my @ret;
  85. return unless -d "$config{srcdir}/{arch}";
  86. eval q{use Date::Parse};
  87. error($@) if $@;
  88. eval q{use Mail::Header};
  89. error($@) if $@;
  90. my $logs = `tla logs -d $config{srcdir}`;
  91. my @changesets = reverse split(/\n/, $logs);
  92. for (my $i=0; $i<$num && $i<$#changesets; $i++) {
  93. my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
  94. open(LOG, "tla cat-log -d $config{srcdir} $change|");
  95. my $head = Mail::Header->new(\*LOG);
  96. close(LOG);
  97. my $rev = $head->get("Revision");
  98. my $summ = $head->get("Summary");
  99. my $newfiles = $head->get("New-files");
  100. my $modfiles = $head->get("Modified-files");
  101. my $remfiles = $head->get("Removed-files");
  102. my $user = $head->get("Creator");
  103. my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
  104. split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
  105. my $sdate = $head->get("Standard-date");
  106. my $when = str2time($sdate, 'UTC');
  107. my $committype = "web";
  108. if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
  109. $user = defined $2 ? "$2" : "$3";
  110. $summ = $4;
  111. }
  112. else {
  113. $committype="tla";
  114. }
  115. my @message;
  116. push @message, { line => $summ };
  117. my @pages;
  118. foreach my $file (@paths) {
  119. my $diffurl=$config{diffurl};
  120. $diffurl=~s/\[\[file\]\]/$file/g;
  121. $diffurl=~s/\[\[rev\]\]/$change/g;
  122. push @pages, {
  123. page => pagename($file),
  124. diffurl => $diffurl,
  125. } if length $file;
  126. }
  127. push @ret, {
  128. rev => $change,
  129. user => $user,
  130. committype => $committype,
  131. when => $when,
  132. message => [@message],
  133. pages => [@pages],
  134. } if @pages;
  135. last if $i == $num;
  136. }
  137. return @ret;
  138. }
  139. sub rcs_diff ($) { #{{{
  140. my $rev=shift;
  141. my $logs = `tla logs -d $config{srcdir}`;
  142. my @changesets = reverse split(/\n/, $logs);
  143. my $i;
  144. for($i=0;$i<$#changesets;$i++) {
  145. last if $changesets[$i] eq $rev;
  146. }
  147. my $revminusone = $changesets[$i+1];
  148. return `tla diff -d $config{srcdir} $revminusone`;
  149. } #}}}
  150. sub rcs_getctime ($) { #{{{
  151. my $file=shift;
  152. eval q{use Date::Parse};
  153. error($@) if $@;
  154. eval q{use Mail::Header};
  155. error($@) if $@;
  156. my $logs = `tla logs -d $config{srcdir}`;
  157. my @changesets = reverse split(/\n/, $logs);
  158. my $sdate;
  159. for (my $i=0; $i<$#changesets; $i++) {
  160. my $change = $changesets[$i];
  161. open(LOG, "tla cat-log -d $config{srcdir} $change|");
  162. my $head = Mail::Header->new(\*LOG);
  163. close(LOG);
  164. $sdate = $head->get("Standard-date");
  165. my $newfiles = $head->get("New-files");
  166. my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
  167. last if defined($lastcreation);
  168. }
  169. my $date=str2time($sdate, 'UTC');
  170. debug("found ctime ".localtime($date)." for $file");
  171. return $date;
  172. } #}}}
  173. 1