2 releases
Uses old Rust 2015
0.1.1 | Sep 23, 2015 |
---|---|
0.1.0 | Sep 21, 2015 |
#12 in #mercurial
16KB
241 lines
HgLib: Rust Client Library for Mercurial Command Server
This crate provides a client interface to the Mercurial distributed version control system (DVCS) in Rust, using Mercurial's command server. The command server is designed to allow tools to be built around Mercurial repositories, without being tied into Mercurial's internal API or licensing.
API documentation: http://kbullock.ringworld.org/rustdoc/hglib/
Installation
To use hglib, add the crate to your Cargo.toml:
[dependencies]
hglib = "0.1.1"
lib.rs
:
Client library for the Mercurial command server
This crate provides a client interface to the Mercurial distributed version control system (DVCS) in Rust, using Mercurial's command server. The command server is designed to allow tools to be built around Mercurial repositories, without being tied into Mercurial's internal API or licensing.
High-level API
The cmdserver
module provides a high-level
interface which manages spawning and communicating with a command
server instance:
use hglib::cmdserver::CommandServer;
let cmdserver = CommandServer::new().ok().expect("failed to start command server");
This high-level interface is largely unimplemented so far, but builds on the raw API that is already functional.
Raw API
The lower-level API in the connection
module allows you to run commands at the level of the command server
protocol. Assembling the command and reading the result
chunk-by-chunk is done manually.
use hglib::connection::Connection;
use hglib::Chunk;
let mut conn = Connection::new().ok().expect("failed to start command server");
let (capabilities, encoding) =
conn.read_hello().ok().expect("failed to read server hello");
let cmditer =
conn.raw_command(vec![b"log", b"-l", b"5"])
.ok().expect("failed to send raw command");
for chunk in cmditer {
match chunk {
Ok(Chunk::Output(s)) => { io::stdout().write(&s); },
Ok(Chunk::Error(s)) => { io::stdout().write(&s); },
Ok(Chunk::Result(r)) => println!("command exited with status: {}", r),
Ok(_) => {},
Err(e) => panic!("failed to read chunk: {}", e),
}
}
Dependencies
~115KB