#! /bin/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 sync [-hqv]\n" if [ x$1 = x-h ] then printf $" Synchronize cache when working directory files have changed (e.g. by a VCS or manual editing) and those changes should not be picked up by quilt. Use 'patch -R' to unapply each applied patch from the working copy, use the result to replace the cache in the .pc folder, and then continue removing any other applied patches. Finish by reapplying any patches that had been applied. sync has the effect of 'ignoring' all changes that since the last refresh operation. sync is idempotent: running it multiple times will have no further effect. sync comes in particularly handy if you forget to pop all patches before modifications to quilt-tracked files because without sync a pop operation will fail. " exit 0 else exit 1 fi } list_patches() { local n patches patches=( $(applied_patches) ) for ((address@hidden; n>=0; n--)) do if [ -n "$number" ] then (( number-- > 0 )) || break fi [ "${patches[n]}" = "$stop_at_patch" ] && break echo "${patches[n]}" done } sync_patch() { local patch=$1 status=0 trap "status=1" SIGINT local patch=$1 local patch_file=$(patch_file_name "$patch") local workdir=$(gen_tempfile -d quilt) status=0 if [ -d "$QUILT_PC/$patch" ] then local prefix=$PWD/ if ! ( echo $(files_in_patch "$patch") | \ $QUILT_DIR/scripts/backup-files -B "$workdir/" -c -s -f - ) then printf $"Failed to copy files to temporary directory\n" >&2 rm -rf $workdir return 1 fi fi local failed if [ -s "$patch_file" ] then cat_file "$patch_file" \ | patch -R -d $workdir $QUILT_PATCH_OPTS \ $(patch_args "$patch") --no-backup-if-mismatch \ -f >/dev/null 2>/dev/null || failed=1 fi if [ -n "$failed" ] then printf $"Couldn't cleanly unapply patch $patch_file\n" \ "$(print_patch "$patch")" >&2 rm -rf $workdir return 1 fi printf $"Updating cache for $patch_file\n" local file for file in $(files_in_patch "$patch") do cp -f "$workdir/$file" "$QUILT_PC/$patch/" done rm -rf $workdir trap - SIGINT return $status } options=`getopt -o qvh -- "$@"` if [ $? -ne 0 ] then usage fi eval set -- "$options" while true do case "$1" in -q) opt_quiet=1 shift ;; -v) opt_verbose=1 shift ;; -h) usage -h ;; --) shift break ;; esac done # ALWAYS prompt for confirmation before rewriting history ... read -p " Ignore all modifications that haven't been staged with 'quilt refresh'? This will rewrite history for all currently applied patches. [n] " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] then : else exit 1 fi [ -n "$opt_quiet" ] && silent=-s [ -z "$opt_verbose" ] && silent_unless_verbose=-s top=$(top_patch) if ! patches=$(list_patches) 2>&1 then exit 1 elif [ -z "$patches" ] then printf $"No patches currently applied\n" >&2 exit 2 fi # We will update the list of applied patches, which in turn will disable the # consistency check. Enable it again if needed. if [ -z "$opt_all" -a ! "$DB" -nt "$SERIES" ] && ! consistency_check then rearm_check=1 fi for patch in $patches do if ! sync_patch "$patch" then exit 1 fi quilt pop -q >/dev/null 2>/dev/null done # reapply all patches for patch in $patches do quilt push -q >/dev/null 2>/dev/null done