{"thread":{"id":"31169","subject":"[PATCH] completion: resolve svn remote upstream refs","startedAt":"2012-08-02T08:20:02Z","lastAt":"2012-08-02T08:20:02Z","messageCount":1,"participants":["Yves Blusseau"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"196324","messageId":"501A3832.5040905@zetam.org","threadId":"31169","inReplyTo":null,"subject":"[PATCH] completion: resolve svn remote upstream refs","fromName":"Yves Blusseau","fromEmail":"blusseau@zetam.org","sentAt":"2012-08-02T08:20:02Z","receivedAt":"2012-08-02T08:20:02Z","isPatch":true,"sender":{"key":"blusseau@zetam.org","avatar":null},"body":"This 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\n   into git remote refs using paths declared in svn-remote.*.branches\n   configurations\n\nSigned-off-by: Yves Blusseau <blusseau@zetam.org>\n---\n  contrib/completion/git-prompt.sh | 48 \n+++++++++++++++++++++++++++++++++++++++-\n  1 file changed, 47 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-prompt.sh \nb/contrib/completion/git-prompt.sh\nindex 29b1ec9..dafcecc 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -73,17 +73,57 @@ __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+\t\tcase $ref in\n+\t\t\t# check if the ref match the glob\n+\t\t\t$left_part_ref_glob)\n+\t\t\t\t# extract the value that match the pattern\n+\t\t\t\tleft=${left_part_ref_glob%%\\**}\n+\t\t\t\tright=${left_part_ref_glob##*\\*}\n+\t\t\t\tvalue=${ref#$left}\n+\t\t\t\tvalue=${value%$right}\n+\t\t\t\t# get the right part ref glob (after the :)\n+\t\t\t\tright_part_ref_glob=\"${ref_globs/${left_part_ref_glob}:/}\"\n+\t\t\t\t# replace the pattern with the value found above\n+\t\t\t\tleft=${right_part_ref_glob%%\\**}\n+\t\t\t\tright=${right_part_ref_glob##*\\*}\n+\t\t\t\tref=${left}${value}${right}\n+\t\t\t\t# remove leading refs/remotes/\n+\t\t\t\tref=${ref/refs\\/remotes\\//}\n+\t\t\t\tbreak\n+\t\t\t\t;;\n+\t\tesac\n+\tdone\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 branches_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\\..*\\.(branches|url)|bash\\.showupstream)$' 2>/dev/null | tr \n'\\0\\n' '\\n ')\"\n  \twhile read -r key value; do\n  \t\tcase \"$key\" in\n  \t\tbash.showupstream)\n@@ -93,6 +133,9 @@ __git_ps1_show_upstream ()\n  \t\t\t\treturn\n  \t\t\tfi\n  \t\t\t;;\n+\t\tsvn-remote.*.branches)\n+\t\t\tbranches_refs_globs[${#branches_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 +175,9 @@ __git_ps1_show_upstream ()\n  \t\t\telse\n  \t\t\t\tupstream=${svn_upstream#/}\n  \t\t\tfi\n+\t\t\tif [[ ${#branches_refs_globs[@]} -gt 0 ]]; then\n+\t\t\t\tupstream=$(__git_resolve_svn_refs branches_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\n"}]}