From 200eae0280bb8cc9eca0a11d5c5fd5181eb2592c Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Thu, 25 Apr 2013 18:47:16 +0200 Subject: [PATCH] Rework error handling in parse_e2versionfile() Remove e2_has_fixed_tag() its return values conflict with error reporting and we can just inline the single use (minus the messages) Signed-off-by: Tobias Ulmer --- generic/e2lib.lua | 33 ++++++++++++++++++++++++--------- local/e2-build.lua | 13 +++++++++++-- local/e2tool.lua | 21 +++++---------------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 7e004d6..af7afd0 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1338,24 +1338,39 @@ function e2lib.parse_versionfile(filename) end --- Parse e2version file. +-- @return Table containing tag and branch. False on error. +-- @return Error object on failure. function e2lib.parse_e2versionfile(filename) local f = luafile.open(filename, "r") if not f then - e2lib.abort("can't open e2version file: " .. filename) + return false, err.new("can't open e2version file: %s", filename) end + local l = f:readline() f:close() if not l then - e2lib.abort("can't parse e2version file: " .. filename) + return false, err.new("can't parse e2version file: %s", filename) end + local match = l:gmatch("[^%s]+") - local v = {} - v.branch = match() or e2lib.abort("invalid branch name `", l, "' in e2 version file ", - filename) - v.tag = match() or e2lib.abort("invalid tag name `", l, "' in e2 version file ", - filename) - e2lib.logf(3, "using e2 branch %s tag %s", v.branch, v.tag) - return v + + local version_table = {} + version_table.branch = match() + if not version_table.branch then + return false, err.new("invalid branch name `%s' in e2 version file %s", + l, filename) + end + + version_table.tag = match() + if not version_table.tag then + return false, err.new("invalid tag name `%s' in e2 version file %s", + l, filename) + end + + e2lib.logf(3, "using e2 branch %s tag %s", + version_table.branch, version_table.tag) + + return strict.lock(version_table) end --- Create a temporary file. diff --git a/local/e2-build.lua b/local/e2-build.lua index 0e19c89..5b491a5 100644 --- a/local/e2-build.lua +++ b/local/e2-build.lua @@ -197,8 +197,17 @@ local function e2_build(arg) return false, re end - if opts.release and not e2tool.e2_has_fixed_tag(info) then - return false, err.new("Failure: e2 is on pseudo tag while building in release mode.") + if opts.release then + local version_table, re = e2lib.parse_e2versionfile( + e2lib.join(info.root, ".e2/e2version")) + if not version_table then + return false, re + end + + if version_table.tag == "^" then + return false, + err.new("e2 is on a pseudo tag while building in release mode.") + end end -- calculate buildids for selected results diff --git a/local/e2tool.lua b/local/e2tool.lua index 47cdfb2..f8346f7 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -1232,7 +1232,11 @@ function e2tool.collect_project_info(info, skip_load_config) if e2option.opts["check"] then local f = ".e2/e2version" - local v = e2lib.parse_e2versionfile(f) + local v, re = e2lib.parse_e2versionfile(f) + if not v then + return false, re + end + if v.tag == "^" then return false, err.new("local tool version is not configured to " .. "a fixed tag\nfix you configuration in %s before running " .. @@ -1883,21 +1887,6 @@ local function projid(info) return info.projid end ---- Check if e2 is in a fixed tag. --- --- e2tool.e2_has_fixed_tag(info) --- --- return true if e2 is at fixed tag, and false if not. -function e2tool.e2_has_fixed_tag(info) - local v = e2lib.parse_e2versionfile(info.root .. "/.e2/e2version") - e2lib.log(2, "Checking for fixed e2 tag.") - if v.tag == "^" then - e2lib.log(1, "Fatal: e2 is not at a fixed tag.") - return false - end - return true -end - --- hashcache write. local function hashcache_write(info) local e = err.new("writing hash cache file") -- 2.39.5