From: Alexander Bluhm Subject: Re: patch: add "-V none" To: tech@openbsd.org Date: Fri, 22 Mar 2024 13:31:11 +0100 On Thu, Mar 21, 2024 at 08:21:18AM -0500, joshua stein wrote: > This prevents patch from making backup files, like --posix but > without changing the filename selection. > > >From FreeBSD OK bluhm@ > Index: usr.bin/patch/backupfile.c > =================================================================== > RCS file: /cvs/src/usr.bin/patch/backupfile.c,v > retrieving revision 1.22 > diff -u -p -u -p -r1.22 backupfile.c > --- usr.bin/patch/backupfile.c 12 Oct 2020 13:58:27 -0000 1.22 > +++ usr.bin/patch/backupfile.c 21 Mar 2024 13:19:16 -0000 > @@ -220,11 +220,11 @@ invalid_arg(const char *kind, const char > } > > static const char *backup_args[] = { > - "never", "simple", "nil", "existing", "t", "numbered", 0 > + "none", "never", "simple", "nil", "existing", "t", "numbered", 0 > }; > > static enum backup_type backup_types[] = { > - simple, simple, numbered_existing, > + none, simple, simple, numbered_existing, > numbered_existing, numbered, numbered > }; > > Index: usr.bin/patch/patch.1 > =================================================================== > RCS file: /cvs/src/usr.bin/patch/patch.1,v > retrieving revision 1.36 > diff -u -p -u -p -r1.36 patch.1 > --- usr.bin/patch/patch.1 31 Mar 2022 17:27:26 -0000 1.36 > +++ usr.bin/patch/patch.1 21 Mar 2024 13:19:16 -0000 > @@ -37,7 +37,7 @@ > .Op Fl o Ar out-file > .Op Fl p Ar strip-count > .Op Fl r Ar rej-name > -.Op Fl V Cm t | nil | never > +.Op Fl V Cm t | nil | never | none > .Op Fl x Ar number > .Op Fl z Ar backup-ext > .Op Fl Fl posix > @@ -289,8 +289,8 @@ Forces > .Nm > to interpret the patch file as a unified context diff (a unidiff). > .It Xo > -.Fl V Cm t | nil | never , > -.Fl Fl version-control Cm t | nil | never > +.Fl V Cm t | nil | never | none , > +.Fl Fl version-control Cm t | nil | never | none > .Xc > Causes the next argument to be interpreted as a method for creating > backup file names. > @@ -321,6 +321,8 @@ Make numbered backups of files that alre > simple backups of the others. > .It Cm never , simple > Always make simple backups. > +.It Cm none > +Do not make backups. > .El > .It Fl v , Fl Fl version > Causes > Index: usr.bin/patch/patch.c > =================================================================== > RCS file: /cvs/src/usr.bin/patch/patch.c,v > retrieving revision 1.75 > diff -u -p -u -p -r1.75 patch.c > --- usr.bin/patch/patch.c 25 Oct 2023 20:05:43 -0000 1.75 > +++ usr.bin/patch/patch.c 21 Mar 2024 13:19:16 -0000 > @@ -109,6 +109,8 @@ static bool remove_empty_files = false; > /* true if -R was specified on command line. */ > static bool reverse_flag_specified = false; > > +static bool Vflag = false; > + > /* buffer holding the name of the rejected patch file. */ > static char rejname[PATH_MAX]; > > @@ -255,7 +257,7 @@ main(int argc, char *argv[]) > my_exit(2); > } > > - if (backup_type == none) { > + if (!Vflag) { > if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL) > v = getenv("VERSION_CONTROL"); > if (v != NULL || !posix) > @@ -641,6 +643,7 @@ get_some_switches(void) > break; > case 'V': > backup_type = get_version(optarg); > + Vflag = true; > break; > #ifdef DEBUGGING > case 'x': > @@ -677,8 +680,8 @@ usage(void) > fprintf(stderr, > "usage: patch [-bCcEeflNnRstuv] [-B backup-prefix] [-D symbol] [-d directory]\n" > " [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]\n" > -" [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n" > -" [--posix] [origfile [patchfile]]\n" > +" [-r rej-name] [-V t | nil | never | none] [-x number]\n" > +" [-z backup-ext] [--posix] [origfile [patchfile]]\n" > " patch my_exit(2); > }