diff --git a/gear-srpmimport b/gear-srpmimport index fc4b96f..cd00110 100755 --- a/gear-srpmimport +++ b/gear-srpmimport @@ -46,6 +46,7 @@ or: $PROG [options] --stdin Options: --branch=BRANCH branch name where to import (default is "srpms"); + --comp-branchs create branchs for spec components (no defoult); --import-only do not perform a checkout after importing; --no-untar do not unpack source tarballs; --rules=FILENAME gear rules filename (default is ".gear-rules"); @@ -120,7 +121,6 @@ optimize_rules() done >"$tmp" sed -ne 's/^[^:]\+: \([^ ]\+ .*\|[^ .]\+$\)/&/p' "$rules" >>"$tmp" mv "$tmp" "$rules" - git-update-index --add ${verbose:+--verbose} -- "$rules" } untar() @@ -194,11 +194,8 @@ untar() printf '%s: %s name=%s base=%s\n' "$method_tar" "$tar_dir" "$tar_name" "$base" fi fi |sed "s/${quoted:-@version@}/@version@/g" >>"$gear_rules" - git-ls-files -z --others --modified -- "$tar_dir" | \ - git-update-index --add ${verbose:+--verbose} -z --stdin else printf '%s: %s\n' "$method_copy" "$f" >>"$gear_rules" - git-update-index --add ${verbose:+--verbose} -- "$f" fi } @@ -224,6 +221,7 @@ import() sed -e s/alt-linux/altlinux/g)" # Use own directory for checkout. + rm -f "$compsfile" "$branchsfile" rm -rf "$workdir" mkdir "$workdir" cd "$workdir" @@ -246,7 +244,6 @@ import() continue fi if [ "$f" = "$spec" ]; then - git-update-index --add ${verbose:+--verbose} -- "$f" continue fi if [ "$f" = "$gear_rules" ]; then @@ -267,13 +264,100 @@ import() ;; *) printf 'copy: %s\n' "$f" >>"$gear_rules" - git-update-index --add ${verbose:+--verbose} -- "$f" ;; esac done + # Set list comps + printf '%s\n%s\n' "$spec" "$gear_rules" > "$compsfile" + awk '{print $2}' "$gear_rules" >> "$compsfile" + optimize_rules "$gear_rules" + # Branches for companents + if [ -n "$comp_branchs" ]; then + + rm -rf "$compsdir" + for f in $(cat "$compsfile"); do + local comp_name="$f" + + if [ "$f" = "$spec" ]; then + comp_name="spec" + elif [ "$f" = "$gear_rules" ]; then + comp_name="gear_rules" + fi + + local branch_comp="$branch_import-$comp_name" + + # Use own directory for companent. + mkdir "$compsdir" + cd "$compsdir" + + git-symbolic-ref HEAD "refs/heads/$branch_comp" + rm -f "$index_orig" + cp -al "$workdir/$f" ./ + + if [ -d "$f" ]; then + git-ls-files -z --others --modified -- "$f" | \ + git-update-index --add ${verbose:+--verbose} -z --stdin + elif [ -f "$f" ]; then + git-update-index --add ${verbose:+--verbose} -- "$f" + else + msg_info "$f: Non-regular file ignored." + continue + fi + + local message + message="$(printf '%s\n\n%s\n' "$comp_name for $verrel" "$changelog")" + TZ=UTC faketime -d "1970-01-01 $buildtime seconds" -- \ + git-commit -a -m "$message" ${author:+--author "$author"} && \ + ( verbose "Committed componet $comp_name into $branch_comp branch" ; + TZ=UTC faketime -d "1970-01-01 $buildtime seconds" -- \ + git-tag -a -m "$comp_name for $name $verrel" "$verrel-$comp_name" ) ||: + msg_info "Imported $comp_name for $srpm" + + printf '%s\n' $branch_comp >> $branchsfile + + cd "$workdir" + rm -rf "$compsdir" + done + + mkdir "$compsdir" + cd "$compsdir" + + git-symbolic-ref HEAD "refs/heads/$branch_import" + + local srpm_new + srpm_new="$(git-rev-parse --verify "$branch_import" 2>/dev/null ||:)" + + if [ -z "$srpm_new" ]; then + git-checkout -f "$branch_import-spec" + git-checkout -b "$branch_import" + else + git-checkout -f "$branch_import" + fi + + git-merge --no-commit -s ours compsimport HEAD $(cat "$branchsfile") ||: + msg_info "Merged all componets into $branch_import branch" + + cd "$workdir" + rm -rf "$compsdir" + fi + + for f in $(cat "$compsfile"); do + if [ -d "$f" ]; then + git-ls-files -z --others --modified -- "$f" | \ + git-update-index --add ${verbose:+--verbose} -z --stdin + continue + fi + if [ -L "$f" -o ! -f "$f" ]; then + msg_info "$f: Non-regular file ignored." + continue + fi + git-update-index --add ${verbose:+--verbose} -- "$f" + + done + local message message="$(printf '%s\n\n%s\n' "$verrel" "$changelog")" TZ=UTC faketime -d "1970-01-01 $buildtime seconds" -- \ @@ -284,11 +368,12 @@ import() msg_info "Imported $srpm" } -TEMP=`getopt -n $PROG -o h,q,v,V -l branch:,import-only,no-untar,rules:,spec-pattern:,stdin,help,quiet,verbose,version -- "$@"` || +TEMP=`getopt -n $PROG -o h,q,v,V -l branch:,comp-branchs,import-only,no-untar,rules:,spec-pattern:,stdin,help,quiet,verbose,version -- "$@"` || show_usage eval set -- "$TEMP" branch_import=srpms +comp_branchs= import_only= no_untar= read_from_stdin= @@ -299,6 +384,8 @@ while :; do ;; --branch) shift; branch_import="$1" ;; + --comp-branchs) comp_branchs=1 + ;; --import-only) import_only=1 ;; --no-untar) no_untar=1 @@ -350,6 +437,9 @@ saved_cwd="$(/bin/pwd)" tmpdir="$(mktemp -dt "$PROG.XXXXXXXX")" trap exit_handler HUP PIPE INT QUIT TERM EXIT workdir="$tmpdir/work" +compsdir="$tmpdir/compsdir" +compsfile="$tmpdir/list" +branchsfile="$tmpdir/branchslist" # Backup index file. [ ! -f "$index_orig" ] ||