Node.js的Mercurial HG库用于本地存储库。

6

我正在寻找一个适用于Node.js的库,可以用来管理我在Mercurial HG中创建的本地代码库,并且可以从Web应用程序中使用。

有人实现过类似的功能吗?


1
如果在http://search.npmjs.org/或https://github.com/joyent/node/wiki/modules上找不到,那么它可能(公开地)不存在。 - user578895
2个回答

7
我从未听说过这样的库 - 它没有在我们的邮件列表上宣布。Mercurial的稳定API是命令行,因此建议直接启动hg并解析输出。它被设计为易于屏幕抓取,您还可以使用模板进一步自定义它。

1
如果您使用服务器命令,就可以避免hg启动时的开销,但这需要更多的努力。 - Laurens Holst
我考虑了一下,但这只是最终解决方案。感谢您的回答。 - mrzepinski
如果您发现这个答案有帮助(即使是负面的),请记得点赞并接受它。 - Martin Geisler

7
我已经为此创建了一个名为node-hg的npm模块。它是对Command Server的封装,通过stdin发出命令并解析stdout输出。
以下是其工作示例:
var path = require("path");

var hg = require("hg");

// Clone into "../example-node-hg"
var destPath = path.resolve(path.join(process.cwd(), "..", "my-node-hg"));

hg.clone("http://bitbucket.org/jgable/node-hg", destPath, function(err, output) {
    if(err) {
        throw err;
    }

    output.forEach(function(line) {
        console.log(line.body);
    });

    // Add some files to the repo with fs.writeFile, omitted for brevity

    hg.add(destPath, ["someFile1.txt", "someFile2.txt"], function(err, output) {
        if(err) {
            throw err;
        }

        output.forEach(function(line) {
            console.log(line.body);
        });

        var commitOpts = {
            "-m": "Doing the needful"
        };

        // Commit our new files
        hg.commit(destPath, commitOpts, function(err, output) {
            if(err) {
                throw err;
            }

            output.forEach(function(line) {
                console.log(line.body);
            });
        });
    });
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接