{"thread":{"id":"1967","subject":"[PATCH] fetch-pack should not ask for a ref which is already there","startedAt":"2005-09-28T23:49:47Z","lastAt":"2005-09-30T12:20:51Z","messageCount":10,"participants":["Johannes Schindelin","Junio C Hamano","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"9443","messageId":"Pine.LNX.4.63.0509290149230.19126@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1967","inReplyTo":null,"subject":"[PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-09-28T23:49:47Z","receivedAt":"2005-09-28T23:49:47Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"With this patch, instead of blindly asking for every remote ref, fetch-pack\nfirst looks in the local repository if that ref is already there.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n fetch-pack.c |   30 ++++++++++++++++++++----------\n 1 files changed, 20 insertions(+), 10 deletions(-)\n\n6bf41421bed0d640677c5233d2be6813b2211979\ndiff --git a/fetch-pack.c b/fetch-pack.c\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -16,20 +16,27 @@ static int find_common(int fd[2], unsign\n \tint count = 0, flushes = 0, retval;\n \tFILE *revs;\n \n-\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n-\tif (!revs)\n-\t\tdie(\"unable to run 'git-rev-list'\");\n-\n \twhile (refs) {\n \t\tunsigned char *remote = refs->old_sha1;\n-\t\tif (verbose)\n-\t\t\tfprintf(stderr,\n-\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n-\t\t\t\trefs->name);\n-\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\tif(!has_sha1_file(remote)) {\n+\t\t\tif (verbose)\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n+\t\t\t\t\trefs->name);\n+\t\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\t\tcount++;\n+\t\t}\n \t\trefs = refs->next;\n \t}\n \tpacket_flush(fd[1]);\n+\n+\tif(count==0)\n+\t\treturn 1;\n+\n+\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n+\tif (!revs)\n+\t\tdie(\"unable to run 'git-rev-list'\");\n+\n \tflushes = 1;\n \tretval = -1;\n \twhile (fgets(line, sizeof(line), revs) != NULL) {\n@@ -86,7 +93,10 @@ static int fetch_pack(int fd[2], int nr_\n \t\tpacket_flush(fd[1]);\n \t\tdie(\"no matching remote head\");\n \t}\n-\tif (find_common(fd, sha1, ref) < 0)\n+\tstatus = find_common(fd, sha1, ref);\n+\tif(status > 0)\n+\t\treturn 0;\n+\tif(status < 0)\n \t\tfprintf(stderr, \"warning: no common commits\\n\");\n \tpid = fork();\n \tif (pid < 0)\n"},{"id":"9466","messageId":"7vll1gl4ms.fsf@assigned-by-dhcp.cox.net","threadId":"1967","inReplyTo":"Pine.LNX.4.63.0509290149230.19126@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-29T07:22:51Z","receivedAt":"2005-09-29T07:22:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> With this patch, instead of blindly asking for every remote ref, fetch-pack\n> first looks in the local repository if that ref is already there.\n\nThis patch breaks things.  git-fetch-pack is supposed to report\nthe resulting SHA1 and refs on its standard output.  If you are\nup to date with this patch you would lose that.\n"},{"id":"9469","messageId":"Pine.LNX.4.63.0509291034450.20717@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1967","inReplyTo":"7vll1gl4ms.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-09-29T08:42:32Z","receivedAt":"2005-09-29T08:42:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 29 Sep 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > With this patch, instead of blindly asking for every remote ref, fetch-pack\n> > first looks in the local repository if that ref is already there.\n> \n> This patch breaks things.  git-fetch-pack is supposed to report\n> the resulting SHA1 and refs on its standard output.  If you are\n> up to date with this patch you would lose that.\n\nYeah, sorry. I did not test that one. Maybe an automated test for \ngit-fetch-pack would be useful after all...\n\nHow about the following? (I avoided an ugly goto, but had to duplicate \ncode :-( )\n\n---\n\n[PATCH] fetch-pack should not ask for a ref which is already there\n\nWith this patch, instead of blindly asking for every remote ref, fetch-pack\nfirst looks in the local repository if that ref is already there.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n fetch-pack.c |   36 ++++++++++++++++++++++++++----------\n 1 files changed, 26 insertions(+), 10 deletions(-)\n\nfbef982e4c5c4591b8d5517ef1694ab71e29c9e5\ndiff --git a/fetch-pack.c b/fetch-pack.c\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -16,20 +16,27 @@ static int find_common(int fd[2], unsign\n \tint count = 0, flushes = 0, retval;\n \tFILE *revs;\n \n-\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n-\tif (!revs)\n-\t\tdie(\"unable to run 'git-rev-list'\");\n-\n \twhile (refs) {\n \t\tunsigned char *remote = refs->old_sha1;\n-\t\tif (verbose)\n-\t\t\tfprintf(stderr,\n-\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n-\t\t\t\trefs->name);\n-\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\tif(!has_sha1_file(remote)) {\n+\t\t\tif (verbose)\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n+\t\t\t\t\trefs->name);\n+\t\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\t\tcount++;\n+\t\t}\n \t\trefs = refs->next;\n \t}\n \tpacket_flush(fd[1]);\n+\n+\tif(count==0)\n+\t\treturn 1;\n+\n+\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n+\tif (!revs)\n+\t\tdie(\"unable to run 'git-rev-list'\");\n+\n \tflushes = 1;\n \tretval = -1;\n \twhile (fgets(line, sizeof(line), revs) != NULL) {\n@@ -86,7 +93,16 @@ static int fetch_pack(int fd[2], int nr_\n \t\tpacket_flush(fd[1]);\n \t\tdie(\"no matching remote head\");\n \t}\n-\tif (find_common(fd, sha1, ref) < 0)\n+\tstatus = find_common(fd, sha1, ref);\n+\tif(status > 0) {\n+\t\twhile (ref) {\n+\t\t\tprintf(\"%s %s\\n\",\n+\t\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n+\t\t\tref = ref->next;\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\tif(status < 0)\n \t\tfprintf(stderr, \"warning: no common commits\\n\");\n \tpid = fork();\n \tif (pid < 0)\n"},{"id":"9473","messageId":"7vhdc4grrf.fsf@assigned-by-dhcp.cox.net","threadId":"1967","inReplyTo":"Pine.LNX.4.63.0509291034450.20717@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-29T09:14:28Z","receivedAt":"2005-09-29T09:14:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Yeah, sorry. I did not test that one. Maybe an automated test for \n> git-fetch-pack would be useful after all...\n\nSounds sensible.  I think git-send-pack has one.\n\n> How about the following? (I avoided an ugly goto, but had to duplicate \n> code :-( )\n\nI suspect it would be cleaner to return (struct ref *) from\nfetch_pack (ideally use NULL to signal failure but there is no\nneed -- it just dies) and print the refs from main() only after\nseeing the last close and finish_connect succeed.\n"},{"id":"9474","messageId":"Pine.LNX.4.63.0509291129220.29969@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1967","inReplyTo":"7vhdc4grrf.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-09-29T09:30:18Z","receivedAt":"2005-09-29T09:30:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 29 Sep 2005, Junio C Hamano wrote:\n\n> I suspect it would be cleaner to return (struct ref *) from\n> fetch_pack (ideally use NULL to signal failure but there is no\n> need -- it just dies) and print the refs from main() only after\n> seeing the last close and finish_connect succeed.\n\nHere's my next try:\n\n[PATCH] fetch-pack should not ask for a ref which is already there\nFrom: Johannes Schindelin <gene099@localhost>\nDate: 1127950437 +0200\n\nWith this patch, instead of blindly asking for every remote ref, fetch-pack\nfirst looks in the local repository if that ref is already there.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n fetch-pack.c |   56 ++++++++++++++++++++++++++++++++++++--------------------\n 1 files changed, 36 insertions(+), 20 deletions(-)\n\n210c4c6fe4a353d59e4ca2871d7f2a3c1b9b1238\ndiff --git a/fetch-pack.c b/fetch-pack.c\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -16,20 +16,27 @@ static int find_common(int fd[2], unsign\n \tint count = 0, flushes = 0, retval;\n \tFILE *revs;\n \n-\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n-\tif (!revs)\n-\t\tdie(\"unable to run 'git-rev-list'\");\n-\n \twhile (refs) {\n \t\tunsigned char *remote = refs->old_sha1;\n-\t\tif (verbose)\n-\t\t\tfprintf(stderr,\n-\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n-\t\t\t\trefs->name);\n-\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\tif(!has_sha1_file(remote)) {\n+\t\t\tif (verbose)\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n+\t\t\t\t\trefs->name);\n+\t\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\t\tcount++;\n+\t\t}\n \t\trefs = refs->next;\n \t}\n \tpacket_flush(fd[1]);\n+\n+\tif(count==0)\n+\t\treturn 1;\n+\n+\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n+\tif (!revs)\n+\t\tdie(\"unable to run 'git-rev-list'\");\n+\n \tflushes = 1;\n \tretval = -1;\n \twhile (fgets(line, sizeof(line), revs) != NULL) {\n@@ -74,7 +81,7 @@ static int find_common(int fd[2], unsign\n \treturn retval;\n }\n \n-static int fetch_pack(int fd[2], int nr_match, char **match)\n+static struct ref *fetch_pack(int fd[2], int nr_match, char **match)\n {\n \tstruct ref *ref;\n \tunsigned char sha1[20];\n@@ -86,7 +93,10 @@ static int fetch_pack(int fd[2], int nr_\n \t\tpacket_flush(fd[1]);\n \t\tdie(\"no matching remote head\");\n \t}\n-\tif (find_common(fd, sha1, ref) < 0)\n+\tstatus = find_common(fd, sha1, ref);\n+\tif(status > 0)\n+\t\treturn ref;\n+\tif(status < 0)\n \t\tfprintf(stderr, \"warning: no common commits\\n\");\n \tpid = fork();\n \tif (pid < 0)\n@@ -109,12 +119,7 @@ static int fetch_pack(int fd[2], int nr_\n \t\tint code = WEXITSTATUS(status);\n \t\tif (code)\n \t\t\tdie(\"git-unpack-objects died with error code %d\", code);\n-\t\twhile (ref) {\n-\t\t\tprintf(\"%s %s\\n\",\n-\t\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n-\t\t\tref = ref->next;\n-\t\t}\n-\t\treturn 0;\n+\t\treturn ref;\n \t}\n \tif (WIFSIGNALED(status)) {\n \t\tint sig = WTERMSIG(status);\n@@ -125,10 +130,11 @@ static int fetch_pack(int fd[2], int nr_\n \n int main(int argc, char **argv)\n {\n-\tint i, ret, nr_heads;\n+\tint i, nr_heads;\n \tchar *dest = NULL, **heads;\n \tint fd[2];\n \tpid_t pid;\n+\tstruct ref *ref;\n \n \tnr_heads = 0;\n \theads = NULL;\n@@ -160,9 +166,19 @@ int main(int argc, char **argv)\n \tpid = git_connect(fd, dest, exec);\n \tif (pid < 0)\n \t\treturn 1;\n-\tret = fetch_pack(fd, nr_heads, heads);\n+\tref = fetch_pack(fd, nr_heads, heads);\n+\tif(!ref)\n+\t\treturn 1;\n+\n+\twhile (ref) {\n+\t\tprintf(\"%s %s\\n\",\n+\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n+\t\tref = ref->next;\n+\t}\n+\n \tclose(fd[0]);\n \tclose(fd[1]);\n \tfinish_connect(pid);\n-\treturn ret;\n+\n+\treturn 0;\n }\n"},{"id":"9488","messageId":"Pine.LNX.4.58.0509291120170.3308@g5.osdl.org","threadId":"1967","inReplyTo":"Pine.LNX.4.63.0509290149230.19126@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-29T18:26:25Z","receivedAt":"2005-09-29T18:26:25Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 29 Sep 2005, Johannes Schindelin wrote:\n>\n> With this patch, instead of blindly asking for every remote ref, fetch-pack\n> first looks in the local repository if that ref is already there.\n\nNo. This is WRONG.\n\nIt may seem like a sane thing to do, but it is very very horribly broken.\n\nThe fact is, if an earlier fetch was interrupted, or if you've used things\nlike rsync, you may have disconnected objects in your object store. The \nfact that you have a particular commit object is _not_ a guarantee that \nyou have everything that leads up to it.\n\nThe \"fetch\" semantics are simple: we only write out new refs _after_ we've \nfetched all the objects that point to them. That means that while we \ncannot trust a \"oh, I already have this commit, let's skip it\", we _can_ \ntrust \"oh, I already have these refs, let's skip them\".\n\nSo please do _not_ add logic like this to git-fetch. I'd _much_ rather\nfetch some objects twice than end up with a corrupt repository.\n\n\t\tLinus\n"},{"id":"9490","messageId":"Pine.LNX.4.63.0509292058020.8413@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1967","inReplyTo":"Pine.LNX.4.58.0509291120170.3308@g5.osdl.org","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-09-29T19:08:23Z","receivedAt":"2005-09-29T19:08:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 29 Sep 2005, Linus Torvalds wrote:\n\n> On Thu, 29 Sep 2005, Johannes Schindelin wrote:\n> >\n> > With this patch, instead of blindly asking for every remote ref, fetch-pack\n> > first looks in the local repository if that ref is already there.\n> \n> No. This is WRONG.\n\nActually, this is not wrong. The patch is wrong. Here's why:\n\n> The \"fetch\" semantics are simple: we only write out new refs _after_ we've \n> fetched all the objects that point to them. That means that while we \n> cannot trust a \"oh, I already have this commit, let's skip it\", we _can_ \n> trust \"oh, I already have these refs, let's skip them\".\n\nWhat the commit message should suggest was: if a local ref is identical to \nthe remote ref, do not \"want\" it. But of course, I got it all wrong. BTW \nthis patch is not to annoy you, but to ease the burden on the server for \ngit-daemon. (Many a developer begins the day by fetching the latest and \ngreatest).\n\nThe correct way to go about it would be to check that\n\n$(git-rev-list <remote_ref> $(git-rev-parse --all | sed \"s/^/^/\"))\n\nis empty. However, I am lazy, and in most cases, it is sufficient to check \nif the remote ref is identical to a local ref. So here goes another try:\n\n[PATCH] fetch-pack should not ask for a ref which is already there\n\nWith this patch, instead of blindly asking for every remote ref, fetch-pack\nfirst looks in the local repository if that ref is already a local ref.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n fetch-pack.c |   72 ++++++++++++++++++++++++++++++++++++++++++----------------\n 1 files changed, 52 insertions(+), 20 deletions(-)\n\nedfbae3927434270c35dfcad417e7d202e509e90\ndiff --git a/fetch-pack.c b/fetch-pack.c\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -9,6 +9,22 @@ static const char fetch_pack_usage[] =\n \"git-fetch-pack [-q] [-v] [--exec=upload-pack] [host:]directory <refs>...\";\n static const char *exec = \"git-upload-pack\";\n \n+static int has_ref_flag;\n+static const unsigned char *has_ref_sha1;\n+\n+static int has_ref_helper(const char *path, const unsigned char *sha1) {\n+\tif(!memcmp(sha1, has_ref_sha1, 20))\n+\t\thas_ref_flag = 1;\n+\treturn has_ref_flag;\n+}\n+\n+static int has_ref(const unsigned char *sha1) {\n+\thas_ref_sha1 = sha1;\n+\thas_ref_flag = 0;\n+\tfor_each_ref(has_ref_helper);\n+\treturn has_ref_flag;\n+}\n+\n static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t       struct ref *refs)\n {\n@@ -16,20 +32,27 @@ static int find_common(int fd[2], unsign\n \tint count = 0, flushes = 0, retval;\n \tFILE *revs;\n \n-\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n-\tif (!revs)\n-\t\tdie(\"unable to run 'git-rev-list'\");\n-\n \twhile (refs) {\n \t\tunsigned char *remote = refs->old_sha1;\n-\t\tif (verbose)\n-\t\t\tfprintf(stderr,\n-\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n-\t\t\t\trefs->name);\n-\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\tif(!has_ref(remote)) {\n+\t\t\tif (verbose)\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"want %s (%s)\\n\", sha1_to_hex(remote),\n+\t\t\t\t\trefs->name);\n+\t\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\t\tcount++;\n+\t\t}\n \t\trefs = refs->next;\n \t}\n \tpacket_flush(fd[1]);\n+\n+\tif(count==0)\n+\t\treturn 1;\n+\n+\trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n+\tif (!revs)\n+\t\tdie(\"unable to run 'git-rev-list'\");\n+\n \tflushes = 1;\n \tretval = -1;\n \twhile (fgets(line, sizeof(line), revs) != NULL) {\n@@ -74,7 +97,7 @@ static int find_common(int fd[2], unsign\n \treturn retval;\n }\n \n-static int fetch_pack(int fd[2], int nr_match, char **match)\n+static struct ref *fetch_pack(int fd[2], int nr_match, char **match)\n {\n \tstruct ref *ref;\n \tunsigned char sha1[20];\n@@ -86,7 +109,10 @@ static int fetch_pack(int fd[2], int nr_\n \t\tpacket_flush(fd[1]);\n \t\tdie(\"no matching remote head\");\n \t}\n-\tif (find_common(fd, sha1, ref) < 0)\n+\tstatus = find_common(fd, sha1, ref);\n+\tif(status > 0)\n+\t\treturn ref;\n+\tif(status < 0)\n \t\tfprintf(stderr, \"warning: no common commits\\n\");\n \tpid = fork();\n \tif (pid < 0)\n@@ -109,12 +135,7 @@ static int fetch_pack(int fd[2], int nr_\n \t\tint code = WEXITSTATUS(status);\n \t\tif (code)\n \t\t\tdie(\"git-unpack-objects died with error code %d\", code);\n-\t\twhile (ref) {\n-\t\t\tprintf(\"%s %s\\n\",\n-\t\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n-\t\t\tref = ref->next;\n-\t\t}\n-\t\treturn 0;\n+\t\treturn ref;\n \t}\n \tif (WIFSIGNALED(status)) {\n \t\tint sig = WTERMSIG(status);\n@@ -125,10 +146,11 @@ static int fetch_pack(int fd[2], int nr_\n \n int main(int argc, char **argv)\n {\n-\tint i, ret, nr_heads;\n+\tint i, nr_heads;\n \tchar *dest = NULL, **heads;\n \tint fd[2];\n \tpid_t pid;\n+\tstruct ref *ref;\n \n \tnr_heads = 0;\n \theads = NULL;\n@@ -160,9 +182,19 @@ int main(int argc, char **argv)\n \tpid = git_connect(fd, dest, exec);\n \tif (pid < 0)\n \t\treturn 1;\n-\tret = fetch_pack(fd, nr_heads, heads);\n+\tref = fetch_pack(fd, nr_heads, heads);\n+\tif(!ref)\n+\t\treturn 1;\n+\n+\twhile (ref) {\n+\t\tprintf(\"%s %s\\n\",\n+\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n+\t\tref = ref->next;\n+\t}\n+\n \tclose(fd[0]);\n \tclose(fd[1]);\n \tfinish_connect(pid);\n-\treturn ret;\n+\n+\treturn 0;\n }\n"},{"id":"9491","messageId":"Pine.LNX.4.63.0509292124190.8668@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1967","inReplyTo":"Pine.LNX.4.63.0509292058020.8413@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-09-29T19:28:52Z","receivedAt":"2005-09-29T19:28:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 29 Sep 2005, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Thu, 29 Sep 2005, Linus Torvalds wrote:\n> \n> > On Thu, 29 Sep 2005, Johannes Schindelin wrote:\n> > >\n> > > With this patch, instead of blindly asking for every remote ref, \n> > > fetch-pack first looks in the local repository if that ref is \n> > > already there.\n> > \n> > No. This is WRONG.\n\nFollowing up on the \"I'd rather download twice than have a corrupt \nrepository\":\n\nWouldn't it make much more sense to add a flag which repairs an incomplete \nfetch? After all, not every day you fsck up a fetch, right? So, be nice to \nthe server, the network and all the rest, in most cases, and be not so \nnice if you know something went wrong and you want to fix it.\n\nCiao,\nDscho\n"},{"id":"9502","messageId":"Pine.LNX.4.64.0509291403050.5362@g5.osdl.org","threadId":"1967","inReplyTo":"Pine.LNX.4.63.0509292124190.8668@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-29T21:07:27Z","receivedAt":"2005-09-29T21:07:27Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 29 Sep 2005, Johannes Schindelin wrote:\n>\n> Wouldn't it make much more sense to add a flag which repairs an incomplete\n> fetch?\n\nNo.\n\nWe've seen crap. We've _seen_ people use the old git-ssh-pull etc that \nwould result in incomplete repositories, and having people use the \n\"--recover\" flag.\n\nTHAT KIND OF CRAP IS UNACCEPTABLE! I had to walk Andrew through a broken \nrepository because he had used those unreliable fetch methods. I was \nashamed of git at that point.\n\nIf a ^C results in a repository that needs to be fixed up, the \"source \ncontrol management\" is BROKEN. It's not source control, it's a buggy mess.\n\nI refuse to use such tools. End of story. We do this right, or we don't do \nit at all. And doing it right means that you only write refs after you've \ndownloaded everything, and you only _ever_ depend on refs. You don't \n_ever_ say \"if I have this object, I think I have everything\".\n\nThe thing is, _reliability_ is #1. It's not performance. Performance is \nimportant, but performance doesn't matter AT ALL if it comes at the \nexpense of reliability.\n\n \t\tLinus\n"},{"id":"9551","messageId":"Pine.LNX.4.63.0509301418380.15604@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1967","inReplyTo":"Pine.LNX.4.64.0509291403050.5362@g5.osdl.org","subject":"Re: [PATCH] fetch-pack should not ask for a ref which is already there","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-09-30T12:20:51Z","receivedAt":"2005-09-30T12:20:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 29 Sep 2005, Linus Torvalds wrote:\n\n> On Thu, 29 Sep 2005, Johannes Schindelin wrote:\n> > \n> > Wouldn't it make much more sense to add a flag which repairs an \n> > incomplete fetch?\n> \n> No.\n> \n> We've seen crap. We've _seen_ people use the old git-ssh-pull etc that \n> would result in incomplete repositories, and having people use the \n> \"--recover\" flag.\n> \n> THAT KIND OF CRAP IS UNACCEPTABLE! I had to walk Andrew through a broken \n> repository because he had used those unreliable fetch methods. I was \n> ashamed of git at that point.\n> \n> If a ^C results in a repository that needs to be fixed up, the \"source \n> control management\" is BROKEN. It's not source control, it's a buggy \n> mess.\n\nOkay, fair enough, I had that coming. But how about the opposite? A flag, \nthat says \"I want to take the fast path, and if I fsck up, it is my fault \nalone\", just like \"-f\" to git-checkout?\n\nCiao,\nDscho\n"}]}