Added first cut at the /blobdiff action.
[catagits/Gitalist.git] / lib / Gitalist / Model / Git.pm
CommitLineData
fbf3eb7e 1package Gitalist::Model::Git;
2
3use Moose;
4use namespace::autoclean;
5
37997f11 6extends 'Catalyst::Model';
7with 'Catalyst::Component::InstancePerContext';
86382b95 8
fbf3eb7e 9use DateTime;
10use Path::Class;
1feb3d6b 11use File::Which;
fbf3eb7e 12use Carp qw/croak/;
13use File::Find::Rule;
14use DateTime::Format::Mail;
15use File::Stat::ModeString;
16use List::MoreUtils qw/any/;
1feb3d6b 17use Scalar::Util qw/blessed/;
18use MooseX::Types::Common::String qw/NonEmptySimpleStr/; # FIXME, use Types::Path::Class and coerce
fbf3eb7e 19
a7cc1ede 20use Git::PurePerl;
21
27e05d7b 22=head1 NAME
23
24Gitalist::Model::Git - the model for git interactions
25
26=head1 DESCRIPTION
27
28[enter your description here]
29
30=head1 METHODS
31
32=cut
33
b3ad9e63 34# Should these live in a separate module? Or perhaps extended Regexp::Common?
35our $SHA1RE = qr/[0-9a-fA-F]{40}/;
36
a7cc1ede 37# These are static and only need to be setup on app start.
8c032474 38has repo_dir => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 ); # Fixme - path::class
39has git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
a7cc1ede 40# These are dynamic and can be different from one request to the next.
41has project => ( isa => NonEmptySimpleStr, is => 'rw');
42has gpp => ( isa => 'Git::PurePerl', is => 'rw', lazy_build => 1 );
43
37997f11 44sub build_per_context_instance {
a7cc1ede 45 my ( $self, $c ) = @_;
46
47 $self->project( $c->req->param('p') );
48
49 (my $pd = $self->project_dir( $self->project )) =~ s{/\.git$}();
50 $self->gpp( Git::PurePerl->new(directory => $pd) );
51
52 return $self;
53}
1feb3d6b 54
27e05d7b 55=head2 BUILD
56
57=cut
58
8c032474 59sub BUILD {
60 my ($self) = @_;
61 $self->git; # Cause lazy value build.
1feb3d6b 62 $self->repo_dir;
8c032474 63}
64
65sub _build_git {
1feb3d6b 66 my $git = File::Which::which('git');
d7c9a32f 67
1feb3d6b 68 if (!$git) {
69 die <<EOR;
fbf3eb7e 70Could not find a git executable.
71Please specify the which git executable to use in gitweb.yml
72EOR
1feb3d6b 73 }
fbf3eb7e 74
1feb3d6b 75 return $git;
04d1d917 76}
1feb3d6b 77
8c032474 78sub _build_repo_dir {
1ef8dc7d 79 return Gitalist->config->{repo_dir};
80}
81
27e05d7b 82=head2 get_object
83
84A wrapper for the equivalent L<Git::PurePerl> method.
85
86=cut
87
1ef8dc7d 88sub get_object {
a7cc1ede 89 my($self, $sha1) = @_;
90
9dc3b9a5 91 # We either want an object or undef, *not* an empty list.
a7cc1ede 92 return $self->gpp->get_object($sha1) || undef;
8c032474 93}
d7c9a32f 94
27e05d7b 95=head2 is_git_repo
96
97Determine whether a given directory (as a L<Path::Class::Dir> object) is a
98C<git> repo.
99
100=cut
101
fbf3eb7e 102sub is_git_repo {
1feb3d6b 103 my ($self, $dir) = @_;
fbf3eb7e 104
1feb3d6b 105 return -f $dir->file('HEAD') || -f $dir->file('.git/HEAD');
fbf3eb7e 106}
107
27e05d7b 108=head2 run_cmd
109
110Call out to the C<git> binary and return a string consisting of the output.
111
112=cut
113
1ef8dc7d 114sub run_cmd {
115 my ($self, @args) = @_;
116
117 print STDERR 'RUNNING: ', $self->git, qq[ @args], $/;
118
119 open my $fh, '-|', $self->git, @args
120 or die "failed to run git command";
121 binmode $fh, ':encoding(UTF-8)';
122
123 my $output = do { local $/ = undef; <$fh> };
124 close $fh;
125
126 return $output;
127}
128
27e05d7b 129=head2 project_dir
130
131The directory under which the given project will reside i.e C<.git/..>
132
133=cut
134
1ef8dc7d 135sub project_dir {
136 my($self, $project) = @_;
137
138 my $dir = blessed($project) && $project->isa('Path::Class::Dir')
139 ? $project->stringify
27e05d7b 140 : $self->dir_from_project_name($project);
1ef8dc7d 141
27e05d7b 142 $dir .= '/.git'
143 if -f dir($dir)->file('.git/HEAD');
1ef8dc7d 144
145 return $dir;
146}
147
27e05d7b 148=head2 run_cmd_in
149
150Run a C<git> command in a given project and return the output as a string.
151
152=cut
153
1ef8dc7d 154sub run_cmd_in {
155 my ($self, $project, @args) = @_;
156
27e05d7b 157 return $self->run_cmd('--git-dir' => $self->project_dir($project), @args);
1ef8dc7d 158}
159
27e05d7b 160=head2 command
161
162Run a C<git> command for the project specified in the C<p> parameter and
163return the output as a list of strings corresponding to the lines of output.
164
165=cut
166
b3ad9e63 167sub command {
168 my($self, @args) = @_;
169
27e05d7b 170 my $output = $self->run_cmd('--git-dir' => $self->project_dir($self->project), @args);
b3ad9e63 171
172 return $output ? split(/\n/, $output) : ();
173}
174
27e05d7b 175=head2 project_info
176
177Returns a hash corresponding to a given project's properties. The keys will
178be:
179
180 name
181 description (empty if .git/description is empty/unnamed)
182 owner
183 last_change
184
185=cut
186
fbf3eb7e 187sub project_info {
1feb3d6b 188 my ($self, $project) = @_;
fbf3eb7e 189
1feb3d6b 190 return {
191 name => $project,
192 $self->get_project_properties(
27e05d7b 193 $self->dir_from_project_name($project),
194 ),
195 };
fbf3eb7e 196}
197
27e05d7b 198=head2 get_project_properties
199
200Called by C<project_info> to get a project's properties.
201
202=cut
203
fbf3eb7e 204sub get_project_properties {
1feb3d6b 205 my ($self, $dir) = @_;
206 my %props;
fbf3eb7e 207
1feb3d6b 208 eval {
209 $props{description} = $dir->file('description')->slurp;
210 chomp $props{description};
fbf3eb7e 211 };
212
1feb3d6b 213 if ($props{description} && $props{description} =~ /^Unnamed repository;/) {
214 delete $props{description};
215 }
fbf3eb7e 216
1feb3d6b 217 ($props{owner} = (getpwuid $dir->stat->uid)[6]) =~ s/,+$//;
fbf3eb7e 218
1feb3d6b 219 my $output = $self->run_cmd_in($dir, qw{
220 for-each-ref --format=%(committer)
221 --sort=-committerdate --count=1 refs/heads
222 });
fbf3eb7e 223
1feb3d6b 224 if (my ($epoch, $tz) = $output =~ /\s(\d+)\s+([+-]\d+)$/) {
225 my $dt = DateTime->from_epoch(epoch => $epoch);
226 $dt->set_time_zone($tz);
227 $props{last_change} = $dt;
228 }
fbf3eb7e 229
1feb3d6b 230 return %props;
fbf3eb7e 231}
232
27e05d7b 233=head2 list_projects
234
235For the C<repo_dir> specified in the config return an array of projects where
236each item will contain the contents of L</project_info>.
237
238=cut
239
fbf3eb7e 240sub list_projects {
27e05d7b 241 my ($self, $dir) = @_;
fbf3eb7e 242
27e05d7b 243 my $base = dir($dir || $self->repo_dir);
fbf3eb7e 244
1feb3d6b 245 my @ret;
246 my $dh = $base->open;
247 while (my $file = $dh->read) {
248 next if $file =~ /^.{1,2}$/;
249
250 my $obj = $base->subdir($file);
251 next unless -d $obj;
252 next unless $self->is_git_repo($obj);
253
254 # XXX Leaky abstraction alert!
255 my $is_bare = !-d $obj->subdir('.git');
d7c9a32f 256
1feb3d6b 257 my $name = (File::Spec->splitdir($obj))[-1];
258 push @ret, {
27e05d7b 259 name => ($name . ( $is_bare ? '' : '/.git' )),
1feb3d6b 260 $self->get_project_properties(
261 $is_bare ? $obj : $obj->subdir('.git')
262 ),
263 };
264 }
265
266 return [sort { $a->{name} cmp $b->{name} } @ret];
fbf3eb7e 267}
268
27e05d7b 269=head2 dir_from_project_name
270
271Get the corresponding directory of a given project.
272
273=cut
274
275sub dir_from_project_name {
1feb3d6b 276 my ($self, $project) = @_;
fbf3eb7e 277
1feb3d6b 278 return dir($self->repo_dir)->subdir($project);
fbf3eb7e 279}
280
27e05d7b 281=head2 head_hash
282
0ee97fec 283Find the hash of a given head (defaults to HEAD) of given (or current) project.
27e05d7b 284
285=cut
286
c8870bd3 287sub head_hash {
0ee97fec 288 my ($self, $head, $project) = @_;
fbf3eb7e 289
0ee97fec 290 my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify/, $head || 'HEAD' );
1feb3d6b 291 return unless defined $output;
fbf3eb7e 292
a7cc1ede 293 my($sha1) = $output =~ /^($SHA1RE)$/;
294 return $sha1;
fbf3eb7e 295}
296
27e05d7b 297=head2 list_tree
298
299For a given tree sha1 return an array describing the tree's contents. Where
300the keys for each item will be:
301
302 mode
303 type
304 object
305 file
306
307=cut
308
fbf3eb7e 309sub list_tree {
27e05d7b 310 my ($self, $rev, $project) = @_;
fbf3eb7e 311
27e05d7b 312 $project ||= $self->project;
c8870bd3 313 $rev ||= $self->head_hash($project);
fbf3eb7e 314
1feb3d6b 315 my $output = $self->run_cmd_in($project, qw/ls-tree -z/, $rev);
316 return unless defined $output;
fbf3eb7e 317
1feb3d6b 318 my @ret;
319 for my $line (split /\0/, $output) {
320 my ($mode, $type, $object, $file) = split /\s+/, $line, 4;
d7c9a32f 321
1feb3d6b 322 push @ret, {
b3fa97cd 323 mode => oct $mode,
0ee97fec 324 # XXX I wonder why directories always turn up as 040000 ...
b3fa97cd 325 modestr => $self->get_object_mode_string({mode=>oct $mode}),
326 type => $type,
327 object => $object,
328 file => $file,
27e05d7b 329 };
1feb3d6b 330 }
331
332 return @ret;
fbf3eb7e 333}
334
27e05d7b 335=head2 get_object_mode_string
336
337Provide a string equivalent of an octal mode e.g 0644 eq '-rw-r--r--'.
338
339=cut
340
fbf3eb7e 341sub get_object_mode_string {
1feb3d6b 342 my ($self, $object) = @_;
fbf3eb7e 343
1feb3d6b 344 return unless $object && $object->{mode};
345 return mode_to_string($object->{mode});
fbf3eb7e 346}
347
27e05d7b 348=head2 get_object_type
349
350=cut
351
fbf3eb7e 352sub get_object_type {
27e05d7b 353 my ($self, $object, $project) = @_;
1feb3d6b 354
27e05d7b 355 chomp(my $output = $self->run_cmd_in($project || $self->project, qw/cat-file -t/, $object));
1feb3d6b 356 return unless $output;
357
1feb3d6b 358 return $output;
359}
360
27e05d7b 361=head2 cat_file
362
363Return the contents of a given file.
364
365=cut
366
367sub cat_file {
368 my ($self, $object, $project) = @_;
369
370 my $type = $self->get_object_type($object);
371 die "object `$object' is not a file\n"
372 if (!defined $type || $type ne 'blob');
373
374 my $output = $self->run_cmd_in($project || $self->project, qw/cat-file -p/, $object);
375 return unless $output;
376
377 return $output;
378}
379
380=head2 hash_by_path
381
382For a given sha1 and path find the corresponding hash. Useful for find blobs.
383
384=cut
385
c8870bd3 386sub hash_by_path {
1feb3d6b 387 my($self, $base, $path, $type) = @_;
fbf3eb7e 388
1feb3d6b 389 $path =~ s{/+$}();
fbf3eb7e 390
c8870bd3 391 my($line) = $self->command('ls-tree', $base, '--', $path)
1feb3d6b 392 or return;
393
394 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
b3ad9e63 395 $line =~ m/^([0-9]+) (.+) ($SHA1RE)\t/;
1feb3d6b 396 return defined $type && $type ne $2
397 ? ()
c8870bd3 398 : $3;
295c9703 399}
400
27e05d7b 401=head2 valid_rev
fbf3eb7e 402
27e05d7b 403Check whether a given rev is valid i.e looks like a sha1.
fbf3eb7e 404
27e05d7b 405=cut
fbf3eb7e 406
407sub valid_rev {
1feb3d6b 408 my ($self, $rev) = @_;
fbf3eb7e 409
1feb3d6b 410 return unless $rev;
b3ad9e63 411 return ($rev =~ /^($SHA1RE)$/);
fbf3eb7e 412}
413
9c0984d1 414=head2 raw_diff
27e05d7b 415
9c0984d1 416Provides the raw output of a diff.
27e05d7b 417
418=cut
419
9c0984d1 420sub raw_diff {
6cf4366a 421 my ($self, @args) = @_;
fbf3eb7e 422
6cf4366a 423 return $self->command(diff => '--full-index', @args);
9c0984d1 424}
fbf3eb7e 425
9c0984d1 426=begin
427diff --git a/TODO b/TODO
428index 6a05e77..2071fd0 100644
429--- a/TODO
430+++ b/TODO
431@@ -2,4 +2,3 @@
432 * An action to find what branches have been merged, either as a list or through a search mechanism.
433 * An action to find which branches a given commit is on.
434 * Fix any not text/html bits e.g the patch action.
435-* Simplify the creation of links.
436diff --git a/lib/Gitalist/Controller/Root.pm b/lib/Gitalist/Controller/Root.pm
437index 706d024..7fac165 100644
438--- a/lib/Gitalist/Controller/Root.pm
439+++ b/lib/Gitalist/Controller/Root.pm
440@@ -157,23 +157,6 @@ sub shortlog : Local {
441 );
442 }
443
444-=head2 tree
445-
446-The tree of a given commit.
447=cut
448
449=head2 diff
450
451Returns a list of diff chunks corresponding to the files contained in the diff
452and some associated metadata.
453
454=cut
455
456sub diff {
457 my($self, @revs) = @_;
458
6cf4366a 459 return $self->parse_diff($self->raw_diff(@revs));
460}
461
462sub parse_diff {
463 my($self, @diff) = @_;
9c0984d1 464
465 my @ret;
9dc3b9a5 466 for (@diff) {
9c0984d1 467 # This regex is a little pathological.
9dc3b9a5 468 if(m{^diff --git (a/(.*?)) (b/\2)}) {
9c0984d1 469 push @ret, {
9dc3b9a5 470 head => $_,
9c0984d1 471 a => $1,
472 b => $3,
473 file => $2,
474 diff => '',
475 };
476 next;
477 }
478
9dc3b9a5 479 if(/^index (\w+)\.\.(\w+) (\d+)$/) {
9c0984d1 480 @{$ret[-1]}{qw(index src dst mode)} = ($_, $1, $2, $3);
481 next
482 }
483
9c0984d1 484 # XXX Somewhat hacky. Ahem.
9dc3b9a5 485 $ret[-1]{diff} .= "$_\n";
9c0984d1 486 }
487
488 return @ret;
fbf3eb7e 489}
490
27e05d7b 491=head2 parse_rev_list
492
493Given the output of the C<rev-list> command return a list of hashes.
494
495=cut
496
47495599 497sub parse_rev_list {
498 my ($self, $output) = @_;
499 my @ret;
500
501 my @revs = split /\0/, $output;
1feb3d6b 502
47495599 503 for my $rev (split /\0/, $output) {
504 for my $line (split /\n/, $rev, 6) {
505 chomp $line;
506 next unless $line;
507
508 if ($self->valid_rev($line)) {
509 push @ret, $self->get_object($line);
510 }
511 }
1feb3d6b 512 }
47495599 513
514 return @ret;
fbf3eb7e 515}
516
27e05d7b 517=head2 list_revs
518
519Calls the C<rev-list> command (a low-level from of C<log>) and returns an
520array of hashes.
521
522=cut
523
fbf3eb7e 524sub list_revs {
27e05d7b 525 my ($self, %args) = @_;
fbf3eb7e 526
0ee97fec 527 $args{sha1} ||= $self->head_hash($args{project});
fbf3eb7e 528
27e05d7b 529 my $output = $self->run_cmd_in($args{project} || $self->project, 'rev-list',
1feb3d6b 530 '--header',
531 (defined $args{ count } ? "--max-count=$args{count}" : ()),
27e05d7b 532 (defined $args{ skip } ? "--skip=$args{skip}" : ()),
0ee97fec 533 $args{sha1},
1feb3d6b 534 '--',
27e05d7b 535 ($args{file} ? $args{file} : ()),
536 );
1feb3d6b 537 return unless $output;
fbf3eb7e 538
1feb3d6b 539 my @revs = $self->parse_rev_list($output);
fbf3eb7e 540
790ce598 541 return @revs;
fbf3eb7e 542}
543
27e05d7b 544=head2 rev_info
545
546Get a single piece of revision information for a given sha1.
547
548=cut
549
fbf3eb7e 550sub rev_info {
27e05d7b 551 my($self, $rev, $project) = @_;
fbf3eb7e 552
1feb3d6b 553 return unless $self->valid_rev($rev);
c5065c66 554
27e05d7b 555 return $self->list_revs(
556 rev => $rev, count => 1,
557 ( $project ? (project => $project) : () )
558 );
1feb3d6b 559}
560
27e05d7b 561=head2 reflog
562
563Calls the C<reflog> command and returns a list of hashes.
564
565=cut
566
1feb3d6b 567sub reflog {
568 my ($self, @logargs) = @_;
569
570 my @entries
571 = $self->run_cmd_in($self->project, qw(log -g), @logargs)
572 =~ /(^commit.+?(?:(?=^commit)|(?=\z)))/msg;
573
574=begin
575
576 commit 02526fc15beddf2c64798a947fecdd8d11bf993d
577 Reflog: HEAD@{14} (The Git Server <git@git.dev.venda.com>)
578 Reflog message: push
1ef8dc7d 579 Author: Foo Barsby <fbarsby@example.com>
1feb3d6b 580 Date: Thu Sep 17 12:26:05 2009 +0100
581
1ef8dc7d 582 Merge branch 'abc123'
1feb3d6b 583=cut
584
585 return map {
586
587 # XXX Stuff like this makes me want to switch to Git::PurePerl
588 my($sha1, $type, $author, $date)
589 = m{
b3ad9e63 590 ^ commit \s+ ($SHA1RE)$
1feb3d6b 591 .*?
592 Reflog[ ]message: \s+ (.+?)$ \s+
593 Author: \s+ ([^<]+) <.*?$ \s+
594 Date: \s+ (.+?)$
27e05d7b 595 }xms;
1feb3d6b 596
597 pos($_) = index($_, $date) + length $date;
598
599 # Yeah, I just did that.
600
601 my($msg) = /\G\s+(\S.*)/sg;
602
603 {
604 hash => $sha1,
605 type => $type,
606 author => $author,
607
608 # XXX Add DateTime goodness.
609 date => $date,
610 message => $msg,
611 };
1ef8dc7d 612 } @entries;
c5065c66 613}
614
790ce598 615=head2 heads
27e05d7b 616
617Returns an array of hashes representing the heads (aka branches) for the
618given, or current, project.
619
620=cut
621
790ce598 622sub heads {
1feb3d6b 623 my ($self, $project) = @_;
fbf3eb7e 624
790ce598 625 my @output = $self->command(qw/for-each-ref --sort=-committerdate /, '--format=%(objectname)%00%(refname)%00%(committer)', 'refs/heads');
fbf3eb7e 626
1feb3d6b 627 my @ret;
790ce598 628 for my $line (@output) {
1feb3d6b 629 my ($rev, $head, $commiter) = split /\0/, $line, 3;
630 $head =~ s!^refs/heads/!!;
fbf3eb7e 631
790ce598 632 push @ret, { sha1 => $rev, name => $head };
fbf3eb7e 633
1feb3d6b 634 #FIXME: That isn't the time I'm looking for..
2247133f 635 if (my ($epoch, $tz) = $line =~ /\s(\d+)\s+([+-]\d+)$/) {
1feb3d6b 636 my $dt = DateTime->from_epoch(epoch => $epoch);
637 $dt->set_time_zone($tz);
638 $ret[-1]->{last_change} = $dt;
fbf3eb7e 639 }
1feb3d6b 640 }
fbf3eb7e 641
790ce598 642 return @ret;
fbf3eb7e 643}
644
1ef8dc7d 645=head2 refs_for
646
27e05d7b 647For a given sha1 check which branches currently point at it.
1ef8dc7d 648
649=cut
650
651sub refs_for {
652 my($self, $sha1) = @_;
653
654 my $refs = $self->references->{$sha1};
655
656 return $refs ? @$refs : ();
657}
658
27e05d7b 659=head2 references
1ef8dc7d 660
661A wrapper for C<git show-ref --dereference>. Based on gitweb's
662C<git_get_references>.
663
664=cut
665
666sub references {
667 my($self) = @_;
668
669 return $self->{references}
670 if $self->{references};
671
672 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
673 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
b3ad9e63 674 my @reflist = $self->command(qw(show-ref --dereference))
1ef8dc7d 675 or return;
676
677 my %refs;
b3ad9e63 678 for(@reflist) {
1ef8dc7d 679 push @{$refs{$1}}, $2
b3ad9e63 680 if m!^($SHA1RE)\srefs/(.*)$!;
1ef8dc7d 681 }
682
683 return $self->{references} = \%refs;
684}
685
b3ad9e63 686=begin
687
688$ git diff-tree -r --no-commit-id -M b222ff0a7260cc1777c7e455dfcaf22551a512fc 7e54e579e196c6c545fee1030175f65a111039d4
689:100644 100644 8976ebc7df65475b3def53a1653533c3f61070d0 852b6e170f1bad1fbd9930d3178dda8fdf1feae7 M TODO
690:100644 100644 75f5e5f9ed10ae82a960fde77ecf138159c37610 7f54f8c3a4ad426f6889b13cfba5f5ad9969e3c6 M lib/Gitalist/Controller/Root.pm
691:100644 100644 2c65caa46b56302502b9e6eef952b6f379c71fee e418acf5f7b5f771b0b2ef8be784e8dcd60a4271 M lib/Gitalist/View/Default.pm
692:000000 100644 0000000000000000000000000000000000000000 642599f9ccfc4dbc7034987ad3233655010ff348 A lib/Gitalist/View/SyntaxHighlight.pm
693:000000 100644 0000000000000000000000000000000000000000 3d2e533c41f01276b6f844bae98297273b38dffc A root/static/css/syntax-dark.css
694:100644 100644 6a85d6c6315b55a99071974eb6ce643aeb2799d6 44c03ed6c328fa6de4b1d9b3f19a3de96b250370 M templates/blob.tt2
695
696=cut
697
698use List::MoreUtils qw(zip);
699# XXX Hrm, getting called twice, not sure why.
27e05d7b 700=head2 diff_tree
701
702Given a L<Git::PurePerl> commit object return a list of hashes corresponding
703to the C<diff-tree> output.
704
705=cut
706
b3ad9e63 707sub diff_tree {
708 my($self, $commit) = @_;
709
710 my @dtout = $self->command(
711 # XXX should really deal with multple parents ...
712 qw(diff-tree -r --no-commit-id -M), $commit->parent_sha1, $commit->sha1
713 );
714
715 my @keys = qw(modesrc modedst sha1src sha1dst status src dst);
716 my @difftree = map {
717 # see. man git-diff-tree for more info
718 # mode src, mode dst, sha1 src, sha1 dst, status, src[, dst]
719 my @vals = /^:(\d+) (\d+) ($SHA1RE) ($SHA1RE) ([ACDMRTUX])\t([^\t]+)(?:\t([^\n]+))?$/;
720 my %line = zip @keys, @vals;
721 # Some convenience keys
722 $line{file} = $line{src};
c8870bd3 723 $line{sha1} = $line{sha1dst};
b3ad9e63 724 $line{is_new} = $line{sha1src} =~ /^0+$/;
725 \%line;
726 } @dtout;
727
728 return @difftree;
729}
730
fbf3eb7e 7311;
732
733__PACKAGE__->meta->make_immutable;