{"thread":{"id":"14070","subject":"git-relink status (or bug?)","startedAt":"2008-06-21T10:36:36Z","lastAt":"2008-06-21T20:23:12Z","messageCount":3,"participants":["Marc Zonzon","Junio C Hamano","marc zonzon"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"80544","messageId":"20080621103636.GA696@kernoel.dyndns.org","threadId":"14070","inReplyTo":null,"subject":"git-relink status (or bug?)","fromName":"Marc Zonzon","fromEmail":"marc.zonzon+git@gmail.com","sentAt":"2008-06-21T10:36:36Z","receivedAt":"2008-06-21T10:36:36Z","isPatch":false,"sender":{"key":"marc.zonzon+git@gmail.com","avatar":null},"body":"When trying to use git-relink, I found it quite disappointing when\ngoing over packs. Git relink seem to make the assumption that there is\na unique mapping from object name to object identity, which is of\ncourse acceptable for loose objects that are named with their sha-1\nbut false for .pack and .idx, to pack objects with the same name have\ncontains the same objects but may be not packed in the same order, or\ncompression.\nMoreover .idx files can not be considered alone, but depends on the\nassociated .pack.\n\nWhen it happen that you have two different packs with the same name\nbut of different sizes, git relink does not hard link the .packs\nbecause the size differ, and hard link the idx. And your repository is\ncorrupted.\n\nIt happen when you clone a repository, repack the clone and relink the\nclone to the original one.\n\nI found very few information about git relink, but as it appears in\nchangelog of v1.5.4 I suppose it is not obsoleted.\n\nWhat about the use of this script?\n\nMarc\n"},{"id":"80562","messageId":"7v4p7ma90e.fsf@gitster.siamese.dyndns.org","threadId":"14070","inReplyTo":"20080621103636.GA696@kernoel.dyndns.org","subject":"Re: git-relink status (or bug?)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-06-21T19:22:09Z","receivedAt":"2008-06-21T19:22:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marc Zonzon <marc.zonzon+git@gmail.com> writes:\n\n> I found very few information about git relink, but as it appears in\n> changelog of v1.5.4 I suppose it is not obsoleted.\n\nI do not think anybody uses it these days.  Instead either they clone with\nreference (or -s), or perhaps use new-workdir.\n\nHere is a totally untested fix.\n\nThe \"careful\" part can be made much more clever and efficient by learning\nimplementation details about the .idx file (it has the checksum for itself\nand the checksum for its .pack file at the end) but I did not bother.\n\nI do not think this in its current shape is committable, without\nimprovements and success reports from the list.  Hint, hint...\n\n\n git-relink.perl |   26 ++++++++++++++++++--------\n 1 files changed, 18 insertions(+), 8 deletions(-)\n\ndiff --git a/git-relink.perl b/git-relink.perl\nindex 15fb932..68e0f0e 100755\n--- a/git-relink.perl\n+++ b/git-relink.perl\n@@ -10,10 +10,11 @@ use 5.006;\n use strict;\n use warnings;\n use Getopt::Long;\n+use File::Compare;\n \n sub get_canonical_form($);\n sub do_scan_directory($$$);\n-sub compare_two_files($$);\n+sub compare_and_link($$$);\n sub usage();\n sub link_two_files($$);\n \n@@ -67,6 +68,7 @@ sub do_scan_directory($$$) {\n \n \tmy $sfulldir = sprintf(\"%sobjects/%s/\",$srcdir,$subdir);\n \tmy $dfulldir = sprintf(\"%sobjects/%s/\",$dstdir,$subdir);\n+\tmy $careful = ($subdir eq 'pack');\n \n \topendir(S,$sfulldir)\n \t\tor die \"Failed to opendir $sfulldir: $!\";\n@@ -75,14 +77,14 @@ sub do_scan_directory($$$) {\n \t\tmy $sfilename = $sfulldir . $file;\n \t\tmy $dfilename = $dfulldir . $file;\n \n-\t\tcompare_two_files($sfilename,$dfilename);\n+\t\tcompare_and_link($sfilename, $dfilename, $careful);\n \n \t}\n \tclosedir(S);\n }\n \n-sub compare_two_files($$) {\n-\tmy ($sfilename, $dfilename) = @_;\n+sub compare_and_link($$$) {\n+\tmy ($sfilename, $dfilename, $careful) = @_;\n \n \t# Perl's stat returns relevant information as follows:\n \t# 0 = dev number\n@@ -100,12 +102,20 @@ sub compare_two_files($$) {\n \n \tif ( ($sstatinfo[0] == $dstatinfo[0]) &&\n \t     ($sstatinfo[1] != $dstatinfo[1])) {\n-\t\tif ($sstatinfo[7] == $dstatinfo[7]) {\n+\t\tmy $differs = undef;\n+\t\tif ($sstatinfo[7] != $dstatinfo[7]) {\n+\t\t\t$differs = \"size\";\n+\t\t}\n+\t\tif (!$differs && $careful) {\n+\t\t\tif (File::Compare::compare($sfilename, $dfilename)) {\n+\t\t\t\t$differs = \"contents\";\n+\t\t\t}\n+\t\t}\n+\t\tif (!$differs) {\n \t\t\tlink_two_files($sfilename, $dfilename);\n-\n \t\t} else {\n-\t\t\tmy $err = sprintf(\"ERROR: File sizes are not the same, cannot relink %s to %s.\\n\",\n-\t\t\t\t$sfilename, $dfilename);\n+\t\t\tmy $err = sprintf(\"ERROR: File differs (%s), cannot relink %s to %s.\\n\",\n+\t\t\t\t\t  $differs, $sfilename, $dfilename);\n \t\t\tif ($fail_on_different_sizes) {\n \t\t\t\tdie $err;\n \t\t\t} else {\n"},{"id":"80563","messageId":"71295b5a0806211323s24d58004m21721a2c878c8737@mail.gmail.com","threadId":"14070","inReplyTo":"7v4p7ma90e.fsf@gitster.siamese.dyndns.org","subject":"Re: git-relink status (or bug?)","fromName":"marc zonzon","fromEmail":"marc.zonzon+git@gmail.com","sentAt":"2008-06-21T20:23:12Z","receivedAt":"2008-06-21T20:23:12Z","isPatch":false,"sender":{"key":"marc.zonzon+git@gmail.com","avatar":null},"body":"Thank you for your answer\n\nOn Sat, Jun 21, 2008 at 9:22 PM, Junio C Hamano <gitster@pobox.com> wrote:\n\n>\n> I do not think anybody uses it these days.  Instead either they clone with\n> reference (or -s), or perhaps use new-workdir.\n\nThe goal of git-relink is analogous to the default local clone,\nhardlinks can be safer than\n sharing because you don't loose anything when the origin directory\nreset a branch.\nI remark that git-clone(1) warn about -s use, but not --reference, but\nthey seems identical on these aspects.\n\nIn numerous cases you cannot suppose your alternate will keep your\nobjects forever.\nI have posted recently such a case study\nhttp://thread.gmane.org/gmane.comp.version-control.git/85407\nand when trying hardlinks, i found this bug. It happens that sharing\nwas a better solution\n(but only with the help of Shawn answer I could set it up!)\n\nThis new-workdir seems also a nice script, that I never looked at\nbefore (But why is there no documentation on these contrib?)\n\n>\n> Here is a totally untested fix.\n>\n> The \"careful\" part can be made much more clever and efficient by learning\n> implementation details about the .idx file (it has the checksum for itself\n> and the checksum for its .pack file at the end) but I did not bother.\n\nThank you\nI see that you only take the safe way, don't hardlink if something is\ndifferent, but there would be a more efficient one, to link when the\npacks have the same name, and link also the idx. If they have the same\nname they have the same content (with a fair probability!)\n\nI cannot provide a patch for that, because I'm not a perl programmer,\nand I'm too lazy to rewrite it in C or python!\n\n> I do not think this in its current shape is committable, without\n> improvements and success reports from the list.  Hint, hint...\n\nBeing \"perl challenged\" I cannot readproof the script, but at least I\ncan test it but only on trivial test cases which make git-relink fail!\n(I have only tried once to use it to solve the previously cited\nproblem)\n\nMarc\n"}]}