]> 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 7713c5ec490dc9f2a98f4fc3beaf8d69c436b7ca..d6595afaf2398daa7bea41b90834d01355964f20 100755 (executable)
@@ -115,6 +115,7 @@ CVS_SERVER="cvs.pld-linux.org"
 CVSTAG=""
 GIT_SERVER="git://github.com/draenog"
 HEAD_DETACHED=""
+DEPTH=""
 
 RES_FILE=""
 
@@ -248,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]
@@ -288,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
@@ -389,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
@@ -735,24 +763,38 @@ get_spec() {
        fi
 
        if [ "$NOCVSSPEC" != "yes" ]; 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
+               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
-                       (
-                               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"
-                               }
-                       )
+                       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
 
                cvsignore_df .gitignore
@@ -777,7 +819,7 @@ get_spec() {
        fi
 
        if [ -n "$CVSTAG" ]; then
-               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
@@ -840,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}$')
 
@@ -1387,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
@@ -1930,7 +1968,9 @@ mr_proper() {
 
        # remove spec and sources
        $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $SPECFILE
-       rm -rf $PACKAGE_DIR/.git
+       rm -rf $PACKAGE_DIR/.git .gitignore
+       cd $__PWD
+       rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
 }
 
 #---------------------------------------------
@@ -1990,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 )
This page took 0.048082 seconds and 4 git commands to generate.