Blame SOURCES/7.4.456

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