Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2021 21:21:08 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 5cb183fe4369 - stable/12 - etcupdate: Add a revert mode to restore one or more stock files.
Message-ID:  <202106092121.159LL8o2051733@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=5cb183fe4369ca7170038d5333f297e9a60168d6

commit 5cb183fe4369ca7170038d5333f297e9a60168d6
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2021-04-20 20:22:35 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2021-06-09 21:19:19 +0000

    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 ba30215ae0efeb49e5e9ca2469d95edaea78680d)
---
 usr.sbin/etcupdate/etcupdate.8  | 24 ++++++++++++--------
 usr.sbin/etcupdate/etcupdate.sh | 49 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/usr.sbin/etcupdate/etcupdate.8 b/usr.sbin/etcupdate/etcupdate.8
index 4cc5d69eb195..c3d95b3261ef 100644
--- a/usr.sbin/etcupdate/etcupdate.8
+++ b/usr.sbin/etcupdate/etcupdate.8
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 29, 2015
+.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
@@ -879,14 +893,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
diff --git a/usr.sbin/etcupdate/etcupdate.sh b/usr.sbin/etcupdate/etcupdate.sh
index 28f6cbb42aff..aa7d12e80be6 100755
--- a/usr.sbin/etcupdate/etcupdate.sh
+++ b/usr.sbin/etcupdate/etcupdate.sh
@@ -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
 		;;
 	*)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106092121.159LL8o2051733>