]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
Inserts git log instead of %changelog
[packages/rpm-build-tools.git] / builder.sh
index bbb8ec054497c780df477dc5fe85ce4d65d4ef98..d6595afaf2398daa7bea41b90834d01355964f20 100755 (executable)
@@ -55,7 +55,6 @@ QUIET=""
 CLEAN=""
 DEBUG=""
 NOURLS=""
-NOCVS=""
 NOCVSSPEC=""
 NODIST=""
 NOINIT=""
@@ -115,6 +114,8 @@ CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
 CVS_SERVER="cvs.pld-linux.org"
 CVSTAG=""
 GIT_SERVER="git://github.com/draenog"
+HEAD_DETACHED=""
+DEPTH=""
 
 RES_FILE=""
 
@@ -221,13 +222,6 @@ if [ -d $HOME/rpm/SOURCES ]; then
        exit 1
 fi
 
-#
-# are we using cvs-nserver ?
-#
-CVS_NSERVER=0
-$CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
-[ $? -eq 0 ] && CVS_NSERVER=1
-
 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
 
@@ -255,7 +249,7 @@ usage() {
        echo "\
 Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
-[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
+[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [--depth <number>]
 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
@@ -295,6 +289,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
                     - setup \$CVSROOT,
 --define <macro> <value>
                     - define a macro <macro> with value <value>,
+--depth <number>
+                                       - make shallow fetch
 --alt_kernel <kernel>
                     - same as --define 'alt_kernel <kernel>'
 --nodeps            - rpm won't check any dependences
@@ -305,7 +301,6 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 --ftp, --http       - use ftp or http protocol to access distfiles server
 -l <logfile>, --logtofile <logfile>
                     - log all to file,
--nc, --no-cvs       - don't download sources from CVS, if source URL is given,
 -ncs, --no-cvs-specs
                     - don't check specs in CVS
 -nd, --no-distfiles - don't download from distfiles
@@ -397,6 +392,31 @@ tempfile() {
        mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
 }
 
+# inserts git log instead of %changelog
+# outputs name of modified file created by tempfile
+insert_gitlog() {
+       local SPECFILE=$1 specfile=$(tempfile) gitlog=$(tempfile) speclog=$(tempfile) 
+
+       # allow this being customized
+       local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
+
+       # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
+       # otherwise i'd use --date=iso here
+       # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
+       # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c#l31
+       # NOTE: changelog date is always in UTC for rpmbuild
+       # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
+       git log -${log_entries:-20} --format=format:"* %ad %an <%ae> %h%n%s%n" --date=raw > $gitlog
+       gawk '/^\* /{printf("* %s %s\n", strftime("%a %b %d %Y", $2), substr($0, length($1)+length($2)+length($3)+4)); next}{print}' $gitlog > $speclog
+       sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
+                       a%changelog
+                       r $speclog
+               }
+       " > $specfile
+       rm -f $gitlog $speclog
+       echo $specfile
+}
+
 # change dependency to specname
 # common changes:
 # - perl(Package::Name) -> perl-Package-Name
@@ -688,7 +708,7 @@ Exit_error() {
                        echo >&2 "Error: conditions reject building this spec (${2})."
                        exit 12 ;;
                "err_not_implemented" )
-                       remov_build_requires
+                       remove_build_requires
                        echo >&2 "Error: functionality not yet imlemented"
                        exit 110 ;;
        esac
@@ -721,6 +741,8 @@ init_builder() {
                REPO_DIR="."
                PACKAGE_DIR="."
        fi
+       export GIT_WORK_TREE=$PACKAGE_DIR
+       export GIT_DIR=$PACKAGE_DIR/.git
 
        __PWD=$(pwd)
 }
@@ -741,21 +763,37 @@ get_spec() {
        fi
 
        if [ "$NOCVSSPEC" != "yes" ]; then
-               if [ -d "$ASSUMED_NAME/.git" ]; then
-                       GIT_DIR=$PACKAGE_DIR/.git git pull  || Exit_error err_no_spec_in_repo
-               elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
-                       if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
-                               echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
-                               exit 101
+               if [ -z "$DEPTH" ]; then
+                       if [ -d "$ASSUMED_NAME/.git" ]; then
+                               git fetch origin || Exit_error err_no_spec_in_repo
+                       elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
+                               if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
+                                       echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
+                                       exit 101
+                               fi
+                               Exit_error err_not_implemented
+                       else
+                               (
+                                       unset GIT_WORK_TREE
+                                       git clone  ${GIT_SERVER}/${ASSUMED_NAME}.git || {
+                                               # softfail if new package, i.e not yet added to cvs
+                                               [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
+                                               echo "Warning: package not in CVS - assuming new package"
+                                               NOCVSSPEC="yes"
+                                       }
+                               )
                        fi
-                       Exit_error err_not_implemented
                else
-                       git clone  ${GIT_SERVER}/${ASSUMED_NAME}.git || {
-                               # softfail if new package, i.e not yet added to cvs
-                               [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
-                               echo "Warning: package not in CVS - assuming new package"
-                               NOCVSSPEC="yes"
-                               NOCVS="yes"
+                       if [ ! -d "$ASSUMED_NAME/.git" ]; then
+                               if [ ! -d "$ASSUMED_NAME" ]; then
+                                       mkdir $ASSUMED_NAME
+                               fi
+                               git init
+                               git remote add origin ${GIT_SERVER}/${ASSUMED_NAME}.git
+                       fi
+                       git fetch "$DEPTH" origin ${CVSTAG}:remotes/origin/${CVSTAG} || {
+                               echo >&2 "Error: branch $CVSTAG does not exist"
+                               exit 3
                        }
                fi
 
@@ -781,7 +819,12 @@ get_spec() {
        fi
 
        if [ -n "$CVSTAG" ]; then
-               GIT_WORK_TREE=$PACKAGE_DIR GIT_DIR=$PACKAGE_DIR/.git git checkout "$CVSTAG" || exit
+               git checkout "$CVSTAG" -- 2>/dev/null || git checkout -t "origin/$CVSTAG" > /dev/null || exit
+               git symbolic-ref -q HEAD > /dev/null &&
+                       git merge '@{u}'
+               if [ -n "$CVSDATE" ]; then
+                       git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
+               fi
        fi
 
        if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
@@ -839,13 +882,8 @@ src_md5() {
        local md5
 
        if [ -f additional-md5sums ]; then
-               local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
-               if [ -z "$spec_rev" ]; then
-                       spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
-               fi
-               local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
                md5=$(grep -s -v '^#' additional-md5sums | \
-               grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
+               grep -E "[      ]$(basename "$1")([     ,]|\$)" | \
                sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
                grep -E '^[0-9a-f]{32}$')
 
@@ -1019,11 +1057,6 @@ get_files() {
        if [ $# -gt 0 ]; then
                cd "$PACKAGE_DIR"
 
-               if [ ! -s .git -a "$NOCVS" != "yes" ]; then
-                       echo "Warning: No git access defined for SOURCES"
-                       NOCVS="yes"
-               fi
-
                local nc=0
                local get_files_cvs=""
                for i in "$@"; do
@@ -1391,10 +1424,11 @@ build_package() {
                        echo "LASTLOG=$LOG" > $LASTLOG_FILE
                fi
                RES_FILE=$(tempfile)
+               local specfile=$(insert_gitlog $SPECFILE)
 
-               (time eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
+               (time eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specfile; echo $? > $RES_FILE) 2>&1 |tee $LOG
                RETVAL=`cat $RES_FILE`
-               rm $RES_FILE
+               rm $RES_FILE $specfile
                if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
                        if [ "$RETVAL" -eq "0" ]; then
                                mv $LOG $LOGDIROK
@@ -1957,7 +1991,6 @@ while [ $# -gt 0 ]; do
                -a5 | --add-md5 )
                        COMMAND="update_md5"
                        NODIST="yes"
-                       NOCVS="yes"
                        NOCVSSPEC="yes"
                        ADD5="yes"
                        shift ;;
@@ -1997,6 +2030,10 @@ while [ $# -gt 0 ]; do
                        CVS_FORCE="-f"; shift;;
                -d | --cvsroot )
                        shift; CVSROOT="${1}"; shift ;;
+               --depth )
+                       DEPTH="--depth=$2"
+                       shift 2
+                       ;;
                -g | --get )
                        COMMAND="get"; shift ;;
                -h | --help )
@@ -2021,8 +2058,6 @@ while [ $# -gt 0 ]; do
                        SKIP_EXISTING_FILES="yes"; shift ;;
                -m | --mr-proper )
                        COMMAND="mr-proper"; shift ;;
-               -nc | --no-cvs )
-                       NOCVS="yes"; shift ;;
                -ncs | --no-cvs-specs )
                        NOCVSSPEC="yes"; shift ;;
                -nd | --no-distfiles )
@@ -2036,7 +2071,6 @@ while [ $# -gt 0 ]; do
                -ns0 | --no-source0 )
                        NOSOURCE0="yes"; shift ;;
                -nn | --no-net )
-                       NOCVS="yes"
                        NOCVSSPEC="yes"
                        NODIST="yes"
                        NOMIRRORS="yes"
@@ -2089,14 +2123,16 @@ while [ $# -gt 0 ]; do
                -q | --quiet )
                        QUIET="--quiet"; shift ;;
                --date )
-                       CVSDATE="${2}"; shift 2 ;;
+                       CVSDATE="${2}"; shift 2
+                       date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
+                       ;;
                -r | --cvstag )
                        CVSTAG="$2"
                        shift 2
                        ;;
                -A)
                        shift
-                       CVSTAG="HEAD"
+                       CVSTAG="master"
                        ;;
                -R | --fetch-build-requires)
                        FETCH_BUILD_REQUIRES="yes"
@@ -2232,15 +2268,20 @@ while [ $# -gt 0 ]; do
        esac
 done
 
-[ -d "$ASSUMED_NAME" ] && CVS_ENTRIES="$ASSUMED_NAME/CVS/Entries" || CVS_ENTRIES="CVS/Entries"
-if [ -f "$CVS_ENTRIES" ] && [ -z "$CVSTAG" ]; then
-       CVSTAG=$(awk -vSPECFILE=$(basename $SPECFILE) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' ${CVS_ENTRIES})
-       if [ "$CVSTAG" ]; then
-               echo >&2 "builder: Sticky tag $CVSTAG active. Use -r TAGNAME to override."
+[ -d "$ASSUMED_NAME" ] && GIT_DIR="$ASSUMED_NAME/.git" || GIT_DIR=.git
+if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ]; then
+       if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
+               CVSTAG=${CVSTAG#refs/heads/}
+               if [ "$CVSTAG" != "master" ]; then
+                       echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
+               fi
+       else
+               echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
+               HEAD_DETACHED="yes"
        fi
 elif [ "$CVSTAG" = "HEAD" ]; then
        # assume -r HEAD is same as -A
-       CVSTAG=""
+       CVSTAG="master"
 fi
 
 if [ "$CVSTAG" ]; then
@@ -2351,17 +2392,14 @@ case "$COMMAND" in
                if [ -n "$TEST_TAG" ]; then
                        local TAGVER=`make_tagver`
                        echo "Searching for tag $TAGVER..."
-                       TAGREL=$($CVS_COMMAND status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
-                       if [ -n "$TAGREL" ]; then
-                               Exit_error err_tag_exists "$TAGVER" "$TAGREL"
-                       fi
+                       git show-ref --quiet --verify "refs/tags/$TAGVER" && Exit_error err_tag_exists "$TAGVER" "$TAGREL"
 
                        # - do not allow to build from HEAD when XX-branch exists
                        TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
                        if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
                                TAG_BRANCH="${TREE_PREFIX}-branch"
-                               TAG_STATUS=$($CVS_COMMAND status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
-                               if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
+                               TAG_STATUS=$(git branch -r | grep -i "origin/$TAG_BRANCH$" | sed 's# *origin/##')
+                               if [ -n "$TAG_STATUS" -a -z "$CVSTAG" ]; then
                                        Exit_error err_branch_exists "$TAG_STATUS"
                                fi
                        fi
This page took 0.069659 seconds and 4 git commands to generate.