MUC: Fix delay@from to be room JID (fixes #1416)
[prosody.git] / util / mercurial.lua
blob3f75c4c1333727498e3cdbd57d71db2329db0790
2 local lfs = require"lfs";
4 local hg = { };
6 function hg.check_id(path)
7 if lfs.attributes(path, 'mode') ~= "directory" then
8 return nil, "not a directory";
9 end
10 local hg_dirstate = io.open(path.."/.hg/dirstate");
11 local hgid, hgrepo
12 if hg_dirstate then
13 hgid = ("%02x%02x%02x%02x%02x%02x"):format(hg_dirstate:read(6):byte(1, 6));
14 hg_dirstate:close();
15 local hg_changelog = io.open(path.."/.hg/store/00changelog.i");
16 if hg_changelog then
17 hg_changelog:seek("set", 0x20);
18 hgrepo = ("%02x%02x%02x%02x%02x%02x"):format(hg_changelog:read(6):byte(1, 6));
19 hg_changelog:close();
20 end
21 else
22 local hg_archival,e = io.open(path.."/.hg_archival.txt");
23 if hg_archival then
24 local repo = hg_archival:read("*l");
25 local node = hg_archival:read("*l");
26 hg_archival:close()
27 hgid = node and node:match("^node: (%x%x%x%x%x%x%x%x%x%x%x%x)")
28 hgrepo = repo and repo:match("^repo: (%x%x%x%x%x%x%x%x%x%x%x%x)")
29 end
30 end
31 return hgid, hgrepo;
32 end
34 return hg;