Comparison

util/mercurial.lua @ 6585:ec94dc502113

util.mercurial: Utility functions for Mercurial repositories
author Kim Alvefur <zash@zash.se>
date Wed, 21 Jan 2015 02:55:18 +0100
child 10533:a6cc5b844d7b
comparison
equal deleted inserted replaced
6584:c3a56f8847ac 6585:ec94dc502113
1
2 local lfs = require"lfs";
3
4 local hg = { };
5
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
33
34 return hg;