#!/bin/csh -f # diffreviewmv # ----------------------------------------------------------------------------- # Shell script to compare the specified 1st and 2nd file, invoking windiff # if there are diffs to allow the user to reconcile the diffs, and then # moving the 2nd file to the 1st if they're now identical, or prompting to # delete if not identical. # Note: This differs from diffreviewdel in that it uses mv to move the # identical 2nd file back to the 1st file instead of deleting the # 2nd file. In cases where the 2nd file was moved from the 1st # file just before creating a new version of the 1st file, this # means the 1st file ends up with an unchanged timestamp, which is # sometimes desirable since the overall process didn't actually # change its contents. # ----------------------------------------------------------------------------- # Usage: See Usage section below or run with -h or --help to see usage. # Assumptions: # Effects: # - Compares file # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ----------------------------------------------------------------------------- # Prevent wildcard and command line pattern expansion because there may # be a regular expression in the --ignore-matching-lines value. We want to # avoid "No match." errors when the shell tries to expand it into filenames. # Also, we really do want the regular expression to get passed to diff. set noglob # Collect command line options set option_quick = "false" set option_interactive = "false" set diff_cmd = "diff" set diffreview_cmd = "diffreview" while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options] newfile oldfile" echo "Options:" echo " -h = Show this help text" echo " --help = Show this help text" echo " -I pattern = Ignore diff of lines containing pattern" echo " --ignore-matching-lines pattern" echo " = Ignore diff of lines containing pattern" echo " -i = Interactive. Allow the user to view and" echo " resolve diffs" echo " -q = Quick. Skip the interactive review of diffs" echo " and delete the old file without prompting." echo " Overrides -i option." exit 1 else if ("$1" == "-I" || "$1" == "--ignore-matching-lines") then shift if ("$1" == "") then echo "Error: Missing argument to -I or --ignore-matching-lines option" $0 --help exit 1 else set diff_cmd = "$diff_cmd --ignore-matching-lines $1" set diffreview_cmd = "$diffreview_cmd --ignore-matching-lines $1" shift endif else if ("$1" == "-i") then shift if ("$option_quick" == "true") then echo "${0:t}: Option -i overridden by option -q" else set option_interactive = "true" endif else if ("$1" == "-q") then shift set option_quick = "true" if ("$option_interactive" == "true") then echo "${0:t}: Option -i overridden by option -q" endif set option_interactive = "false" else if ("-" == "`echo $1:q | cut -c 1`") then echo "Error: Invalid option: $1:q" $0 --help exit 1 else # Not a recognized option. Assume it's the first argument break endif end # Collect command line arguments if ($#argv < 2) then $0 --help exit 1 else if (! -e $1:q) then echo "Error: File $1:q does not exist." exit 1 else if (! -r $1:q) then echo "Error: File $1:q is not readable." exit 1 else if (! -e $2:q) then echo "Error: File $2:q does not exist." exit 1 else if (! -r $2:q) then echo "Error: File $2:q is not readable." exit 1 endif if ("$option_interactive" == "true") then set diffreview_cmd = "$diffreview_cmd -i" endif set diffreview_status = 0 if ("$option_quick" == "false") then $diffreview_cmd -q $1:q $2:q set diffreview_status = $status endif # If the files now match, move the old file back to the new file name, # else prompt to delete. # Note: Don't use --ignore-matching-lines here. Or we'll discard # the newly generated file when only diff is version number. diff $1:q $2:q >& /dev/null if ($status) then # There are diffs, but are they more than just the version number? $diff_cmd $1:q $2:q >& /dev/null if ($status) then # There are real diffs. Show them, unless the user has already # seen them. if ("$option_quick" == "false") then if ($diffreview_status == 3) then # Nothing to do. User has already seen changes. else echo "File $1 still has changes:" $diff_cmd $1:q $2:q | less endif rm -iv $2:q else echo "File $1 has changed. Accepting changes..." if ($diffreview_status == 3) then # Nothing to do. User has already seen changes. else $diff_cmd $1:q $2:q endif rm $2:q endif else # There are only diffs in version number. Delete the old one. rm $2:q endif else # There are no diffs. Move the old one back to the new one to avoid # updating the timestamp of the new one. mv $2:q $1:q endif