summaryrefslogtreecommitdiff
path: root/IkiWiki/Rcs/mercurial.pm
blob: 36972c560e3c6b6f5426610bb0209bce99b86b5f (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) = @_;
  54. $message = possibly_foolish_untaint($message);
  55. my @cmdline = ("hg", "-R", "$config{srcdir}", "commit", "-m", "$message");
  56. if (system(@cmdline) != 0) {
  57. warn "'@cmdline' failed: $!";
  58. }
  59. return undef; # success
  60. } #}}}
  61. sub rcs_add ($) { # {{{
  62. my ($file) = @_;
  63. my @cmdline = ("hg", "-R", "$config{srcdir}", "add", "$file");
  64. if (system(@cmdline) != 0) {
  65. warn "'@cmdline' failed: $!";
  66. }
  67. } #}}}
  68. sub rcs_recentchanges ($) { #{{{
  69. my ($num) = @_;
  70. eval q{use CGI 'escapeHTML'};
  71. error($@) if $@;
  72. my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num);
  73. open (my $out, "@cmdline |");
  74. my @ret;
  75. foreach my $info (mercurial_log($out)) {
  76. my @pages = ();
  77. my @message = ();
  78. foreach my $msgline (split(/\n/, $info->{description})) {
  79. push @message, { line => $msgline };
  80. }
  81. foreach my $file (split / /,$info->{files}) {
  82. my $diffurl = $config{'diffurl'};
  83. $diffurl =~ s/\[\[file\]\]/$file/go;
  84. $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
  85. push @pages, {
  86. page => pagename($file),
  87. diffurl => $diffurl,
  88. };
  89. }
  90. my $user = $info->{"user"};
  91. $user =~ s/\s*<.*>\s*$//;
  92. $user =~ s/^\s*//;
  93. push @ret, {
  94. rev => $info->{"changeset"},
  95. user => $user,
  96. committype => "mercurial",
  97. when => $info->{"date"},
  98. message => [@message],
  99. pages => [@pages],
  100. };
  101. }
  102. return @ret;
  103. } #}}}
  104. sub rcs_notify () { #{{{
  105. # TODO
  106. } #}}}
  107. sub rcs_getctime ($) { #{{{
  108. error "getctime not implemented";
  109. } #}}}
  110. 1