Advertisement
tangent

Fossil wrapper script to emulate git log -p

Jul 11th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.28 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4.  
  5. use Carp;
  6. use File::Which;
  7. use IO::Interactive qw(is_interactive);
  8.  
  9. die "usage: $0 <files...>\n\n" unless @ARGV;
  10.  
  11. my $out;
  12. if (is_interactive()) {
  13.     my $pager = $ENV{PAGER} || which('less') || which('more');
  14.     open $out, '|-', $pager or croak "Cannot pipe to $pager: $!";
  15. }
  16. else {
  17.     $out = *STDOUT;
  18. }
  19.  
  20. open my $bcmd, '-|', 'fossil branch current'
  21.         or die "Cannot get branch: $!\n";
  22. my $cbranch = <$bcmd>;
  23. chomp $cbranch;
  24. close $bcmd;
  25.  
  26. for my $file (@ARGV) {
  27.     my $lastckid;
  28.     open my $finfo, '-|', "fossil finfo --brief --limit 0 '$file'"
  29.             or die "Failed to get file info: $!\n";
  30.     my @filines = <$finfo>;
  31.     close $finfo;
  32.    
  33.     for my $line (@filines) {
  34.         my ($currckid, $date, $user, $branch, @cwords) = split ' ', $line;
  35.         next unless $branch eq $cbranch;
  36.         if (defined $lastckid and defined $branch) {
  37.             my $comment = join ' ', @cwords;
  38.             open my $diff, '-|', 'fossil', 'diff', $file,
  39.                     '--from', $currckid
  40.                     '--to',   $lastckid,
  41.                     or die "Failed to diff $currckid -> $lastckid: $!\n";
  42.             my @dl = <$diff>;
  43.             close $diff;
  44.             my $patch = join '', @dl;
  45.  
  46.             print $out <<"OUT"
  47. Checkin ID $currckid to $branch by $user on $date
  48. Comment: $comment
  49.  
  50. $patch
  51.  
  52. OUT
  53.         }
  54.  
  55.         $lastckid = $currckid;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement