From 8df51d0b8c5be8fc67bd55e34c17686006da1e2f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 9 Feb 2015 20:23:03 +0100 Subject: [PATCH 1/2] awful.util.deprecate: display deprecations only once This remembers displayed tracebacks and skips them if they were displayed already. --- lib/awful/util.lua.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index d9709b79..1b4ad779 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -30,13 +30,21 @@ util.table = {} util.shell = os.getenv("SHELL") or "/bin/sh" +local displayed_deprecations = {} +--- Display a deprecation notice, but only once per traceback. +-- @param see Optional message to a new method / function to use. function util.deprecate(see) + local tb = debug.traceback() + if util.table.hasitem(displayed_deprecations, tb) then + return + end + table.insert(displayed_deprecations, tb) io.stderr:write("W: awful: function is deprecated") if see then io.stderr:write(", see " .. see) end io.stderr:write("\n") - io.stderr:write(debug.traceback()) + io.stderr:write(tb) end --- Strip alpha part of color. From 0a76e41cb850e67c34085a4e3aa87b11424588d7 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 10 Feb 2015 00:59:15 +0100 Subject: [PATCH 2/2] Use lgi.GLib.String():append(tb):hash() --- lib/awful/util.lua.in | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index 1b4ad779..51b543f3 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -17,6 +17,7 @@ local type = type local rtable = table local pairs = pairs local string = string +local glib = require("lgi").GLib local capi = { awesome = awesome, @@ -35,16 +36,16 @@ local displayed_deprecations = {} -- @param see Optional message to a new method / function to use. function util.deprecate(see) local tb = debug.traceback() - if util.table.hasitem(displayed_deprecations, tb) then + local tbhash = glib.String():append(tb):hash() + if displayed_deprecations[tbhash] then return end - table.insert(displayed_deprecations, tb) + displayed_deprecations[tbhash] = true io.stderr:write("W: awful: function is deprecated") if see then io.stderr:write(", see " .. see) end - io.stderr:write("\n") - io.stderr:write(tb) + io.stderr:write("\n" .. tb .. "\n") end --- Strip alpha part of color.