summaryrefslogtreecommitdiff
path: root/IkiWiki/Rcs/mercurial.pm
blob: 82a2fa642646cec3c54ad3be639babeb908ce4fe (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. my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num);
  72. open (my $out, "@cmdline |");
  73. my @ret;
  74. foreach my $info (mercurial_log($out)) {
  75. my @pages = ();
  76. my @message = ();
  77. foreach my $msgline (split(/\n/, $info->{description})) {
  78. push @message, { line => $msgline };
  79. }
  80. foreach my $file (split / /,$info->{files}) {
  81. my $diffurl = $config{'diffurl'};
  82. $diffurl =~ s/\[\[file\]\]/$file/go;
  83. $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
  84. push @pages, {
  85. page => pagename($file),
  86. diffurl => $diffurl,
  87. };
  88. }
  89. my $user = $info->{"user"};
  90. $user =~ s/\s*<.*>\s*$//;
  91. $user =~ s/^\s*//;
  92. push @ret, {
  93. rev => $info->{"changeset"},
  94. user => $user,
  95. committype => "mercurial",
  96. when => $info->{"date"},
  97. message => [@message],
  98. pages => [@pages],
  99. };
  100. }
  101. return @ret;
  102. } #}}}
  103. sub rcs_notify () { #{{{
  104. # TODO
  105. } #}}}
  106. sub rcs_getctime ($) { #{{{
  107. error "getctime not implemented";
  108. } #}}}
  109. 1