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