Advertisement
Guest User

mercurial-findtimes-notemp.patch

a guest
Jul 19th, 2011
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.57 KB | None | 0 0
  1. diff -r 78a217fb13f3 -r 1b6c46b62a28 Plugin/mercurial.pm
  2. --- a/Plugin/mercurial.pm   Sat Jul 16 03:19:25 2011 +0200
  3. +++ b/Plugin/mercurial.pm   Tue Jul 19 13:35:17 2011 +0200
  4. @@ -310,28 +310,76 @@
  5.     # TODO
  6.  }
  7.  
  8. -sub rcs_getctime ($) {
  9. -   my ($file) = @_;
  10. +{
  11. +my %time_cache;
  12.  
  13. -   my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v",
  14. -       "--style", "default", "$config{srcdir}/$file");
  15. -   open (my $out, "-|", @cmdline);
  16. +sub findtimes ($$) {
  17. +   my $file=shift;
  18. +   my $id=shift; # 0 = mtime ; 1 = ctime
  19.  
  20. -   my @log = (mercurial_log($out));
  21. +   if (! keys %time_cache) {
  22. +       my $date;
  23.  
  24. -   if (@log < 1) {
  25. -       return 0;
  26. +       # It doesn't seem possible to specify the format wanted for the
  27. +       # changelog (same format as is generated in git.pm:findtimes(),
  28. +       # though the date differs slightly) without using a style
  29. +       # _file_. There is a "hg log" switch "--template" to directly
  30. +       # control simple output formatting, but in this case, the
  31. +       # {file} directive must be redefined, which can only be done
  32. +       # with "--style".
  33. +       #
  34. +       # If {file} is not redefined, all files are output on a single
  35. +       # line separated with a space. It is not possible to conclude
  36. +       # if the space is part of a filename or just a separator, and
  37. +       # thus impossible to use in this case.
  38. +       #
  39. +       # Some output filters are available in hg, but they are not fit
  40. +       # for this cause (and would slow down the process
  41. +       # unnecessarily).
  42. +
  43. +       my $tmpl_filename='/path/to/map-cmdline.ikiwiki-log';
  44. +
  45. +       foreach my $line (run_or_die('hg', 'log', '--style',
  46. +               $tmpl_filename)) {
  47. +           # {date} gives output on the form
  48. +           # 1310694511.0-7200
  49. +           # where the first number is UTC Unix timestamp with one
  50. +           # decimal (decimal always 0, at least on my system)
  51. +           # followed by local timezone offset from UTC in
  52. +           # seconds.
  53. +           if (! defined $date && $line =~ /^\d+\.\d[+-]\d*$/) {
  54. +               $line =~ s/^(\d+).*/$1/;
  55. +               $date=$line;
  56. +           }
  57. +           elsif (! length $line) {
  58. +               $date=undef;
  59. +           }
  60. +           else {
  61. +               my $f=$line;
  62. +
  63. +               if (! $time_cache{$f}) {
  64. +                   $time_cache{$f}[0]=$date; # mtime
  65. +               }
  66. +               $time_cache{$f}[1]=$date; # ctime
  67. +           }
  68. +       }
  69.     }
  70.  
  71. -   eval q{use Date::Parse};
  72. -   error($@) if $@;
  73. -  
  74. -   my $ctime = str2time($log[$#log]->{"date"});
  75. -   return $ctime;
  76. +   return exists $time_cache{$file} ? $time_cache{$file}[$id] : 0;
  77. +}
  78. +
  79. +}
  80. +
  81. +sub rcs_getctime ($) {
  82. +   my $file = shift;
  83. +
  84. +   return findtimes($file, 1);
  85.  }
  86.  
  87.  sub rcs_getmtime ($) {
  88. -   error "rcs_getmtime is not implemented for mercurial\n"; # TODO
  89. +   my $file = shift;
  90. +
  91. +   return findtimes($file, 0);
  92.  }
  93.  
  94.  1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement