Skip to content

Commit f0ab8b6

Browse files
AxosoftBrandonjdgarcia
authored andcommitted
git log
1 parent 6869844 commit f0ab8b6

File tree

6 files changed

+109
-2
lines changed

6 files changed

+109
-2
lines changed

gitrs_server/src/dispatch/git_command/bisect/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn dispatch(connection_state: state::Connection, bad: String, good: String)
4949
.and_then(|result| -> DispatchFuture {
5050
println!("{:?}", result);
5151
Box::new(future::ok(connection_state))
52-
})
52+
}),
5353
),
5454
None => Box::new(send_message(
5555
connection_state,

gitrs_server/src/dispatch/git_command/bisect/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use nom::digit1;
2-
use util::parse::{parse_u32, sha};
2+
use util::parse::{sha, parse_u32};
33

44
#[derive(Debug, Serialize)]
55
pub struct BisectStep {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
mod parse;
2+
3+
use self::parse::{parse_log, LogEntry};
4+
use futures::{future, Future};
5+
use state;
6+
use std::str;
7+
use tokio_process::CommandExt;
8+
use types::DispatchFuture;
9+
use util::git;
10+
use util::transport::send_message;
11+
12+
#[derive(Debug, Serialize)]
13+
#[serde(tag = "reason")]
14+
pub enum ErrorReason {
15+
RepoPathNotSet,
16+
}
17+
18+
#[derive(Debug, Serialize)]
19+
#[serde(tag = "type")]
20+
pub enum OutboundMessage {
21+
Success { log: Vec<LogEntry> },
22+
Error(ErrorReason),
23+
}
24+
25+
pub fn dispatch(connection_state: state::Connection) -> DispatchFuture {
26+
use self::ErrorReason::RepoPathNotSet;
27+
use error::protocol::{Error, ProcessError::{Encoding, Failed, Parsing}};
28+
29+
match connection_state.repo_path.clone() {
30+
Some(repo_path) => Box::new(
31+
git::new_command_with_repo_path(&repo_path)
32+
.arg("log")
33+
.output_async()
34+
.map_err(|_| Error::Process(Failed))
35+
.and_then(|output| match str::from_utf8(&output.stdout) {
36+
Ok(output) => future::ok(String::from(output)),
37+
Err(_) => future::err(Error::Process(Encoding)),
38+
})
39+
.and_then(|result| -> DispatchFuture {
40+
if result.len() == 0 {
41+
// TODO: more semantic error
42+
return Box::new(future::err(Error::Process(Parsing)));
43+
}
44+
45+
match parse_log(&format!("{}\n", result)) {
46+
Ok((_, log)) => Box::new(send_message(
47+
connection_state,
48+
OutboundMessage::Success { log },
49+
)),
50+
Err(_) => Box::new(future::err(Error::Process(Parsing))),
51+
}
52+
}),
53+
),
54+
None => Box::new(send_message(
55+
connection_state,
56+
OutboundMessage::Error(RepoPathNotSet),
57+
)),
58+
}
59+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use nom;
2+
use util::parse::sha;
3+
4+
#[derive(Debug, Serialize)]
5+
pub struct LogEntry {
6+
commit_sha: String,
7+
author: String,
8+
date: String,
9+
commit_message: String,
10+
}
11+
12+
/*
13+
* Each indent starts with 4 spaces
14+
* seperator line with no spaces
15+
*/
16+
named!(pub parse_log_entry<&str, LogEntry>,
17+
do_parse!(
18+
tag!("commit ") >>
19+
commit_sha: sha >>
20+
char!('\n') >>
21+
tag!("Author: ") >>
22+
author: take_until!("\n") >>
23+
char!('\n') >>
24+
tag!("Date: ") >>
25+
date: take_until!("\n") >>
26+
tag!("\n\n ") >>
27+
commit_message: take_until!("\n\n") >>
28+
(LogEntry {
29+
commit_sha: String::from(commit_sha),
30+
author: String::from(author),
31+
date: String::from(date),
32+
commit_message: String::from(commit_message),
33+
})
34+
)
35+
);
36+
37+
named!(pub parse_log<&str, Vec<LogEntry>>,
38+
do_parse!(
39+
entries: separated_list!(
40+
tag!("\n\n"),
41+
complete!(parse_log_entry)
42+
) >>
43+
(entries)
44+
)
45+
);

gitrs_server/src/dispatch/git_command/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod bisect;
2+
mod log;
23
mod open_repo;
34
mod status;
45

@@ -14,6 +15,7 @@ pub fn dispatch(
1415

1516
match message {
1617
Inbound::Bisect { bad, good } => bisect::dispatch(connection_state, bad, good),
18+
Inbound::Log => log::dispatch(connection_state),
1719
Inbound::OpenRepo { path } => open_repo::dispatch(connection_state, path),
1820
Inbound::Status => status::dispatch(connection_state),
1921
}

gitrs_server/src/message/git_command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod protocol {
22
#[derive(Debug, Deserialize)]
33
pub enum Inbound {
44
Bisect { bad: String, good: String },
5+
Log,
56
OpenRepo { path: String },
67
Status,
78
}

0 commit comments

Comments
 (0)