1

プロジェクトで python mercurial API を使用しています。

from mercurial import ui, hg, commands
from mercurial.node import hex

user_id = ui.ui()
hg_repo = hg.repository(user_id, '/path/to/repo')

hg_repo.ui.pushbuffer()
some_is_coming = commands.incoming(hg_repo.ui, hg_repo, source='default',
                                       bundle=None, force=False)
if some_is_coming:
    output = hg_repo.ui.popbuffer()

In [95]: output
Out[95]: 'comparing with ssh:host-name\nsearching for changes\nchangeset:   1:e74dcb2eb5e1\ntag:         tip\nuser:        that-is-me\ndate:        Fri Nov 06 12:26:53 2015 +0100\nsummary:     added input.txt\n\n'

短いノード情報の抽出はe74dcb2eb5e1簡単です。しかし、私が本当に必要としているのは、40 桁の 16 進数のリビジョン ID です。最初にリポジトリをプルせずにこの情報を取得する方法はありますか?

4

1 に答える 1

3

出力の一部として完全なノード ハッシュを提供するテンプレートを指定する必要があります。また、commands.incoming数字のエラー コードを返します。ゼロは成功を示します。つまり、次のようなものが必要です。

from mercurial import ui, hg, commands
from mercurial.node import hex

user_id = ui.ui()
hg_repo = hg.repository(user_id, '/path/to/repo')

hg_repo.ui.pushbuffer()
command_result = commands.incoming(hg_repo.ui, hg_repo, source='default',
    bundle=None, force=False, template="json")
if command_result == 0:
    output = hg_repo.ui.popbuffer()
    print output

さらに2つのこと:最初に、診断出力(「...と比較」)も取得します。これは、-q(またはui.setconfig("ui", "quiet", "yes"))を介して抑制できます。ただし、このオプションはデフォルトのテンプレートにも影響するため、独自のテンプレートを提供する必要がある場合があることに注意してください。次に、環境変数を設定してHGPLAIN、エイリアスとデフォルト.hgrcが無視されるようにすることをお勧めします (「参考文献」を参照hg help scripting)。

別の方法として、Mercurialコマンド サーバーを に実装されているものとして使用することもできますhglib( から入手できますpip install python-hglib)。

import hglib

client = hglib.open(".")
# Standard implementation of incoming, which returns a list of tuples.
# force=False and bundle=None are the defaults, so we don't need to
# provide them here.
print client.incoming(path="default")
# Or the raw command output with a custom template.
changeset = "[ {rev|json}, {node|json}, {author|json}, {desc|json}, {branch|json}, {bookmarks|json}, {tags|json}, {date|json} ]\n"
print client.rawcommand(["incoming", "-q", "-T" + changeset])
于 2015-11-06T16:34:50.113 に答える