Marc Zonzon <marc.zonzon+git@xxxxxxxxx> writes: > I found very few information about git relink, but as it appears in > changelog of v1.5.4 I suppose it is not obsoleted. I do not think anybody uses it these days. Instead either they clone with reference (or -s), or perhaps use new-workdir. Here is a totally untested fix. The "careful" part can be made much more clever and efficient by learning implementation details about the .idx file (it has the checksum for itself and the checksum for its .pack file at the end) but I did not bother. I do not think this in its current shape is committable, without improvements and success reports from the list. Hint, hint... git-relink.perl | 26 ++++++++++++++++++-------- 1 files changed, 18 insertions(+), 8 deletions(-) diff --git a/git-relink.perl b/git-relink.perl index 15fb932..68e0f0e 100755 --- a/git-relink.perl +++ b/git-relink.perl @@ -10,10 +10,11 @@ use 5.006; use strict; use warnings; use Getopt::Long; +use File::Compare; sub get_canonical_form($); sub do_scan_directory($$$); -sub compare_two_files($$); +sub compare_and_link($$$); sub usage(); sub link_two_files($$); @@ -67,6 +68,7 @@ sub do_scan_directory($$$) { my $sfulldir = sprintf("%sobjects/%s/",$srcdir,$subdir); my $dfulldir = sprintf("%sobjects/%s/",$dstdir,$subdir); + my $careful = ($subdir eq 'pack'); opendir(S,$sfulldir) or die "Failed to opendir $sfulldir: $!"; @@ -75,14 +77,14 @@ sub do_scan_directory($$$) { my $sfilename = $sfulldir . $file; my $dfilename = $dfulldir . $file; - compare_two_files($sfilename,$dfilename); + compare_and_link($sfilename, $dfilename, $careful); } closedir(S); } -sub compare_two_files($$) { - my ($sfilename, $dfilename) = @_; +sub compare_and_link($$$) { + my ($sfilename, $dfilename, $careful) = @_; # Perl's stat returns relevant information as follows: # 0 = dev number @@ -100,12 +102,20 @@ sub compare_two_files($$) { if ( ($sstatinfo[0] == $dstatinfo[0]) && ($sstatinfo[1] != $dstatinfo[1])) { - if ($sstatinfo[7] == $dstatinfo[7]) { + my $differs = undef; + if ($sstatinfo[7] != $dstatinfo[7]) { + $differs = "size"; + } + if (!$differs && $careful) { + if (File::Compare::compare($sfilename, $dfilename)) { + $differs = "contents"; + } + } + if (!$differs) { link_two_files($sfilename, $dfilename); - } else { - my $err = sprintf("ERROR: File sizes are not the same, cannot relink %s to %s.\n", - $sfilename, $dfilename); + my $err = sprintf("ERROR: File differs (%s), cannot relink %s to %s.\n", + $differs, $sfilename, $dfilename); if ($fail_on_different_sizes) { die $err; } else { -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html