patch 8.2.2772: problems when restoring 'runtimepath' from a session file

Problem:    Problems when restoring 'runtimepath' from a session file.
Solution:   Add the "skiprtp" item in 'sessionoptions'.
diff --git a/src/option.c b/src/option.c
index b9d7edb..d7997b0 100644
--- a/src/option.c
+++ b/src/option.c
@@ -4615,6 +4615,9 @@
 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
 		continue;
 
+	    if ((opt_flags & OPT_SKIPRTP) && p->var == (char_u *)&p_rtp)
+		continue;
+
 	    round = 2;
 	    if (p->indir != PV_NONE)
 	    {
diff --git a/src/option.h b/src/option.h
index 0b1183f..30053cc 100644
--- a/src/option.h
+++ b/src/option.h
@@ -864,6 +864,7 @@
 # define SSOP_CURSOR		0x4000
 # define SSOP_TABPAGES		0x8000
 # define SSOP_TERMINAL		0x10000
+# define SSOP_SKIP_RTP		0x20000
 #endif
 EXTERN char_u	*p_sh;		// 'shell'
 EXTERN char_u	*p_shcf;	// 'shellcmdflag'
diff --git a/src/optionstr.c b/src/optionstr.c
index 521242d..91d0a69 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -34,10 +34,11 @@
 				 "undo", "jump", NULL};
 #endif
 #ifdef FEAT_SESSION
-// Also used for 'viewoptions'!
+// Also used for 'viewoptions'!  Keep in sync with SSOP_ flags.
 static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize",
     "localoptions", "options", "help", "blank", "globals", "slash", "unix",
-    "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", NULL};
+    "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", "skiprtp",
+    NULL};
 #endif
 // Keep in sync with SWB_ flags in option.h
 static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", "uselast", NULL};
diff --git a/src/session.c b/src/session.c
index 6e73bb6..4475ca0 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1225,8 +1225,16 @@
 		|| (eap->cmdidx == CMD_mksession
 		    && (*flagp & SSOP_OPTIONS)))
 #endif
+	{
+	    int flags = OPT_GLOBAL;
+
+#ifdef FEAT_SESSION
+	    if (eap->cmdidx == CMD_mksession && (*flagp & SSOP_SKIP_RTP))
+		flags |= OPT_SKIPRTP;
+#endif
 	    failed |= (makemap(fd, NULL) == FAIL
-				   || makeset(fd, OPT_GLOBAL, FALSE) == FAIL);
+					 || makeset(fd, flags, FALSE) == FAIL);
+	}
 
 #ifdef FEAT_SESSION
 	if (!failed && view_session)
diff --git a/src/testdir/test_mksession.vim b/src/testdir/test_mksession.vim
index fca1227..8eed111 100644
--- a/src/testdir/test_mksession.vim
+++ b/src/testdir/test_mksession.vim
@@ -131,6 +131,32 @@
   set sessionoptions&
 endfunc
 
+def Test_mksession_skiprtp()
+  mksession! Xtest_mks.out
+  var found = 0
+  for line in readfile('Xtest_mks.out')
+    if line =~ 'set runtimepath'
+      found = 1
+      break
+    endif
+  endfor
+  assert_equal(1, found)
+  delete('Xtest_mks.out')
+
+  set sessionoptions+=skiprtp
+  mksession! Xtest_mks.out
+  found = 0
+  for line in readfile('Xtest_mks.out')
+    if line =~ 'set runtimepath'
+      found = 1
+      break
+    endif
+  endfor
+  assert_equal(0, found)
+  delete('Xtest_mks.out')
+  set sessionoptions&
+enddef
+
 func Test_mksession_winheight()
   new
   set winheight=10
diff --git a/src/version.c b/src/version.c
index 44cf5ff..4bc8423 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2772,
+/**/
     2771,
 /**/
     2770,
diff --git a/src/vim.h b/src/vim.h
index 4c9e095..844627d 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1201,6 +1201,7 @@
 #define OPT_NOWIN	0x20	// don't set window-local options
 #define OPT_ONECOLUMN	0x40	// list options one per line
 #define OPT_NO_REDRAW	0x80	// ignore redraw flags on option
+#define OPT_SKIPRTP	0x100	// "skiprtp" in 'sessionoptions'
 
 // Magic chars used in confirm dialog strings
 #define DLG_BUTTON_SEP	'\n'