Here's a cleaned-up version.

-- Andreas.
Index: bash_completion
===================================================================
RCS file: /cvsroot/quilt/quilt/bash_completion,v
retrieving revision 1.19
diff -u -r1.19 bash_completion
--- bash_completion	26 Aug 2005 10:20:48 -0000	1.19
+++ bash_completion	11 Sep 2005 10:57:51 -0000
@@ -132,8 +132,15 @@
 	   esac
 	   ;;
 	annotate)
-	   _quilt_comfile 
-	   COMPREPLY=( [EMAIL PROTECTED]:-} $( compgen -W "-h" -- $cur ) )
+	   case $prev in
+	     -p)
+ 	        COMPREPLY=( $( compgen -W "$(quilt applied)" -- $cur ) )
+		;;
+	     *)
+	        _quilt_comfile
+	        COMPREPLY=( [EMAIL PROTECTED]:-} $( compgen -W "-p -h" -- $cur ) )
+	        ;;
+	   esac
 	   ;;
 	applied) 
 	   COMPREPLY=( $( compgen -W "-h $(quilt applied)" -- $cur ) )
Index: quilt/annotate.in
===================================================================
RCS file: /cvsroot/quilt/quilt/quilt/annotate.in,v
retrieving revision 1.5
diff -u -r1.5 annotate.in
--- quilt/annotate.in	18 Jul 2005 10:18:13 -0000	1.5
+++ quilt/annotate.in	11 Sep 2005 10:57:53 -0000
@@ -19,12 +19,15 @@
 
 usage()
 {
-	printf $"Usage: quilt annotate {file}\n"
+	printf $"Usage: quilt [-p patch] annotate {file}\n"
 	if [ x$1 = x-h ]
 	then
 		printf $"
 Print an annotated listing of the specified file showing which
-patches modify which lines.
+patches modify which lines. Only applied patches are included.
+
+-p	Stop checking for changes at the specified rather than the
+	topmost patch.
 "
 		exit 0
 	else
@@ -34,24 +37,16 @@
 
 empty_file()
 {
-	local patch=$1 file=$2
-	local backup_file=$(backup_file_name $patch $file)
-	[ -s "$backup_file" ] \
-	&& sed -e 's:.*::' "$backup_file"
+	local file=$1
+	[ -s "$file" ] \
+	&& sed -e 's:.*::' "$file"
 }
 
 annotation_for()
 {
-	local patch=$1 next_patch=$2 file=$3 annotation=$4
-	local old_file=$(backup_file_name $patch "$file") new_file
+	local old_file=$1 new_file=$2 annotation=$3
 	[ -s "$old_file" ] || old_file=/dev/null
-        if [ -z "$next_patch" ]
-        then
-                new_file="$file"
-        else
-                new_file="$(backup_file_name $next_patch $file)"
-		[ -s "$new_file" ] || new_file=/dev/null
-        fi
+	[ -s "$new_file" ] || new_file=/dev/null
 	@DIFF@ -Ne "$old_file" "$new_file" \
 	| @PERL@ -e '
 	while (<>) {
@@ -89,7 +84,7 @@
 	exec 4<&-
 }
 
-options=`getopt -o h -- "$@"`
+options=`getopt -o p:h -- "$@"`
 
 if [ $? -ne 0 ]
 then
@@ -101,6 +96,13 @@
 while true
 do
 	case "$1" in
+	-p)
+		if ! opt_patch=$(find_patch $2)
+		then
+			printf $"Patch %s is not in series\n" "$2" >&2
+			exit 1
+		fi
+		shift 2 ;;
 	-h)
 		usage -h ;;
 	--)
@@ -115,16 +117,38 @@
 fi
 opt_file="$SUBDIR$1"
 
-for patch in $(cat_series); do
-	if [ -f "$(backup_file_name $patch "$opt_file")" ]
+if [ -n "$opt_patch" ] && ! is_applied "$opt_patch"
+then
+	printf $"Patch %s is not applied\n" \
+	       "$(print_patch $opt_patch)" >&2
+	exit 1
+fi
+
+for patch in $(applied_patches); do
+	old_file="$(backup_file_name $patch "$opt_file")"
+	if [ -f "$old_file" ]
 	then
 		[EMAIL PROTECTED]"$patch"
+		[EMAIL PROTECTED]"$old_file"
+	fi
+	if [ "$opt_patch" = $patch ]
+	then
+		# We also need to know the next patch, if any
+		next_patch="$(next_patch_for_file "$opt_patch" "$opt_file")"
+		break
 	fi
 done
 
+if [ -z "$next_patch" ]
+then
+	[EMAIL PROTECTED]"$opt_file"
+else
+	[EMAIL PROTECTED]"$(backup_file_name $next_patch "$opt_file")"
+fi
+
 if [ [EMAIL PROTECTED] = 0 ]
 then
-	sed -e 's:^:'$'\t'':' "$opt_file"
+	sed -e 's:^:'$'\t'':' "[EMAIL PROTECTED]"
 	exit 0
 fi
 
@@ -145,19 +169,18 @@
 # Finally, the annotations listing is merged with the source file line
 # by line.
 
-empty_file ${patches[0]} "$opt_file" > $template
+empty_file ${files[0]} > $template
 for ((n = 0; n < [EMAIL PROTECTED]; n++))
 do
-	annotation_for "${patches[$n]}" "${patches[$((n+1))]}" "$opt_file" \
-		       $((n+1))
+	annotation_for "${files[n]}" "${files[n+1]}" $((n+1))
 done \
 | @PATCH@ $template
-merge_files $template "$opt_file"
+merge_files $template "[EMAIL PROTECTED]"
 
 echo
 for ((n = 0; n < [EMAIL PROTECTED]; n++))
 do
-	echo "$((n+1))"$'\t'"$(print_patch ${patches[$n]})"
+	echo "$((n+1))"$'\t'"$(print_patch ${patches[n]})"
 done
 
 ### Local Variables:
Index: test/annotate.test
===================================================================
RCS file: /cvsroot/quilt/quilt/test/annotate.test,v
retrieving revision 1.3
diff -u -r1.3 annotate.test
--- test/annotate.test	9 Sep 2005 18:27:51 -0000	1.3
+++ test/annotate.test	11 Sep 2005 10:57:53 -0000
@@ -62,6 +62,29 @@
 	> 2	patches/patch2
 	> 3	patches/patch3
 
+	$ quilt annotate -p patch3 foo
+	>	foo
+	> 2	baz
+	>
+	> 1	patches/patch
+	> 2	patches/patch2
+	> 3	patches/patch3
+
+	$ quilt annotate -p patch2 foo
+	>	foo
+	> 1	Bar
+	> 2	baz
+	>
+	> 1	patches/patch
+	> 2	patches/patch2
+
+	$ quilt annotate -p patch foo
+	>	foo
+	> 1	Bar
+	> 1	Baz
+	>
+	> 1	patches/patch
+
 	$ quilt new patch4
 	> Patch patches/patch4 is now on top
 
_______________________________________________
Quilt-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/quilt-dev

Reply via email to