summaryrefslogblamecommitdiffstats
path: root/quilt/patches.in
blob: fe95300940d21478e5ed126bfab879e464a43ea7 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
         









                                                                      
                                               
            
                                                                          

                      
                                     



       
                                                    

                        
                         


                                                                       
 

                                           





                      
              
 

                                        

                   
                         
          
                                                              
                    
                                                                             



                  



                                                                          


                               
                                  
                                            
                
                        

                                             


                                            

                             


          

                
                                              




                                                 



                                                   

                                           
                                                                             
                  


            
                                             













                             












                                                  











                           
                    
 
                


                        


                      
    


                    
  
 

                                   

           

                                                         
                  




                                                                 



                      
#! @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 $QUILT_DIR/scripts/patchfns ]
	then
		echo "Cannot read library $QUILT_DIR/scripts/patchfns" >&2
		exit 1
	fi
	. $QUILT_DIR/scripts/patchfns
fi

usage()
{
	printf $"Usage: quilt patches [-v] {file}\n"
	if [ x$1 = x-h ]
	then
		printf $"
Print the list of patches that modify the specified file. (Uses a
heuristic to determine which files are modified by unapplied patches.
Note that this heuristic is much slower than scanning applied patches.)

-v	Verbose, more user friendly output.
"
		exit 0
	else
		exit 1
	fi
}

scan_applied()
{
	local color=$1 prefix=$2 file=$3
	shift 3
	local patch

	for patch in "$@"
	do
		if [ -f "$(backup_file_name $patch "$file")" ]
		then
			echo "$color$prefix$(print_patch $patch)$color_clear"
		fi
	done
}

# Note that we can only guess which files a patch touches because of the
# complicated heuristics that patch uses (see "Multiple Patches in a File"
# in the diff info pages).

touched_by_patch()
{
	local strip=$1 patch=$2
	[ $strip = ab ] && strip=1
	cat_file $(patch_file_name $patch) \
	|  awk '
	/^\+\+\+[ \t]/ {
		sub(/^(\+\+\+|---)[ \t]/, "")
		sub(/[ \t][^ \t]*$/, "")
		sub(/^\/dev\/null/, "")
		for (i=0; i<'$strip'; i++)
			sub(/^[^\/]*\//, "")
		if ($0 != "")
			print
	}'
}

scan_unapplied()
{
	local color=$1 prefix=$2 file=$3 strip
	shift 2
	local file_bre="$(quote_bre $file)" patch

	for patch in "$@"
	do
		strip=$(patch_strip_level $patch)
		[ "$strip" = ab ] && strip=1

		if touched_by_patch $strip $patch \
		   | grep -q "^$file_bre\$"
		then
			echo "$color$prefix$(print_patch $patch)$color_clear"
		fi
	done
}

options=`getopt -o vh --long color:: -- "$@"`

if [ $? -ne 0 ]
then
	usage
fi

eval set -- "$options"

while true
do
	case "$1" in
	-v)
		opt_verbose=1
		shift ;;
	--color)
		case "$2" in
		"" | always)
			opt_color=1 ;;
		auto | tty)
			opt_color=
			[ -t 1 ] && opt_color=1 ;;
		never)
			opt_color= ;;
		*)
			usage ;;
		esac
		shift 2 ;;
	-h)
		usage -h ;;
	--)
		shift
		break ;;
	esac
done

if [ $# -ne 1 ]
then
	usage
fi
opt_file="$SUBDIR$1"

top=$(top_patch)

if [ -n "$opt_verbose" ]
then
	applied="+ "
	current="= "
	unapplied="  "
else
	applied=""
	current=""
	unapplied=""
fi

[ -n "$opt_color" ] && setup_colors

setup_pager

scan_applied "$color_series_app" "$applied" "$opt_file" \
	$(patches_before $top)
[ -n "$top" ] && \
	scan_applied "$color_series_top" "$current" "$opt_file" \
		$top
scan_unapplied "$color_series_una" "$unapplied" "$opt_file" \
	$(patches_after $top)

### Local Variables:
### mode: shell-script
### End:
# vim:filetype=sh