#!/bin/sh
-SPECFILE="$1"
-SPECFILE="${SPECFILE%%/*}"
-SPECFILE="$(basename $SPECFILE .spec)"
-SPEC="$SPECFILE/$SPECFILE.spec"
+SPEC=$(basename "$1" .spec).spec
+PACKAGE=$(basename "$SPEC" .spec)
+TOPDIR=$(rpm -E %_topdir)
+PACKAGEDIR=$TOPDIR/$PACKAGE
+SPECFILE="$TOPDIR/$PACKAGE/$SPEC"
CLEANBUILDDIR="$HOME/PLD"
+CIVIM=$PWD/civim
-if [ $# -ne 1 -o ! -d "$SPECFILE" -o ! -f "$SPEC" ]; then
+if [ $# -ne 1 -o ! -d "$PACKAGEDIR" -o ! -f "$SPECFILE" ]; then
echo "spec file missing"
exit 1
fi
+if [ ! -x "$CIVIM" ]; then
+ echo "civim missing"
+ exit 1
+fi
+
diffcol()
{
# vim like diff colourization
' "$@"
}
-cvs -z9 diff -u $SPECFILE | diffcol
+pause()
+{
+ echo "$*"
+ echo -n "[Press ENTER to continue, ^C to abort] "
+ read ans
+}
+
+cd $PACKAGEDIR
-echo -n "Proceed ? "
-read ans
+git diff --color=auto $SPEC
-if [ "$ans" != "y" ]; then
- exit
-fi
+pause "Proceed ?"
-sed '/^# AUTO: /d' -i "$SPEC"
-SIMPLE_DIFF="$(cvs -z9 diff "$SPEC")"
+sed '/^# AUTO: /d' -i "$SPECFILE"
+SIMPLE_DIFF="$(cd $PACKAGEDIR && git diff "$SPEC")"
-./adapter "$SPEC"
+./adapter "$SPECFILE"
-diff="$(cvs -z9 diff -u $SPEC)"
+diff=$(git diff $SPEC)
+git diff --color=auto $SPEC
-echo "$diff" | diffcol
+ver=$(echo "$diff" | awk '
+ /^\+Version/ { ver = $2 }
+ /^\+%define[ \t]+[_a-zA-Z0-9]*ver/ { ver = $3 }
+ END { print ver }
+')
+rel=$(echo "$diff" | awk '
+ /^\+Release/ { rel = $2 }
+ /^\+%define[ \t]+_?rel/ { rel = $3 }
+ END { print rel }
+')
-add=$(echo "$diff" | awk '/^\+BuildRequires/ { add[ $2 ] = 1; }; /^-BuildRequires/ { del[ $2 ] = 1; };
+add=$(echo "$diff" | awk '
+ function s( n ) { sub(/}/,"",n); return n; }
+ /^\+(%{[a-zA-Z0-9_]+:)?BuildRequires/ { add[ s( $2 ) ] = 1; };
+ /^-(%{[a-zA-Z0-9_]+:)?BuildRequires/ { del[ s( $2 ) ] = 1; };
END { for ( n in add ) { if ( !del[ n ] ) print n; } }' |
- perl -p -e 'chomp; push @a, $_; undef $_; END { print join ", ", sort @a }')
+ perl -p -e 'chomp; push @a, $_; undef $_; END { print join ", ", sort @a }
+')
-del=$(echo "$diff" | awk '/^\+BuildRequires/ { add[ $2 ] = 1; }; /^-BuildRequires/ { del[ $2 ] = 1; };
+del=$(echo "$diff" | awk '
+ function s( n ) { sub(/}/,"",n); return n; }
+ /^\+(%{[a-zA-Z0-9_]+:)?BuildRequires/ { add[ s( $2 ) ] = 1; };
+ /^-(%{[a-zA-Z0-9_]+:)?BuildRequires/ { del[ s( $2 ) ] = 1; };
END { for ( n in del ) { if ( !add[ n ] ) print n; } }' |
- perl -p -e 'chomp; push @a, $_; undef $_; END { print join ", ", sort @a }')
+ perl -p -e 'chomp; push @a, $_; undef $_; END { print join ", ", sort @a }
+')
n="$(echo -e '\nn')"
n="${n%%n}"
msg=""
+[ -n "$ver" ] && msg="$msg- updated to: $ver$n"
+[ -n "$rel" ] && msg="$msg- release: $rel$n"
[ -n "$add" ] && msg="$msg- BR: $add$n"
[ -n "$del" ] && msg="$msg- dropped BR: $del$n"
echo
echo "Message:"
echo "$msg"
-echo -n "Commit ? "
-read ans
-if [ "$ans" != "y" ]; then
- exit
-fi
+pause "Commit ?"
export COMMIT_MESSAGE="$msg"
export COMMIT_PACKAGES="$SPECFILE"
-export VISUAL="$PWD/civim"
-cvs -z9 ci "$SPECFILE"
+export VISUAL="$CIVIM"
+git ci "$SPECFILE"
-[ -n "$CLEANBUILDDIR" ] && rm -f $CLEANBUILDDIR/installed/$SPECFILE
+[ -n "$CLEANBUILDDIR" ] && rm -f $CLEANBUILDDIR/installed/$SPEC