开发者

Interact with remote Mercurial and Git http repositories

开发者 https://www.devze.com 2023-02-08 05:52 出处:网络
Background: I\'m writing a Java server application that needs to perform basic intera开发者_如何学编程ctions with remote SCM systems served over http.

Background: I'm writing a Java server application that needs to perform basic intera开发者_如何学编程ctions with remote SCM systems served over http.

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? 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. For Git, I scrape the screens of repositories served using gitweb.


Mercurial isn't designed to work on remote repositories except to clone, push, and pull. 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. Some examples:

  • https://www.mercurial-scm.org/repo/hg/file/tip?style=raw
  • https://www.mercurial-scm.org/repo/hg/file/tip/README?style=raw
  • https://www.mercurial-scm.org/repo/hg/rev/8f5c865b7b4a?style=raw
  • https://www.mercurial-scm.org/repo/hg/raw-rev/8f5c865b7b4a
  • https://www.mercurial-scm.org/repo/hg/tags?style=raw
  • https://www.mercurial-scm.org/repo/hg/branches?style=raw

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.


Mercurial has two web APIs. One you probably shouldn't use. It's designed for other instances of Mercurial to use to send and receive changesets.

The other is easily accessible via an ordinary web browser. The URLs you see are designed to be clear and easy to parse or put together programatically. 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消