简体   繁体   English

与远程Mercurial和Git http存储库进行交互

[英]Interact with remote Mercurial and Git http repositories

Background: I'm writing a Java server application that needs to perform basic interactions with remote SCM systems served over http. 背景:我正在编写一个Java服务器应用程序,该应用程序需要与通过http服务的远程SCM系统执行基本交互。

Is it possible to interact with Mercurial and Git repositories using some sort of predefined API (or if there is a convention to how these repositories are laid out when served via http) from the server without having to clone? 是否可以从服务器使用某种预定义的API与Mercurial和Git存储库进行交互(或者是否存在通过http提供服务时如何布置这些存储库的约定),而无需进行克隆? The only sort of interactions needed are listing of files currently under version control and the ability to download particular revisions of a version controlled file. 唯一需要进行的交互是列出当前受版本控制的文件,以及下载受版本控制的文件的特定修订版的功能。

EDIT: For Mercurial, I used Ry4an's solution. 编辑:对于Mercurial,我使用Ry4an的解决方案。 For Git, I scrape the screens of repositories served using gitweb. 对于Git,我抓取了使用gitweb服务的存储库的屏幕。

Mercurial isn't designed to work on remote repositories except to clone, push, and pull. 除了克隆,推入和拉出之外,Mercurial并非设计用于远程存储库。 That said, there's a lot one can do depending how it's served. 就是说,根据服务方式,有很多人可以做。 If it's being served through hgweb, the built in web interface available as hg serve there are style=raw views of many details which can be easily handled programmatically. 如果通过hgweb提供hg serve ,则可作为hg serve使用的内置Web界面中有很多细节的style=raw视图,可以通过编程轻松地对其进行处理。 Some examples: 一些例子:

With those you can browse files, revision, tags, and branches. 使用这些文件,您可以浏览文件,修订版,标签和分支。

If, however, you want to write you're best off running Mercurial in Jython in your Java app and invoking the commands directly. 但是,如果要编写代码,最好在Java应用程序的Jython中运行Mercurial并直接调用命令。

Mercurial has two web APIs. Mercurial有两个Web API。 One you probably shouldn't use. 您可能不应该使用的一种。 It's designed for other instances of Mercurial to use to send and receive changesets. 它是为Mercurial的其他实例设计的,用于发送和接收变更集。

The other is easily accessible via an ordinary web browser. 另一个可以通过普通的Web浏览器轻松访问。 The URLs you see are designed to be clear and easy to parse or put together programatically. 您看到的URL旨在使之清晰易懂,或者易于以编程方式组合在一起。 As @Ry4an points out, the file browser also has the ability to give you a raw (aka verbatim, with no HTML tags) copy of any version of any file. 正如@ Ry4an指出的,文件浏览器还具有为您提供任何文件任何版本的原始副本(即逐字记录,没有HTML标记)的能力。

Though, you raise an interesting point. 不过,您提出了一个有趣的观点。 I think Mercurial could use an XML template in which it sends you the same information as the pages in a Mercurial specific XML format that's designed to be used by programs. 我认为Mercurial可以使用XML模板,在其中向您发送与Mercurial专用XML格式的页面相同的信息,这些XML格式旨在供程序使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM