summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2005-06-18 13:15:57 +0000
committerAndreas Gruenbacher <agruen@suse.de>2005-06-18 13:15:57 +0000
commit442b3debff33d2d0f13214abf42bd53525557ff9 (patch)
tree051bcb979e039725eb44262d8ab857d7a8e8361c
parent0eb29c356d79095bf000ad2584f69435dfba3043 (diff)
downloadquilt-442b3debff33d2d0f13214abf42bd53525557ff9.tar.gz
- Add new annotate command.
-rw-r--r--Makefile.in6
-rw-r--r--TODO2
-rw-r--r--quilt.changes5
-rw-r--r--quilt/.cvsignore1
-rw-r--r--quilt/annotate.in145
-rw-r--r--quilt/patches.in14
-rw-r--r--test/annotate.test63
7 files changed, 226 insertions, 10 deletions
diff --git a/Makefile.in b/Makefile.in
index e9ca301..d174f0a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -56,9 +56,9 @@ BIN := $(BIN_IN)
SRC += $(BIN_SRC:%=bin/%)
DIRT += $(BIN_IN:%=bin/%)
-QUILT_IN := add applied delete diff edit files fold fork graph grep \
- import mail new next patches pop previous push refresh remove \
- rename series setup snapshot top unapplied upgrade
+QUILT_IN := add annotate applied delete diff edit files fold fork graph \
+ grep import mail new next patches pop previous push refresh \
+ remove rename series setup snapshot top unapplied upgrade
QUILT_SRC := $(QUILT_IN:%=%.in)
QUILT := $(QUILT_IN)
diff --git a/TODO b/TODO
index 2f446cd..81ec8b6 100644
--- a/TODO
+++ b/TODO
@@ -72,6 +72,8 @@ quilt refresh:
- Remove existing diffstat if --diffstat is not specified?
+ - Improve whitespace stripping
+
quilt import:
- Add option to replace the currently applied patch with a new
diff --git a/quilt.changes b/quilt.changes
index 92bd847..9e851e8 100644
--- a/quilt.changes
+++ b/quilt.changes
@@ -1,4 +1,9 @@
-------------------------------------------------------------------
+Sat Jun 18 15:03:13 CEST 2005 - agruen@suse.de
+
+- Add new annotate command.
+
+-------------------------------------------------------------------
Thu Jun 16 13:18:33 CEST 2005 - agruen@suse.de
- rpm build: add missing files to file list; remove percent-prep
diff --git a/quilt/.cvsignore b/quilt/.cvsignore
index ba968c8..235cf3b 100644
--- a/quilt/.cvsignore
+++ b/quilt/.cvsignore
@@ -1,4 +1,5 @@
add
+annotate
applied
delete
diff
diff --git a/quilt/annotate.in b/quilt/annotate.in
new file mode 100644
index 0000000..7bdd844
--- /dev/null
+++ b/quilt/annotate.in
@@ -0,0 +1,145 @@
+#! @BASH@
+
+# This script is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# See the COPYING and AUTHORS files for more details.
+
+# Read in library functions
+if [ "$(type -t patch_file_name)" != function ]
+then
+ if ! [ -r @SCRIPTS@/patchfns ]
+ then
+ echo "Cannot read library @SCRIPTS@/patchfns" >&2
+ exit 1
+ fi
+ . @SCRIPTS@/patchfns
+fi
+
+usage()
+{
+ printf $"Usage: quilt annotate {file}\n"
+ if [ x$1 = x-h ]
+ then
+ printf $"
+Print an annotated listing of the specified file showing which
+patches modify which lines.
+"
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+empty_file()
+{
+ local patch=$1 file=$2
+ sed -e 's:.*::' $(backup_file_name $patch $file)
+}
+
+annotation_for()
+{
+ local patch=$1 next_patch=$2 file=$3 annotation=$4 new_file
+ if [ -z "$next_patch" ]
+ then
+ new_file="$file"
+ else
+ new_file="$(backup_file_name $next_patch $file)"
+ fi
+ @DIFF@ -e "$(backup_file_name $patch "$file")" "$new_file" \
+ | @PERL@ -e '
+ while (<>) {
+ if (/^\d+(?:,\d+)?[ac]$/) {
+ print;
+ while (<>) {
+ last if /^\.$/;
+ print "'"$annotation"'\n";
+ }
+ print;
+ next;
+ }
+ print;
+ }
+ '
+}
+
+merge_files()
+{
+ local a b saved_IFS="$IFS"
+
+ exec 3< "$1"
+ exec 4< "$2"
+ IFS=
+ while read -r a <&3
+ do
+ read -r b <&4
+ echo "$a"$'\t'"$b"
+ done
+ IFS="$saved_IFS"
+ exec 3<&-
+ exec 4<&-
+}
+
+options=`getopt -o h -- "$@"`
+
+if [ $? -ne 0 ]
+then
+ usage
+fi
+
+eval set -- "$options"
+
+while true
+do
+ case "$1" in
+ -h)
+ usage -h ;;
+ --)
+ shift
+ break ;;
+ esac
+done
+
+if [ $# -ne 1 ]
+then
+ usage
+fi
+opt_file="$SUBDIR$1"
+
+for patch in $(cat_series); do
+ if [ -f "$(backup_file_name $patch "$opt_file")" ]
+ then
+ patches[${#patches[@]}]="$patch"
+ fi
+done
+
+if [ ${#patches[@]} = 0 ]
+then
+ sed -e 's:^:'$'\t'':' "$opt_file"
+ exit 0
+fi
+
+template=$(gen_tempfile)
+apatch=$(gen_tempfile)
+
+trap "rm -f $template $apatch" EXIT
+
+empty_file ${patches[0]} "$opt_file" > $template
+for ((n = 0; n < ${#patches[@]}; n++))
+do
+ annotation_for "${patches[$n]}" "${patches[$((n+1))]}" "$opt_file" $((n+1))
+done \
+| @PATCH@ $template
+merge_files $template "$opt_file"
+
+echo
+for ((n = 0; n < ${#patches[@]}; n++))
+do
+ echo "$((n+1))"$'\t'"$(print_patch ${patches[$n]})"
+done
+
+### Local Variables:
+### mode: shell-script
+### End:
+# vim:filetype=sh
diff --git a/quilt/patches.in b/quilt/patches.in
index 9f680b6..1ecc77a 100644
--- a/quilt/patches.in
+++ b/quilt/patches.in
@@ -37,13 +37,13 @@ Note that this heuristic is much slower than scanning applied patches.)
scan_applied()
{
- local prefix=$1 file=$SUBDIR$2
+ local prefix=$1 file=$2
shift 2
local patch
for patch in "$@"
do
- if [ -f "$QUILT_PC/$patch/$file" ]
+ if [ -f "$(backup_file_name $patch "$file")" ]
then
echo "$prefix$(print_patch $patch)"
fi
@@ -52,7 +52,7 @@ scan_applied()
scan_unapplied()
{
- local prefix=$1 file=$SUBDIR$2
+ local prefix=$1 file=$2
shift 2
local file_bre="$(quote_bre $file)" patch
@@ -93,7 +93,7 @@ if [ $# -ne 1 ]
then
usage
fi
-opt_file=$1
+opt_file="$SUBDIR$1"
top=$(top_patch)
@@ -108,10 +108,10 @@ else
unapplied=""
fi
-scan_applied "$applied" $opt_file $(patches_before $top)
+scan_applied "$applied" "$opt_file" $(patches_before $top)
[ -n "$top" ] && \
- scan_applied "$current" $opt_file $top
-scan_unapplied "$unapplied" $opt_file $(patches_after $top)
+ scan_applied "$current" "$opt_file" $top
+scan_unapplied "$unapplied" "$opt_file" $(patches_after $top)
### Local Variables:
### mode: shell-script
### End:
diff --git a/test/annotate.test b/test/annotate.test
new file mode 100644
index 0000000..4f6def8
--- /dev/null
+++ b/test/annotate.test
@@ -0,0 +1,63 @@
+ $ mkdir d
+ $ cd d
+
+ $ cat > foo
+ < foo
+ < bar
+ < baz
+
+ $ quilt new patch
+ > Patch patches/patch is now on top
+
+ $ quilt add foo
+ > File foo added to patch patches/patch
+
+ $ sed -ie 's:b:B:' foo
+ $ quilt refresh
+ > Refreshed patch patches/patch
+
+ $ quilt annotate foo
+ > foo
+ > 1 Bar
+ > 1 Baz
+ >
+ > 1 patches/patch
+
+ $ quilt new patch2
+ > Patch patches/patch2 is now on top
+
+ $ quilt add foo
+ > File foo added to patch patches/patch2
+
+ $ sed -ie 's:Baz:baz:' foo
+ $ quilt refresh
+ > Refreshed patch patches/patch2
+
+ $ quilt annotate foo
+ > foo
+ > 1 Bar
+ > 2 baz
+ >
+ > 1 patches/patch
+ > 2 patches/patch2
+
+ $ quilt new patch3
+ > Patch patches/patch3 is now on top
+
+ $ quilt add foo
+ > File foo added to patch patches/patch3
+
+ $ sed -ie '/Bar/d' foo
+ $ quilt refresh
+ > Refreshed patch patches/patch3
+
+ $ quilt annotate foo
+ > foo
+ > 2 baz
+ >
+ > 1 patches/patch
+ > 2 patches/patch2
+ > 3 patches/patch3
+
+ $ cd ..
+ $ rm -rf d