etcupdate: Add a revert mode to restore one or more stock files.
Reviewed by: imp MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D29846
This commit is contained in:
parent
ada7fd17d5
commit
ba30215ae0
@ -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
|
||||
|
@ -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
|
||||
;;
|
||||
*)
|
||||
|
Loading…
Reference in New Issue
Block a user