summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/git.pm
blob: 6a7f6c3ae3f9eaf3e5dafab166fa3060d946cdf0 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::git;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. use Encode;
  7. use open qw{:utf8 :std};
  8. my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate Git sha1sums
  9. my $dummy_commit_msg = 'dummy commit'; # message to skip in recent changes
  10. my $no_chdir=0;
  11. sub import {
  12. hook(type => "checkconfig", id => "git", call => \&checkconfig);
  13. hook(type => "getsetup", id => "git", call => \&getsetup);
  14. hook(type => "rcs", id => "rcs_update", call => \&rcs_update);
  15. hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit);
  16. hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit);
  17. hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged);
  18. hook(type => "rcs", id => "rcs_add", call => \&rcs_add);
  19. hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove);
  20. hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename);
  21. hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges);
  22. hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff);
  23. hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime);
  24. hook(type => "rcs", id => "rcs_receive", call => \&rcs_receive);
  25. }
  26. sub checkconfig () {
  27. if (! defined $config{gitorigin_branch}) {
  28. $config{gitorigin_branch}="origin";
  29. }
  30. if (! defined $config{gitmaster_branch}) {
  31. $config{gitmaster_branch}="master";
  32. }
  33. if (defined $config{git_wrapper} &&
  34. length $config{git_wrapper}) {
  35. push @{$config{wrappers}}, {
  36. wrapper => $config{git_wrapper},
  37. wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"),
  38. };
  39. }
  40. if (defined $config{git_test_receive_wrapper} &&
  41. length $config{git_test_receive_wrapper}) {
  42. push @{$config{wrappers}}, {
  43. test_receive => 1,
  44. wrapper => $config{git_test_receive_wrapper},
  45. wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"),
  46. };
  47. }
  48. }
  49. sub getsetup () {
  50. return
  51. plugin => {
  52. safe => 0, # rcs plugin
  53. rebuild => undef,
  54. },
  55. git_wrapper => {
  56. type => "string",
  57. example => "/git/wiki.git/hooks/post-update",
  58. description => "git hook to generate",
  59. safe => 0, # file
  60. rebuild => 0,
  61. },
  62. git_wrappermode => {
  63. type => "string",
  64. example => '06755',
  65. description => "mode for git_wrapper (can safely be made suid)",
  66. safe => 0,
  67. rebuild => 0,
  68. },
  69. git_test_receive_wrapper => {
  70. type => "string",
  71. example => "/git/wiki.git/hooks/pre-receive",
  72. description => "git pre-receive hook to generate",
  73. safe => 0, # file
  74. rebuild => 0,
  75. },
  76. untrusted_committers => {
  77. type => "string",
  78. example => [],
  79. description => "unix users whose commits should be checked by the pre-receive hook",
  80. safe => 0,
  81. rebuild => 0,
  82. },
  83. historyurl => {
  84. type => "string",
  85. example => "http://git.example.com/gitweb.cgi?p=wiki.git;a=history;f=[[file]]",
  86. description => "gitweb url to show file history ([[file]] substituted)",
  87. safe => 1,
  88. rebuild => 1,
  89. },
  90. diffurl => {
  91. type => "string",
  92. example => "http://git.example.com/gitweb.cgi?p=wiki.git;a=blobdiff;h=[[sha1_to]];hp=[[sha1_from]];hb=[[sha1_parent]];f=[[file]]",
  93. description => "gitweb url to show a diff ([[sha1_to]], [[sha1_from]], [[sha1_parent]], [[sha1_commit]] and [[file]] substituted)",
  94. safe => 1,
  95. rebuild => 1,
  96. },
  97. gitorigin_branch => {
  98. type => "string",
  99. example => "origin",
  100. description => "where to pull and push changes (set to empty string to disable)",
  101. safe => 0, # paranoia
  102. rebuild => 0,
  103. },
  104. gitmaster_branch => {
  105. type => "string",
  106. example => "master",
  107. description => "branch that the wiki is stored in",
  108. safe => 0, # paranoia
  109. rebuild => 0,
  110. },
  111. }
  112. sub safe_git (&@) {
  113. # Start a child process safely without resorting /bin/sh.
  114. # Return command output or success state (in scalar context).
  115. my ($error_handler, @cmdline) = @_;
  116. my $pid = open my $OUT, "-|";
  117. error("Cannot fork: $!") if !defined $pid;
  118. if (!$pid) {
  119. # In child.
  120. # Git commands want to be in wc.
  121. if (! $no_chdir) {
  122. chdir $config{srcdir}
  123. or error("Cannot chdir to $config{srcdir}: $!");
  124. }
  125. exec @cmdline or error("Cannot exec '@cmdline': $!");
  126. }
  127. # In parent.
  128. my @lines;
  129. while (<$OUT>) {
  130. chomp;
  131. push @lines, $_;
  132. }
  133. close $OUT;
  134. $error_handler->("'@cmdline' failed: $!") if $? && $error_handler;
  135. return wantarray ? @lines : ($? == 0);
  136. }
  137. # Convenient wrappers.
  138. sub run_or_die ($@) { safe_git(\&error, @_) }
  139. sub run_or_cry ($@) { safe_git(sub { warn @_ }, @_) }
  140. sub run_or_non ($@) { safe_git(undef, @_) }
  141. sub merge_past ($$$) {
  142. # Unlike with Subversion, Git cannot make a 'svn merge -rN:M file'.
  143. # Git merge commands work with the committed changes, except in the
  144. # implicit case of '-m' of git checkout(1). So we should invent a
  145. # kludge here. In principle, we need to create a throw-away branch
  146. # in preparing for the merge itself. Since branches are cheap (and
  147. # branching is fast), this shouldn't cost high.
  148. #
  149. # The main problem is the presence of _uncommitted_ local changes. One
  150. # possible approach to get rid of this situation could be that we first
  151. # make a temporary commit in the master branch and later restore the
  152. # initial state (this is possible since Git has the ability to undo a
  153. # commit, i.e. 'git reset --soft HEAD^'). The method can be summarized
  154. # as follows:
  155. #
  156. # - create a diff of HEAD:current-sha1
  157. # - dummy commit
  158. # - create a dummy branch and switch to it
  159. # - rewind to past (reset --hard to the current-sha1)
  160. # - apply the diff and commit
  161. # - switch to master and do the merge with the dummy branch
  162. # - make a soft reset (undo the last commit of master)
  163. #
  164. # The above method has some drawbacks: (1) it needs a redundant commit
  165. # just to get rid of local changes, (2) somewhat slow because of the
  166. # required system forks. Until someone points a more straight method
  167. # (which I would be grateful) I have implemented an alternative method.
  168. # In this approach, we hide all the modified files from Git by renaming
  169. # them (using the 'rename' builtin) and later restore those files in
  170. # the throw-away branch (that is, we put the files themselves instead
  171. # of applying a patch).
  172. my ($sha1, $file, $message) = @_;
  173. my @undo; # undo stack for cleanup in case of an error
  174. my $conflict; # file content with conflict markers
  175. eval {
  176. # Hide local changes from Git by renaming the modified file.
  177. # Relative paths must be converted to absolute for renaming.
  178. my ($target, $hidden) = (
  179. "$config{srcdir}/${file}", "$config{srcdir}/${file}.${sha1}"
  180. );
  181. rename($target, $hidden)
  182. or error("rename '$target' to '$hidden' failed: $!");
  183. # Ensure to restore the renamed file on error.
  184. push @undo, sub {
  185. return if ! -e "$hidden"; # already renamed
  186. rename($hidden, $target)
  187. or warn "rename '$hidden' to '$target' failed: $!";
  188. };
  189. my $branch = "throw_away_${sha1}"; # supposed to be unique
  190. # Create a throw-away branch and rewind backward.
  191. push @undo, sub { run_or_cry('git', 'branch', '-D', $branch) };
  192. run_or_die('git', 'branch', $branch, $sha1);
  193. # Switch to throw-away branch for the merge operation.
  194. push @undo, sub {
  195. if (!run_or_cry('git', 'checkout', $config{gitmaster_branch})) {
  196. run_or_cry('git', 'checkout','-f',$config{gitmaster_branch});
  197. }
  198. };
  199. run_or_die('git', 'checkout', $branch);
  200. # Put the modified file in _this_ branch.
  201. rename($hidden, $target)
  202. or error("rename '$hidden' to '$target' failed: $!");
  203. # _Silently_ commit all modifications in the current branch.
  204. run_or_non('git', 'commit', '-m', $message, '-a');
  205. # ... and re-switch to master.
  206. run_or_die('git', 'checkout', $config{gitmaster_branch});
  207. # Attempt to merge without complaining.
  208. if (!run_or_non('git', 'pull', '--no-commit', '.', $branch)) {
  209. $conflict = readfile($target);
  210. run_or_die('git', 'reset', '--hard');
  211. }
  212. };
  213. my $failure = $@;
  214. # Process undo stack (in reverse order). By policy cleanup
  215. # actions should normally print a warning on failure.
  216. while (my $handle = pop @undo) {
  217. $handle->();
  218. }
  219. error("Git merge failed!\n$failure\n") if $failure;
  220. return $conflict;
  221. }
  222. sub parse_diff_tree ($@) {
  223. # Parse the raw diff tree chunk and return the info hash.
  224. # See git-diff-tree(1) for the syntax.
  225. my ($prefix, $dt_ref) = @_;
  226. # End of stream?
  227. return if !defined @{ $dt_ref } ||
  228. !defined @{ $dt_ref }[0] || !length @{ $dt_ref }[0];
  229. my %ci;
  230. # Header line.
  231. while (my $line = shift @{ $dt_ref }) {
  232. return if $line !~ m/^(.+) ($sha1_pattern)/;
  233. my $sha1 = $2;
  234. $ci{'sha1'} = $sha1;
  235. last;
  236. }
  237. # Identification lines for the commit.
  238. while (my $line = shift @{ $dt_ref }) {
  239. # Regexps are semi-stolen from gitweb.cgi.
  240. if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
  241. $ci{'tree'} = $1;
  242. }
  243. elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
  244. # XXX: collecting in reverse order
  245. push @{ $ci{'parents'} }, $1;
  246. }
  247. elsif ($line =~ m/^(author|committer) (.*) ([0-9]+) (.*)$/) {
  248. my ($who, $name, $epoch, $tz) =
  249. ($1, $2, $3, $4 );
  250. $ci{ $who } = $name;
  251. $ci{ "${who}_epoch" } = $epoch;
  252. $ci{ "${who}_tz" } = $tz;
  253. if ($name =~ m/^[^<]+\s+<([^@>]+)/) {
  254. $ci{"${who}_username"} = $1;
  255. }
  256. elsif ($name =~ m/^([^<]+)\s+<>$/) {
  257. $ci{"${who}_username"} = $1;
  258. }
  259. else {
  260. $ci{"${who}_username"} = $name;
  261. }
  262. }
  263. elsif ($line =~ m/^$/) {
  264. # Trailing empty line signals next section.
  265. last;
  266. }
  267. }
  268. debug("No 'tree' seen in diff-tree output") if !defined $ci{'tree'};
  269. if (defined $ci{'parents'}) {
  270. $ci{'parent'} = @{ $ci{'parents'} }[0];
  271. }
  272. else {
  273. $ci{'parent'} = 0 x 40;
  274. }
  275. # Commit message (optional).
  276. while ($dt_ref->[0] =~ /^ /) {
  277. my $line = shift @{ $dt_ref };
  278. $line =~ s/^ //;
  279. push @{ $ci{'comment'} }, $line;
  280. }
  281. shift @{ $dt_ref } if $dt_ref->[0] =~ /^$/;
  282. # Modified files.
  283. while (my $line = shift @{ $dt_ref }) {
  284. if ($line =~ m{^
  285. (:+) # number of parents
  286. ([^\t]+)\t # modes, sha1, status
  287. (.*) # file names
  288. $}xo) {
  289. my $num_parents = length $1;
  290. my @tmp = split(" ", $2);
  291. my ($file, $file_to) = split("\t", $3);
  292. my @mode_from = splice(@tmp, 0, $num_parents);
  293. my $mode_to = shift(@tmp);
  294. my @sha1_from = splice(@tmp, 0, $num_parents);
  295. my $sha1_to = shift(@tmp);
  296. my $status = shift(@tmp);
  297. # git does not output utf-8 filenames, but instead
  298. # double-quotes them with the utf-8 characters
  299. # escaped as \nnn\nnn.
  300. if ($file =~ m/^"(.*)"$/) {
  301. ($file=$1) =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
  302. }
  303. $file =~ s/^\Q$prefix\E//;
  304. if (length $file) {
  305. push @{ $ci{'details'} }, {
  306. 'file' => decode("utf8", $file),
  307. 'sha1_from' => $sha1_from[0],
  308. 'sha1_to' => $sha1_to,
  309. 'mode_from' => $mode_from[0],
  310. 'mode_to' => $mode_to,
  311. 'status' => $status,
  312. };
  313. }
  314. next;
  315. };
  316. last;
  317. }
  318. return \%ci;
  319. }
  320. sub git_commit_info ($;$) {
  321. # Return an array of commit info hashes of num commits
  322. # starting from the given sha1sum.
  323. my ($sha1, $num) = @_;
  324. my @opts;
  325. push @opts, "--max-count=$num" if defined $num;
  326. my @raw_lines = run_or_die('git', 'log', @opts,
  327. '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
  328. '-r', $sha1, '--', '.');
  329. my ($prefix) = run_or_die('git', 'rev-parse', '--show-prefix');
  330. my @ci;
  331. while (my $parsed = parse_diff_tree(($prefix or ""), \@raw_lines)) {
  332. push @ci, $parsed;
  333. }
  334. warn "Cannot parse commit info for '$sha1' commit" if !@ci;
  335. return wantarray ? @ci : $ci[0];
  336. }
  337. sub git_sha1 (;$) {
  338. # Return head sha1sum (of given file).
  339. my $file = shift || q{--};
  340. # Ignore error since a non-existing file might be given.
  341. my ($sha1) = run_or_non('git', 'rev-list', '--max-count=1', 'HEAD',
  342. '--', $file);
  343. if ($sha1) {
  344. ($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now
  345. } else { debug("Empty sha1sum for '$file'.") }
  346. return defined $sha1 ? $sha1 : q{};
  347. }
  348. sub rcs_update () {
  349. # Update working directory.
  350. if (length $config{gitorigin_branch}) {
  351. run_or_cry('git', 'pull', $config{gitorigin_branch});
  352. }
  353. }
  354. sub rcs_prepedit ($) {
  355. # Return the commit sha1sum of the file when editing begins.
  356. # This will be later used in rcs_commit if a merge is required.
  357. my ($file) = @_;
  358. return git_sha1($file);
  359. }
  360. sub rcs_commit ($$$;$$) {
  361. # Try to commit the page; returns undef on _success_ and
  362. # a version of the page with the rcs's conflict markers on
  363. # failure.
  364. my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
  365. # Check to see if the page has been changed by someone else since
  366. # rcs_prepedit was called.
  367. my $cur = git_sha1($file);
  368. my ($prev) = $rcstoken =~ /^($sha1_pattern)$/; # untaint
  369. if (defined $cur && defined $prev && $cur ne $prev) {
  370. my $conflict = merge_past($prev, $file, $dummy_commit_msg);
  371. return $conflict if defined $conflict;
  372. }
  373. rcs_add($file);
  374. return rcs_commit_staged($message, $user, $ipaddr);
  375. }
  376. sub rcs_commit_staged ($$$) {
  377. # Commits all staged changes. Changes can be staged using rcs_add,
  378. # rcs_remove, and rcs_rename.
  379. my ($message, $user, $ipaddr)=@_;
  380. # Set the commit author and email to the web committer.
  381. my %env=%ENV;
  382. if (defined $user || defined $ipaddr) {
  383. my $u=defined $user ? $user : $ipaddr;
  384. $ENV{GIT_AUTHOR_NAME}=$u;
  385. $ENV{GIT_AUTHOR_EMAIL}="$u\@web";
  386. }
  387. $message = IkiWiki::possibly_foolish_untaint($message);
  388. my @opts;
  389. if ($message !~ /\S/) {
  390. # Force git to allow empty commit messages.
  391. # (If this version of git supports it.)
  392. my ($version)=`git --version` =~ /git version (.*)/;
  393. if ($version ge "1.5.4") {
  394. push @opts, '--cleanup=verbatim';
  395. }
  396. else {
  397. $message.=".";
  398. }
  399. }
  400. push @opts, '-q';
  401. # git commit returns non-zero if file has not been really changed.
  402. # so we should ignore its exit status (hence run_or_non).
  403. if (run_or_non('git', 'commit', @opts, '-m', $message)) {
  404. if (length $config{gitorigin_branch}) {
  405. run_or_cry('git', 'push', $config{gitorigin_branch});
  406. }
  407. }
  408. %ENV=%env;
  409. return undef; # success
  410. }
  411. sub rcs_add ($) {
  412. # Add file to archive.
  413. my ($file) = @_;
  414. run_or_cry('git', 'add', $file);
  415. }
  416. sub rcs_remove ($) {
  417. # Remove file from archive.
  418. my ($file) = @_;
  419. run_or_cry('git', 'rm', '-f', $file);
  420. }
  421. sub rcs_rename ($$) {
  422. my ($src, $dest) = @_;
  423. run_or_cry('git', 'mv', '-f', $src, $dest);
  424. }
  425. sub rcs_recentchanges ($) {
  426. # List of recent changes.
  427. my ($num) = @_;
  428. eval q{use Date::Parse};
  429. error($@) if $@;
  430. my @rets;
  431. foreach my $ci (git_commit_info('HEAD', $num || 1)) {
  432. # Skip redundant commits.
  433. next if ($ci->{'comment'} && @{$ci->{'comment'}}[0] eq $dummy_commit_msg);
  434. my ($sha1, $when) = (
  435. $ci->{'sha1'},
  436. $ci->{'author_epoch'}
  437. );
  438. my @pages;
  439. foreach my $detail (@{ $ci->{'details'} }) {
  440. my $file = $detail->{'file'};
  441. my $diffurl = defined $config{'diffurl'} ? $config{'diffurl'} : "";
  442. $diffurl =~ s/\[\[file\]\]/$file/go;
  443. $diffurl =~ s/\[\[sha1_parent\]\]/$ci->{'parent'}/go;
  444. $diffurl =~ s/\[\[sha1_from\]\]/$detail->{'sha1_from'}/go;
  445. $diffurl =~ s/\[\[sha1_to\]\]/$detail->{'sha1_to'}/go;
  446. $diffurl =~ s/\[\[sha1_commit\]\]/$sha1/go;
  447. push @pages, {
  448. page => pagename($file),
  449. diffurl => $diffurl,
  450. };
  451. }
  452. my @messages;
  453. my $pastblank=0;
  454. foreach my $line (@{$ci->{'comment'}}) {
  455. $pastblank=1 if $line eq '';
  456. next if $pastblank && $line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i;
  457. push @messages, { line => $line };
  458. }
  459. my $user=$ci->{'author_username'};
  460. my $web_commit = ($ci->{'author'} =~ /\@web>/);
  461. # compatability code for old web commit messages
  462. if (! $web_commit &&
  463. defined $messages[0] &&
  464. $messages[0]->{line} =~ m/$config{web_commit_regexp}/) {
  465. $user = defined $2 ? "$2" : "$3";
  466. $messages[0]->{line} = $4;
  467. $web_commit=1;
  468. }
  469. push @rets, {
  470. rev => $sha1,
  471. user => $user,
  472. committype => $web_commit ? "web" : "git",
  473. when => $when,
  474. message => [@messages],
  475. pages => [@pages],
  476. } if @pages;
  477. last if @rets >= $num;
  478. }
  479. return @rets;
  480. }
  481. sub rcs_diff ($) {
  482. my $rev=shift;
  483. my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
  484. my @lines;
  485. foreach my $line (run_or_non("git", "show", $sha1)) {
  486. if (@lines || $line=~/^diff --git/) {
  487. push @lines, $line."\n";
  488. }
  489. }
  490. if (wantarray) {
  491. return @lines;
  492. }
  493. else {
  494. return join("", @lines);
  495. }
  496. }
  497. sub rcs_getctime ($) {
  498. my $file=shift;
  499. # Remove srcdir prefix
  500. $file =~ s/^\Q$config{srcdir}\E\/?//;
  501. my $sha1 = git_sha1($file);
  502. my $ci = git_commit_info($sha1, 1);
  503. my $ctime = $ci->{'author_epoch'};
  504. debug("ctime for '$file': ". localtime($ctime));
  505. return $ctime;
  506. }
  507. sub rcs_receive () {
  508. # The wiki may not be the only thing in the git repo.
  509. # Determine if it is in a subdirectory by examining the srcdir,
  510. # and its parents, looking for the .git directory.
  511. my $subdir="";
  512. my $dir=$config{srcdir};
  513. while (! -d "$dir/.git") {
  514. $subdir=IkiWiki::basename($dir)."/".$subdir;
  515. $dir=IkiWiki::dirname($dir);
  516. if (! length $dir) {
  517. error("cannot determine root of git repo");
  518. }
  519. }
  520. my @rets;
  521. while (<>) {
  522. chomp;
  523. my ($oldrev, $newrev, $refname) = split(' ', $_, 3);
  524. # only allow changes to gitmaster_branch
  525. if ($refname !~ /^refs\/heads\/\Q$config{gitmaster_branch}\E$/) {
  526. error sprintf(gettext("you are not allowed to change %s"), $refname);
  527. }
  528. # Avoid chdir when running git here, because the changes
  529. # are in the master git repo, not the srcdir repo.
  530. # The pre-recieve hook already puts us in the right place.
  531. $no_chdir=1;
  532. my @changes=git_commit_info($oldrev."..".$newrev);
  533. $no_chdir=0;
  534. foreach my $ci (@changes) {
  535. foreach my $detail (@{ $ci->{'details'} }) {
  536. my $file = $detail->{'file'};
  537. # check that all changed files are in the
  538. # subdir
  539. if (length $subdir &&
  540. ! ($file =~ s/^\Q$subdir\E//)) {
  541. error sprintf(gettext("you are not allowed to change %s"), $file);
  542. }
  543. my ($action, $mode, $path);
  544. if ($detail->{'status'} =~ /^[M]+\d*$/) {
  545. $action="change";
  546. $mode=$detail->{'mode_to'};
  547. }
  548. elsif ($detail->{'status'} =~ /^[AM]+\d*$/) {
  549. $action="add";
  550. $mode=$detail->{'mode_to'};
  551. }
  552. elsif ($detail->{'status'} =~ /^[DAM]+\d*/) {
  553. $action="remove";
  554. $mode=$detail->{'mode_from'};
  555. }
  556. else {
  557. error "unknown status ".$detail->{'status'};
  558. }
  559. # test that the file mode is ok
  560. if ($mode !~ /^100[64][64][64]$/) {
  561. error sprintf(gettext("you cannot act on a file with mode %s"), $mode);
  562. }
  563. if ($action eq "change") {
  564. if ($detail->{'mode_from'} ne $detail->{'mode_to'}) {
  565. error gettext("you are not allowed to change file modes");
  566. }
  567. }
  568. # extract attachment to temp file
  569. if (($action eq 'add' || $action eq 'change') &&
  570. ! pagetype($file)) {
  571. eval q{use File::Temp};
  572. die $@ if $@;
  573. my $fh;
  574. ($fh, $path)=File::Temp::tempfile("XXXXXXXXXX", UNLINK => 1);
  575. if (system("git show ".$detail->{sha1_to}." > '$path'") != 0) {
  576. error("failed writing temp file");
  577. }
  578. }
  579. push @rets, {
  580. file => $file,
  581. action => $action,
  582. path => $path,
  583. };
  584. }
  585. }
  586. }
  587. return reverse @rets;
  588. }
  589. 1