From: NeilBrown Date: Sat, 3 Aug 2019 02:34:37 +0000 (+1000) Subject: Add --no-backup option X-Git-Tag: v1.2~8 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=d55ce20c7fa5301011396b6302c584b3680b2583;p=wiggle.git Add --no-backup option If --no-backup is given, the files are never renamed to "foo.porig", They are simply replaced. Requested-by: youssefsharief @ github.com Resolves-github-issue: #14 Signed-off-by: NeilBrown --- diff --git a/ReadMe.c b/ReadMe.c index c559a58..5ab6d88 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -58,6 +58,7 @@ struct option long_options[] = { {"no-ignore", 0, 0, 'i'}, {"show-wiggles",0, 0, 'W'}, {"ignore-blanks",0,0, 'b'}, + {"no-backup", 0, 0, NO_BACKUP }, {"self-test", 0, 0, SELF_TEST}, {"report-wiggles", 0, 0, REPORT_WIGGLES}, {0, 0, 0, 0} @@ -96,6 +97,7 @@ char Help[] = "\n" " --quiet -q : don't print un-necessary messages.\n" "\n" " --replace -r : replace first file with result of merger.\n" +" --no-backup : Never save original file (as name.porig).\n" "\n" " --strip= -p : number of path components to strip from file names.\n" "\n" diff --git a/vpatch.c b/vpatch.c index 2b9bd29..9929e23 100644 --- a/vpatch.c +++ b/vpatch.c @@ -1292,7 +1292,7 @@ static void *memdup(void *a, int len) } static int merge_window(struct plist *p, FILE *f, int reverse, int replace, - int selftest, int ignore_blanks, int just_diff) + int selftest, int ignore_blanks, int just_diff, int backup) { /* Display the merge window in one of the selectable modes, * starting with the 'merge' mode. @@ -1791,7 +1791,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, p->chunks = p->conflicts; save_merge(fm, fb, fa, ci.merger, p->outfile ? p->outfile : p->file, - p->outfile ? 0 : !p->is_merge); + backup && (p->outfile ? 0 : !p->is_merge)); } if (!just_diff) free(sm.body); @@ -2347,7 +2347,7 @@ static int show_merge(char *origname, FILE *patch, int reverse, int is_merge, char *before, char *after, int replace, char *outfile, int selftest, int ignore_blanks, - int just_diff) + int just_diff, int backup) { struct plist p = {0}; @@ -2366,7 +2366,7 @@ static int show_merge(char *origname, FILE *patch, int reverse, freopen("/dev/null","w",stderr); return merge_window(&p, patch, reverse, replace, selftest, - ignore_blanks, just_diff); + ignore_blanks, just_diff, backup); } static void calc_one(struct plist *pl, FILE *f, int reverse, @@ -2538,7 +2538,7 @@ static void draw_one(int row, struct plist *pl, FILE *f, int reverse, } static int save_one(FILE *f, struct plist *pl, int reverse, - int ignore_blanks) + int ignore_blanks, int backup) { struct stream sp, sa, sb, sm; struct file fa, fb, fm; @@ -2559,7 +2559,7 @@ static int save_one(FILE *f, struct plist *pl, int reverse, csl2 = diff_patch(fb, fa); ci = make_merger(fm, fb, fa, csl1, csl2, 0, 1, 0); return save_merge(fm, fb, fa, ci.merger, - pl->file, 1); + pl->file, backup); } static char *main_help[] = { @@ -2614,7 +2614,7 @@ static char *saveall_query[] = { NULL }; static void main_window(struct plist *pl, int *np, FILE *f, int reverse, - int replace, int ignore_blanks, int just_diff) + int replace, int ignore_blanks, int just_diff, int backup) { /* The main window lists all files together with summary information: * number of chunks, number of wiggles, number of conflicts. @@ -2790,9 +2790,11 @@ static void main_window(struct plist *pl, int *np, FILE *f, int reverse, } else { int c; if (pl[pos].is_merge) - c = merge_window(&pl[pos], NULL, reverse, 0, 0, ignore_blanks, just_diff); + c = merge_window(&pl[pos], NULL, reverse, 0, 0, + ignore_blanks, just_diff, backup); else - c = merge_window(&pl[pos], f, reverse, 0, 0, ignore_blanks, just_diff); + c = merge_window(&pl[pos], f, reverse, 0, 0, + ignore_blanks, just_diff, backup); refresh = 2; if (c) { pl[pos].is_merge = 1; @@ -2848,7 +2850,7 @@ static void main_window(struct plist *pl, int *np, FILE *f, int reverse, && !pl[i].is_merge) save_one(f, &pl[i], reverse, - ignore_blanks); + ignore_blanks, backup); } } else cnt = 0; @@ -2879,7 +2881,7 @@ static void main_window(struct plist *pl, int *np, FILE *f, int reverse, /* Already saved */ mesg = "File is already saved."; } else { - if (save_one(f, &pl[pos], reverse, ignore_blanks) == 0) { + if (save_one(f, &pl[pos], reverse, ignore_blanks, backup) == 0) { pl[pos].is_merge = 1; snprintf(mesg_buf, cols, "Saved file %s.", @@ -3014,7 +3016,7 @@ static void term_init(int doraw) int vpatch(int argc, char *argv[], int patch, int strip, int reverse, int replace, char *outfilename, - int selftest, int ignore_blanks) + int selftest, int ignore_blanks, int backup) { /* NOTE argv[0] is first arg... * Behaviour depends on number of args and 'patch'. @@ -3071,7 +3073,8 @@ int vpatch(int argc, char *argv[], int patch, int strip, fprintf(stderr, "%s: aborting\n", Cmd); exit(2); } - main_window(pl, &num_patches, in, reverse, replace, ignore_blanks, just_diff); + main_window(pl, &num_patches, in, reverse, replace, ignore_blanks, + just_diff, backup); plist_free(pl, num_patches); fclose(in); break; @@ -3089,7 +3092,8 @@ int vpatch(int argc, char *argv[], int patch, int strip, fprintf(stderr, "%s: aborting\n", Cmd); exit(2); } - main_window(pl, &num_patches, f, reverse, replace,ignore_blanks, just_diff); + main_window(pl, &num_patches, f, reverse, replace, + ignore_blanks, just_diff, backup); plist_free(pl, num_patches); } else if (strlen(argv[0]) > 4 && strcmp(argv[0]+strlen(argv[0])-4, ".rej") == 0) { @@ -3097,18 +3101,18 @@ int vpatch(int argc, char *argv[], int patch, int strip, origname[strlen(origname) - 4] = '\0'; show_merge(origname, f, reverse, 0, NULL, NULL, replace, outfilename, - selftest, ignore_blanks, just_diff); + selftest, ignore_blanks, just_diff, backup); } else show_merge(argv[0], f, reverse, 1, NULL, NULL, replace, outfilename, - selftest, ignore_blanks, just_diff); + selftest, ignore_blanks, just_diff, backup); break; case 2: /* an orig and a diff/.rej or two files */ if (just_diff) { show_merge(NULL, NULL, reverse, 0, argv[0], argv[1], replace, outfilename, - selftest, ignore_blanks, just_diff); + selftest, ignore_blanks, just_diff, backup); break; } f = fopen(argv[1], "r"); @@ -3119,12 +3123,12 @@ int vpatch(int argc, char *argv[], int patch, int strip, } show_merge(argv[0], f, reverse, 0, NULL, NULL, replace, outfilename, - selftest, ignore_blanks, just_diff); + selftest, ignore_blanks, just_diff, backup); break; case 3: /* orig, before, after */ show_merge(argv[0], NULL, reverse, 0, argv[1], argv[2], replace, outfilename, - selftest, ignore_blanks, just_diff); + selftest, ignore_blanks, just_diff, backup); break; } diff --git a/wiggle.1 b/wiggle.1 index 7437604..a87c542 100644 --- a/wiggle.1 +++ b/wiggle.1 @@ -3,6 +3,7 @@ .\" .\" Copyright (C) 2003 Neil Brown .\" Copyright (C) 2010-2013 Neil Brown +.\" Copyright (C) 2018-2019 Neil Brown .\" .\" .\" This program is free software; you can redistribute it and/or modify @@ -19,7 +20,7 @@ .\" along with this program. .\" .\" Author: Neil Brown -.\" Email: +.\" Email: .\" .TH WIGGLE 1 "" v1.1 .SH NAME @@ -211,6 +212,12 @@ mode, this instructs .I wiggle to always save the resulting merge when exiting. .TP +.B \-\-no-backup +Normally when an original file is replaced with the merged result, that +file is renamed to have a ".porig" extension, so that it is preserved. +If you don't want to keep the original, use this option to suppress +the backup. +.TP .BR \-o ", " \-\-output= Rather than writing the result to stdout or to replace the original file, this requests that the output be written to the given file. @@ -358,13 +365,15 @@ If the .B \-r flag is given, the output is written to a file which replaces the original given file. In this case the original file -is renamed to have a +will normally be renamed to have a .B .porig suffix (for "patched original" which makes sense if you first use .I patch to apply a patch, and then use .I wiggle -to wiggle the rejects in). +to wiggle the rejects in). This can be suppressed with the +.B \-\-no\-backup +uption. .P Further if the .B -o diff --git a/wiggle.c b/wiggle.c index 4289573..140b292 100644 --- a/wiggle.c +++ b/wiggle.c @@ -664,6 +664,7 @@ int main(int argc, char *argv[]) int mode = 0; int obj = 0; int replace = 0; + int backup = 1; int which = 0; int ispatch = 0; int reverse = 0; @@ -745,6 +746,9 @@ int main(int argc, char *argv[]) case 'r': replace = 1; continue; + case NO_BACKUP: + backup = 0; + continue; case 'o': outfile = optarg; replace = 1; @@ -802,7 +806,7 @@ int main(int argc, char *argv[]) if (mode == 'B') { vpatch(argc-optind, argv+optind, ispatch, strip, reverse, replace, outfile, selftest, - ignore_blanks); + ignore_blanks, backup); /* should not return */ exit(1); } diff --git a/wiggle.h b/wiggle.h index 6b967f3..0de65b2 100644 --- a/wiggle.h +++ b/wiggle.h @@ -191,7 +191,7 @@ extern int do_trace; extern int vpatch(int argc, char *argv[], int patch, int strip, int reverse, int replace, char *outfile, int selftest, - int ignore_blanks); + int ignore_blanks, int backup); extern char *Cmd; extern char Version[]; @@ -200,6 +200,7 @@ extern struct option long_options[]; enum other_options { SELF_TEST = 300, REPORT_WIGGLES = 301, + NO_BACKUP, }; extern char Usage[]; extern char Help[];