mercurial: any command or python api to get repository name

时光毁灭记忆、已成空白 提交于 2020-01-04 03:50:00

问题


Is there any Mercurial command or Python API that could yield the repo name? This will help developing cross-repo scripts.

The only related solution that I found is to parse the .hg/hgrc [paths] section 'default' config option.

[paths]
default = ssh://server//path/tools

There must be a more elegant solution, I think.


回答1:


There is no real concept of a "repository name" in Mercurial (a repository doesn't "know" or care about its own name). I think you mean "last past component of the default pull path"?

If so, then parsing the output of hg path default would be the most direct way to get that information.

However, you should note that the default path can (and often is) changed: think of cloning a local clone time for testing:

$ hg clone http://server/lib-foo
$ hg clone lib-foo lib-foo-test
$ hg clone lib-foo-test lib-foo-more-testing

The lib-foo-more-testing clone has a default push path back to lib-foo-test.

This means that parsing hg paths default wont be much more reliable than using basename $(hg root) — both can be completely different from the (base)name of the repository that was originally cloned.

If what you really want is to get an "identity" for a repository, then you should instead use

$ hg log -r 0 --template "{node}"

The first changeset hash in a repository will normally uniquely identify the repository and it will be stable even when clones change names. (If a repository has two or more roots, then the zeroth changeset can in principle differ between clones. People will have to actively try to make it differ, though.)




回答2:


If you want to get last segment of path for remote default alias, processing output of hg path default will be better choice

If you want to get local directory name of you mercurial repository, I haven't good solution, except checking code of Notify extension (in which, after some tricks, you can get project-name)



来源:https://stackoverflow.com/questions/17497455/mercurial-any-command-or-python-api-to-get-repository-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!