From 44812f68dbdf116253416aac1cc1077d9ca2ded8 Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Sun, 31 Dec 2006 00:24:48 -0500 Subject: [PATCH] Ignore empty/commented series lines Signed-off-by: Josef 'Jeff' Sipek --- Documentation/TODO | 1 - gq-delete | 4 +- gq-header | 4 +- gq-new | 4 +- gq-next | 4 +- gq-pop | 4 +- gq-push | 6 +-- gq-series | 2 +- gq-unapplied | 2 +- gq.lib | 10 +++++ regression/050-series.sh | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 133 insertions(+), 15 deletions(-) create mode 100755 regression/050-series.sh diff --git a/Documentation/TODO b/Documentation/TODO index 7fab837..5f668a8 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -36,4 +36,3 @@ Here are some things I want to do one of these days... - Grab the From: line out of the patch and use that as author string - gq-delete should allow the user to delete the patch file as well - Make sh a requirement, not bash -- Ignore empty & "commented out" lines in series file diff --git a/gq-delete b/gq-delete index cffa3df..5e3f9c0 100755 --- a/gq-delete +++ b/gq-delete @@ -12,10 +12,10 @@ if [ -z "$patch" ]; then exit 1 fi -p=`cat "$applied" | grep -e "^$patch\$"` +p=`grep -e "^$patch\$" < "$applied"` if [ ! -z "$p" ] ; then echo "Cannot delete an applied patch" exit 1 fi -ex -s -c ":%g/^foobar$/d|:wq" "$series" +ex -s -c ":%g/^$patch\$/d|:wq" "$series" diff --git a/gq-header b/gq-header index c267cae..8784797 100755 --- a/gq-header +++ b/gq-header @@ -18,7 +18,7 @@ if [ -z "$patch" ]; then else # use the specified patch - eidx=`cat $series | grep -ne "^$patch\$" | cut -d: -f1` + eidx=`get_series | grep -ne "^$patch\$" | cut -d: -f1` if [ $eidx -eq 0 ]; then echo "Patch $patch is not in the series" exit 1 @@ -26,7 +26,7 @@ else fi idx=0 -for p in `cat $series`; do +for p in `get_series`; do idx=`expr $idx + 1` [ $idx -lt $eidx ] && continue [ $idx -gt $eidx ] && break diff --git a/gq-new b/gq-new index c54473d..8f7eea2 100755 --- a/gq-new +++ b/gq-new @@ -28,7 +28,9 @@ top=`get_top` if [ ! -z "$top" ]; then sed -i -e "s,^$top\$,$top\n$patch," $series else - echo $patch >> $series + echo "$patch" > $series.tmp + cat $series >> $series.tmp + mv $series.tmp $series fi # apply the patch diff --git a/gq-next b/gq-next index 57ac49c..381f9c4 100755 --- a/gq-next +++ b/gq-next @@ -5,8 +5,8 @@ source "`dirname $0`/gq.lib" -n=`wc -l < $GQ_DIR/$branch/status` +n=`wc -l < $applied` n=`expr $n + 1` -awk "{ if (NR == $n) print \$0}" < $GQ_DIR/$branch/series +get_series | awk "{ if (NR == $n) print \$0}" diff --git a/gq-pop b/gq-pop index 0f67c21..9a5f6c3 100755 --- a/gq-pop +++ b/gq-pop @@ -40,8 +40,8 @@ if ! must_commit_first; then exit 1 fi -idx=`wc -l < $series` -for p in `cat $series | tac`; do +idx=`get_series | wc -l` +for p in `get_series | tac`; do idx=`expr $idx - 1` [ $idx -gt $sidx ] && continue [ $idx -lt $eidx ] && break diff --git a/gq-push b/gq-push index 485520f..00c261f 100755 --- a/gq-push +++ b/gq-push @@ -11,7 +11,7 @@ if [ "$patch" = "--all" -o "$patch" = "-a" ]; then # we are supposed to push all patches, get the last one out of # series - eidx=`wc -l < $series` + eidx=`get_series | wc -l` if [ $eidx -eq 0 ]; then echo "There are no patches to push" exit 1 @@ -25,7 +25,7 @@ else # we're supposed to push only up to a patch, make sure the patch is # in the series - eidx=`cat $series | grep -ne "^$patch\$" | cut -d: -f1` + eidx=`get_series | grep -ne "^$patch\$" | cut -d: -f1` if [ $eidx -eq 0 ]; then echo "Patch $patch is not in the series" exit 1 @@ -44,7 +44,7 @@ sidx=`expr $sidx + 1` bail=0 idx=0 -for p in `cat $series`; do +for p in `get_series`; do idx=`expr $idx + 1` [ $idx -lt $sidx ] && continue [ $idx -gt $eidx ] && break diff --git a/gq-series b/gq-series index 112fee6..8465eef 100755 --- a/gq-series +++ b/gq-series @@ -5,4 +5,4 @@ source "`dirname $0`/gq.lib" -cat $series +get_series diff --git a/gq-unapplied b/gq-unapplied index 9f24f57..4d69eeb 100755 --- a/gq-unapplied +++ b/gq-unapplied @@ -9,7 +9,7 @@ n=`wc -l < $applied` n=`expr $n + 1` idx=0 -for p in `cat $series`; do +for p in `get_series`; do idx=`expr $idx + 1` [ $idx -lt $n ] && continue diff --git a/gq.lib b/gq.lib index 5becf98..7093959 100644 --- a/gq.lib +++ b/gq.lib @@ -63,6 +63,16 @@ function get_prev done } +function get_series +{ + # ignore all lines matching: + # - empty lines + # - whitespace only + # - optional whitespace followed by '#' followed by more + # optional whitespace + grep -ve '^[[:space:]]*\(#.*\)*$' < $series +} + # usage: index_update_magic function index_update_magic { diff --git a/regression/050-series.sh b/regression/050-series.sh new file mode 100755 index 0000000..58d49ac --- /dev/null +++ b/regression/050-series.sh @@ -0,0 +1,107 @@ +# +# Test the series parsing code +# + +source scaffold + +function prepare_for_tests +{ + # set up the repo so we have something interesting to run gq on + echo "abc" > def + git-add def + git-commit -s -m "initial" 2> /dev/null > /dev/null + + # patch to modify a file + cat << DONE > .git/patches/master/modify +diff --git a/def b/def +index 8baef1b..7d69c2f 100644 +--- a/def ++++ b/def +@@ -1 +1,2 @@ + abc ++asjhfksad +DONE + + # patch to add a new file + cat << DONE > .git/patches/master/add +diff --git a/abd b/abd +new file mode 100644 +index 0000000..489450e +--- /dev/null ++++ b/abd +@@ -0,0 +1 @@ ++qweert +DONE + + # patch to remove an existing file + cat << DONE > .git/patches/master/remove +diff --git a/abd b/abd +deleted file mode 100644 +index 489450e..0000000 +--- a/abd ++++ /dev/null +@@ -1 +0,0 @@ +-qweert +DONE + + # patch to change a mode + cat << DONE > .git/patches/master/mode +diff --git a/def b/def +old mode 100644 +new mode 100755 +DONE + + # the series file of all the things + cat << DONE > .git/patches/master/series +# + +# +# foo +# + + # + # + # some text + # some text +modify +add + +remove +mode +#sure +DONE +} + +function expected_series +{ + echo "modify" + echo "add" + echo "remove" + echo "mode" +} + +# the test itself +empty_repo +cd $REPODIR +gq-init + +prepare_for_tests + +# NOTE: this has to be in the same order as the series file +tests="empty modify add remove mode" + +for t in $tests +do + [ "$t" != "empty" ] && gq-push > /dev/null + + gq-series > /tmp/reg.$$ + + expected_series | diff -u - /tmp/reg.$$ + + echo -n "[$t] " +done + +rm -f /tmp/reg.$$ + +complete_test + -- 2.11.4.GIT