Crate hglib [] [src]

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),
    }
}

Modules

cmdserver

High-level interface to the Mercurial command server.

connection

Raw command server API.

Enums

Chunk

A type representing a "chunk" of data received from the command server.