summaryrefslogtreecommitdiff
path: root/IkiWiki/Rcs/tla.pm
blob: 4232e1fe8372429902b7438f20e6c0c25189ce52 (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_commit_staged ($$$) {
  71. # Commits all staged changes. Changes can be staged using rcs_add,
  72. # rcs_remove, and rcs_rename.
  73. my ($message, $user, $ipaddr)=@_;
  74. error("rcs_commit_staged not implemented for tla"); # TODO
  75. }
  76. sub rcs_add ($) { #{{{
  77. my $file=shift;
  78. if (-d "$config{srcdir}/{arch}") {
  79. if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) {
  80. warn("tla add failed\n");
  81. }
  82. }
  83. } #}}}
  84. sub rcs_remove ($) { # {{{
  85. my $file = shift;
  86. error("rcs_remove not implemented for tla"); # TODO
  87. } #}}}
  88. sub rcs_rename ($$) { # {{{a
  89. my ($src, $dest) = @_;
  90. error("rcs_rename not implemented for tla"); # TODO
  91. } #}}}
  92. sub rcs_recentchanges ($) {
  93. my $num=shift;
  94. my @ret;
  95. return unless -d "$config{srcdir}/{arch}";
  96. eval q{use Date::Parse};
  97. error($@) if $@;
  98. eval q{use Mail::Header};
  99. error($@) if $@;
  100. my $logs = `tla logs -d $config{srcdir}`;
  101. my @changesets = reverse split(/\n/, $logs);
  102. for (my $i=0; $i<$num && $i<$#changesets; $i++) {
  103. my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint
  104. open(LOG, "tla cat-log -d $config{srcdir} $change|");
  105. my $head = Mail::Header->new(\*LOG);
  106. close(LOG);
  107. my $rev = $head->get("Revision");
  108. my $summ = $head->get("Summary");
  109. my $newfiles = $head->get("New-files");
  110. my $modfiles = $head->get("Modified-files");
  111. my $remfiles = $head->get("Removed-files");
  112. my $user = $head->get("Creator");
  113. my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ }
  114. split(/ /, "$newfiles $modfiles .arch-ids/fake.id");
  115. my $sdate = $head->get("Standard-date");
  116. my $when = str2time($sdate, 'UTC');
  117. my $committype = "web";
  118. if (defined $summ && $summ =~ /$config{web_commit_regexp}/) {
  119. $user = defined $2 ? "$2" : "$3";
  120. $summ = $4;
  121. }
  122. else {
  123. $committype="tla";
  124. }
  125. my @message;
  126. push @message, { line => $summ };
  127. my @pages;
  128. foreach my $file (@paths) {
  129. my $diffurl=$config{diffurl};
  130. $diffurl=~s/\[\[file\]\]/$file/g;
  131. $diffurl=~s/\[\[rev\]\]/$change/g;
  132. push @pages, {
  133. page => pagename($file),
  134. diffurl => $diffurl,
  135. } if length $file;
  136. }
  137. push @ret, {
  138. rev => $change,
  139. user => $user,
  140. committype => $committype,
  141. when => $when,
  142. message => [@message],
  143. pages => [@pages],
  144. } if @pages;
  145. last if $i == $num;
  146. }
  147. return @ret;
  148. }
  149. sub rcs_diff ($) { #{{{
  150. my $rev=shift;
  151. my $logs = `tla logs -d $config{srcdir}`;
  152. my @changesets = reverse split(/\n/, $logs);
  153. my $i;
  154. for($i=0;$i<$#changesets;$i++) {
  155. last if $changesets[$i] eq $rev;
  156. }
  157. my $revminusone = $changesets[$i+1];
  158. return `tla diff -d $config{srcdir} $revminusone`;
  159. } #}}}
  160. sub rcs_getctime ($) { #{{{
  161. my $file=shift;
  162. eval q{use Date::Parse};
  163. error($@) if $@;
  164. eval q{use Mail::Header};
  165. error($@) if $@;
  166. my $logs = `tla logs -d $config{srcdir}`;
  167. my @changesets = reverse split(/\n/, $logs);
  168. my $sdate;
  169. for (my $i=0; $i<$#changesets; $i++) {
  170. my $change = $changesets[$i];
  171. open(LOG, "tla cat-log -d $config{srcdir} $change|");
  172. my $head = Mail::Header->new(\*LOG);
  173. close(LOG);
  174. $sdate = $head->get("Standard-date");
  175. my $newfiles = $head->get("New-files");
  176. my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles");
  177. last if defined($lastcreation);
  178. }
  179. my $date=str2time($sdate, 'UTC');
  180. debug("found ctime ".localtime($date)." for $file");
  181. return $date;
  182. } #}}}
  183. 1