{"thread":{"id":"6513","subject":"[PATCH/RFC] git-fetch: Only fetch in fetch","startedAt":"2007-01-25T00:43:42Z","lastAt":"2007-01-25T09:37:51Z","messageCount":4,"participants":["Santi Béjar","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32577","messageId":"87veiwszpd.fsf@gmail.com","threadId":"6513","inReplyTo":null,"subject":"[PATCH/RFC] git-fetch: Only fetch in fetch","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2007-01-25T00:43:42Z","receivedAt":"2007-01-25T00:43:42Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"\n---\n\n Hi *,\n\n   I've tried to separate the fetch and merge logic. At the same time it\n   has removed 40 lines of code to the git-*.sh.\n\n   What do you think?\n\n   Santi\n\n   P.D.: I supose it is too late for v1.5.0.\n\n git-fetch.sh             |   41 +++++++-------------------\n git-parse-remote.sh      |   71 ++++++----------------------------------------\n git-pull.sh              |   40 +++++++++++++++++++++++--\n t/t5510-fetch.sh         |    6 ++--\n t/t6200-fmt-merge-msg.sh |   23 ++++++++++-----\n 5 files changed, 74 insertions(+), 107 deletions(-)\n\ndiff --git a/git-fetch.sh b/git-fetch.sh\nindex 87b940b..564d633 100755\n--- a/git-fetch.sh\n+++ b/git-fetch.sh\n@@ -74,9 +74,9 @@ do\n \tshift\n done\n \n+origin=$(get_default_remote)\n case \"$#\" in\n 0)\n-\torigin=$(get_default_remote)\n \ttest -n \"$(get_remote_url ${origin})\" ||\n \t\tdie \"Where do you want to fetch from today?\"\n \tset x $origin ; shift ;;\n@@ -88,6 +88,12 @@ refs=\n rref=\n rsync_slurped_objects=\n \n+cat > $GIT_DIR/FETCH_REMOTE <<EOF\n+remote: $remote_nick\n+url: $remote\n+default: $origin\n+refspec: $@\n+EOF\n if test \"\" = \"$append\"\n then\n \t: >\"$GIT_DIR/FETCH_HEAD\"\n@@ -103,10 +109,6 @@ append_fetch_head () {\n     remote_name_=\"$3\"\n     remote_nick_=\"$4\"\n     local_name_=\"$5\"\n-    case \"$6\" in\n-    t) not_for_merge_='not-for-merge' ;;\n-    '') not_for_merge_= ;;\n-    esac\n \n     # remote-nick is the URL given on the command line (or a shorthand)\n     # remote-name is the $GIT_DIR relative refs/ path we computed\n@@ -137,10 +139,8 @@ append_fetch_head () {\n     if git-cat-file commit \"$head_\" >/dev/null 2>&1\n     then\n \theadc_=$(git-rev-parse --verify \"$head_^0\") || exit\n-\techo \"$headc_\t$not_for_merge_\t$note_\" >>\"$GIT_DIR/FETCH_HEAD\"\n-    else\n-\techo \"$head_\tnot-for-merge\t$note_\" >>\"$GIT_DIR/FETCH_HEAD\"\n     fi\n+    echo \"$headc_\t$remote_name\t$note_\" >>\"$GIT_DIR/FETCH_HEAD\"\n \n     update_local_ref \"$local_name_\" \"$head_\" \"$note_\"\n }\n@@ -283,13 +283,6 @@ fetch_main () {\n \n       # These are relative path from $GIT_DIR, typically starting at refs/\n       # but may be HEAD\n-      if expr \"z$ref\" : 'z\\.' >/dev/null\n-      then\n-\t  not_for_merge=t\n-\t  ref=$(expr \"z$ref\" : 'z\\.\\(.*\\)')\n-      else\n-\t  not_for_merge=\n-      fi\n       if expr \"z$ref\" : 'z+' >/dev/null\n       then\n \t  single_force=t\n@@ -370,7 +363,7 @@ fetch_main () {\n       esac\n \n       append_fetch_head \"$head\" \"$remote\" \\\n-\t  \"$remote_name\" \"$remote_nick\" \"$local_name\" \"$not_for_merge\" || exit\n+\t  \"$remote_name\" \"$remote_nick\" \"$local_name\" || exit\n \n   done\n \n@@ -413,28 +406,16 @@ fetch_main () {\n \t      case \"$ref\" in\n \t      +$remote_name:*)\n \t\t  single_force=t\n-\t\t  not_for_merge=\n-\t\t  found=\"$ref\"\n-\t\t  break ;;\n-\t      .+$remote_name:*)\n-\t\t  single_force=t\n-\t\t  not_for_merge=t\n-\t\t  found=\"$ref\"\n-\t\t  break ;;\n-\t      .$remote_name:*)\n-\t\t  not_for_merge=t\n \t\t  found=\"$ref\"\n \t\t  break ;;\n \t      $remote_name:*)\n-\t\t  not_for_merge=\n \t\t  found=\"$ref\"\n \t\t  break ;;\n \t      esac\n \t  done\n \t  local_name=$(expr \"z$found\" : 'z[^:]*:\\(.*\\)')\n \t  append_fetch_head \"$sha1\" \"$remote\" \\\n-\t\t  \"$remote_name\" \"$remote_nick\" \"$local_name\" \\\n-\t\t  \"$not_for_merge\" || exit\n+\t\t  \"$remote_name\" \"$remote_nick\" \"$local_name\" || exit\n         done\n       )\n     ) || exit ;;\n@@ -458,7 +439,7 @@ case \"$no_tags$tags\" in\n \t\tdo\n \t\t\tgit-cat-file -t \"$sha1\" >/dev/null 2>&1 || continue\n \t\t\techo >&2 \"Auto-following $name\"\n-\t\t\techo \".${name}:${name}\"\n+\t\t\techo \"${name}:${name}\"\n \t\tdone)\n \tesac\n \tcase \"$taglist\" in\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex 4fc6020..3352964 100755\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -70,16 +70,11 @@ get_remote_default_refs_for_push () {\n \tesac\n }\n \n-# Called from canon_refs_list_for_fetch -d \"$remote\", which\n-# is called from get_remote_default_refs_for_fetch to grok\n+# Called from get_remote_default_refs_for_fetch to grok\n # refspecs that are retrieved from the configuration, but not\n # from get_remote_refs_for_fetch when it deals with refspecs\n # supplied on the command line.  $ls_remote_result has the list\n # of refs available at remote.\n-#\n-# The first token returned is either \"explicit\" or \"glob\"; this\n-# is to help prevent randomly \"globbed\" ref from being chosen as\n-# a merge candidate\n expand_refs_wildcard () {\n \tfirst_one=yes\n \tfor ref\n@@ -87,21 +82,10 @@ expand_refs_wildcard () {\n \t\tlref=${ref#'+'}\n \t\t# a non glob pattern is given back as-is.\n \t\texpr \"z$lref\" : 'zrefs/.*/\\*:refs/.*/\\*$' >/dev/null || {\n-\t\t\tif test -n \"$first_one\"\n-\t\t\tthen\n-\t\t\t\techo \"explicit\"\n-\t\t\t\tfirst_one=\n-\t\t\tfi\n \t\t\techo \"$ref\"\n \t\t\tcontinue\n \t\t}\n \n-\t\t# glob\n-\t\tif test -n \"$first_one\"\n-\t\tthen\n-\t\t\techo \"glob\"\n-\t\t\tfirst_one=\n-\t\tfi\n \t\tfrom=`expr \"z$lref\" : 'z\\(refs/.*/\\)\\*:refs/.*/\\*$'`\n \t\tto=`expr \"z$lref\" : 'zrefs/.*/\\*:\\(refs/.*/\\)\\*$'`\n \t\tlocal_force=\n@@ -123,30 +107,6 @@ expand_refs_wildcard () {\n \n # Subroutine to canonicalize remote:local notation.\n canon_refs_list_for_fetch () {\n-\t# If called from get_remote_default_refs_for_fetch\n-\t# leave the branches in branch.${curr_branch}.merge alone,\n-\t# or the first one otherwise; add prefix . to the rest\n-\t# to prevent the secondary branches to be merged by default.\n-\tmerge_branches=\n-\tcurr_branch=\n-\tif test \"$1\" = \"-d\"\n-\tthen\n-\t\tshift ; remote=\"$1\" ; shift\n-\t\tset $(expand_refs_wildcard \"$@\")\n-\t\tis_explicit=\"$1\"\n-\t\tshift\n-\t\tif test \"$remote\" = \"$(get_default_remote)\"\n-\t\tthen\n-\t\t\tcurr_branch=$(git-symbolic-ref -q HEAD | \\\n-\t\t\t    sed -e 's|^refs/heads/||')\n-\t\t\tmerge_branches=$(git-repo-config \\\n-\t\t\t    --get-all \"branch.${curr_branch}.merge\")\n-\t\tfi\n-\t\tif test -z \"$merge_branches\" && test $is_explicit != explicit\n-\t\tthen\n-\t\t\tmerge_branches=..this.will.never.match.any.ref..\n-\t\tfi\n-\tfi\n \tfor ref\n \tdo\n \t\tforce=\n@@ -159,22 +119,6 @@ canon_refs_list_for_fetch () {\n \t\texpr \"z$ref\" : 'z.*:' >/dev/null || ref=\"${ref}:\"\n \t\tremote=$(expr \"z$ref\" : 'z\\([^:]*\\):')\n \t\tlocal=$(expr \"z$ref\" : 'z[^:]*:\\(.*\\)')\n-\t\tdot_prefix=.\n-\t\tif test -z \"$merge_branches\"\n-\t\tthen\n-\t\t\tmerge_branches=$remote\n-\t\t\tdot_prefix=\n-\t\telse\n-\t\t\tfor merge_branch in $merge_branches\n-\t\t\tdo\n-\t\t\t    if\ttest \"$remote\" = \"$merge_branch\" ||\n-\t\t\t\ttest \"$local\" = \"$merge_branch\"\n-\t\t\t    then\n-\t\t\t\t    dot_prefix=\n-\t\t\t\t    break\n-\t\t\t    fi\n-\t\t\tdone\n-\t\tfi\n \t\tcase \"$remote\" in\n \t\t'') remote=HEAD ;;\n \t\trefs/heads/* | refs/tags/* | refs/remotes/*) ;;\n@@ -193,7 +137,7 @@ canon_refs_list_for_fetch () {\n \t\t   git-check-ref-format \"$local_ref_name\" ||\n \t\t   die \"* refusing to create funny ref '$local_ref_name' locally\"\n \t\tfi\n-\t\techo \"${dot_prefix}${force}${remote}:${local}\"\n+\t\techo \"${force}${remote}:${local}\"\n \tdone\n }\n \n@@ -204,17 +148,20 @@ get_remote_default_refs_for_fetch () {\n \t'')\n \t\techo \"HEAD:\" ;;\n \tconfig)\n-\t\tcanon_refs_list_for_fetch -d \"$1\" \\\n-\t\t\t$(git-repo-config --get-all \"remote.$1.fetch\") ;;\n+\t\tset $(expand_refs_wildcard \\\n+\t\t\t$(git-repo-config --get-all \"remote.$1.fetch\"))\n+\t\tcanon_refs_list_for_fetch \"$@\"\n+\t\t;;\n \tbranches)\n \t\tremote_branch=$(sed -ne '/#/s/.*#//p' \"$GIT_DIR/branches/$1\")\n \t\tcase \"$remote_branch\" in '') remote_branch=master ;; esac\n \t\techo \"refs/heads/${remote_branch}:refs/heads/$1\"\n \t\t;;\n \tremotes)\n-\t\tcanon_refs_list_for_fetch -d \"$1\" $(sed -ne '/^Pull: */{\n+\t\tset $(expand_refs_wildcard $(sed -ne '/^Pull: */{\n \t\t\t\t\t\ts///p\n-\t\t\t\t\t}' \"$GIT_DIR/remotes/$1\")\n+\t\t\t\t\t}' \"$GIT_DIR/remotes/$1\"))\n+\t\tcanon_refs_list_for_fetch \"$@\"\n \t\t;;\n \t*)\n \t\tdie \"internal error: get-remote-default-ref-for-push $1\" ;;\ndiff --git a/git-pull.sh b/git-pull.sh\nindex a3665d7..cc1295a 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -77,9 +77,41 @@ to recover.'\n \n fi\n \n-merge_head=$(sed -e '/\tnot-for-merge\t/d' \\\n-\t-e 's/\t.*//' \"$GIT_DIR\"/FETCH_HEAD | \\\n-\ttr '\\012' ' ')\n+remote=$(grep \"^remote: \" $GIT_DIR/FETCH_REMOTE)\n+remote=${remote#remote: }\n+url=$(grep \"^url: \" $GIT_DIR/FETCH_REMOTE)\n+url=${url#url: }\n+default=$(grep \"^default: \" $GIT_DIR/FETCH_REMOTE)\n+default=${default#default: }\n+refspec=$(grep \"^refspec: \" $GIT_DIR/FETCH_REMOTE)\n+refspec=${refspec#refspec: $remote}\n+\n+merge_head=\n+merge_branches=\n+if test \",$remote,$refspec,\" == \",$default,,\" ; then\n+\tcurr_branch=$(git-symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')\n+\tmerge_branches=$(git-repo-config \\\n+\t\t--get-all \"branch.${curr_branch}.merge\")\n+elif test -n \"$refspec\" ; then\n+\tmerge_branches=$(for ref in $refspec ; do\n+\t\texpr \"z$ref\" : 'z.*:' >/dev/null || ref=\"${ref}:\"\n+\t\techo \" $(expr \"z$ref\" : 'z\\([^:]*\\):')\"; done)\n+elif test \"$remote\" == \"$url\" ; then\n+\tmerge_branches=HEAD\n+fi\n+\n+for branch in $merge_branches\n+do\n+\tcase \"$branch\" in\n+\tHEAD | refs/heads/* | refs/tags/* | refs/remotes/*) ;;\n+\theads/* | tags/* | remotes/* ) branch=\"refs/$branch\" ;;\n+\t*) branch=\"refs/heads/$branch\" ;;\n+\tesac\n+\tgrep \"\t$branch\t\"  \"$GIT_DIR\"/FETCH_HEAD | \\\n+\t\tsed -e 's@\t'\"$branch\"'\t@\t\t@'\n+done > \"$GIT_DIR\"/FETCH_MERGE\n+\n+merge_head=$(sed -e 's/\t.*//' \"$GIT_DIR\"/FETCH_MERGE | tr '\\012' ' ')\n \n case \"$merge_head\" in\n '')\n@@ -115,6 +147,6 @@ then\n \texit\n fi\n \n-merge_name=$(git-fmt-merge-msg <\"$GIT_DIR/FETCH_HEAD\") || exit\n+merge_name=$(git-fmt-merge-msg <\"$GIT_DIR/FETCH_MERGE\") || exit\n exec git-merge $no_summary $no_commit $squash $strategy_args \\\n \t\"$merge_name\" HEAD $merge_head\ndiff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\nindex 3ce9446..2e196de 100755\n--- a/t/t5510-fetch.sh\n+++ b/t/t5510-fetch.sh\n@@ -50,7 +50,7 @@ test_expect_success \"fetch test\" '\n \ttest \"z$mine\" = \"z$his\"\n '\n \n-test_expect_success \"fetch test for-merge\" '\n+test_expect_success \"fetch test FETCH_HEAD\" '\n \tcd \"$D\" &&\n \tcd three &&\n \tgit fetch &&\n@@ -59,8 +59,8 @@ test_expect_success \"fetch test for-merge\" '\n \tmaster_in_two=`cd ../two && git rev-parse master` &&\n \tone_in_two=`cd ../two && git rev-parse one` &&\n \t{\n-\t\techo \"$master_in_two\tnot-for-merge\"\n-\t\techo \"$one_in_two\t\"\n+\t\techo \"$master_in_two\trefs/heads/master\"\n+\t\techo \"$one_in_two\trefs/heads/one\"\n \t} >expected &&\n \tcut -f -2 .git/FETCH_HEAD >actual &&\n \tdiff expected actual'\ndiff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\nindex 63e49f3..7776823 100755\n--- a/t/t6200-fmt-merge-msg.sh\n+++ b/t/t6200-fmt-merge-msg.sh\n@@ -77,8 +77,9 @@ test_expect_success 'merge-msg test #1' '\n \n \tgit checkout master &&\n \tgit fetch . left &&\n-\n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tsed -e \"s/\t.*\t/\t\t/\" \\\n+\t\t.git/FETCH_HEAD >.git/FETCH_MERGE &&\n+\tgit fmt-merge-msg <.git/FETCH_MERGE >actual &&\n \tdiff -u actual expected\n '\n \n@@ -90,8 +91,9 @@ test_expect_success 'merge-msg test #2' '\n \n \tgit checkout master &&\n \tgit fetch ../trash left &&\n-\n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tsed -e \"s/\t.*\t/\t\t/\" \\\n+\t\t.git/FETCH_HEAD >.git/FETCH_MERGE &&\n+\tgit fmt-merge-msg <.git/FETCH_MERGE >actual &&\n \tdiff -u actual expected\n '\n \n@@ -113,8 +115,9 @@ test_expect_success 'merge-msg test #3' '\n \tgit checkout master &&\n \tsetdate &&\n \tgit fetch . left &&\n-\n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tsed -e \"s/\t.*\t/\t\t/\" \\\n+\t\t.git/FETCH_HEAD >.git/FETCH_MERGE &&\n+\tgit fmt-merge-msg <.git/FETCH_MERGE >actual &&\n \tdiff -u actual expected\n '\n \n@@ -143,8 +146,10 @@ test_expect_success 'merge-msg test #4' '\n \tgit checkout master &&\n \tsetdate &&\n \tgit fetch . left right &&\n+\tsed -e \"s/\t.*\t/\t\t/\" \\\n+\t\t.git/FETCH_HEAD >.git/FETCH_MERGE &&\n \n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tgit fmt-merge-msg <.git/FETCH_MERGE >actual &&\n \tdiff -u actual expected\n '\n \n@@ -155,8 +160,10 @@ test_expect_success 'merge-msg test #5' '\n \tgit checkout master &&\n \tsetdate &&\n \tgit fetch . left right &&\n+\tsed -e \"s/\t.*\t/\t\t/\" \\\n+\t\t.git/FETCH_HEAD >.git/FETCH_MERGE &&\n \n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tgit fmt-merge-msg <.git/FETCH_MERGE >actual &&\n \tdiff -u actual expected\n '\n \n-- \n1.5.0.rc2.g7dd4c-dirty\n"},{"id":"32578","messageId":"8aa486160701241652x375f0d0eoba1cdf3d14550034@mail.gmail.com","threadId":"6513","inReplyTo":"87veiwszpd.fsf@gmail.com","subject":"Re: [PATCH/RFC] git-fetch: Only fetch in fetch","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2007-01-25T00:52:50Z","receivedAt":"2007-01-25T00:52:50Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"On 1/25/07, Santi Béjar <sbejar@gmail.com> wrote:\n>    I've tried to separate the fetch and merge logic. At the same time it\n>    has removed 40 lines of code to the git-*.sh.\n\nJust some words for the basic idea.\n\ngit-fetch: fetches the branches from the remote and save this\ninformation in .git/FETCH_HEAD. In .git/FETCH_REMOTE it save\nadditional information, as the remote nick, the remote url, the\nrefspec used and the default remote.\n\ngit-pull: uses this information to select the branches to merge and\nsave them in .git/FETCH_MERGE.\n\nSee you.\n\nSanti\n"},{"id":"32579","messageId":"7vhcufc3j5.fsf@assigned-by-dhcp.cox.net","threadId":"6513","inReplyTo":"8aa486160701241652x375f0d0eoba1cdf3d14550034@mail.gmail.com","subject":"Re: [PATCH/RFC] git-fetch: Only fetch in fetch","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-25T01:13:02Z","receivedAt":"2007-01-25T01:13:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Santi Béjar\" <sbejar@gmail.com> writes:\n\n> On 1/25/07, Santi Béjar <sbejar@gmail.com> wrote:\n>>    I've tried to separate the fetch and merge logic. At the same time it\n>>    has removed 40 lines of code to the git-*.sh.\n>\n> Just some words for the basic idea.\n>\n> git-fetch: fetches the branches from the remote and save this\n> information in .git/FETCH_HEAD. In .git/FETCH_REMOTE it save\n> additional information, as the remote nick, the remote url, the\n> refspec used and the default remote.\n>\n> git-pull: uses this information to select the branches to merge and\n> save them in .git/FETCH_MERGE.\n\nOne thing I suspect is problematic is that this would make\nfmt-merge-message much less useful after running git-fetch.  You\nhave to go all the way to git-pull and replace reading from\nFETCH_HEAD with reading from FETCH_MERGE (just like you had to\ndo that in git-pull).  In other words, this may break people's\nscripts and workflows.\n\nThis is probably a good clean-up at the conceptual level.  If\nyou had done this before v1.0.0 there would have been no\nquestion about its inclusion.\n\nPlease discuss this patch post 1.5.0.\n"},{"id":"32597","messageId":"8aa486160701250137g59916e51rb53b065bd920c455@mail.gmail.com","threadId":"6513","inReplyTo":"8aa486160701242344y465ff541i6d4d4b46a96bda64@mail.gmail.com","subject":"Re: [PATCH/RFC] git-fetch: Only fetch in fetch","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2007-01-25T09:37:51Z","receivedAt":"2007-01-25T09:37:51Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"Reply to all :)\n\nSanti\n\nOn 1/25/07, Santi Béjar <sbejar@gmail.com> wrote:\n> On 1/25/07, Junio C Hamano <junkio@cox.net> wrote:\n> >\n> > Please discuss this patch post 1.5.0.\n> >\n>\n> OK. Just a patch that was left in the working directory.\n"}]}