3

I'm writing a mercurial extension and I need to store a small amount of metadata. This is a dumb example, but enough to get something like this to work:

$ hg myextension --set a=2
$ hg myextension --get a
2

This data does not need to be copied if the repo is cloned, although if that's easy it would be cool to do that.

What is the proper way to do this in a mercurial extension? Is there a folder under .hg that I can just create arbitrary files in or something like that?

4

1 回答 1

4

对此没有内置机制——每个扩展都决定如何最好地存储数据。扩展通常将它们的数据存储在以它们命名的文件或目录中,因此您可以使用

.hg/myextension/

作为你的根。您可以使用repo.opener打开该目录中的文件:

fp = repo.opener('myextension/state.json')
data = json.load(fp)
fp.close()
于 2014-01-30T07:21:11.113 回答