Skip to content

Commit

Permalink
fix diff path handling for new git
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Nov 1, 2017
1 parent 385e0e6 commit faf5957
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/MetaCPAN/Server/Diff.pm
Expand Up @@ -7,6 +7,7 @@ use Moose;
use Encoding::FixLatin ();
use IPC::Run3;
use MetaCPAN::Types qw( ArrayRef );
use File::Spec;

has git => (
is => 'ro',
Expand Down Expand Up @@ -41,21 +42,13 @@ has relative => (
required => 1,
);

# NOTE: Found this in the git(1) change log (cd676a513672eeb9663c6d4de276a1c860a4b879):
# > [--relative] is inherently incompatible with --no-index, which is a
# > bolted-on hack that does not have much to do with git
# > itself. I didn't bother checking and erroring out on the
# > combined use of the options, but probably I should.
# So if that ever stops working we'll have to strip the prefix from the paths ourselves.

sub _build_raw {
my $self = shift;
my $raw = q[];
run3(
[
$self->git,
qw(diff --no-renames -z --no-index -u --no-color --numstat),
'--relative=' . $self->relative,
$self->source,
$self->target
],
Expand Down Expand Up @@ -85,6 +78,8 @@ sub _build_structured {
my @lines = split( /\0/, $self->numstat );

while ( my $line = shift @lines ) {
my $source = File::Spec->abs2rel(shift @lines, $self->relative);
my $target = File::Spec->abs2rel(shift @lines, $self->relative);
my ( $insertions, $deletions ) = split( /\t/, $line );
my $segment = q[];
while ( my $diff = shift @raw ) {
Expand All @@ -94,13 +89,13 @@ sub _build_structured {
if $diff =~ /[^\x00-\x7f]/;

$segment .= $diff . "\n";
last if ( $raw[0] && $raw[0] =~ /^diff --git a\//m );
last if ( $raw[0] && $raw[0] =~ /^diff --git .\//m );
}
push(
@structured,
{
source => shift @lines,
target => shift @lines,
source => $source,
target => $target,
insertions => $insertions,
deletions => $deletions,
diff => $segment,
Expand Down

0 comments on commit faf5957

Please sign in to comment.