From 58f26451e4344ee6351cd666dc379d948712ebc1 Mon Sep 17 00:00:00 2001
From: Roman Tsisyk <roman@tsisyk.com>
Date: Wed, 4 Feb 2015 18:23:39 +0300
Subject: [PATCH] Restore box.info.version

Keep compatibility with Tarantool 1.5
---
 src/box/lua/info.cc     | 13 +++++++++++++
 test/box/admin.result   |  2 +-
 test/box/admin.test.lua |  2 +-
 test/box/info.result    |  5 +++++
 test/box/info.test.lua  |  1 +
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/box/lua/info.cc b/src/box/lua/info.cc
index 439ef71f1f..0b72990db8 100644
--- a/src/box/lua/info.cc
+++ b/src/box/lua/info.cc
@@ -172,6 +172,16 @@ lbox_info_index(struct lua_State *L)
 	return 1;
 }
 
+/** Push a bunch of compile-time or start-time constants into a Lua table. */
+static void
+lbox_info_init_static_values(struct lua_State *L)
+{
+	/* tarantool version */
+	lua_pushstring(L, "version");
+	lua_pushstring(L, tarantool_version());
+	lua_settable(L, -3);
+}
+
 /**
  * When user invokes box.info(), return a table of key/value
  * pairs containing the current info.
@@ -180,6 +190,7 @@ static int
 lbox_info_call(struct lua_State *L)
 {
 	lua_newtable(L);
+	lbox_info_init_static_values(L);
 	for (int i = 0; lbox_info_dynamic_meta[i].name; i++) {
 		lua_pushstring(L, lbox_info_dynamic_meta[i].name);
 		lbox_info_dynamic_meta[i].func(L);
@@ -217,5 +228,7 @@ box_lua_info_init(struct lua_State *L)
 
 	lua_setmetatable(L, -2);
 
+	lbox_info_init_static_values(L);
+
 	lua_pop(L, 1); /* info module */
 }
diff --git a/test/box/admin.result b/test/box/admin.result
index 681bf5834f..10cd74f25e 100644
--- a/test/box/admin.result
+++ b/test/box/admin.result
@@ -68,7 +68,7 @@ end;
 function test_box_info()
     local tmp = box.info()
     local num = {'pid', 'snapshot_pid', 'recovery_last_update', 'recovery_lag', 'uptime'}
-    local str = {'status' }
+    local str = {'version', 'status' }
     local failed = {}
     if check_type(tmp.server, 'table') == false then
         table.insert(failed1, 'box.info().server')
diff --git a/test/box/admin.test.lua b/test/box/admin.test.lua
index d973fb424c..e070545a7f 100644
--- a/test/box/admin.test.lua
+++ b/test/box/admin.test.lua
@@ -20,7 +20,7 @@ end;
 function test_box_info()
     local tmp = box.info()
     local num = {'pid', 'snapshot_pid', 'recovery_last_update', 'recovery_lag', 'uptime'}
-    local str = {'status' }
+    local str = {'version', 'status' }
     local failed = {}
     if check_type(tmp.server, 'table') == false then
         table.insert(failed1, 'box.info().server')
diff --git a/test/box/info.result b/test/box/info.result
index a7ef13cd07..c630c8eeca 100644
--- a/test/box/info.result
+++ b/test/box/info.result
@@ -12,6 +12,10 @@ box.info['unknown_variable']
 ---
 - null
 ...
+string.match(box.info.version, '^[1-9]') ~= nil
+---
+- true
+...
 string.match(box.info.pid, '^[1-9][0-9]*$') ~= nil
 ---
 - true
@@ -60,6 +64,7 @@ t
   - status
   - uptime
   - vclock
+  - version
 ...
 box.info.snapshot_pid
 ---
diff --git a/test/box/info.test.lua b/test/box/info.test.lua
index 5dc3e2c157..6edb102e47 100644
--- a/test/box/info.test.lua
+++ b/test/box/info.test.lua
@@ -3,6 +3,7 @@
 box.info.unknown_variable
 box.info[23]
 box.info['unknown_variable']
+string.match(box.info.version, '^[1-9]') ~= nil
 string.match(box.info.pid, '^[1-9][0-9]*$') ~= nil
 #box.info.server > 0
 box.info.recovery_lag
-- 
GitLab