Merge #10664 from janlazo/vim-8.1.1780

vim-patch:8.1.{1374,1780}
This commit is contained in:
Justin M. Keyes 2019-08-02 06:01:46 +02:00 committed by GitHub
commit b92a5bc3c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4807,13 +4807,12 @@ buf_check_timestamp(
char_u *path; char_u *path;
char *mesg = NULL; char *mesg = NULL;
char *mesg2 = ""; char *mesg2 = "";
int helpmesg = FALSE; bool helpmesg = false;
int reload = FALSE; bool reload = false;
int can_reload = FALSE; bool can_reload = false;
uint64_t orig_size = buf->b_orig_size; uint64_t orig_size = buf->b_orig_size;
int orig_mode = buf->b_orig_mode; int orig_mode = buf->b_orig_mode;
static int busy = FALSE; static bool busy = false;
int n;
char_u *s; char_u *s;
char *reason; char *reason;
@ -4838,16 +4837,16 @@ buf_check_timestamp(
&& buf->b_mtime != 0 && buf->b_mtime != 0
&& (!(file_info_ok = os_fileinfo((char *)buf->b_ffname, &file_info)) && (!(file_info_ok = os_fileinfo((char *)buf->b_ffname, &file_info))
|| time_differs(file_info.stat.st_mtim.tv_sec, buf->b_mtime) || time_differs(file_info.stat.st_mtim.tv_sec, buf->b_mtime)
|| (int)file_info.stat.st_mode != buf->b_orig_mode || (int)file_info.stat.st_mode != buf->b_orig_mode)) {
)) { const long prev_b_mtime = buf->b_mtime;
retval = 1; retval = 1;
// set b_mtime to stop further warnings (e.g., when executing // set b_mtime to stop further warnings (e.g., when executing
// FileChangedShell autocmd) // FileChangedShell autocmd)
if (!file_info_ok) { if (!file_info_ok) {
// When 'autoread' is set we'll check the file again to see if it // Check the file again later to see if it re-appears.
// re-appears. buf->b_mtime = -1;
buf->b_mtime = buf->b_p_ar;
buf->b_orig_size = 0; buf->b_orig_size = 0;
buf->b_orig_mode = 0; buf->b_orig_mode = 0;
} else { } else {
@ -4856,28 +4855,25 @@ buf_check_timestamp(
/* Don't do anything for a directory. Might contain the file /* Don't do anything for a directory. Might contain the file
* explorer. */ * explorer. */
if (os_isdir(buf->b_fname)) if (os_isdir(buf->b_fname)) {
; } else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar)
&& !bufIsChanged(buf) && file_info_ok) {
/* // If 'autoread' is set, the buffer has no changes and the file still
* If 'autoread' is set, the buffer has no changes and the file still // exists, reload the buffer. Use the buffer-local option value if it
* exists, reload the buffer. Use the buffer-local option value if it // was set, the global option value otherwise.
* was set, the global option value otherwise. reload = true;
*/ } else {
else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) if (!file_info_ok) {
&& !bufIsChanged(buf) && file_info_ok)
reload = TRUE;
else {
if (!file_info_ok)
reason = "deleted"; reason = "deleted";
else if (bufIsChanged(buf)) } else if (bufIsChanged(buf)) {
reason = "conflict"; reason = "conflict";
else if (orig_size != buf->b_orig_size || buf_contents_changed(buf)) } else if (orig_size != buf->b_orig_size || buf_contents_changed(buf)) {
reason = "changed"; reason = "changed";
else if (orig_mode != buf->b_orig_mode) } else if (orig_mode != buf->b_orig_mode) {
reason = "mode"; reason = "mode";
else } else {
reason = "time"; reason = "time";
}
// Only give the warning if there are no FileChangedShell // Only give the warning if there are no FileChangedShell
// autocommands. // autocommands.
@ -4886,7 +4882,7 @@ buf_check_timestamp(
set_vim_var_string(VV_FCS_REASON, reason, -1); set_vim_var_string(VV_FCS_REASON, reason, -1);
set_vim_var_string(VV_FCS_CHOICE, "", -1); set_vim_var_string(VV_FCS_CHOICE, "", -1);
allbuf_lock++; allbuf_lock++;
n = apply_autocmds(EVENT_FILECHANGEDSHELL, bool n = apply_autocmds(EVENT_FILECHANGEDSHELL,
buf->b_fname, buf->b_fname, false, buf); buf->b_fname, buf->b_fname, false, buf);
allbuf_lock--; allbuf_lock--;
busy = false; busy = false;
@ -4895,25 +4891,28 @@ buf_check_timestamp(
EMSG(_("E246: FileChangedShell autocommand deleted buffer")); EMSG(_("E246: FileChangedShell autocommand deleted buffer"));
} }
s = get_vim_var_str(VV_FCS_CHOICE); s = get_vim_var_str(VV_FCS_CHOICE);
if (STRCMP(s, "reload") == 0 && *reason != 'd') if (STRCMP(s, "reload") == 0 && *reason != 'd') {
reload = TRUE; reload = true;
else if (STRCMP(s, "ask") == 0) } else if (STRCMP(s, "ask") == 0) {
n = FALSE; n = false;
else } else {
return 2; return 2;
} }
}
if (!n) { if (!n) {
if (*reason == 'd') if (*reason == 'd') {
// Only give the message once.
if (prev_b_mtime != -1) {
mesg = _("E211: File \"%s\" no longer available"); mesg = _("E211: File \"%s\" no longer available");
else { }
helpmesg = TRUE; } else {
can_reload = TRUE; helpmesg = true;
/* can_reload = true;
* Check if the file contents really changed to avoid
* giving a warning when only the timestamp was set (e.g., // Check if the file contents really changed to avoid
* checked out of CVS). Always warn when the buffer was // giving a warning when only the timestamp was set (e.g.,
* changed. // checked out of CVS). Always warn when the buffer was
*/ // changed.
if (reason[2] == 'n') { if (reason[2] == 'n') {
mesg = _( mesg = _(
"W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well"); "W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well");
@ -4939,7 +4938,7 @@ buf_check_timestamp(
retval = 1; retval = 1;
mesg = _("W13: Warning: File \"%s\" has been created after editing started"); mesg = _("W13: Warning: File \"%s\" has been created after editing started");
buf->b_flags |= BF_NEW_W; buf->b_flags |= BF_NEW_W;
can_reload = TRUE; can_reload = true;
} }
if (mesg != NULL) { if (mesg != NULL) {