0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

updated for version 7.4.456

Problem:    'backupcopy' is global, cannot write only some files in a
            different way.
Solution:   Make 'backupcopy' global-local. (Christian Brabandt)
This commit is contained in:
Bram Moolenaar
2014-09-23 15:45:08 +02:00
parent 4b9d637e9c
commit b8ee25acab
8 changed files with 62 additions and 21 deletions

View File

@@ -921,7 +921,7 @@ A jump table for the options with a short description can be found at |Q_op|.
*'backupcopy'* *'bkc'* *'backupcopy'* *'bkc'*
'backupcopy' 'bkc' string (Vi default for Unix: "yes", otherwise: "auto") 'backupcopy' 'bkc' string (Vi default for Unix: "yes", otherwise: "auto")
global global or local to buffer |global-local|
{not in Vi} {not in Vi}
When writing a file and a backup is made, this option tells how it's When writing a file and a backup is made, this option tells how it's
done. This is a comma separated list of words. done. This is a comma separated list of words.

View File

@@ -2001,6 +2001,7 @@ free_buf_options(buf, free_p_ff)
#ifdef FEAT_LISP #ifdef FEAT_LISP
clear_string_option(&buf->b_p_lw); clear_string_option(&buf->b_p_lw);
#endif #endif
clear_string_option(&buf->b_p_bkc);
} }
/* /*

View File

@@ -3149,6 +3149,7 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
int write_undo_file = FALSE; int write_undo_file = FALSE;
context_sha256_T sha_ctx; context_sha256_T sha_ctx;
#endif #endif
unsigned int bkc = get_bkc_value(buf);
if (fname == NULL || *fname == NUL) /* safety check */ if (fname == NULL || *fname == NUL) /* safety check */
return FAIL; return FAIL;
@@ -3647,10 +3648,10 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
struct stat st; struct stat st;
#endif #endif
if ((bkc_flags & BKC_YES) || append) /* "yes" */ if ((bkc & BKC_YES) || append) /* "yes" */
backup_copy = TRUE; backup_copy = TRUE;
#if defined(UNIX) || defined(WIN32) #if defined(UNIX) || defined(WIN32)
else if ((bkc_flags & BKC_AUTO)) /* "auto" */ else if ((bkc & BKC_AUTO)) /* "auto" */
{ {
int i; int i;
@@ -3738,7 +3739,7 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
/* /*
* Break symlinks and/or hardlinks if we've been asked to. * Break symlinks and/or hardlinks if we've been asked to.
*/ */
if ((bkc_flags & BKC_BREAKSYMLINK) || (bkc_flags & BKC_BREAKHARDLINK)) if ((bkc & BKC_BREAKSYMLINK) || (bkc & BKC_BREAKHARDLINK))
{ {
# ifdef UNIX # ifdef UNIX
int lstat_res; int lstat_res;
@@ -3746,24 +3747,24 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
lstat_res = mch_lstat((char *)fname, &st); lstat_res = mch_lstat((char *)fname, &st);
/* Symlinks. */ /* Symlinks. */
if ((bkc_flags & BKC_BREAKSYMLINK) if ((bkc & BKC_BREAKSYMLINK)
&& lstat_res == 0 && lstat_res == 0
&& st.st_ino != st_old.st_ino) && st.st_ino != st_old.st_ino)
backup_copy = FALSE; backup_copy = FALSE;
/* Hardlinks. */ /* Hardlinks. */
if ((bkc_flags & BKC_BREAKHARDLINK) if ((bkc & BKC_BREAKHARDLINK)
&& st_old.st_nlink > 1 && st_old.st_nlink > 1
&& (lstat_res != 0 || st.st_ino == st_old.st_ino)) && (lstat_res != 0 || st.st_ino == st_old.st_ino))
backup_copy = FALSE; backup_copy = FALSE;
# else # else
# if defined(WIN32) # if defined(WIN32)
/* Symlinks. */ /* Symlinks. */
if ((bkc_flags & BKC_BREAKSYMLINK) && mch_is_symbolic_link(fname)) if ((bkc & BKC_BREAKSYMLINK) && mch_is_symbolic_link(fname))
backup_copy = FALSE; backup_copy = FALSE;
/* Hardlinks. */ /* Hardlinks. */
if ((bkc_flags & BKC_BREAKHARDLINK) && mch_is_hard_link(fname)) if ((bkc & BKC_BREAKHARDLINK) && mch_is_hard_link(fname))
backup_copy = FALSE; backup_copy = FALSE;
# endif # endif
# endif # endif

View File

@@ -56,6 +56,7 @@
*/ */
#define PV_AI OPT_BUF(BV_AI) #define PV_AI OPT_BUF(BV_AI)
#define PV_AR OPT_BOTH(OPT_BUF(BV_AR)) #define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
# define PV_BH OPT_BUF(BV_BH) # define PV_BH OPT_BUF(BV_BH)
# define PV_BT OPT_BUF(BV_BT) # define PV_BT OPT_BUF(BV_BT)
@@ -582,7 +583,7 @@ static struct vimoption
(char_u *)&p_bk, PV_NONE, (char_u *)&p_bk, PV_NONE,
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
{"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP, {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
(char_u *)&p_bkc, PV_NONE, (char_u *)&p_bkc, PV_BKC,
#ifdef UNIX #ifdef UNIX
{(char_u *)"yes", (char_u *)"auto"} {(char_u *)"yes", (char_u *)"auto"}
#else #else
@@ -5412,6 +5413,7 @@ check_buf_options(buf)
#ifdef FEAT_LISP #ifdef FEAT_LISP
check_string_option(&buf->b_p_lw); check_string_option(&buf->b_p_lw);
#endif #endif
check_string_option(&buf->b_p_bkc);
} }
/* /*
@@ -5729,16 +5731,25 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
} }
/* 'backupcopy' */ /* 'backupcopy' */
else if (varp == &p_bkc) else if (gvarp == &p_bkc)
{ {
if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK) char_u *bkc = p_bkc;
unsigned int *flags = &bkc_flags;
if (opt_flags & OPT_LOCAL)
{
bkc = curbuf->b_p_bkc;
flags = &curbuf->b_bkc_flags;
}
if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
errmsg = e_invarg; errmsg = e_invarg;
if (((bkc_flags & BKC_AUTO) != 0) if ((((int)*flags & BKC_AUTO) != 0)
+ ((bkc_flags & BKC_YES) != 0) + (((int)*flags & BKC_YES) != 0)
+ ((bkc_flags & BKC_NO) != 0) != 1) + (((int)*flags & BKC_NO) != 0) != 1)
{ {
/* Must have exactly one of "auto", "yes" and "no". */ /* Must have exactly one of "auto", "yes" and "no". */
(void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE); (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
errmsg = e_invarg; errmsg = e_invarg;
} }
} }
@@ -9025,12 +9036,13 @@ get_option_value_strict(name, numval, stringval, opt_type, from)
} }
/* /*
* Iterate over options. First argument is a pointer to a pointer to a structure * Iterate over options. First argument is a pointer to a pointer to a
* inside options[] array, second is option type like in the above function. * structure inside options[] array, second is option type like in the above
* function.
* *
* If first argument points to NULL it is assumed that iteration just started * If first argument points to NULL it is assumed that iteration just started
* and caller needs the very first value. * and caller needs the very first value.
* If first argument points to the end marker function returns NULL and sets * If first argument points to the end marker function returns NULL and sets
* first argument to NULL. * first argument to NULL.
* *
* Returns full option name for current option on each call. * Returns full option name for current option on each call.
@@ -9856,6 +9868,10 @@ unset_global_local_option(name, from)
case PV_AR: case PV_AR:
buf->b_p_ar = -1; buf->b_p_ar = -1;
break; break;
case PV_BKC:
clear_string_option(&buf->b_p_bkc);
buf->b_bkc_flags = 0;
break;
case PV_TAGS: case PV_TAGS:
clear_string_option(&buf->b_p_tags); clear_string_option(&buf->b_p_tags);
break; break;
@@ -9961,6 +9977,7 @@ get_varp_scope(p, opt_flags)
#ifdef FEAT_LISP #ifdef FEAT_LISP
case PV_LW: return (char_u *)&(curbuf->b_p_lw); case PV_LW: return (char_u *)&(curbuf->b_p_lw);
#endif #endif
case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
} }
return NULL; /* "cannot happen" */ return NULL; /* "cannot happen" */
} }
@@ -9993,6 +10010,8 @@ get_varp(p)
? (char_u *)&(curbuf->b_p_ar) : p->var; ? (char_u *)&(curbuf->b_p_ar) : p->var;
case PV_TAGS: return *curbuf->b_p_tags != NUL case PV_TAGS: return *curbuf->b_p_tags != NUL
? (char_u *)&(curbuf->b_p_tags) : p->var; ? (char_u *)&(curbuf->b_p_tags) : p->var;
case PV_BKC: return *curbuf->b_p_bkc != NUL
? (char_u *)&(curbuf->b_p_bkc) : p->var;
#ifdef FEAT_FIND_ID #ifdef FEAT_FIND_ID
case PV_DEF: return *curbuf->b_p_def != NUL case PV_DEF: return *curbuf->b_p_def != NUL
? (char_u *)&(curbuf->b_p_def) : p->var; ? (char_u *)&(curbuf->b_p_def) : p->var;
@@ -10585,6 +10604,8 @@ buf_copy_options(buf, flags)
* are not copied, start using the global value */ * are not copied, start using the global value */
buf->b_p_ar = -1; buf->b_p_ar = -1;
buf->b_p_ul = NO_LOCAL_UNDOLEVEL; buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
buf->b_p_bkc = empty_option;
buf->b_bkc_flags = 0;
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
buf->b_p_gp = empty_option; buf->b_p_gp = empty_option;
buf->b_p_mp = empty_option; buf->b_p_mp = empty_option;
@@ -12052,3 +12073,13 @@ briopt_check(wp)
return OK; return OK;
} }
#endif #endif
/*
* Get the local or global value of 'backupcopy'.
*/
unsigned int
get_bkc_value(buf)
buf_T *buf;
{
return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
}

View File

@@ -327,7 +327,7 @@ EXTERN char_u *p_bs; /* 'backspace' */
EXTERN char_u *p_bg; /* 'background' */ EXTERN char_u *p_bg; /* 'background' */
EXTERN int p_bk; /* 'backup' */ EXTERN int p_bk; /* 'backup' */
EXTERN char_u *p_bkc; /* 'backupcopy' */ EXTERN char_u *p_bkc; /* 'backupcopy' */
EXTERN unsigned bkc_flags; EXTERN unsigned bkc_flags; /* flags from 'backupcopy' */
#ifdef IN_OPTION_C #ifdef IN_OPTION_C
static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL}; static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
#endif #endif
@@ -918,6 +918,9 @@ enum
, BV_AR , BV_AR
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
, BV_BH , BV_BH
#endif
, BV_BKC
#ifdef FEAT_QUICKFIX
, BV_BT , BV_BT
, BV_EFM , BV_EFM
, BV_GP , BV_GP

View File

@@ -62,4 +62,5 @@ int check_ff_value __ARGS((char_u *p));
long get_sw_value __ARGS((buf_T *buf)); long get_sw_value __ARGS((buf_T *buf));
long get_sts_value __ARGS((void)); long get_sts_value __ARGS((void));
void find_mps_values __ARGS((int *initc, int *findc, int *backwards, int switchit)); void find_mps_values __ARGS((int *initc, int *findc, int *backwards, int switchit));
unsigned int get_bkc_value __ARGS((buf_T *buf));
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@@ -137,7 +137,7 @@ typedef struct
#ifdef FEAT_LINEBREAK #ifdef FEAT_LINEBREAK
int wo_bri; int wo_bri;
# define w_p_bri w_onebuf_opt.wo_bri /* 'breakindent' */ # define w_p_bri w_onebuf_opt.wo_bri /* 'breakindent' */
char_u *wo_briopt; char_u *wo_briopt;
# define w_p_briopt w_onebuf_opt.wo_briopt /* 'breakindentopt' */ # define w_p_briopt w_onebuf_opt.wo_briopt /* 'breakindentopt' */
#endif #endif
#ifdef FEAT_DIFF #ifdef FEAT_DIFF
@@ -1537,6 +1537,8 @@ struct file_buffer
int b_p_ai; /* 'autoindent' */ int b_p_ai; /* 'autoindent' */
int b_p_ai_nopaste; /* b_p_ai saved for paste mode */ int b_p_ai_nopaste; /* b_p_ai saved for paste mode */
char_u *b_p_bkc; /* 'backupcopy' */
unsigned b_bkc_flags; /* flags for 'backupcopy' */
int b_p_ci; /* 'copyindent' */ int b_p_ci; /* 'copyindent' */
int b_p_bin; /* 'binary' */ int b_p_bin; /* 'binary' */
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE

View File

@@ -741,6 +741,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
456,
/**/ /**/
455, 455,
/**/ /**/