git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Marc Zonzon <marc.zonzon+git@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git-relink status (or bug?)
Date: Sat, 21 Jun 2008 12:22:09 -0700	[thread overview]
Message-ID: <7v4p7ma90e.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20080621103636.GA696@kernoel.dyndns.org> (Marc Zonzon's message of "Sat, 21 Jun 2008 12:36:36 +0200")

Marc Zonzon <marc.zonzon+git@gmail.com> 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 {

  reply	other threads:[~2008-06-21 19:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-21 10:36 git-relink status (or bug?) Marc Zonzon
2008-06-21 19:22 ` Junio C Hamano [this message]
2008-06-21 20:23   ` marc zonzon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v4p7ma90e.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=marc.zonzon+git@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).