2330
my $alternate = 1;
2331
my $patchno = 0;
2332
foreach my $line (@{$difftree}) {
2333
- my %diff = parse_difftree_raw_line($line);
2333
+ my $diff;
2334
+ if (ref($line) eq "HASH") {
2335
+ # pre-parsed (or generated by hand)
2336
+ $diff = $line;
2337
+ } else {
2338
+ $diff = parse_difftree_raw_line($line);
2339
+ }
2340
2341
if ($alternate) {
2342
print "<tr class=\"dark\">\n";
2345
}
2346
$alternate ^= 1;
2347
2342
- if (exists $diff{'nparents'}) { # combined diff
2348
+ if (exists $diff->{'nparents'}) { # combined diff
2349
2344
- fill_from_file_info(\%diff, @parents);
2350
+ fill_from_file_info($diff, @parents)
2351
+ unless exists $diff->{'from_file'};
2352
2346
- if ($diff{'to_id'} ne ('0' x 40)) {
2353
+ if ($diff->{'to_id'} ne ('0' x 40)) {
2354
# file exists in the result (child) commit
2355
print "<td>" .
2349
- $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
2350
- file_name=>$diff{'to_file'},
2356
+ $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2357
+ file_name=>$diff->{'to_file'},
2358
hash_base=>$hash),
2352
- -class => "list"}, esc_path($diff{'to_file'})) .
2359
+ -class => "list"}, esc_path($diff->{'to_file'})) .
2360
"</td>\n";
2361
} else {
2362
print "<td>" .
2356
- esc_path($diff{'to_file'}) .
2363
+ esc_path($diff->{'to_file'}) .
2364
"</td>\n";
2365
}
2366
2375
2376
my $has_history = 0;
2377
my $not_deleted = 0;
2371
- for (my $i = 0; $i < $diff{'nparents'}; $i++) {
2378
+ for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2379
my $hash_parent = $parents[$i];
2373
- my $from_hash = $diff{'from_id'}[$i];
2374
- my $from_path = $diff{'from_file'}[$i];
2375
- my $status = $diff{'status'}[$i];
2380
+ my $from_hash = $diff->{'from_id'}[$i];
2381
+ my $from_path = $diff->{'from_file'}[$i];
2382
+ my $status = $diff->{'status'}[$i];
2383
2384
$has_history ||= ($status ne 'A');
2385
$not_deleted ||= ($status ne 'D');
2395
"blob" . ($i+1)) .
2396
" | </td>\n";
2397
} else {
2391
- if ($diff{'to_id'} eq $from_hash) {
2398
+ if ($diff->{'to_id'} eq $from_hash) {
2399
print "<td class=\"link nochange\">";
2400
} else {
2401
print "<td class=\"link\">";
2402
}
2403
print $cgi->a({-href => href(action=>"blobdiff",
2397
- hash=>$diff{'to_id'},
2404
+ hash=>$diff->{'to_id'},
2405
hash_parent=>$from_hash,
2406
hash_base=>$hash,
2407
hash_parent_base=>$hash_parent,
2401
- file_name=>$diff{'to_file'},
2408
+ file_name=>$diff->{'to_file'},
2409
file_parent=>$from_path)},
2410
"diff" . ($i+1)) .
2411
" | </td>\n";
2415
print "<td class=\"link\">";
2416
if ($not_deleted) {
2417
print $cgi->a({-href => href(action=>"blob",
2411
- hash=>$diff{'to_id'},
2412
- file_name=>$diff{'to_file'},
2418
+ hash=>$diff->{'to_id'},
2419
+ file_name=>$diff->{'to_file'},
2420
hash_base=>$hash)},
2421
"blob");
2422
print " | " if ($has_history);
2423
}
2424
if ($has_history) {
2425
print $cgi->a({-href => href(action=>"history",
2419
- file_name=>$diff{'to_file'},
2426
+ file_name=>$diff->{'to_file'},
2427
hash_base=>$hash)},
2428
"history");
2429
}
2436
2437
my ($to_mode_oct, $to_mode_str, $to_file_type);
2438
my ($from_mode_oct, $from_mode_str, $from_file_type);
2432
- if ($diff{'to_mode'} ne ('0' x 6)) {
2433
- $to_mode_oct = oct $diff{'to_mode'};
2439
+ if ($diff->{'to_mode'} ne ('0' x 6)) {
2440
+ $to_mode_oct = oct $diff->{'to_mode'};
2441
if (S_ISREG($to_mode_oct)) { # only for regular file
2442
$to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2443
}
2437
- $to_file_type = file_type($diff{'to_mode'});
2444
+ $to_file_type = file_type($diff->{'to_mode'});
2445
}
2439
- if ($diff{'from_mode'} ne ('0' x 6)) {
2440
- $from_mode_oct = oct $diff{'from_mode'};
2446
+ if ($diff->{'from_mode'} ne ('0' x 6)) {
2447
+ $from_mode_oct = oct $diff->{'from_mode'};
2448
if (S_ISREG($to_mode_oct)) { # only for regular file
2449
$from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2450
}
2444
- $from_file_type = file_type($diff{'from_mode'});
2451
+ $from_file_type = file_type($diff->{'from_mode'});
2452
}
2453
2447
- if ($diff{'status'} eq "A") { # created
2454
+ if ($diff->{'status'} eq "A") { # created
2455
my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2456
$mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2457
$mode_chng .= "]</span>";
2458
print "<td>";
2452
- print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
2453
- hash_base=>$hash, file_name=>$diff{'file'}),
2454
- -class => "list"}, esc_path($diff{'file'}));
2459
+ print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2460
+ hash_base=>$hash, file_name=>$diff->{'file'}),
2461
+ -class => "list"}, esc_path($diff->{'file'}));
2462
print "</td>\n";
2463
print "<td>$mode_chng</td>\n";
2464
print "<td class=\"link\">";
2468
print $cgi->a({-href => "#patch$patchno"}, "patch");
2469
print " | ";
2470
}
2464
- print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
2465
- hash_base=>$hash, file_name=>$diff{'file'})},
2471
+ print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2472
+ hash_base=>$hash, file_name=>$diff->{'file'})},
2473
"blob");
2474
print "</td>\n";
2475
2469
- } elsif ($diff{'status'} eq "D") { # deleted
2476
+ } elsif ($diff->{'status'} eq "D") { # deleted
2477
my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2478
print "<td>";
2472
- print $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
2473
- hash_base=>$parent, file_name=>$diff{'file'}),
2474
- -class => "list"}, esc_path($diff{'file'}));
2479
+ print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
2480
+ hash_base=>$parent, file_name=>$diff->{'file'}),
2481
+ -class => "list"}, esc_path($diff->{'file'}));
2482
print "</td>\n";
2483
print "<td>$mode_chng</td>\n";
2484
print "<td class=\"link\">";
2488
print $cgi->a({-href => "#patch$patchno"}, "patch");
2489
print " | ";
2490
}
2484
- print $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
2485
- hash_base=>$parent, file_name=>$diff{'file'})},
2491
+ print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
2492
+ hash_base=>$parent, file_name=>$diff->{'file'})},
2493
"blob") . " | ";
2494
if ($have_blame) {
2495
print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
2489
- file_name=>$diff{'file'})},
2496
+ file_name=>$diff->{'file'})},
2497
"blame") . " | ";
2498
}
2499
print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
2493
- file_name=>$diff{'file'})},
2500
+ file_name=>$diff->{'file'})},
2501
"history");
2502
print "</td>\n";
2503
2497
- } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2504
+ } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2505
my $mode_chnge = "";
2499
- if ($diff{'from_mode'} != $diff{'to_mode'}) {
2506
+ if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2507
$mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2508
if ($from_file_type ne $to_file_type) {
2509
$mode_chnge .= " from $from_file_type to $to_file_type";
2518
$mode_chnge .= "]</span>\n";
2519
}
2520
print "<td>";
2514
- print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
2515
- hash_base=>$hash, file_name=>$diff{'file'}),
2516
- -class => "list"}, esc_path($diff{'file'}));
2521
+ print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2522
+ hash_base=>$hash, file_name=>$diff->{'file'}),
2523
+ -class => "list"}, esc_path($diff->{'file'}));
2524
print "</td>\n";
2525
print "<td>$mode_chnge</td>\n";
2526
print "<td class=\"link\">";
2529
$patchno++;
2530
print $cgi->a({-href => "#patch$patchno"}, "patch") .
2531
" | ";
2525
- } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2532
+ } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2533
# "commit" view and modified file (not onlu mode changed)
2534
print $cgi->a({-href => href(action=>"blobdiff",
2528
- hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
2535
+ hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
2536
hash_base=>$hash, hash_parent_base=>$parent,
2530
- file_name=>$diff{'file'})},
2537
+ file_name=>$diff->{'file'})},
2538
"diff") .
2539
" | ";
2540
}
2534
- print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
2535
- hash_base=>$hash, file_name=>$diff{'file'})},
2541
+ print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2542
+ hash_base=>$hash, file_name=>$diff->{'file'})},
2543
"blob") . " | ";
2544
if ($have_blame) {
2545
print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
2539
- file_name=>$diff{'file'})},
2546
+ file_name=>$diff->{'file'})},
2547
"blame") . " | ";
2548
}
2549
print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
2543
- file_name=>$diff{'file'})},
2550
+ file_name=>$diff->{'file'})},
2551
"history");
2552
print "</td>\n";
2553
2547
- } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2554
+ } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2555
my %status_name = ('R' => 'moved', 'C' => 'copied');
2549
- my $nstatus = $status_name{$diff{'status'}};
2556
+ my $nstatus = $status_name{$diff->{'status'}};
2557
my $mode_chng = "";
2551
- if ($diff{'from_mode'} != $diff{'to_mode'}) {
2558
+ if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2559
# mode also for directories, so we cannot use $to_mode_str
2560
$mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2561
}
2562
print "<td>" .
2563
$cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2557
- hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
2558
- -class => "list"}, esc_path($diff{'to_file'})) . "</td>\n" .
2564
+ hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
2565
+ -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
2566
"<td><span class=\"file_status $nstatus\">[$nstatus from " .
2567
$cgi->a({-href => href(action=>"blob", hash_base=>$parent,
2561
- hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
2562
- -class => "list"}, esc_path($diff{'from_file'})) .
2563
- " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2568
+ hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
2569
+ -class => "list"}, esc_path($diff->{'from_file'})) .
2570
+ " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2571
"<td class=\"link\">";
2572
if ($action eq 'commitdiff') {
2573
# link to patch
2574
$patchno++;
2575
print $cgi->a({-href => "#patch$patchno"}, "patch") .
2576
" | ";
2570
- } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2577
+ } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2578
# "commit" view and modified file (not only pure rename or copy)
2579
print $cgi->a({-href => href(action=>"blobdiff",
2573
- hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
2580
+ hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
2581
hash_base=>$hash, hash_parent_base=>$parent,
2575
- file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
2582
+ file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
2583
"diff") .
2584
" | ";
2585
}
2579
- print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
2580
- hash_base=>$parent, file_name=>$diff{'to_file'})},
2586
+ print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
2587
+ hash_base=>$parent, file_name=>$diff->{'to_file'})},
2588
"blob") . " | ";
2589
if ($have_blame) {
2590
print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
2584
- file_name=>$diff{'to_file'})},
2591
+ file_name=>$diff->{'to_file'})},
2592
"blame") . " | ";
2593
}
2594
print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
2588
- file_name=>$diff{'to_file'})},
2595
+ file_name=>$diff->{'to_file'})},
2596
"history");
2597
print "</td>\n";
2598
4408
chomp $line;
4409
# empty line ends raw part of diff-tree output
4410
last unless $line;
4404
- push @difftree, $line;
4411
+ push @difftree, scalar parse_difftree_raw_line($line);
4412
}
4413
4414
} elsif ($format eq 'plain') {