From e0c5859f85967520d65a8361a066e1e3f84ace6e Mon Sep 17 00:00:00 2001 From: Steve McIntyre Date: Thu, 31 May 2018 10:10:41 +0100 Subject: Add more useful links for git/salsa diffs Gitlab doesn't give us an interface for direct diffs on a per-file basis. Instead, add a link to the commit diff and a git command line that people can use for the direct per-file diff. --- stattrans.pl | 69 ++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 18 deletions(-) (limited to 'stattrans.pl') diff --git a/stattrans.pl b/stattrans.pl index 2e56506bae3..7e8a7b30ac0 100755 --- a/stattrans.pl +++ b/stattrans.pl @@ -396,7 +396,7 @@ if ($config{'difftype'} eq 'u') { } sub vcs_log_url { - my ($path) = @_; + my ($path, $rev) = @_; if ($VCSHOST =~ m/alioth/) { return "$VCSBASE/$path#rev$rev"; @@ -443,6 +443,16 @@ sub vcs_raw_url { } } +# Return a shortened version string to make things less unwieldy +sub short { + my $in = shift; + if ($VCSHOST =~ m/salsa/) { + return substr $in, 0, 12; # 12 is a common length people use for git + } else { + return $in; + } +} + print "Creating files: " if ($config{'verbose'}); foreach $lang (@search_in) { my @processed_langs = ($langs{$lang}); @@ -489,26 +499,45 @@ foreach $lang (@search_in) { } else { if (defined $status_db{$lang}) { if ($transversion{"$lang/$file"} ne ''){ - $o_body .= sprintf 'Unified diff\' href="%s">%s → %s ', - vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, 'u' ), - $transversion{"$lang/$file"}, $version{"$orig/$file"}; - $o_body .= sprintf 'Colored diff\' href="%s">%s → %s ', - vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, 'h' ), - $transversion{"$lang/$file"}, $version{"$orig/$file"}; - $o_body .= "$statspan"; + if ($VCSHOST =~ m/alioth/) { + $o_body .= sprintf 'Unified diff\' href="%s">%s → %s ', + vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, 'u' ), + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}); + $o_body .= sprintf 'Colored diff\' href="%s">%s → %s ', + vcs_diff_url( "$orig/$file", short($transversion{"$lang/$file"}), short($version{"$orig/$file"}), 'h' ), + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}); + $o_body .= "$statspan"; + } else { + $o_body .= sprintf 'Commit diff\' href="%s">%s → %s ', + vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, 'u' ), + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}); + # FIXME - this is clearly wrong, but no idea what's meant to go here! + $o_body .= sprintf 'Git command line\' href="%s">%s → %s ', + vcs_diff_url( "$orig/$file", short($transversion{"$lang/$file"}), short($version{"$orig/$file"}), 'h' ), + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}); + $o_body .= "$statspan"; + } } else { $o_body .= sprintf "%d (%.2f ‰)", $sizes{$file}, $sizes{$file}/$nsize * 1000; } } else { - $o_body .= sprintf "%s\ ->\ %s", - vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, $firstdifftype ), - $transversion{"$lang/$file"}, $version{"$orig/$file"}; - $o_body .= sprintf "%s\ ->\ %s", - vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, $seconddifftype ), - $transversion{"$lang/$file"}, $version{"$orig/$file"}; + if ($VCSHOST =~ m/alioth/) { + $o_body .= sprintf "%s\ ->\ %s", + vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, $firstdifftype ), + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}); + $o_body .= sprintf "%s\ ->\ %s", + vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, $seconddifftype ), + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}); + } else { + $o_body .= sprintf "%s\ ->\ %s", + vcs_diff_url( "$orig/$file", $transversion{"$lang/$file"}, $version{"$orig/$file"}, $firstdifftype ), + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}); + $o_body .= sprintf "git diff %s..%s -- %s", + short($transversion{"$lang/$file"}), short($version{"$orig/$file"}), "$orig/$file"; + } } } - $o_body .= sprintf "[L]", $msg, vcs_log_url("$orig/$file"), $version{"$orig/$file"}; + $o_body .= sprintf "[L]", $msg, vcs_log_url("$orig/$file", $version{"$orig/$file"}); $o_body .= sprintf "[V]\ ", vcs_view_url("$lang/$file"); $o_body .= sprintf "[F]", vcs_raw_url("$lang/$file"); $o_body .= sprintf "%s", $maintainer{"$lang/$file"} || ""; @@ -633,9 +662,13 @@ foreach $lang (@search_in) { } else { print HTML 'Comment'."\n"; print HTML 'Diffstat'."\n"; - if ($opt_d eq "u") { print HTML 'Unified diffColored diff'; } - elsif ($opt_d eq "h") { print HTML 'Colored diffUnified diff'; } - else { print HTML 'Diff'; } + if ($VCSHOST =~ m/alioth/) { + if ($opt_d eq "u") { print HTML 'Unified diffColored diff'; } + elsif ($opt_d eq "h") { print HTML 'Colored diffUnified diff'; } + else { print HTML 'Diff'; } + } else { + print HTML 'Commit diffGit command line'; + } } print HTML 'Log'; print HTML 'Translation'; -- cgit v1.2.3