From 37df9a4401f6737d6216306ea77a7e080c942aea Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 14 Jun 2019 14:39:51 +0200 Subject: patch 8.1.1526: no numerical value for the patchlevel Problem: No numerical value for the patchlevel. Solution: Add v:versionlong. --- runtime/doc/eval.txt | 11 +++++++++++ src/eval.c | 8 +++++--- src/testdir/test_eval_stuff.vim | 3 +++ src/version.c | 11 ++++------- src/vim.h | 3 ++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 5f8156003..da45de805 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2173,6 +2173,17 @@ v:version Version number of Vim: Major version number times 100 plus version 5.0 and 5.1 may have a patch 123, but these are completely different. + *v:versionlong* *versionlong-variable* +v:versionlong Like v:version, but also including the patchlevel. Version + 8.1 with patch 1234 has value 8011234. This can be used like + this: > + if v:versionlong >= 8011234 +< However, if there are gaps in the list of patches included + this will not work well. This can happen if a recent patch + was included into an older version, e.g. for a security fix. + Use the has() function to make sure the patch is actually + included. + *v:vim_did_enter* *vim_did_enter-variable* v:vim_did_enter Zero until most of startup is done. It is set to one just before |VimEnter| autocommands are triggered. diff --git a/src/eval.c b/src/eval.c index c86d0a664..e2d3d48bd 100644 --- a/src/eval.c +++ b/src/eval.c @@ -193,9 +193,10 @@ static struct vimvar {VV_NAME("termrfgresp", VAR_STRING), VV_RO}, {VV_NAME("termrbgresp", VAR_STRING), VV_RO}, {VV_NAME("termu7resp", VAR_STRING), VV_RO}, - {VV_NAME("termstyleresp", VAR_STRING), VV_RO}, - {VV_NAME("termblinkresp", VAR_STRING), VV_RO}, - {VV_NAME("event", VAR_DICT), VV_RO}, + {VV_NAME("termstyleresp", VAR_STRING), VV_RO}, + {VV_NAME("termblinkresp", VAR_STRING), VV_RO}, + {VV_NAME("event", VAR_DICT), VV_RO}, + {VV_NAME("versionlong", VAR_NUMBER), VV_RO}, }; /* shorthand */ @@ -354,6 +355,7 @@ eval_init(void) hash_add(&compat_hashtab, p->vv_di.di_key); } vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; + vimvars[VV_VERSIONLONG].vv_nr = VIM_VERSION_100 * 10000 + highest_patch(); set_vim_var_nr(VV_SEARCHFORWARD, 1L); set_vim_var_nr(VV_HLSEARCH, 1L); diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim index db68e2a40..08ab59ea5 100644 --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -171,6 +171,9 @@ func Test_vvar_scriptversion2() echo version call assert_fails('let version = 1', 'E46:') call assert_equal(v:version, version) + + call assert_equal(v:version, v:versionlong / 10000) + call assert_true(v:versionlong > 8011525) endfunc func Test_scriptversion() diff --git a/src/version.c b/src/version.c index 058dbc702..8a9885c39 100644 --- a/src/version.c +++ b/src/version.c @@ -777,6 +777,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1526, /**/ 1525, /**/ @@ -3847,13 +3849,8 @@ static char *(extra_patches[]) = int highest_patch(void) { - int i; - int h = 0; - - for (i = 0; included_patches[i] != 0; ++i) - if (included_patches[i] > h) - h = included_patches[i]; - return h; + // this relies on the highest patch number to be the first entry + return included_patches[0]; } #if defined(FEAT_EVAL) || defined(PROTO) diff --git a/src/vim.h b/src/vim.h index 3b4582bc9..90208cdc7 100644 --- a/src/vim.h +++ b/src/vim.h @@ -1960,7 +1960,8 @@ typedef int sock_T; #define VV_TERMSTYLERESP 85 #define VV_TERMBLINKRESP 86 #define VV_EVENT 87 -#define VV_LEN 88 /* number of v: vars */ +#define VV_VERSIONLONG 88 +#define VV_LEN 89 // number of v: vars /* used for v_number in VAR_SPECIAL */ #define VVAL_FALSE 0L -- cgit v1.2.1