[devel] RFC: girar-download (was: [newbies] gear. Первый опыт)

Michael Shigorin mike на osdn.org.ua
Пт Янв 1 20:44:19 UTC 2010


On Wed, Dec 30, 2009 at 04:14:39PM +0300, Alexey I. Froloff wrote:
> > git remote add origin git.alt:packages/$(basename `pwd`)
> girar-upload

Подумал и сочинил по мотивам того письма girar-download наконец.
Возможно, лучше было бы назвать girar-remotes, но так очевидней.

К сожалению, разуть глаза на girar-clone сообразил только уже
при написании этого письма -- но он всё равно реализует немного
другую задачу: вытащить/обновить всех, кто занимается пакетом
(возможно, стоя в уже существующем репо).

Прилагаю демо-версию (также отправлена в мой girar-utils.git),
прошу комментариев по TODO в конце скрипта и надеюсь увидеть
доработанный вариант в пакете.

* http://lists.altlinux.org/pipermail/devel-newbies/2009-December/000123.html

-- 
 ---- WBR, Michael Shigorin <mike на altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/
----------- следующая часть -----------
#!/bin/sh -efu
#
# Copyright (C) 2010  Michael Shigorin <mike на altlinux.org>
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

. gear-sh-functions
. girar-client-sh-functions

show_help()
{
	cat <<EOF
Usage: $PROG [options] [<package> [<maintainer>...]]

$PROG facilitates downloading an existing project repo from git.alt.

Desired package name should be either specified explicitly
or $PROG will assume that current working directory is inside
a corresponding existing git repo (to just add remotes).

Options:
  -N,--no-update      do not try to download remote repos;

  -q,--quiet          try to be more quiet;
  -v,--verbose        print a message for each action;
  -V,--version        print program version and exit;
  -h,--help           show this text and exit.

Report bugs to http://bugs.altlinux.ru/

EOF
	exit
}

print_version()
{
	cat <<EOF
$PROG version $PROG_VERSION
Written by Michael Shigorin <mike на altlinux.org>

Copyright (C) 2010 Michael Shigorin <mike на altlinux.org>
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
EOF
	exit
}

init_repo()
{
	verbose "initializing gear repo"
	mkdir -p "$1"
	cd "$1"
	git init
}

git_dir()
{
	verbose "figuring out git directory"
	GIT_DIR="$(git rev-parse --git-dir)"
	GIT_DIR="$(readlink -ev "$GIT_DIR")"
	export GIT_DIR
	package="${GIT_DIR%.git}"
	package="${package%/}"
	printf "%s\n" "${package##*/}"
}

add_remote()
{
	verbose "adding $1"
	git remote add "$1" "$(girar-remote-uri "$package" "$1")"
}

TEMP=`getopt -n $PROG -o N,q,v,V,h \
	     -l no-update,quiet,verbose,version,help -- "$@"` ||
	show_usage
eval set -- "$TEMP"

no_update=
while :; do
	case "$1" in
		-N|--no-update) no_update=1;;
		-q|--quiet) quiet=-q;;
		-v|--verbose) verbose=-v;;
		-V|--version) print_version;;
		-h|--help) show_help;;
		--) shift; break;;
		*) fatal "unrecognized option: $1";;
	esac
	shift
done

if [ "$#" -gt 0 ]; then
	package="$1"; shift
	[ -d "$package" ] || init_repo "$package"
else
	package="$(git_dir)" || show_help
fi

if [ "$#" -gt 0 ]; then
	verbose "going after specified maintainers"
	for maintainer in "$@"; do
		add_remote "$maintainer"
	done
else
	verbose "looking for remote repositories"
	run_remote_command find-package "$package" |
		while read path timestamp; do
			maintainer="${path#/people/}"
			add_remote "${maintainer%/packages/*}"
		done
fi

[ -n "$no_update" ] || {
	verbose "updating remotes"
	git remote update
}

# TODO:
# - options to add only package maintainer/acl folks/N recent
# - add gears remote too
# - automate initial merge e.g. according to gears archive
# - compare proposed remotes against `git remote show`
#   to either skip or force adding existing ones
# - consider --max-age option to omit stale repos


Подробная информация о списке рассылки Devel