summaryrefslogtreecommitdiff
path: root/IkiWiki/Rcs/mercurial.pm
blob: 66ff0996a619fd482846d43831954143cff1bf71 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use IkiWiki;
  5. use Encode;
  6. use open qw{:utf8 :std};
  7. package IkiWiki;
  8. sub mercurial_log($) {
  9. my $out = shift;
  10. my @infos;
  11. while (<$out>) {
  12. my $line = $_;
  13. my ($key, $value);
  14. if (/^description:/) {
  15. $key = "description";
  16. $value = "";
  17. # slurp everything as the description text
  18. # until the next changeset
  19. while (<$out>) {
  20. if (/^changeset: /) {
  21. $line = $_;
  22. last;
  23. }
  24. $value .= $_;
  25. }
  26. local $/ = "";
  27. chomp $value;
  28. $infos[$#infos]{$key} = $value;
  29. }
  30. chomp $line;
  31. ($key, $value) = split /: +/, $line, 2;
  32. if ($key eq "changeset") {
  33. push @infos, {};
  34. # remove the revision index, which is strictly
  35. # local to the repository
  36. $value =~ s/^\d+://;
  37. }
  38. $infos[$#infos]{$key} = $value;
  39. }
  40. close $out;
  41. return @infos;
  42. }
  43. sub rcs_update () { #{{{
  44. my @cmdline = ("hg", "-R", "$config{srcdir}", "update");
  45. if (system(@cmdline) != 0) {
  46. warn "'@cmdline' failed: $!";
  47. }
  48. } #}}}
  49. sub rcs_prepedit ($) { #{{{
  50. return "";
  51. } #}}}
  52. sub rcs_commit ($$$) { #{{{
  53. my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
  54. if (defined $user) {
  55. $message="web commit by $user".(length $message ? ": $message" : "");
  56. }
  57. elsif (defined $ipaddr) {
  58. $message="web commit from $ipaddr".(length $message ? ": $message" : "");
  59. }
  60. $message = possibly_foolish_untaint($message);
  61. my @cmdline = ("hg", "-R", "$config{srcdir}", "commit", "-m", "$message");
  62. if (system(@cmdline) != 0) {
  63. warn "'@cmdline' failed: $!";
  64. }
  65. return undef; # success
  66. } #}}}
  67. sub rcs_add ($) { # {{{
  68. my ($file) = @_;
  69. my @cmdline = ("hg", "-R", "$config{srcdir}", "add", "$file");
  70. if (system(@cmdline) != 0) {
  71. warn "'@cmdline' failed: $!";
  72. }
  73. } #}}}
  74. sub rcs_recentchanges ($) { #{{{
  75. my ($num) = @_;
  76. eval q{use CGI 'escapeHTML'};
  77. error($@) if $@;
  78. my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num);
  79. open (my $out, "@cmdline |");
  80. my @ret;
  81. foreach my $info (mercurial_log($out)) {
  82. my @pages = ();
  83. my @message = ();
  84. foreach my $msgline (split(/\n/, $info->{description})) {
  85. push @message, { line => $msgline };
  86. }
  87. foreach my $file (split / /,$info->{files}) {
  88. my $diffurl = $config{'diffurl'};
  89. $diffurl =~ s/\[\[file\]\]/$file/go;
  90. $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
  91. push @pages, {
  92. page => pagename($file),
  93. diffurl => $diffurl,
  94. };
  95. }
  96. my $user = $info->{"user"};
  97. $user =~ s/\s*<.*>\s*$//;
  98. $user =~ s/^\s*//;
  99. push @ret, {
  100. rev => $info->{"changeset"},
  101. user => $user,
  102. committype => "mercurial",
  103. when => $info->{"date"},
  104. message => [@message],
  105. pages => [@pages],
  106. };
  107. }
  108. return @ret;
  109. } #}}}
  110. sub rcs_notify () { #{{{
  111. # TODO
  112. } #}}}
  113. sub rcs_getctime ($) { #{{{
  114. error "getctime not implemented";
  115. } #}}}
  116. 1