From 326f994486a64f925df89979cce101b323997a70 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Tue, 27 Dec 2022 02:59:58 +0000 Subject: [PATCH] Add 'duplicates' command --- cdb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/cdb b/cdb index 25ca782..1eabc1f 100755 --- a/cdb +++ b/cdb @@ -670,6 +670,45 @@ mksubcmd(function(c) end end) +----------------------------------------------------------------- }}} +--------------------------------------- Command: duplicates dupes {{{ + +mksubcmd(function(c) + c:name("duplicates dupes") + :description("List hashes with multiple associated files") + c:option("--glob"):default("*") + c:flag("--verbose") + :description("Be chatty on stderr about the generated comand stream") + local f = argparse_for_render(c) + f:default("$u$z") + argp_group("Query", c) + end, + function(args, dbh) + local render = renderer_for(args) + + local sth = assert(sql_do(dbh, + [[SELECT hash, path, pairid, timestamp FROM v_path_hash NATURAL JOIN + (SELECT hashid, hcount FROM + (SELECT hashid, COUNT(pairid) AS hcount FROM path_hash GROUP BY hashid) + WHERE hcount > 1) + NATURAL JOIN (SELECT hashid FROM v_path_hash WHERE path NOT GLOB ?1) + WHERE path GLOB ?1 ORDER BY hashid]], args.glob)) + local lasthash = nil + for row in sth:rows() do + local h, p, pairid, ts = table.unpack(row) + if h ~= lasthash then + lasthash = h + if args.verbose then io.stderr:write(("HASH %s\n"):format(h)) end + end + if args.verbose then + -- TODO: this is probably not the right thing to print + io.stderr:write((" observed path %s with id %d at %s\n") + :format(cdblib.posix_shell_escape(p), pairid, ts)) + end + io.write(render("-", p)) + end + end) + ----------------------------------------------------------------- }}} ---------------------------------------- Command: filterhash filh {{{ -- 2.50.1