Guest User

mercurial-findtimes.patch

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