{"thread":{"id":"31180","subject":"[PATCH] completion: resolve svn remote upstream refs","startedAt":"2012-08-03T09:54:25Z","lastAt":"2012-08-03T20:40:28Z","messageCount":2,"participants":["Yves Blusseau","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"196405","messageId":"501B9FD1.8090204@zetam.org","threadId":"31180","inReplyTo":null,"subject":"[PATCH] completion: resolve svn remote upstream refs","fromName":"Yves Blusseau","fromEmail":"blusseau@zetam.org","sentAt":"2012-08-03T09:54:25Z","receivedAt":"2012-08-03T09:54:25Z","isPatch":true,"sender":{"key":"blusseau@zetam.org","avatar":null},"body":"Updated version of my previous patch\n\nThis fix is used to return the svn reference of the remote svn upstream\nbranch when the git repository is a clone of a svn repository that was\ncreated with the --stdlayout and --prefix options of git svn command.\n\n* completion/git-prompt.sh: add function to resolve svn branches into\n   git remote refs using paths declared in svn-remote.*.fetch and\n   svn-remote.*.branches configurations\n\nSigned-off-by: Yves Blusseau <blusseau@zetam.org>\n---\n  contrib/completion/git-prompt.sh | 56 \n+++++++++++++++++++++++++++++++++++++++-\n  1 file changed, 55 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-prompt.sh \nb/contrib/completion/git-prompt.sh\nindex 29b1ec9..f9a3421 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -73,17 +73,65 @@ __gitdir ()\n  \tfi\n  }\n  +# resolve svn refs\n+# The function accepts 2 arguments:\n+# 1: An array containing the translation ref(s) (ie \nbranches/*:refs/remotes/svn/*)\n+# 2: the ref to be translated (ie. branches/prod)\n+# returns the remote refs or original ref if it could not be translated\n+__git_resolve_svn_refs ()\n+{\n+\tlocal idx ref_globs left_part_ref_glob right_part_ref_glob left right \nvalue\n+\n+\tlocal all_ref_globs=(\"${!1}\")\n+\tlocal ref=\"$2\"\n+\n+\tfor (( idx=0 ; idx < ${#all_ref_globs[@]}; idx++ ));do\n+\t\tref_globs=\"${all_ref_globs[$idx]}\"\n+\t\t# get the left part ref glob (before the :refs/)\n+\t\tleft_part_ref_glob=\"${ref_globs%%:refs/*}\"\n+\n+\t\t# If the ref match the left part we can resolve the ref directly\n+\t\tif [[ \"$ref\" == \"$left_part_ref_glob\" ]];then\n+\t\t\t# resolve the ref into the right part (after the :)\n+\t\t\tref=\"${ref_globs/${left_part_ref_glob}:/}\"\n+\t\t\tbreak\n+\t\telse\n+\t\t\tcase $ref in\n+\t\t\t\t# check if the ref match the glob\n+\t\t\t\t$left_part_ref_glob)\n+\t\t\t\t\t# extract the value that match the pattern\n+\t\t\t\t\tleft=${left_part_ref_glob%%\\**}\n+\t\t\t\t\tright=${left_part_ref_glob##*\\*}\n+\t\t\t\t\tvalue=${ref#$left}\n+\t\t\t\t\tvalue=${value%$right}\n+\t\t\t\t\t# get the right part ref glob (after the :)\n+\t\t\t\t\tright_part_ref_glob=\"${ref_globs/${left_part_ref_glob}:/}\"\n+\t\t\t\t\t# replace the pattern with the value found above\n+\t\t\t\t\tleft=${right_part_ref_glob%%\\**}\n+\t\t\t\t\tright=${right_part_ref_glob##*\\*}\n+\t\t\t\t\tref=${left}${value}${right}\n+\t\t\t\t\tbreak\n+\t\t\t\t\t;;\n+\t\t\tesac\n+\t\tfi\n+\tdone\n+\t# remove leading refs/remotes/\n+\tref=${ref/refs\\/remotes\\//}\n+\techo \"$ref\"\n+}\n+\n  # stores the divergence from upstream in $p\n  # used by GIT_PS1_SHOWUPSTREAM\n  __git_ps1_show_upstream ()\n  {\n  \tlocal key value\n  \tlocal svn_remote svn_url_pattern count n\n+\tlocal svn_refs_globs=()\n  \tlocal upstream=git legacy=\"\" verbose=\"\"\n   \tsvn_remote=()\n  \t# get some config options from git-config\n-\tlocal output=\"$(git config -z --get-regexp \n'^(svn-remote\\..*\\.url|bash\\.showupstream)$' 2>/dev/null | tr '\\0\\n' '\\n ')\"\n+\tlocal output=\"$(git config -z --get-regexp \n'^(svn-remote\\..*\\.(fetch|branches|url)|bash\\.showupstream)$' \n2>/dev/null | tr '\\0\\n' '\\n ')\"\n  \twhile read -r key value; do\n  \t\tcase \"$key\" in\n  \t\tbash.showupstream)\n@@ -93,6 +141,9 @@ __git_ps1_show_upstream ()\n  \t\t\t\treturn\n  \t\t\tfi\n  \t\t\t;;\n+\t\tsvn-remote.*.fetch|svn-remote.*.branches)\n+\t\t\tsvn_refs_globs[${#svn_refs_globs[*]}]=\"$value\"\n+\t\t\t;;\n  \t\tsvn-remote.*.url)\n  \t\t\tsvn_remote[ $((${#svn_remote[@]} + 1)) ]=\"$value\"\n  \t\t\tsvn_url_pattern+=\"\\\\|$value\"\n@@ -132,6 +183,9 @@ __git_ps1_show_upstream ()\n  \t\t\telse\n  \t\t\t\tupstream=${svn_upstream#/}\n  \t\t\tfi\n+\t\t\tif [[ ${#svn_refs_globs[@]} -gt 0 ]]; then\n+\t\t\t\tupstream=$(__git_resolve_svn_refs svn_refs_globs[@] \"$upstream\")\n+\t\t\tfi\n  \t\telif [[ \"svn+git\" = \"$upstream\" ]]; then\n  \t\t\tupstream=\"@{upstream}\"\n  \t\tfi\n-- \n1.7.12.rc1.17.g6cf3663\n"},{"id":"196440","messageId":"7v7gtfbtfn.fsf@alter.siamese.dyndns.org","threadId":"31180","inReplyTo":"501B9FD1.8090204@zetam.org","subject":"Re: [PATCH] completion: resolve svn remote upstream refs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-03T20:40:28Z","receivedAt":"2012-08-03T20:40:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Administrivia: \n\n - \"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\" in\n   the header tells us that the patch is corrupted and will not\n   apply cleanly, but we still can discuss the contents of the\n   patch.\n\n - \"git shortlog --since=6.months -n --no-merges contrib/completion\"\n   tells us who the area experts who may be able to help you move\n   this patch forward.  Also people who are involved in git-svn may\n   be able to help with the configurations you are reading from.  By\n   Cc'ing them, your patch may have a better chance of getting\n   polished more quickly (I added Cc to relevant people).\n\nYves Blusseau <blusseau@zetam.org> writes:\n\n> Updated version of my previous patch\n\nEverything before the \"---\" line we see below will be for people who\nread \"git log\" history 6 months down the road, when they have to\nunderstand what you did and why (perhaps because they found bugs or\nthey want to further enhance what your patch did).\n\nBecause your previous patch will not appear in that \"git log\"\noutput, the above is not an appropriate thing to say here.\n\n> This fix is used to return the svn reference of the remote svn upstream\n> branch when the git repository is a clone of a svn repository that was\n> created with the --stdlayout and --prefix options of git svn command.\n\nBefore using the word \"fix\", please describe what the current\n(i.e. without the \"fix\") behaviour visible to the users, why it is\nbad, and what behaviour you want to give your users instead.  And\nthen describe what change you made to give that desired behaviour.\n\n> * completion/git-prompt.sh: add function to resolve svn branches into\n>   git remote refs using paths declared in svn-remote.*.fetch and\n>   svn-remote.*.branches configurations\n>\n> Signed-off-by: Yves Blusseau <blusseau@zetam.org>\n> ---\n\nHere, immediately after \"---\", is where you would say \"Updated\nversion of my patch.  The difference from the previous round are\n1. fixed foo, 2. fixed bar, 3. reworded baz....\" if you want to.\n\n>  contrib/completion/git-prompt.sh | 56\n> +++++++++++++++++++++++++++++++++++++++-\n\nLine-wrapped (comes from \"format=flawed\" we saw in the Content-Type\nheader).\n\n>  1 file changed, 55 insertions(+), 1 deletion(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh\n> b/contrib/completion/git-prompt.sh\n> index 29b1ec9..f9a3421 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -73,17 +73,65 @@ __gitdir ()\n>  \tfi\n>  }\n>  +# resolve svn refs\n> +# The function accepts 2 arguments:\n> +# 1: An array containing the translation ref(s) (ie\n> branches/*:refs/remotes/svn/*)\n> +# 2: the ref to be translated (ie. branches/prod)\n> +# returns the remote refs or original ref if it could not be translated\n\nWe see \"translation ref(s)\", which is an unheard-of term, and it is\nunclear what is translated and into what other thing.  Is this the\nmoral equivalent of the ref mapping that maps refs at the remote\nrepository to remote tracking refs we have at our local repository?\n\nIf the first item of above were written like this:\n\n    # 1: An array containing the mapping from branches in the subversion\n    #  repository to remote tracking branches in this repository (e.g\n    #  \"branches/*:refs/remotes/svn/*\").\n\nI wouldn't have had to ask the above question, but it is unclear if\nthat is what you meant, hence this question.\n\n> +__git_resolve_svn_refs ()\n> +{\n> +\tlocal idx ref_globs left_part_ref_glob right_part_ref_glob\n> left right value\n> +\n> +\tlocal all_ref_globs=(\"${!1}\")\n> +\tlocal ref=\"$2\"\n\nBash/Zsh reusability czars might want to comment on the way\nall_ref_globs is declared and initialized.\n\n> +\tfor (( idx=0 ; idx < ${#all_ref_globs[@]}; idx++ ));do\n> +\t\tref_globs=\"${all_ref_globs[$idx]}\"\n> +\t\t# get the left part ref glob (before the :refs/)\n> +\t\tleft_part_ref_glob=\"${ref_globs%%:refs/*}\"\n\nIs doubling of %% significant here?  I am assuming there isn't, as\nthere would be no colon in $ref_globs other than the boundary\nbetween LHS and RHS.\n\n> +\t\t# If the ref match the left part we can resolve the ref directly\n> +\t\tif [[ \"$ref\" == \"$left_part_ref_glob\" ]];then\n\nThe coding standard used in this file is kept deliberately lax\ncompared to the remainder of the codebase, but I think the lack of\nSP between \";\" and \"then\" goes a bit too far.\n\n> +\t\t\t# resolve the ref into the right part (after the :)\n> +\t\t\tref=\"${ref_globs/${left_part_ref_glob}:/}\"\n> +\t\t\tbreak\n> +\t\telse\n> +\t\t\tcase $ref in\n> +\t\t\t\t# check if the ref match the glob\n> +\t\t\t\t$left_part_ref_glob)\n\ncase/esac and case arms should align at the same column (otherwise\nthe body will be indented unreadably too deep to the right, like\nthis code).\n\n>  # stores the divergence from upstream in $p\n>  # used by GIT_PS1_SHOWUPSTREAM\n>  __git_ps1_show_upstream ()\n>  {\n>  \tlocal key value\n>  \tlocal svn_remote svn_url_pattern count n\n> +\tlocal svn_refs_globs=()\n>  \tlocal upstream=git legacy=\"\" verbose=\"\"\n>   \tsvn_remote=()\n\nDoesn't this have the same problem as the one fixed by 471dcfd\n(contrib/completion: \"local var=()\" is misinterpreted as func-decl\nby zsh, 2011-09-01)?\n\nThanks.\n"}]}