1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-18 02:19:39 +00:00

etcupdate: Add a revert mode to restore one or more stock files.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D29846

(cherry picked from commit ba30215ae0)
This commit is contained in:
John Baldwin 2021-04-20 13:22:35 -07:00
parent 76a0f6f3bf
commit 960c954c55
2 changed files with 60 additions and 13 deletions

View File

@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd November 27, 2018
.Dd April 20, 2021
.Dt ETCUPDATE 8
.Os
.Sh NAME
@ -69,6 +69,12 @@
.Op Fl D Ar destdir
.Op Fl L Ar logfile
.Nm
.Cm revert
.Op Fl d Ar workdir
.Op Fl D Ar destdir
.Op Fl L Ar logfile
.Ar
.Nm
.Cm status
.Op Fl d Ar workdir
.Op Fl D Ar destdir
@ -342,6 +348,14 @@ tree and discard any local changes made to the file.
.It (h) help
Display the list of commands.
.El
.Ss Revert Mode
The
.Cm revert
mode is used to restore the stock versions of files.
In this mode,
.Nm
installs the stock version of requested files.
This mode cannot be used to restore directories, only individual files.
.Ss Status Mode
The
.Cm status
@ -880,14 +894,6 @@ For example, one can imagine a syntax along the lines of
.Pp
to resolve a specific conflict in an automated fashion.
.Pp
It might be nice to have something like a
.Sq revert
command to replace a locally modified version of a file with the stock
version of the file.
For example:
.Pp
.Dl "etcupdate revert /etc/mail/freebsd.cf"
.Pp
Bootstrapping
.Nm
often results in gratuitous diffs in

View File

@ -58,7 +58,6 @@
# TODO:
# - automatable conflict resolution
# - a 'revert' command to make a file "stock"
usage()
{
@ -72,6 +71,7 @@ usage: etcupdate [-npBF] [-d workdir] [-r | -s source | -t tarball]
etcupdate extract [-B] [-d workdir] [-s source | -t tarball] [-L logfile]
[-M options]
etcupdate resolve [-p] [-d workdir] [-D destdir] [-L logfile]
etcupdate revert [-d workdir] [-D destdir] [-L logfile] file ...
etcupdate status [-d workdir] [-D destdir]
EOF
exit 1
@ -1415,6 +1415,47 @@ resolve_cmd()
fi
}
# Restore files to the stock version. Only files with a local change
# are restored from the stock version.
revert_cmd()
{
local cmp file
if [ $# -eq 0 ]; then
usage
fi
for file; do
log "revert $file"
if ! [ -e $NEWTREE/$file ]; then
echo "File $file does not exist in the current tree."
exit 1
fi
if [ -d $NEWTREE/$file ]; then
echo "File $file is a directory."
exit 1
fi
compare $DESTDIR/$file $NEWTREE/$file
cmp=$?
if [ $cmp -eq $COMPARE_EQUAL ]; then
continue
fi
if update_unmodified $file; then
# If this file had a conflict, clean up the
# conflict.
if [ -e $CONFLICTS/$file ]; then
if ! rm $CONFLICTS/$file >&3 2>&1; then
echo "Failed to remove conflict " \
"for $file".
fi
fi
fi
done
}
# Report a summary of the previous merge. Specifically, list any
# remaining conflicts followed by any warnings from the previous
# update.
@ -1622,7 +1663,7 @@ EOF
command="update"
if [ $# -gt 0 ]; then
case "$1" in
build|diff|extract|status|resolve)
build|diff|extract|status|resolve|revert)
command="$1"
shift
;;
@ -1801,7 +1842,7 @@ case $command in
usage
fi
;;
build|diff|status)
build|diff|status|revert)
if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" -o \
-n "$preworld" ]; then
usage
@ -1835,7 +1876,7 @@ if ! mkdir -p $WORKDIR 2>/dev/null; then
fi
case $command in
diff|resolve|status)
diff|resolve|revert|status)
exec 3>>$LOGFILE
;;
*)