diff options
-rw-r--r-- | eclass/ChangeLog | 6 | ||||
-rw-r--r-- | eclass/git-r3.eclass | 59 | ||||
-rwxr-xr-x | eclass/tests/git-r3:subrepos.sh | 35 |
3 files changed, 89 insertions, 11 deletions
diff --git a/eclass/ChangeLog b/eclass/ChangeLog index 3431deafd504..03d4812a6f92 100644 --- a/eclass/ChangeLog +++ b/eclass/ChangeLog @@ -1,6 +1,10 @@ # ChangeLog for eclass directory # Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1278 2014/05/31 10:23:36 mgorny Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1279 2014/06/01 22:07:59 mgorny Exp $ + + 01 Jun 2014; Michał Górny <mgorny@gentoo.org> git-r3.eclass, + +tests/git-r3:subrepos.sh: + Properly canonicalize relative submodule URIs, bug #501250. 31 May 2014; Michał Górny <mgorny@gentoo.org> systemd.eclass: Add systemd_{do,new}userunit. diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass index 563e5d0e7a97..01937248d617 100644 --- a/eclass/git-r3.eclass +++ b/eclass/git-r3.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.42 2014/05/23 07:09:07 mgorny Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.43 2014/06/01 22:07:59 mgorny Exp $ # @ECLASS: git-r3.eclass # @MAINTAINER: @@ -352,6 +352,49 @@ _git-r3_set_submodules() { done < <(echo "${data}" | git config -f /dev/fd/0 -l || die) } +# @FUNCTION: _git-r3_set_subrepos +# @USAGE: <submodule-uri> <parent-repo-uri>... +# @INTERNAL +# @DESCRIPTION: +# Create 'subrepos' array containing absolute (canonical) submodule URIs +# for the given <submodule-uri>. If the URI is relative, URIs will be +# constructed using all <parent-repo-uri>s. Otherwise, this single URI +# will be placed in the array. +_git-r3_set_subrepos() { + debug-print-function ${FUNCNAME} "$@" + + local suburl=${1} + subrepos=( "${@:2}" ) + + if [[ ${suburl} == ./* || ${suburl} == ../* ]]; then + # drop all possible trailing slashes for consistency + subrepos=( "${subrepos[@]%%/}" ) + + while true; do + if [[ ${suburl} == ./* ]]; then + suburl=${suburl:2} + elif [[ ${suburl} == ../* ]]; then + suburl=${suburl:3} + + # XXX: correctness checking + + # drop the last path component + subrepos=( "${subrepos[@]%/*}" ) + # and then the trailing slashes, again + subrepos=( "${subrepos[@]%%/}" ) + else + break + fi + done + + # append the preprocessed path to the preprocessed URIs + subrepos=( "${subrepos[@]/%//${suburl}}") + else + subrepos=( "${suburl}" ) + fi +} + + # @FUNCTION: _git-r3_is_local_repo # @USAGE: <repo-uri> # @INTERNAL @@ -645,11 +688,9 @@ git-r3_fetch() { if [[ ! ${commit} ]]; then die "Unable to get commit id for submodule ${subname}" fi - if [[ ${url} == ./* || ${url} == ../* ]]; then - local subrepos=( "${repos[@]/%//${url}}" ) - else - local subrepos=( "${url}" ) - fi + + local subrepos + _git-r3_set_subrepos "${url}" "${repos[@]}" git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" @@ -781,10 +822,8 @@ git-r3_checkout() { local subname=${submodules[0]} local url=${submodules[1]} local path=${submodules[2]} - - if [[ ${url} == ./* || ${url} == ../* ]]; then - url=${repos[0]%%/}/${url} - fi + local subrepos + _git-r3_set_subrepos "${url}" "${repos[@]}" git-r3_checkout "${url}" "${out_dir}/${path}" \ "${local_id}/${subname}" diff --git a/eclass/tests/git-r3:subrepos.sh b/eclass/tests/git-r3:subrepos.sh new file mode 100755 index 000000000000..0fa0fb13e11d --- /dev/null +++ b/eclass/tests/git-r3:subrepos.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +source tests-common.sh + +inherit git-r3 + +# Test getting submodule URIs +test_subrepos() { + local suburi=${1} + local expect=( "${@:2}" ) + + tbegin "subrepos for ${suburi} -> ${expect[0]}${expect[1]+...}" + + local subrepos + _git-r3_set_subrepos "${suburi}" "${repos[@]}" + + [[ ${expect[@]} == ${subrepos[@]} ]] + tend ${?} || eerror "Expected: ${expect[@]}, got: ${subrepos[@]}" +} + +# parent repos +repos=( http://foohub/fooman/foo.git git://foohub/fooman/foo.git ) + +# absolute URI +test_subrepos http://foo/bar http://foo/bar +test_subrepos /foo/bar /foo/bar + +# plain relative URI +test_subrepos ./baz http://foohub/fooman/foo.git/baz git://foohub/fooman/foo.git/baz + +# backward relative URIs +test_subrepos ../baz.git http://foohub/fooman/baz.git git://foohub/fooman/baz.git +test_subrepos ../../bazman/baz.git http://foohub/bazman/baz.git git://foohub/bazman/baz.git + +texit |