从远程 Mercurial 存储库获取单个文件
有没有一种方法可以在 Java 中以编程方式从远程 Mercurial 存储库下载单个文件?我问过一个关于git的非常相似的问题;现在我希望我也能用 Mercurial 做类似的事情。
- 我更喜欢使用尽可能少的带宽的解决方案,最好只下载单个文件。我不需要浏览存储库,我已经有了文件的路径。
- 我不关心文件的历史记录,我只想要它的最新版本。
- 当然,仅将文件打印到输出的解决方案也很棒 - 它实际上不必将文件保存到磁盘,我自己可以做到这一点。
- 我更喜欢不依赖于其他应用程序的解决方案(例如,在计算机上安装 Mercurial 客户端)。包含一个善变的客户端实现本身的 Java 库将是最佳的。不过,如果没有其他方法,我会很乐意调用
hg
。
根据我对 Mercurial 工作原理的了解(仅允许针对本地存储库工作),这可能会出现问题;但由于我能够使用类似的 Git SCM 来做到这一点,我希望 Mercurial 也有一个解决方案。
Is there a way to programmatically download a single file from a remote Mercurial repository, in Java? I have asked a very similar question regarding git; now I'm hoping I can do something similar with mercurial as well.
- I prefer a solution which uses as little bandwidth as possible, preferably only downloading that single file. I do not need to browse the repository, I already have the file's path.
- I am not concerned with the history of the file, I only want its latest version.
- A solution that only prints the file to the output is great as well, of course - it doesn't really have to save the file to disk, I can do that myself.
- I prefer a solution which does not depend on other applications (e.g. an installation of a mercurial client on the machine). A Java library which contains a mercurial client implementation itself would be optimal. However, I will happily invoke
hg
if there's no other way.
From what I understand about how Mercurial works - allowing working only against local repositories - this could prove to be problematic; but as I was able to do this with the similar Git SCM I'm hoping there's a solution for Mercurial as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mercurial 线路协议 没有用于从远程读取单个文件的命令存储库。这就是为什么
hg
命令行客户端也无法执行此操作。这个想法是你应该总是为这些东西创建一个本地克隆。然而,mercurial 的各种 Web 界面通常都有一种获取文件内容的方法。例如,对于 bitbucket 存储库,URL 如下所示:
对于
hgserve
Web 界面,URL 如下所示:The mercurial wire protocol doesn't have a command for reading a single file from a remote repository. That's why the
hg
command line client can't do this either. The idea is that you should always make a local clone for such things.However, the various web interfaces for mercurial typically have a way to get at file content. For example, for bitbucket repositories the URL looks like this:
For the
hg serve
web interface, the URL looks like this:Bitbucket REST API 是您需要的工具。
https://api.bitbucket/1.0/repositories/{USER}/{REPO-NAME}/raw/tip/{PATH/TO/FILE}
示例来自 文档:
The Bitbucket REST API is the tool you want for this.
https://api.bitbucket/1.0/repositories/{USER}/{REPO-NAME}/raw/tip/{PATH/TO/FILE}
Example from their docs: