列出 Mercurial 中的远程分支

发布于 2024-10-05 13:12:00 字数 230 浏览 3 评论 0原文

有没有办法像 Git 一样在 Mercurial 中列出远程分支?

git branch -r

我想列出远程计算机(例如 Bitbucket)上的分支,因此使用:

hg branches -R `hg showconfig paths.default` --color false

失败并中止:存储库不是本地的

Is there a way to list remote branches in Mercurial like there in Git?

git branch -r

I want to list the branches on a remote machine (e.g. Bitbucket), so using:

hg branches -R `hg showconfig paths.default` --color false

fails with abort: repository not local

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夕色琉璃 2024-10-12 13:12:00

Mercurial API 允许这样做:

from mercurial import ui, hg, node

peer = hg.peer(ui.ui(), {}, 'http://hg.python.org/cpython')
for name, rev in peer.branchmap().items():
    print(name, node.short(rev[0]))

上面的代码片段生成:

default aaa68dce117e
legacy-trunk b77918288f7d
3.2 4787b9b2f860
3.0 4cd9f5e89061
3.1 5a6fa1b8767f
2.3 364638d6434d
2.2 61b0263d6881
2.1 e849d484029f
2.0 5fd74354d73b
2.7 260f3ad7af4b
2.6 f130ce67387d
2.5 b48e1b48e670
2.4 ceec209b26d4

The mercurial API allows it:

from mercurial import ui, hg, node

peer = hg.peer(ui.ui(), {}, 'http://hg.python.org/cpython')
for name, rev in peer.branchmap().items():
    print(name, node.short(rev[0]))

The above snippet produces:

default aaa68dce117e
legacy-trunk b77918288f7d
3.2 4787b9b2f860
3.0 4cd9f5e89061
3.1 5a6fa1b8767f
2.3 364638d6434d
2.2 61b0263d6881
2.1 e849d484029f
2.0 5fd74354d73b
2.7 260f3ad7af4b
2.6 f130ce67387d
2.5 b48e1b48e670
2.4 ceec209b26d4
一念一轮回 2024-10-12 13:12:00

不,如果不将远程存储库克隆到本地,则无法列出远程存储库的分支。

如果可以通过 SSH 访问具有远程存储库的计算机,则可以直接使用 Mercurial:ssh server hg -R path/to/repobranch

如果存储库由 hgweb 提供服务,则可以使用原始样式从中获取分支列表以便于解析: https://www.mercurial-scm.org/repo/hg/branches?style=raw

BitBucket 有自己的 API,可以在其中获取分支,请参阅他们的帮助并对类似 https://api.bitbucket.org/1.0/repositories/mirror/mercurial/branches/

No, it is not possible to list branches of a remote repository without cloning it to local.

If there is SSH access to the machine having the remote repository, then Mercurial could be used directly: ssh server hg -R path/to/repo branches.

If the repository is served with hgweb, then a list of branches can be fetched from that, using the raw style for easy parsing: https://www.mercurial-scm.org/repo/hg/branches?style=raw

BitBucket has its own API, where it is possible to get the branches, see their help and make a query like to a URL like https://api.bitbucket.org/1.0/repositories/mirror/mercurial/branches/

肥爪爪 2024-10-12 13:12:00

要扩展 @gvalkov 的答案,您可以通过编写文件 rheads.py 使其成为真正的扩展:

from mercurial import hg, commands, cmdutil, node
cmdtable = {}
command = cmdutil.command(cmdtable)
@command('rheads', commands.remoteopts, 'hg rheads [SOURCE]')
def rheads(ui, repo, source='default', **opts):
    """print (possibly remote) heads

    Prints a series of lines consisting of hashes and branch names.
    Specify a local or remote repository, defaulting to the configured remote.
    """
    other = hg.peer(ui or repo, opts, ui.expandpath(source))
    for tag, heads in other.branchmap().iteritems():
        for h in heads:
            ui.write("%s %s\n" % (node.short(h), tag))

~/.hgrc 中配置时,

[extensions]
rheads = …/rheads.py

您可以像这样运行它:

hg rheads

我尝试使其成为可以在任何存储库外部调用的命令,只需指定 URL 作为参数,但无法使语法正常工作:

commands.norepo += " rheads"

To expand on @gvalkov’s answer, you can make this a real extension by writing a file rheads.py:

from mercurial import hg, commands, cmdutil, node
cmdtable = {}
command = cmdutil.command(cmdtable)
@command('rheads', commands.remoteopts, 'hg rheads [SOURCE]')
def rheads(ui, repo, source='default', **opts):
    """print (possibly remote) heads

    Prints a series of lines consisting of hashes and branch names.
    Specify a local or remote repository, defaulting to the configured remote.
    """
    other = hg.peer(ui or repo, opts, ui.expandpath(source))
    for tag, heads in other.branchmap().iteritems():
        for h in heads:
            ui.write("%s %s\n" % (node.short(h), tag))

When configured in ~/.hgrc with

[extensions]
rheads = …/rheads.py

you can run it like:

hg rheads

I tried to make it a command that can be invoked outside any repository, just specifying the URL as an argument, but could not get the syntax to work:

commands.norepo += " rheads"
守不住的情 2024-10-12 13:12:00

也许您正在寻找hg传入-B这对我来说效果很好。这会显示书签。

maybe you are looking for hg incoming -B This worked quite well for me. This shows the bookmarks.

路弥 2024-10-12 13:12:00

请注意,这不会显示仅远程分支,它只会显示本地存储库知道的分支。

作为谷歌搜索“hg 命令时出现的唯一相关问题行列表分支”,我想我应该把它留在这里。当您运行以下命令时 -

hg log | grep “分支”| grep -v“摘要”| sort --unique

它输出;

branch:      branch1
branch:      branch2
branch:      branch3
branch:      branch4
branch:      branch5

Please note, this will not display remote only branches, it will only show branches that your local repository is aware of.

As the only relevant question to appear when googling "hg command line list branches", I thought I'd leave this here. When you run the following -

hg log | grep "branch" | grep -v "summary" | sort --unique

it outputs;

branch:      branch1
branch:      branch2
branch:      branch3
branch:      branch4
branch:      branch5
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文