[source] busybox: vi: backporting patches to fix ZZ and :x command

LEDE Commits lede-commits at lists.infradead.org
Fri Mar 24 22:18:59 PDT 2017


yousong pushed a commit to source.git, branch master:
https://git.lede-project.org/f3474ca130601a6c905cb2acbb8f4995a64b106c

commit f3474ca130601a6c905cb2acbb8f4995a64b106c
Author: Yousong Zhou <yszhou4tech at gmail.com>
AuthorDate: Sat Mar 25 12:16:36 2017 +0800

    busybox: vi: backporting patches to fix ZZ and :x command
    
    Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
---
 package/utils/busybox/Makefile                     |   2 +-
 ...t-touch-file-with-x-when-modified_count-0.patch | 100 +++++++++++++++++++++
 ...uching-a-new-file-with-ZZ-when-no-editing.patch |  53 +++++++++++
 3 files changed, 154 insertions(+), 1 deletion(-)

diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile
index 0937ef9..b75b455 100644
--- a/package/utils/busybox/Makefile
+++ b/package/utils/busybox/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=busybox
 PKG_VERSION:=1.26.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 PKG_FLAGS:=essential
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
diff --git a/package/utils/busybox/patches/401-vi-don-t-touch-file-with-x-when-modified_count-0.patch b/package/utils/busybox/patches/401-vi-don-t-touch-file-with-x-when-modified_count-0.patch
new file mode 100644
index 0000000..e83999d
--- /dev/null
+++ b/package/utils/busybox/patches/401-vi-don-t-touch-file-with-x-when-modified_count-0.patch
@@ -0,0 +1,100 @@
+From e88608eae24ae5934034e1ecb6c494fefbf1b9ae Mon Sep 17 00:00:00 2001
+From: Denys Vlasenko <vda.linux at googlemail.com>
+Date: Mon, 13 Mar 2017 20:50:42 +0100
+Subject: [PATCH 1/2] vi: don't touch file with :x when modified_count == 0
+
+Along with it, there are other changes
+
+ - Check for uppercase X is removed as the expression will be always false and
+   :X itself is another totally different command in standard vim
+ - The status line will show number of written lines instead of lines requested
+   by the colon command.  This is also how the standard vim is doing, though
+   the difference is that '!' has to be explicitly specified in vim to allow
+   partial writes
+
+Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
+Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
+---
+ editors/vi.c | 43 ++++++++++++++++++++++++++-----------------
+ 1 file changed, 26 insertions(+), 17 deletions(-)
+
+--- a/editors/vi.c
++++ b/editors/vi.c
+@@ -1038,7 +1038,9 @@ static void colon(char *buf)
+ 	 || strncmp(p, "wn", cnt) == 0
+ 	 || (p[0] == 'x' && !p[1])
+ 	) {
+-		cnt = file_write(current_filename, text, end - 1);
++		if (modified_count != 0 || p[0] != 'x') {
++			cnt = file_write(current_filename, text, end - 1);
++		}
+ 		if (cnt < 0) {
+ 			if (cnt == -1)
+ 				status_line_bold("Write error: %s", strerror(errno));
+@@ -1049,8 +1051,9 @@ static void colon(char *buf)
+ 				current_filename,
+ 				count_lines(text, end - 1), cnt
+ 			);
+-			if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n'
+-			 || p[0] == 'X' || p[1] == 'Q' || p[1] == 'N'
++			if (p[0] == 'x'
++			 || p[1] == 'q' || p[1] == 'n'
++			 || p[1] == 'Q' || p[1] == 'N'
+ 			) {
+ 				editing = 0;
+ 			}
+@@ -1480,16 +1483,19 @@ static void colon(char *buf)
+ 			goto ret;
+ 		}
+ #endif
+-		// how many lines in text[]?
+-		li = count_lines(q, r);
+-		size = r - q + 1;
+ 		//if (useforce) {
+ 			// if "fn" is not write-able, chmod u+w
+ 			// sprintf(syscmd, "chmod u+w %s", fn);
+ 			// system(syscmd);
+ 			// forced = TRUE;
+ 		//}
+-		l = file_write(fn, q, r);
++		if (modified_count != 0 || cmd[0] != 'x') {
++			size = r - q + 1;
++			l = file_write(fn, q, r);
++		} else {
++			size = 0;
++			l = 0;
++		}
+ 		//if (useforce && forced) {
+ 			// chmod u-w
+ 			// sprintf(syscmd, "chmod u-w %s", fn);
+@@ -1500,17 +1506,20 @@ static void colon(char *buf)
+ 			if (l == -1)
+ 				status_line_bold_errno(fn);
+ 		} else {
++			// how many lines written
++			li = count_lines(q, q + l - 1);
+ 			status_line("'%s' %dL, %dC", fn, li, l);
+-			if (q == text && r == end - 1 && l == size) {
+-				modified_count = 0;
+-				last_modified_count = -1;
+-			}
+-			if ((cmd[0] == 'x' || cmd[1] == 'q' || cmd[1] == 'n'
+-			    || cmd[0] == 'X' || cmd[1] == 'Q' || cmd[1] == 'N'
+-			    )
+-			 && l == size
+-			) {
+-				editing = 0;
++			if (l == size) {
++				if (q == text && q + l == end) {
++					modified_count = 0;
++					last_modified_count = -1;
++				}
++				if (cmd[0] == 'x'
++				 || cmd[1] == 'q' || cmd[1] == 'n'
++				 || cmd[1] == 'Q' || cmd[1] == 'N'
++				) {
++					editing = 0;
++				}
+ 			}
+ 		}
+ #if ENABLE_FEATURE_VI_YANKMARK
diff --git a/package/utils/busybox/patches/402-vi-avoid-touching-a-new-file-with-ZZ-when-no-editing.patch b/package/utils/busybox/patches/402-vi-avoid-touching-a-new-file-with-ZZ-when-no-editing.patch
new file mode 100644
index 0000000..b56cf73
--- /dev/null
+++ b/package/utils/busybox/patches/402-vi-avoid-touching-a-new-file-with-ZZ-when-no-editing.patch
@@ -0,0 +1,53 @@
+From 8f3bf4f0d3605b50a8e4c48c89aeabc455f04884 Mon Sep 17 00:00:00 2001
+From: Yousong Zhou <yszhou4tech at gmail.com>
+Date: Fri, 24 Mar 2017 21:13:10 +0100
+Subject: [PATCH 2/2] vi: avoid touching a new file with ZZ when no editing has
+ been done
+
+This is the behaviour observed with standard vim and busybox vi of at
+least 1.22.1.  It was changed with commit "32afd3a vi: some
+simplifications" which happened before 1.23.0.
+
+Mistyping filename on command line happens fairly often and it's better
+we restore the old behaviour to avoid a few unnecessary flash writes and
+sometimes efforts of debugging bugs caused by those unneeded stray
+files.
+
+Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
+Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
+---
+ editors/vi.c | 16 ++++++++--------
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+
+--- a/editors/vi.c
++++ b/editors/vi.c
+@@ -719,14 +719,6 @@ static int init_text_buffer(char *fn)
+ {
+ 	int rc;
+ 
+-	flush_undo_data();
+-	modified_count = 0;
+-	last_modified_count = -1;
+-#if ENABLE_FEATURE_VI_YANKMARK
+-	/* init the marks */
+-	memset(mark, 0, sizeof(mark));
+-#endif
+-
+ 	/* allocate/reallocate text buffer */
+ 	free(text);
+ 	text_size = 10240;
+@@ -741,6 +733,14 @@ static int init_text_buffer(char *fn)
+ 		// file doesnt exist. Start empty buf with dummy line
+ 		char_insert(text, '\n', NO_UNDO);
+ 	}
++
++	flush_undo_data();
++	modified_count = 0;
++	last_modified_count = -1;
++#if ENABLE_FEATURE_VI_YANKMARK
++	/* init the marks */
++	memset(mark, 0, sizeof(mark));
++#endif
+ 	return rc;
+ }
+ 



More information about the lede-commits mailing list