073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.456
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.456
073263
Problem:    'backupcopy' is global, cannot write only some files in a
073263
	    different way.
073263
Solution:   Make 'backupcopy' global-local. (Christian Brabandt)
073263
Files:	    runtime/doc/options.txt, src/buffer.c, src/fileio.c, src/option.c,
073263
	    src/option.h, src/proto/option.pro, src/structs.h
073263
073263
073263
*** ../vim-7.4.455/runtime/doc/options.txt	2014-08-10 13:34:59.052785459 +0200
073263
--- runtime/doc/options.txt	2014-09-23 14:28:40.530791041 +0200
073263
***************
073263
*** 921,927 ****
073263
  
073263
  						*'backupcopy'* *'bkc'*
073263
  'backupcopy' 'bkc'	string	(Vi default for Unix: "yes", otherwise: "auto")
073263
! 			global
073263
  			{not in Vi}
073263
  	When writing a file and a backup is made, this option tells how it's
073263
  	done.  This is a comma separated list of words.
073263
--- 921,927 ----
073263
  
073263
  						*'backupcopy'* *'bkc'*
073263
  'backupcopy' 'bkc'	string	(Vi default for Unix: "yes", otherwise: "auto")
073263
! 			global or local to buffer |global-local|
073263
  			{not in Vi}
073263
  	When writing a file and a backup is made, this option tells how it's
073263
  	done.  This is a comma separated list of words.
073263
*** ../vim-7.4.455/src/buffer.c	2014-09-23 14:24:36.406790508 +0200
073263
--- src/buffer.c	2014-09-23 14:28:40.530791041 +0200
073263
***************
073263
*** 2001,2006 ****
073263
--- 2001,2007 ----
073263
  #ifdef FEAT_LISP
073263
      clear_string_option(&buf->b_p_lw);
073263
  #endif
073263
+     clear_string_option(&buf->b_p_bkc);
073263
  }
073263
  
073263
  /*
073263
*** ../vim-7.4.455/src/fileio.c	2014-09-09 16:59:34.792537789 +0200
073263
--- src/fileio.c	2014-09-23 14:28:40.530791041 +0200
073263
***************
073263
*** 3149,3154 ****
073263
--- 3149,3155 ----
073263
      int		    write_undo_file = FALSE;
073263
      context_sha256_T sha_ctx;
073263
  #endif
073263
+     unsigned int    bkc = get_bkc_value(buf);
073263
  
073263
      if (fname == NULL || *fname == NUL)	/* safety check */
073263
  	return FAIL;
073263
***************
073263
*** 3647,3656 ****
073263
  	struct stat st;
073263
  #endif
073263
  
073263
! 	if ((bkc_flags & BKC_YES) || append)	/* "yes" */
073263
  	    backup_copy = TRUE;
073263
  #if defined(UNIX) || defined(WIN32)
073263
! 	else if ((bkc_flags & BKC_AUTO))	/* "auto" */
073263
  	{
073263
  	    int		i;
073263
  
073263
--- 3648,3657 ----
073263
  	struct stat st;
073263
  #endif
073263
  
073263
! 	if ((bkc & BKC_YES) || append)	/* "yes" */
073263
  	    backup_copy = TRUE;
073263
  #if defined(UNIX) || defined(WIN32)
073263
! 	else if ((bkc & BKC_AUTO))	/* "auto" */
073263
  	{
073263
  	    int		i;
073263
  
073263
***************
073263
*** 3738,3744 ****
073263
  	/*
073263
  	 * Break symlinks and/or hardlinks if we've been asked to.
073263
  	 */
073263
! 	if ((bkc_flags & BKC_BREAKSYMLINK) || (bkc_flags & BKC_BREAKHARDLINK))
073263
  	{
073263
  # ifdef UNIX
073263
  	    int	lstat_res;
073263
--- 3739,3745 ----
073263
  	/*
073263
  	 * Break symlinks and/or hardlinks if we've been asked to.
073263
  	 */
073263
! 	if ((bkc & BKC_BREAKSYMLINK) || (bkc & BKC_BREAKHARDLINK))
073263
  	{
073263
  # ifdef UNIX
073263
  	    int	lstat_res;
073263
***************
073263
*** 3746,3769 ****
073263
  	    lstat_res = mch_lstat((char *)fname, &st);
073263
  
073263
  	    /* Symlinks. */
073263
! 	    if ((bkc_flags & BKC_BREAKSYMLINK)
073263
  		    && lstat_res == 0
073263
  		    && st.st_ino != st_old.st_ino)
073263
  		backup_copy = FALSE;
073263
  
073263
  	    /* Hardlinks. */
073263
! 	    if ((bkc_flags & BKC_BREAKHARDLINK)
073263
  		    && st_old.st_nlink > 1
073263
  		    && (lstat_res != 0 || st.st_ino == st_old.st_ino))
073263
  		backup_copy = FALSE;
073263
  # else
073263
  #  if defined(WIN32)
073263
  	    /* Symlinks. */
073263
! 	    if ((bkc_flags & BKC_BREAKSYMLINK) && mch_is_symbolic_link(fname))
073263
  		backup_copy = FALSE;
073263
  
073263
  	    /* Hardlinks. */
073263
! 	    if ((bkc_flags & BKC_BREAKHARDLINK) && mch_is_hard_link(fname))
073263
  		backup_copy = FALSE;
073263
  #  endif
073263
  # endif
073263
--- 3747,3770 ----
073263
  	    lstat_res = mch_lstat((char *)fname, &st);
073263
  
073263
  	    /* Symlinks. */
073263
! 	    if ((bkc & BKC_BREAKSYMLINK)
073263
  		    && lstat_res == 0
073263
  		    && st.st_ino != st_old.st_ino)
073263
  		backup_copy = FALSE;
073263
  
073263
  	    /* Hardlinks. */
073263
! 	    if ((bkc & BKC_BREAKHARDLINK)
073263
  		    && st_old.st_nlink > 1
073263
  		    && (lstat_res != 0 || st.st_ino == st_old.st_ino))
073263
  		backup_copy = FALSE;
073263
  # else
073263
  #  if defined(WIN32)
073263
  	    /* Symlinks. */
073263
! 	    if ((bkc & BKC_BREAKSYMLINK) && mch_is_symbolic_link(fname))
073263
  		backup_copy = FALSE;
073263
  
073263
  	    /* Hardlinks. */
073263
! 	    if ((bkc & BKC_BREAKHARDLINK) && mch_is_hard_link(fname))
073263
  		backup_copy = FALSE;
073263
  #  endif
073263
  # endif
073263
*** ../vim-7.4.455/src/option.c	2014-09-09 17:33:02.700542175 +0200
073263
--- src/option.c	2014-09-23 14:41:25.890792713 +0200
073263
***************
073263
*** 56,61 ****
073263
--- 56,62 ----
073263
   */
073263
  #define PV_AI		OPT_BUF(BV_AI)
073263
  #define PV_AR		OPT_BOTH(OPT_BUF(BV_AR))
073263
+ #define PV_BKC		OPT_BOTH(OPT_BUF(BV_BKC))
073263
  #ifdef FEAT_QUICKFIX
073263
  # define PV_BH		OPT_BUF(BV_BH)
073263
  # define PV_BT		OPT_BUF(BV_BT)
073263
***************
073263
*** 582,588 ****
073263
  			    (char_u *)&p_bk, PV_NONE,
073263
  			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
073263
      {"backupcopy",  "bkc",  P_STRING|P_VIM|P_COMMA|P_NODUP,
073263
! 			    (char_u *)&p_bkc, PV_NONE,
073263
  #ifdef UNIX
073263
  			    {(char_u *)"yes", (char_u *)"auto"}
073263
  #else
073263
--- 583,589 ----
073263
  			    (char_u *)&p_bk, PV_NONE,
073263
  			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
073263
      {"backupcopy",  "bkc",  P_STRING|P_VIM|P_COMMA|P_NODUP,
073263
! 			    (char_u *)&p_bkc, PV_BKC,
073263
  #ifdef UNIX
073263
  			    {(char_u *)"yes", (char_u *)"auto"}
073263
  #else
073263
***************
073263
*** 5412,5417 ****
073263
--- 5413,5419 ----
073263
  #ifdef FEAT_LISP
073263
      check_string_option(&buf->b_p_lw);
073263
  #endif
073263
+     check_string_option(&buf->b_p_bkc);
073263
  }
073263
  
073263
  /*
073263
***************
073263
*** 5729,5744 ****
073263
      }
073263
  
073263
      /* 'backupcopy' */
073263
!     else if (varp == &p_bkc)
073263
      {
073263
! 	if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
073263
  	    errmsg = e_invarg;
073263
! 	if (((bkc_flags & BKC_AUTO) != 0)
073263
! 		+ ((bkc_flags & BKC_YES) != 0)
073263
! 		+ ((bkc_flags & BKC_NO) != 0) != 1)
073263
  	{
073263
  	    /* Must have exactly one of "auto", "yes"  and "no". */
073263
! 	    (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
073263
  	    errmsg = e_invarg;
073263
  	}
073263
      }
073263
--- 5731,5755 ----
073263
      }
073263
  
073263
      /* 'backupcopy' */
073263
!     else if (gvarp == &p_bkc)
073263
      {
073263
! 	char_u		*bkc = p_bkc;
073263
! 	unsigned int	*flags = &bkc_flags;
073263
! 
073263
! 	if (opt_flags & OPT_LOCAL)
073263
! 	{
073263
! 	    bkc = curbuf->b_p_bkc;
073263
! 	    flags = &curbuf->b_bkc_flags;
073263
! 	}
073263
! 
073263
! 	if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
073263
  	    errmsg = e_invarg;
073263
! 	if ((((int)*flags & BKC_AUTO) != 0)
073263
! 		+ (((int)*flags & BKC_YES) != 0)
073263
! 		+ (((int)*flags & BKC_NO) != 0) != 1)
073263
  	{
073263
  	    /* Must have exactly one of "auto", "yes"  and "no". */
073263
! 	    (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
073263
  	    errmsg = e_invarg;
073263
  	}
073263
      }
073263
***************
073263
*** 9025,9036 ****
073263
  }
073263
  
073263
  /*
073263
!  * Iterate over options. First argument is a pointer to a pointer to a structure 
073263
!  * inside options[] array, second is option type like in the above function.
073263
   *
073263
!  * If first argument points to NULL it is assumed that iteration just started 
073263
   * and caller needs the very first value.
073263
!  * If first argument points to the end marker function returns NULL and sets 
073263
   * first argument to NULL.
073263
   *
073263
   * Returns full option name for current option on each call.
073263
--- 9036,9048 ----
073263
  }
073263
  
073263
  /*
073263
!  * Iterate over options. First argument is a pointer to a pointer to a
073263
!  * structure inside options[] array, second is option type like in the above
073263
!  * function.
073263
   *
073263
!  * If first argument points to NULL it is assumed that iteration just started
073263
   * and caller needs the very first value.
073263
!  * If first argument points to the end marker function returns NULL and sets
073263
   * first argument to NULL.
073263
   *
073263
   * Returns full option name for current option on each call.
073263
***************
073263
*** 9856,9861 ****
073263
--- 9868,9877 ----
073263
  	case PV_AR:
073263
  	    buf->b_p_ar = -1;
073263
  	    break;
073263
+ 	case PV_BKC:
073263
+ 	    clear_string_option(&buf->b_p_bkc);
073263
+ 	    buf->b_bkc_flags = 0;
073263
+ 	    break;
073263
  	case PV_TAGS:
073263
  	    clear_string_option(&buf->b_p_tags);
073263
  	    break;
073263
***************
073263
*** 9961,9966 ****
073263
--- 9977,9983 ----
073263
  #ifdef FEAT_LISP
073263
  	    case PV_LW:   return (char_u *)&(curbuf->b_p_lw);
073263
  #endif
073263
+ 	    case PV_BKC:  return (char_u *)&(curbuf->b_p_bkc);
073263
  	}
073263
  	return NULL; /* "cannot happen" */
073263
      }
073263
***************
073263
*** 9993,9998 ****
073263
--- 10010,10017 ----
073263
  				    ? (char_u *)&(curbuf->b_p_ar) : p->var;
073263
  	case PV_TAGS:	return *curbuf->b_p_tags != NUL
073263
  				    ? (char_u *)&(curbuf->b_p_tags) : p->var;
073263
+ 	case PV_BKC:	return *curbuf->b_p_bkc != NUL
073263
+ 				    ? (char_u *)&(curbuf->b_p_bkc) : p->var;
073263
  #ifdef FEAT_FIND_ID
073263
  	case PV_DEF:	return *curbuf->b_p_def != NUL
073263
  				    ? (char_u *)&(curbuf->b_p_def) : p->var;
073263
***************
073263
*** 10585,10590 ****
073263
--- 10604,10611 ----
073263
  	     * are not copied, start using the global value */
073263
  	    buf->b_p_ar = -1;
073263
  	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
073263
+ 	    buf->b_p_bkc = empty_option;
073263
+ 	    buf->b_bkc_flags = 0;
073263
  #ifdef FEAT_QUICKFIX
073263
  	    buf->b_p_gp = empty_option;
073263
  	    buf->b_p_mp = empty_option;
073263
***************
073263
*** 12052,12054 ****
073263
--- 12073,12085 ----
073263
      return OK;
073263
  }
073263
  #endif
073263
+ 
073263
+ /*
073263
+  * Get the local or global value of 'backupcopy'.
073263
+  */
073263
+     unsigned int
073263
+ get_bkc_value(buf)
073263
+     buf_T *buf;
073263
+ {
073263
+     return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
073263
+ }
073263
*** ../vim-7.4.455/src/option.h	2014-08-06 14:52:05.047236174 +0200
073263
--- src/option.h	2014-09-23 14:41:45.614792756 +0200
073263
***************
073263
*** 327,333 ****
073263
  EXTERN char_u	*p_bg;		/* 'background' */
073263
  EXTERN int	p_bk;		/* 'backup' */
073263
  EXTERN char_u	*p_bkc;		/* 'backupcopy' */
073263
! EXTERN unsigned	bkc_flags;
073263
  #ifdef IN_OPTION_C
073263
  static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
073263
  #endif
073263
--- 327,333 ----
073263
  EXTERN char_u	*p_bg;		/* 'background' */
073263
  EXTERN int	p_bk;		/* 'backup' */
073263
  EXTERN char_u	*p_bkc;		/* 'backupcopy' */
073263
! EXTERN unsigned	bkc_flags;	/* flags from 'backupcopy' */
073263
  #ifdef IN_OPTION_C
073263
  static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
073263
  #endif
073263
***************
073263
*** 918,923 ****
073263
--- 918,926 ----
073263
      , BV_AR
073263
  #ifdef FEAT_QUICKFIX
073263
      , BV_BH
073263
+ #endif
073263
+     , BV_BKC
073263
+ #ifdef FEAT_QUICKFIX
073263
      , BV_BT
073263
      , BV_EFM
073263
      , BV_GP
073263
*** ../vim-7.4.455/src/proto/option.pro	2014-08-24 21:39:45.488526954 +0200
073263
--- src/proto/option.pro	2014-09-23 14:28:40.534791041 +0200
073263
***************
073263
*** 62,65 ****
073263
--- 62,66 ----
073263
  long get_sw_value __ARGS((buf_T *buf));
073263
  long get_sts_value __ARGS((void));
073263
  void find_mps_values __ARGS((int *initc, int *findc, int *backwards, int switchit));
073263
+ unsigned int get_bkc_value __ARGS((buf_T *buf));
073263
  /* vim: set ft=c : */
073263
*** ../vim-7.4.455/src/structs.h	2014-08-10 13:34:59.064785459 +0200
073263
--- src/structs.h	2014-09-23 14:41:56.218792779 +0200
073263
***************
073263
*** 137,143 ****
073263
  #ifdef FEAT_LINEBREAK
073263
      int		wo_bri;
073263
  # define w_p_bri w_onebuf_opt.wo_bri	/* 'breakindent' */
073263
!     char_u		*wo_briopt;
073263
  # define w_p_briopt w_onebuf_opt.wo_briopt /* 'breakindentopt' */
073263
  #endif
073263
  #ifdef FEAT_DIFF
073263
--- 137,143 ----
073263
  #ifdef FEAT_LINEBREAK
073263
      int		wo_bri;
073263
  # define w_p_bri w_onebuf_opt.wo_bri	/* 'breakindent' */
073263
!     char_u	*wo_briopt;
073263
  # define w_p_briopt w_onebuf_opt.wo_briopt /* 'breakindentopt' */
073263
  #endif
073263
  #ifdef FEAT_DIFF
073263
***************
073263
*** 1537,1542 ****
073263
--- 1537,1544 ----
073263
  
073263
      int		b_p_ai;		/* 'autoindent' */
073263
      int		b_p_ai_nopaste;	/* b_p_ai saved for paste mode */
073263
+     char_u	*b_p_bkc;	/* 'backupcopy' */
073263
+     unsigned	b_bkc_flags;    /* flags for 'backupcopy' */
073263
      int		b_p_ci;		/* 'copyindent' */
073263
      int		b_p_bin;	/* 'binary' */
073263
  #ifdef FEAT_MBYTE
073263
*** ../vim-7.4.455/src/version.c	2014-09-23 14:24:36.410790508 +0200
073263
--- src/version.c	2014-09-23 14:29:15.706791118 +0200
073263
***************
073263
*** 743,744 ****
073263
--- 743,746 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     456,
073263
  /**/
073263
073263
-- 
073263
If Apple would build a car...
073263
... it would be powered by the sun, be reliable, five times
073263
as fast and twice as easy to drive; but would only run on
073263
five percent of the roads.
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///