从远程 Mercurial 存储库获取单个文件

发布于 2024-10-18 13:58:21 字数 594 浏览 4 评论 0原文

有没有一种方法可以在 Java 中以编程方式从远程 Mercurial 存储库下载单个文件?我问过一个关于git的非常相似的问题;现在我希望我也能用 Mercurial 做类似的事情。

  1. 我更喜欢使用尽可能少的带宽的解决方案,最好只下载单个文件。我不需要浏览存储库,我已经有了文件的路径。
  2. 我不关心文件的历史记录,我只想要它的最新版本。
  3. 当然,仅将文件打印到输出的解决方案也很棒 - 它实际上不必将文件保存到磁盘,我自己可以做到这一点。
  4. 我更喜欢不依赖于其他应用程序的解决方案(例如,在计算机上安装 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.

  1. 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.
  2. I am not concerned with the history of the file, I only want its latest version.
  3. 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.
  4. 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 技术交流群。

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

发布评论

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

评论(2

伤痕我心 2024-10-25 13:58:21

mercurial 线路协议 没有用于从远程读取单个文件的命令存储库。这就是为什么 hg 命令行客户端也无法执行此操作。这个想法是你应该总是为这些东西创建一个本地克隆。

然而,mercurial 的各种 Web 界面通常都有一种获取文件内容的方法。例如,对于 bitbucket 存储库,URL 如下所示:

http://bitbucket.org/<user>/<project>/raw/<revision>/<filename>

对于 hgserve Web 界面,URL 如下所示:

http://<host>:<port>/raw-file/<revision>/<filename>

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:

http://bitbucket.org/<user>/<project>/raw/<revision>/<filename>

For the hg serve web interface, the URL looks like this:

http://<host>:<port>/raw-file/<revision>/<filename>
猫弦 2024-10-25 13:58:21

Bitbucket REST API 是您需要的工具。

https://api.bitbucket/1.0/repositories/{USER}/{REPO-NAME}/raw/tip/{PATH/TO/FILE}

示例来自 文档

您可以获得原始文件,而不是获取 JSON 格式的文件
文件:

$ 卷曲
https://api.bitbucket.org /1.0/repositories/jespern/django-piston/raw/tip/piston/utils.py
导入时间 from django.http import HttpResponseNotAllowed,
HttpResponseForbidden、HttpResponse、HttpResponseBadRequest 来自
django.core....

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:

Instead of getting the file formatted as JSON, you can get the raw
file:

$ curl
https://api.bitbucket.org/1.0/repositories/jespern/django-piston/raw/tip/piston/utils.py
import time from django.http import HttpResponseNotAllowed,
HttpResponseForbidden, HttpResponse, HttpResponseBadRequest from
django.core....

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