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