{"thread":{"id":"1480","subject":"[PATCH] fetch-pack: start multi-head pulling.","startedAt":"2005-08-12T09:41:38Z","lastAt":"2005-08-13T09:09:57Z","messageCount":7,"participants":["Junio C Hamano","Linus Torvalds","Johannes Schindelin","Matthias Urlichs"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7112","messageId":"7vwtmr4hm5.fsf@assigned-by-dhcp.cox.net","threadId":"1480","inReplyTo":null,"subject":"[PATCH] fetch-pack: start multi-head pulling.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-12T09:41:38Z","receivedAt":"2005-08-12T09:41:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This is a beginning of resurrecting the multi-head pulling support\nfor git-fetch-pack command.  The git-fetch-script wrapper still\nonly knows about fetching a single head, without renaming, so it is\nnot very useful unless you directly call git-fetch-pack itself yet.\n\nIt also fixes a longstanding obsolete description of how the command\ndiscovers the list of local commits.\n---\n\nLinus, I need a bit of guidance from you about this one; an\nancient commit 4f7770c87ce3c302e1639a7737a6d2531fe4b160 removed\nthe multi-head support fetch-pack once had, labelling it as \"a\nmisguided attempt\", and I would like to know if I am making the\nsame misguided attempt again.  This update actually makes\nclone-pack almost redundant.\n\n\n Documentation/git-fetch-pack.txt |   18 +++++-------\n fetch-pack.c                     |   56 +++++++++++++++++++++++++++-----------\n git-fetch-script                 |    4 +++\n 3 files changed, 51 insertions(+), 27 deletions(-)\n\n880df673e412bae9603782833d8a80a7c7c59769\ndiff --git a/Documentation/git-fetch-pack.txt b/Documentation/git-fetch-pack.txt\n--- a/Documentation/git-fetch-pack.txt\n+++ b/Documentation/git-fetch-pack.txt\n@@ -9,19 +9,19 @@ git-fetch-pack - Receive missing objects\n \n SYNOPSIS\n --------\n-git-fetch-pack [-q] [--exec=<git-upload-pack>] [<host>:]<directory> [<head>...] < <commit-list>\n+git-fetch-pack [-q] [--exec=<git-upload-pack>] [<host>:]<directory> [<refs>...]\n \n DESCRIPTION\n -----------\n Invokes 'git-upload-pack' on a potentially remote repository,\n and asks it to send objects missing from this repository, to\n update the named heads.  The list of commits available locally\n-is fed from the standard input, to be sent to 'git-upload-pack'\n-running on the other end.\n+is found out by scanning local $GIT_DIR/refs/ and sent to\n+'git-upload-pack' running on the other end.\n \n-This command can be used only when the local side has a common\n-(ancestor) commit with the remote head that is being pulled\n-from.  Use 'git-clone-pack' for that.\n+This command degenerates to download everything to complete the\n+asked refs from the remote side when the local side does not\n+have a common ancestor commit.\n \n \n OPTIONS\n@@ -50,15 +50,11 @@ OPTIONS\n <directory>::\n \tThe repository to sync from.\n \n-<head>...::\n+<refs>...::\n \tThe remote heads to update from. This is relative to\n \t$GIT_DIR (e.g. \"HEAD\", \"refs/heads/master\").  When\n \tunspecified, update from all heads the remote side has.\n \n-\tHowever the program refuses to work if more than one\n-\tremote head matches the specified heads.  I am not sure\n-\twhat this means... Help!!!!!\n-\n \n Author\n ------\ndiff --git a/fetch-pack.c b/fetch-pack.c\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -4,10 +4,13 @@\n #include <sys/wait.h>\n \n static int quiet;\n-static const char fetch_pack_usage[] = \"git-fetch-pack [-q] [--exec=upload-pack] [host:]directory [heads]* < mycommitlist\";\n+static int verbose;\n+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 find_common(int fd[2], unsigned char *result_sha1, unsigned char *remote)\n+static int find_common(int fd[2], unsigned char *result_sha1,\n+\t\t       struct ref *refs)\n {\n \tstatic char line[1000];\n \tint count = 0, flushes = 0, retval;\n@@ -16,7 +19,16 @@ static int find_common(int fd[2], unsign\n \trevs = popen(\"git-rev-list $(git-rev-parse --all)\", \"r\");\n \tif (!revs)\n \t\tdie(\"unable to run 'git-rev-list'\");\n-\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\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\trefs = refs->next;\n+\t}\n \tpacket_flush(fd[1]);\n \tflushes = 1;\n \tretval = -1;\n@@ -25,6 +37,8 @@ static int find_common(int fd[2], unsign\n \t\tif (get_sha1_hex(line, sha1))\n \t\t\tdie(\"git-fetch-pack: expected object name, got crud\");\n \t\tpacket_write(fd[1], \"have %s\\n\", sha1_to_hex(sha1));\n+\t\tif (verbose)\n+\t\t\tfprintf(stderr, \"have %s\\n\", sha1_to_hex(sha1));\n \t\tif (!(31 & ++count)) {\n \t\t\tpacket_flush(fd[1]);\n \t\t\tflushes++;\n@@ -38,6 +52,8 @@ static int find_common(int fd[2], unsign\n \t\t\tif (get_ack(fd[0], result_sha1)) {\n \t\t\t\tflushes = 0;\n \t\t\t\tretval = 0;\n+\t\t\t\tif (verbose)\n+\t\t\t\t\tfprintf(stderr, \"got ack\\n\");\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\tflushes--;\n@@ -45,19 +61,19 @@ static int find_common(int fd[2], unsign\n \t}\n \tpclose(revs);\n \tpacket_write(fd[1], \"done\\n\");\n+\tif (verbose)\n+\t\tfprintf(stderr, \"done\\n\");\n \twhile (flushes) {\n \t\tflushes--;\n-\t\tif (get_ack(fd[0], result_sha1))\n+\t\tif (get_ack(fd[0], result_sha1)) {\n+\t\t\tif (verbose)\n+\t\t\t\tfprintf(stderr, \"got ack\\n\");\n \t\t\treturn 0;\n+\t\t}\n \t}\n \treturn retval;\n }\n \n-/*\n- * Eventually we'll want to be able to fetch multiple heads.\n- *\n- * Right now we'll just require a single match.\n- */\n static int fetch_pack(int fd[2], int nr_match, char **match)\n {\n \tstruct ref *ref;\n@@ -70,12 +86,8 @@ 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 (ref->next) {\n-\t\tpacket_flush(fd[1]);\n-\t\tdie(\"multiple remote heads\");\n-\t}\n-\tif (find_common(fd, sha1, ref->old_sha1) < 0)\n-\t\tdie(\"git-fetch-pack: no common commits\");\n+\tif (find_common(fd, sha1, ref) < 0)\n+\t\tfprintf(stderr, \"warning: no common commits\\n\");\n \tpid = fork();\n \tif (pid < 0)\n \t\tdie(\"git-fetch-pack: unable to fork off git-unpack-objects\");\n@@ -97,7 +109,11 @@ 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\tputs(sha1_to_hex(ref->old_sha1));\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 (WIFSIGNALED(status)) {\n@@ -124,6 +140,14 @@ int main(int argc, char **argv)\n \t\t\t\texec = arg + 7;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(\"-q\", arg)) {\n+\t\t\t\tquiet = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(\"-v\", arg)) {\n+\t\t\t\tverbose = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tusage(fetch_pack_usage);\n \t\t}\n \t\tdest = arg;\ndiff --git a/git-fetch-script b/git-fetch-script\n--- a/git-fetch-script\n+++ b/git-fetch-script\n@@ -31,6 +31,10 @@ rsync://*)\n \t;;\n *)\n \thead=$(git-fetch-pack \"$merge_repo\" \"$merge_head\")\n+\tif h=`expr \"$head\" : '\\([^ ][^ ]*\\) '`\n+\tthen\n+\t    head=$h\n+\tfi\n \t;;\n esac || exit 1\n \n"},{"id":"7128","messageId":"Pine.LNX.4.58.0508120858420.3295@g5.osdl.org","threadId":"1480","inReplyTo":"7vwtmr4hm5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] fetch-pack: start multi-head pulling.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-08-12T16:12:57Z","receivedAt":"2005-08-12T16:12:57Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 12 Aug 2005, Junio C Hamano wrote:\n>\n> Linus, I need a bit of guidance from you about this one; an\n> ancient commit 4f7770c87ce3c302e1639a7737a6d2531fe4b160 removed\n> the multi-head support fetch-pack once had, labelling it as \"a\n> misguided attempt\", and I would like to know if I am making the\n> same misguided attempt again.  This update actually makes\n> clone-pack almost redundant.\n\nI like your version.\n\nMy misguided attempt was not the ability to pull multiple heads, but what \nto _do_ with them. I originally envisioned something more \"git-push-pack\" \nlike, where it would pull multiple heads into real references, and _that_ \nwas the misguided part. I then ended up just printing it out to stdout, \nand that made it \"one ref only\".\n\nYour version where you just print out multiple heads with names is, I \nthink, the right thing to do.\n\nThe shell script looks a bit unreadable to me, personally.\n\n>  \thead=$(git-fetch-pack \"$merge_repo\" \"$merge_head\")\n> +\tif h=`expr \"$head\" : '\\([^ ][^ ]*\\) '`\n> +\tthen\n> +\t    head=$h\n> +\tfi\n\nBack-ticks, and the \":\" operator to \"expr\". You really _are_ old-fashioned \nwhen it comes to shell ;)\n\nWouldn't it be simpler/cleaner to just do\n\n\thead=($(git-fetch-pack \"$merge_repo\" \"$merge_head\"))\n\nwhich gets you \"$head\" being the same as ${head[0]}, namely the SHA1 you \nwant (and if you ever implement multi-head pulling, you'll have it all in \n${head[..]}..)\n\n\t\t\tLinus\n"},{"id":"7129","messageId":"Pine.LNX.4.63.0508121818230.26488@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1480","inReplyTo":"Pine.LNX.4.58.0508120858420.3295@g5.osdl.org","subject":"Re: [PATCH] fetch-pack: start multi-head pulling.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-08-12T16:19:30Z","receivedAt":"2005-08-12T16:19:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 12 Aug 2005, Linus Torvalds wrote:\n\n> Wouldn't it be simpler/cleaner to just do\n> \n> \thead=($(git-fetch-pack \"$merge_repo\" \"$merge_head\"))\n\nI seem to remember Junio does not like bash arrays... And in a recent \ncommit message, he even admits to using something different than bash!\n\nCiao,\nDscho\n"},{"id":"7132","messageId":"7vk6irumv3.fsf@assigned-by-dhcp.cox.net","threadId":"1480","inReplyTo":"Pine.LNX.4.63.0508121818230.26488@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fetch-pack: start multi-head pulling.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-12T16:43:44Z","receivedAt":"2005-08-12T16:43:44Z","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> I seem to remember Junio does not like bash arrays... And in a recent \n> commit message, he even admits to using something different than bash!\n\nCorrect and somewhat misleading.  My usual shell is bash but\nfrom time to time I try to run things with (d)ash to see how far\nI strayed from the common denominator.\n\nYes, I am old fashioned.\n\nI have been trying, admittably perhaps not very successfully, to\nstay away from bashism in the core GIT scripts.  I knew we\nstarted using shell array when Linus did the git-diff-script,\nbut I have been hoping somebody coming from other platforms\n(hello, Solaris and Darwin guys) would send in patches if they\ncared enough.  So I try to avoid making their life harder than\nalready is.\n\nHere is a semi off-topic joke, hopefully to give you a better\nsense of where I am coming from.\n\n    Anybody can start pretending to be an old fashioned shell\n    programmer by adhering to the following simple rules:\n\n     1. Never, ever say [ ... ]; we old-timers always spell that\n        \"test\".\n\n     2. Never use \"test\" when \"case\" would do; this comes from\n        the days when test was not built-in and machines were\n        small.  We tried to reduce number of forks in our\n        scripts.  We also never use echo piped to grep when\n        \"case\" would do.\n\n     3. We tend to write && || more often than we use if\n        ... then ... fi, especially for simple things.  We do\n        not use parantheses () to introduce command grouping\n        lightly.  We usually say braces {} and use parentheses\n        only when we do want a subshell.\n\n     4. Say ${var-default} more often than ${var:-default};\n        colon form is more recent invention, and we old-timers\n        tend to be more careful to consider the possibility\n        that, when a user says this variable is empty, the user\n        really means it.\n\n     5. We are still allowed to use $() form in preference to\n        ``, because it is clearly superior (it can nest) and\n        should have been the way to spell it from the beginning.\n\n-jc\n"},{"id":"7133","messageId":"Pine.LNX.4.58.0508121000320.3295@g5.osdl.org","threadId":"1480","inReplyTo":"Pine.LNX.4.63.0508121818230.26488@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fetch-pack: start multi-head pulling.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-08-12T17:12:12Z","receivedAt":"2005-08-12T17:12:12Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 12 Aug 2005, Johannes Schindelin wrote:\n> \n> I seem to remember Junio does not like bash arrays... \n\nWell, fair enough, although they aren't really \"bash\" arrays, they\nappeared in other shells before \"bash\". \n\nAt least ksh and zsh have them, although the zsh implementation seems to\nbe pretty broken (indices start at 1, and $var acts like $var[*] etc).\n\nAfaik, ksh is actually the origin of the thing.\n\n\t\tLinus\n"},{"id":"7164","messageId":"pan.2005.08.13.03.25.28.489523@smurf.noris.de","threadId":"1480","inReplyTo":"7vk6irumv3.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] fetch-pack: start multi-head pulling.","fromName":"Matthias Urlichs","fromEmail":"smurf@smurf.noris.de","sentAt":"2005-08-13T03:25:30Z","receivedAt":"2005-08-13T03:25:30Z","isPatch":true,"sender":{"key":"matthias@urlichs.de","avatar":"https://gravatar.com/avatar/2708905af227313eba6f2b2ae0f7d0259b5ac5d71baef58fe5a13c699ce0bbf0?d=mp&s=160"},"body":"Hi, Junio C Hamano wrote:\n\n> I have been trying, admittably perhaps not very successfully, to\n> stay away from bashism in the core GIT scripts.\n\nWe should probably use #!/bin/bash for scripts with bashisms...\n\n-- \nMatthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de\nDisclaimer: The quote was selected randomly. Really. | http://smurf.noris.de\n - -\nHe has more goodness in his little finger Than you have in your whole\nbody.\n\t\t\t\t\t-- Jonathan Swift\n"},{"id":"7182","messageId":"7vd5oip5i2.fsf@assigned-by-dhcp.cox.net","threadId":"1480","inReplyTo":"pan.2005.08.13.03.25.28.489523@smurf.noris.de","subject":"Re: [PATCH] fetch-pack: start multi-head pulling.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-13T09:09:57Z","receivedAt":"2005-08-13T09:09:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthias Urlichs <smurf@smurf.noris.de> writes:\n\n>> I have been trying, admittably perhaps not very successfully, to\n>> stay away from bashism in the core GIT scripts.\n>\n> We should probably use #!/bin/bash for scripts with bashisms...\n\nAs a fall-back position, yes, but I'd rather see trivial\nbashisms eradicated when the rewrite does not make things too\ncomplicated.\n"}]}