1#!/bin/bash 2# 3# bzr.sh - function for handling the download and "extraction" of Bazaar sources 4# 5# Copyright (c) 2015-2018 Pacman Development Team <pacman-dev@archlinux.org> 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21[[ -n "$LIBMAKEPKG_SOURCE_BZR_SH" ]] && return 22LIBMAKEPKG_SOURCE_BZR_SH=1 23 24 25LIBRARY=${LIBRARY:-'@libmakepkgdir@'} 26 27source "$LIBRARY/util/message.sh" 28source "$LIBRARY/util/pkgbuild.sh" 29 30 31download_bzr() { 32 local netfile=$1 33 34 local url=$(get_url "$netfile") 35 if [[ $url != bzr+ssh* ]]; then 36 url=${url#bzr+} 37 fi 38 url=${url%%#*} 39 40 local repo=$(get_filename "$netfile") 41 local displaylocation="$url" 42 43 local dir=$(get_filepath "$netfile") 44 [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" 45 46 if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then 47 msg2 "$(gettext "Branching %s...")" "${displaylocation}" 48 if ! bzr branch "$url" "$dir" --no-tree --use-existing-dir; then 49 error "$(gettext "Failure while branching %s")" "${displaylocation}" 50 plain "$(gettext "Aborting...")" 51 exit 1 52 fi 53 elif (( ! HOLDVER )); then 54 msg2 "$(gettext "Pulling %s...")" "${displaylocation}" 55 cd_safe "$dir" 56 if ! bzr pull "$url"; then 57 # only warn on failure to allow offline builds 58 warning "$(gettext "Failure while pulling %s")" "${displaylocation}" 59 fi 60 fi 61} 62 63extract_bzr() { 64 local netfile=$1 65 66 local repo=$(get_filename "$netfile") 67 local fragment=${netfile#*#} 68 if [[ $fragment = "$netfile" ]]; then 69 unset fragment 70 fi 71 72 rev="last:1" 73 if [[ -n $fragment ]]; then 74 case ${fragment%%=*} in 75 revision) 76 rev="${fragment#*=}" 77 displaylocation="$url -r ${fragment#*=}" 78 ;; 79 *) 80 error "$(gettext "Unrecognized reference: %s")" "${fragment}" 81 plain "$(gettext "Aborting...")" 82 exit 1 83 esac 84 fi 85 86 local dir=$(get_filepath "$netfile") 87 [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" 88 89 msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "bzr" 90 pushd "$srcdir" &>/dev/null 91 92 if [[ -d "${dir##*/}" ]]; then 93 cd_safe "${dir##*/}" 94 if ! (bzr pull "$dir" -q --overwrite -r "$rev" && bzr clean-tree -q --detritus --force); then 95 error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "bzr" 96 plain "$(gettext "Aborting...")" 97 exit 1 98 fi 99 elif ! bzr checkout "$dir" -r "$rev"; then 100 error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr" 101 plain "$(gettext "Aborting...")" 102 exit 1 103 fi 104 105 popd &>/dev/null 106} 107