Module Name:    src
Committed By:   martin
Date:           Fri Feb 26 13:32:14 UTC 2021

Modified Files:
        src/usr.bin/patch [netbsd-8]: backupfile.c backupfile.h patch.c

Log Message:
Pull up following revision(s) (requested by nia in ticket #1660):

        usr.bin/patch/backupfile.c: revision 1.16
        usr.bin/patch/backupfile.h: revision 1.7
        usr.bin/patch/patch.c: revision 1.30

patch: make '-V none' work in the expected way

Internally the code confuses the concept of "the user doesn't want
a backup file" and "the user hasn't defined a type of backup file".

Introduce a new "undefined" backup type to serve the purpose "none"
previously did, and make "none" not generate backup files, as expected.

http://mail-index.netbsd.org/tech-userlevel/2021/02/19/msg012901.html

XXX pullup?


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.15.16.1 src/usr.bin/patch/backupfile.c
cvs rdiff -u -r1.6 -r1.6.52.1 src/usr.bin/patch/backupfile.h
cvs rdiff -u -r1.29 -r1.29.34.1 src/usr.bin/patch/patch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/patch/backupfile.c
diff -u src/usr.bin/patch/backupfile.c:1.15 src/usr.bin/patch/backupfile.c:1.15.16.1
--- src/usr.bin/patch/backupfile.c:1.15	Fri Apr 11 17:30:03 2014
+++ src/usr.bin/patch/backupfile.c	Fri Feb 26 13:32:14 2021
@@ -1,7 +1,7 @@
 /*
  * $OpenBSD: backupfile.c,v 1.19 2006/03/11 19:41:30 otto Exp $
  * $DragonFly: src/usr.bin/patch/backupfile.c,v 1.5 2008/08/11 00:05:06 joerg Exp $
- * $NetBSD: backupfile.c,v 1.15 2014/04/11 17:30:03 christos Exp $
+ * $NetBSD: backupfile.c,v 1.15.16.1 2021/02/26 13:32:14 martin Exp $
  */
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: backupfile.c,v 1.15 2014/04/11 17:30:03 christos Exp $");
+__RCSID("$NetBSD: backupfile.c,v 1.15.16.1 2021/02/26 13:32:14 martin Exp $");
 
 #include <ctype.h>
 #include <dirent.h>
@@ -38,7 +38,7 @@ __RCSID("$NetBSD: backupfile.c,v 1.15 20
 #define ISDIGIT(c) (isascii ((unsigned char)c) && isdigit ((unsigned char)c))
 
 /* Which type of backup file names are generated. */
-enum backup_type backup_type = none;
+enum backup_type backup_type = undefined;
 
 /*
  * The extension added to file names to produce a simple (as opposed to

Index: src/usr.bin/patch/backupfile.h
diff -u src/usr.bin/patch/backupfile.h:1.6 src/usr.bin/patch/backupfile.h:1.6.52.1
--- src/usr.bin/patch/backupfile.h:1.6	Fri Sep 19 18:33:34 2008
+++ src/usr.bin/patch/backupfile.h	Fri Feb 26 13:32:14 2021
@@ -1,7 +1,7 @@
 /*
  * $OpenBSD: backupfile.h,v 1.6 2003/07/28 18:35:36 otto Exp $
  * $DragonFly: src/usr.bin/patch/backupfile.h,v 1.3 2007/09/29 23:11:10 swildner Exp $
- * $NetBSD: backupfile.h,v 1.6 2008/09/19 18:33:34 joerg Exp $
+ * $NetBSD: backupfile.h,v 1.6.52.1 2021/02/26 13:32:14 martin Exp $
  */
 
 /*
@@ -19,6 +19,8 @@
 
 /* When to make backup files. */
 enum backup_type {
+	undefined,
+
 	/* Never make backups. */
 	none,
 

Index: src/usr.bin/patch/patch.c
diff -u src/usr.bin/patch/patch.c:1.29 src/usr.bin/patch/patch.c:1.29.34.1
--- src/usr.bin/patch/patch.c:1.29	Tue Sep  6 18:25:14 2011
+++ src/usr.bin/patch/patch.c	Fri Feb 26 13:32:14 2021
@@ -1,7 +1,7 @@
 /*
  * $OpenBSD: patch.c,v 1.45 2007/04/18 21:52:24 sobrado Exp $
  * $DragonFly: src/usr.bin/patch/patch.c,v 1.10 2008/08/10 23:39:56 joerg Exp $
- * $NetBSD: patch.c,v 1.29 2011/09/06 18:25:14 joerg Exp $
+ * $NetBSD: patch.c,v 1.29.34.1 2021/02/26 13:32:14 martin Exp $
  */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: patch.c,v 1.29 2011/09/06 18:25:14 joerg Exp $");
+__RCSID("$NetBSD: patch.c,v 1.29.34.1 2021/02/26 13:32:14 martin Exp $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -197,17 +197,18 @@ main(int argc, char *argv[])
 	else
 		simple_backup_suffix = ORIGEXT;
 
+	if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL)
+		v = getenv("VERSION_CONTROL");
+	if (v != NULL)
+		backup_type = get_version(v);
+
 	/* parse switches */
 	Argc = argc;
 	Argv = argv;
 	get_some_switches();
 
-	if (backup_type == none) {
-		if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL)
-			v = getenv("VERSION_CONTROL");
-		if (v != NULL || !posix)
-			backup_type = get_version(v);	/* OK to pass NULL. */
-	}
+	if (backup_type == undefined)
+		backup_type = posix ? none : numbered_existing;
 
 	/* make sure we clean up /tmp in case of disaster */
 	set_signals(0);
@@ -493,7 +494,7 @@ get_some_switches(void)
 	while ((ch = getopt_long(Argc, Argv, options, longopts, NULL)) != -1) {
 		switch (ch) {
 		case 'b':
-			if (backup_type == none)
+			if (backup_type == undefined)
 				backup_type = numbered_existing;
 			if (optarg == NULL)
 				break;

Reply via email to